/**
 * components.css
 * مكونات واجهة المستخدم لنظام كوست المحاسبي
 */

/* ===== User Menu ===== */
.user-menu {
    position: fixed;
    top: 70px;
    left: 20px;
    width: 280px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-lg);
    padding: var(--space-4);
    display: none;
    z-index: var(--z-menu);
    backdrop-filter: blur(12px);
}

.user-menu.active {
    display: block;
    animation: slideIn 0.2s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-menu-header {
    text-align: center;
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-light);
    margin-bottom: var(--space-4);
}

.user-menu-header img {
    width: 130px;
    height: 130px;
    border-radius: var(--radius-full);
    border: 3px solid var(--accent-primary);
    margin: 0 auto var(--space-3);
    object-fit: cover;
}

.user-menu-header h4 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
}

.user-menu-nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.user-menu-nav a {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.user-menu-nav a:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.lang-switcher-container {
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-light);
}

.lang-switcher {
    width: 100%;
    padding: var(--space-3);
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--font-size-sm);
    cursor: pointer;
}

.lang-switcher:focus {
    border-color: var(--accent-primary);
    outline: none;
}

/* ===== Floating Assistant Button ===== */
#floatingAssistantBtn {
    position: fixed;
    top: 100px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary-700) 0%, var(--primary-800) 100%);
    border: 2px solid var(--accent-primary);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: var(--font-size-2xl);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: var(--z-floating-btn);
    box-shadow: var(--shadow-md), var(--shadow-glow);
    transition: all var(--transition-base);
    user-select: none;
}

#floatingAssistantBtn:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg), 0 0 30px rgba(0, 229, 160, 0.4);
}

#floatingAssistantBtn.active {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    color: var(--text-dark);
}

#floatingAssistantBtn.dragging {
    cursor: grabbing;
    transform: scale(1.1);
}

.menu-icon {
    font-size: 24px;
    line-height: 1;
}

/* ===== Assistant Tools Menu ===== */
#assistantToolsMenu {
    position: fixed;
    top: 170px;
    right: 30px;
    width: 220px;
    background: var(--bg-card);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-4);
    display: none;
    z-index: var(--z-menu);
    backdrop-filter: blur(12px);
}

#assistantToolsMenu.active {
    display: block;
    animation: menuAppear 0.25s ease;
}

@keyframes menuAppear {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

#assistantToolsMenu h4 {
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--accent-primary);
    text-align: center;
    padding-bottom: var(--space-3);
    margin-bottom: var(--space-3);
    border-bottom: 2px solid var(--accent-primary);
}

#assistantToolsMenu ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

#assistantToolsMenu button {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-glass);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    text-align: right;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    transition: all var(--transition-fast);
}

#assistantToolsMenu button:hover {
    background: var(--primary-800);
    border-color: var(--accent-primary);
    transform: translateX(-4px);
}

/* ===== Widget System ===== */
.assistant-widget {
    position: fixed;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    min-width: 320px;
    min-height: 200px;
    overflow: hidden;
    z-index: var(--z-widget);
}

.assistant-widget.active {
    display: flex;
    flex-direction: column;
    z-index: var(--z-widget-active);
    animation: widgetAppear 0.3s ease;
}

@keyframes widgetAppear {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.assistant-widget.focused {
    z-index: calc(var(--z-widget-active) + 10);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: linear-gradient(135deg, var(--primary-800) 0%, var(--primary-900) 100%);
    cursor: move;
    user-select: none;
}

.widget-header h5 {
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.widget-controls {
    display: flex;
    gap: var(--space-2);
}

.widget-controls button {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    background: var(--bg-glass);
    color: var(--text-primary);
    font-size: var(--font-size-md);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all var(--transition-fast);
}

.widget-minimize-btn:hover {
    background: var(--warning);
    color: var(--text-dark);
}

.widget-maximize-btn:hover {
    background: var(--success);
    color: var(--text-dark);
}

.widget-close-btn:hover {
    background: var(--error);
    color: var(--text-primary);
}

.widget-content {
    flex: 1;
    padding: var(--space-4);
    overflow: auto;
    background: var(--bg-surface);
}

.widget-placeholder {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    min-height: 150px;
    color: var(--text-muted);
    font-size: var(--font-size-lg);
}

/* ===== Resize Handles ===== */
.resize-handle {
    position: absolute;
    background: transparent;
    z-index: 10;
}

.resize-handle:hover {
    background: var(--accent-primary);
    opacity: 0.5;
}

.resize-handle.top,
.resize-handle.bottom {
    height: 6px;
    left: 10px;
    right: 10px;
}

.resize-handle.top {
    top: 0;
    cursor: n-resize;
}

.resize-handle.bottom {
    bottom: 0;
    cursor: s-resize;
}

.resize-handle.left,
.resize-handle.right {
    width: 6px;
    top: 10px;
    bottom: 10px;
}

.resize-handle.left {
    left: 0;
    cursor: w-resize;
}

.resize-handle.right {
    right: 0;
    cursor: e-resize;
}

.resize-handle.top-left,
.resize-handle.top-right,
.resize-handle.bottom-left,
.resize-handle.bottom-right {
    width: 12px;
    height: 12px;
}

.resize-handle.top-left {
    top: 0;
    left: 0;
    cursor: nw-resize;
}

.resize-handle.top-right {
    top: 0;
    right: 0;
    cursor: ne-resize;
}

.resize-handle.bottom-left {
    bottom: 0;
    left: 0;
    cursor: sw-resize;
}

.resize-handle.bottom-right {
    bottom: 0;
    right: 0;
    cursor: se-resize;
}

/* ===== Widget Manager ===== */
.widget-manager {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 240px;
    background: var(--bg-card);
    border-top-right-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    border-left: none;
    border-bottom: none;
    box-shadow: var(--shadow-md);
    z-index: var(--z-menu);
    transform: translateY(calc(100% - 44px));
    transition: transform var(--transition-base);
}

.widget-manager:hover,
.widget-manager.expanded {
    transform: translateY(0);
}

.widget-manager-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: linear-gradient(135deg, var(--primary-800) 0%, var(--primary-900) 100%);
    border-top-right-radius: var(--radius-lg);
}

.widget-manager-header h4 {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.widget-manager-controls {
    display: flex;
    gap: var(--space-2);
}

.widget-manager-controls button {
    background: none;
    color: var(--text-secondary);
    font-size: var(--font-size-md);
    transition: color var(--transition-fast);
}

.widget-manager-controls button:hover {
    color: var(--accent-primary);
}

#open-widgets-list {
    list-style: none;
    padding: var(--space-3);
    max-height: 200px;
    overflow-y: auto;
}

#open-widgets-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

#open-widgets-list li:hover {
    background: var(--primary-800);
    color: var(--text-primary);
}

#open-widgets-list li:last-child {
    margin-bottom: 0;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    #floatingAssistantBtn {
        width: 50px;
        height: 50px;
        right: 20px;
        top: 80px;
    }

    #assistantToolsMenu {
        right: 20px;
        width: 200px;
    }

    .widget-manager {
        width: 100%;
        border-radius: 0;
    }

    .user-menu {
        left: 10px;
        right: 10px;
        width: auto;
    }
}

/* ===== Widget Status Bar ===== */
.widget-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) var(--space-4);
    background: linear-gradient(135deg, var(--primary-900) 0%, var(--bg-dark) 100%);
    border-top: 1px solid var(--border-light);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    min-height: 28px;
}

.widget-status-bar .status-text {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.widget-status-bar .status-text::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: var(--radius-full);
    animation: pulse 2s infinite;
}

.widget-status-bar .status-info {
    color: var(--text-secondary);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== Widget Drag State ===== */
.assistant-widget.dragging {
    opacity: 0.9;
    cursor: grabbing !important;
    box-shadow: var(--shadow-lg), 0 0 40px rgba(0, 229, 160, 0.3);
}

.assistant-widget.dragging .widget-header {
    cursor: grabbing;
}

/* ===== Widget Resize State ===== */
.assistant-widget.resizing {
    user-select: none;
    opacity: 0.95;
}

.assistant-widget.resizing::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 229, 160, 0.05);
    pointer-events: none;
}

/* ===== Widget Minimized State in List ===== */
#open-widgets-list li.minimized {
    opacity: 0.6;
    border-right: 3px solid var(--warning);
}

#open-widgets-list li.minimized:hover {
    opacity: 1;
}

.widget-list-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.widget-list-status {
    font-size: var(--font-size-xs);
}

/* ===== Enhanced Animations ===== */
@keyframes widgetMinimize {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(0.5) translateY(100px);
    }
}

@keyframes widgetRestore {
    from {
        opacity: 0;
        transform: scale(0.5) translateY(100px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ===== Snap Indicator ===== */
.assistant-widget.snapping {
    transition: left 0.15s ease, top 0.15s ease;
}

/* ===== Keyboard Focus Indicator ===== */
.assistant-widget.focused .widget-header {
    background: linear-gradient(135deg, var(--primary-700) 0%, var(--primary-800) 100%);
}

/* ===== Touch-friendly Resize Handles ===== */
@media (pointer: coarse) {
    .resize-handle.top,
    .resize-handle.bottom {
        height: 12px;
    }
    
    .resize-handle.left,
    .resize-handle.right {
        width: 12px;
    }
    
    .resize-handle.top-left,
    .resize-handle.top-right,
    .resize-handle.bottom-left,
    .resize-handle.bottom-right {
        width: 20px;
        height: 20px;
    }
}

/* ===== Widget Maximized State ===== */
.assistant-widget.maximized {
    border-radius: 0;
    border: none;
}

.assistant-widget.maximized .resize-handle {
    display: none;
}

.assistant-widget.maximized .widget-status-bar {
    border-radius: 0;
}