/* FactureAlger - Modern UI Design System */

/* ===== Design Tokens ===== */
:root {
    /* Colors - 60-30-10 Rule */
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --secondary: #64748b;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --info: #3b82f6;
    --info-light: #dbeafe;
    
    /* Surfaces */
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    
    /* Text */
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;
    
    /* Borders */
    --border: #e2e8f0;
    --border-focus: var(--primary);
    
    /* Shadows - Elevation System */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    /* Spacing Scale (4px base) */
    --space-1: 0.25rem;   /* 4px */
    --space-2: 0.5rem;    /* 8px */
    --space-3: 0.75rem;   /* 12px */
    --space-4: 1rem;      /* 16px */
    --space-5: 1.25rem;   /* 20px */
    --space-6: 1.5rem;    /* 24px */
    --space-8: 2rem;      /* 32px */
    --space-10: 2.5rem;   /* 40px */
    --space-12: 3rem;     /* 48px */
    
    /* Typography Scale */
    --text-xs: 0.75rem;    /* 12px */
    --text-sm: 0.875rem;   /* 14px */
    --text-base: 1rem;     /* 16px */
    --text-lg: 1.125rem;   /* 18px */
    --text-xl: 1.25rem;    /* 20px */
    --text-2xl: 1.5rem;    /* 24px */
    --text-3xl: 1.875rem;  /* 30px */
    
    /* Font Weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;
    
    /* Border Radius */
    --radius-sm: 0.375rem;   /* 6px */
    --radius: 0.5rem;        /* 8px */
    --radius-md: 0.75rem;    /* 12px */
    --radius-lg: 1rem;       /* 16px */
    --radius-xl: 1.5rem;     /* 24px */
    --radius-full: 9999px;
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed: 64px;
    --header-height: 64px;
}

/* ===== Reset ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ===== Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: var(--transition-slow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

/* Sidebar Header */
.sidebar-header {
    height: var(--header-height);
    padding: 0 var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-brand {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    text-decoration: none;
    color: var(--text);
    font-weight: var(--font-bold);
    font-size: var(--text-lg);
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-brand:hover {
    color: var(--primary);
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: var(--text-inverse);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    flex-shrink: 0;
}

.brand-text {
    transition: opacity var(--transition-fast);
}

.sidebar.collapsed .brand-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* Toggle Button */
.sidebar-toggle {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.sidebar.collapsed .sidebar-toggle {
    position: absolute;
    top: var(--space-4);
    right: calc(var(--sidebar-collapsed) / 2 - 12px);
}

.sidebar.collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-3) 0;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
}

.nav-section {
    margin-bottom: var(--space-2);
}

.nav-section-title {
    padding: var(--space-3) var(--space-4) var(--space-2);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .nav-section-title {
    text-align: center;
    font-size: 0;
    padding: var(--space-3);
}

.sidebar.collapsed .nav-section-title::after {
    content: '•••';
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Nav Items */
.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    margin: var(--space-1) var(--space-2);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    transition: var(--transition-fast);
    border-radius: var(--radius);
    white-space: nowrap;
    position: relative;
}

.nav-item:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: var(--font-semibold);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-icon svg {
    width: 20px !important;
    height: 20px !important;
    stroke-width: 2;
}

.nav-text {
    transition: opacity var(--transition-fast);
}

.sidebar.collapsed .nav-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* Tooltip for collapsed state */
.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: var(--space-2);
    margin: var(--space-1) var(--space-2);
}

.sidebar.collapsed .nav-item::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--text);
    color: var(--text-inverse);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    z-index: 1000;
    box-shadow: var(--shadow-md);
}

.sidebar.collapsed .nav-item:hover::after {
    opacity: 1;
}

/* Sidebar Footer */
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: var(--space-3) 0;
    flex-shrink: 0;
}

.company-switcher {
    padding: 0 var(--space-2) var(--space-2);
}

.company-switcher select {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--text-sm);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    transition: var(--transition-fast);
}

.company-switcher select:hover {
    border-color: var(--text-muted);
}

.company-switcher select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.sidebar.collapsed .company-switcher {
    display: none;
}

/* User Menu */
.user-menu {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    margin: 0 var(--space-2);
    border-radius: var(--radius);
}

.user-menu:hover {
    background: var(--surface-hover);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-semibold);
    font-size: var(--text-sm);
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    overflow: hidden;
}

.user-name {
    font-weight: var(--font-semibold);
    font-size: var(--text-sm);
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.sidebar.collapsed .user-info {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    margin: var(--space-1) var(--space-2);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    transition: var(--transition-fast);
    border-radius: var(--radius);
    white-space: nowrap;
}

.logout-btn:hover {
    background: var(--danger-light);
    color: var(--danger);
}

.sidebar.collapsed .logout-btn {
    justify-content: center;
    padding: var(--space-2);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: var(--transition-slow);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed ~ .main-content {
    margin-left: var(--sidebar-collapsed);
}

/* Top Bar (Mobile) */
.top-bar {
    display: none;
    height: var(--header-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 var(--space-4);
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 90;
}

.menu-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-2);
    color: var(--text);
    border-radius: var(--radius);
    transition: var(--transition-fast);
}

.menu-button:hover {
    background: var(--surface-hover);
}

.top-bar-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
}

/* ===== Container ===== */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-6);
    flex: 1;
    width: 100%;
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-semibold);
    line-height: 1.25;
    color: var(--text);
}

h1 { font-size: var(--text-3xl); margin-bottom: var(--space-4); }
h2 { font-size: var(--text-2xl); margin-bottom: var(--space-3); }
h3 { font-size: var(--text-xl); margin-bottom: var(--space-3); }
h4 { font-size: var(--text-lg); margin-bottom: var(--space-2); }

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
    transition: var(--transition-fast);
}

.card:hover {
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-5);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    text-decoration: none;
    transition: var(--transition-fast);
    min-height: 40px;
    line-height: 1;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: var(--text-inverse);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--text-inverse);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    box-shadow: none;
}

.btn-outline:hover {
    background: var(--surface-hover);
    border-color: var(--text-muted);
}

.btn-danger {
    background: var(--danger);
    color: var(--text-inverse);
}

.btn-danger:hover {
    background: #dc2626;
    box-shadow: var(--shadow);
}

.btn-success {
    background: var(--success);
    color: var(--text-inverse);
}

.btn-success:hover {
    background: #059669;
    box-shadow: var(--shadow);
}

.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
    min-height: 32px;
}

.btn-block {
    width: 100%;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: var(--space-4);
}

.form-group label {
    display: block;
    margin-bottom: var(--space-2);
    font-weight: var(--font-medium);
    font-size: var(--text-sm);
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--text-base);
    transition: var(--transition-fast);
    background: var(--surface);
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

/* ===== Tables ===== */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}

th, td {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--bg);
    font-weight: var(--font-semibold);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background: var(--surface-hover);
}

/* ===== Status Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
}

.badge-brouillon {
    background: var(--info-light);
    color: #1e40af;
}

.badge-envoye {
    background: var(--warning-light);
    color: #92400e;
}

.badge-rejete {
    background: var(--danger-light);
    color: #991b1b;
}

.badge-paye {
    background: var(--success-light);
    color: #166534;
}

/* ===== Alerts ===== */
.alert {
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
    border: 1px solid;
}

.alert-error {
    background: var(--danger-light);
    color: #991b1b;
    border-color: #fecaca;
}

.alert-success {
    background: var(--success-light);
    color: #166534;
    border-color: #bbf7d0;
}

.alert-warning {
    background: var(--warning-light);
    color: #92400e;
    border-color: #fde68a;
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-5);
    margin-bottom: var(--space-8);
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: var(--transition-fast);
}

.stat-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.stat-value {
    font-size: var(--text-3xl);
    font-weight: var(--font-bold);
    color: var(--primary);
    line-height: 1;
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: var(--space-2);
    font-weight: var(--font-medium);
}

/* ===== Dashboard ===== */
.dashboard-header {
    margin-bottom: var(--space-8);
}

.dashboard-header h1 {
    font-size: var(--text-3xl);
    margin-bottom: var(--space-2);
    font-weight: var(--font-bold);
}

.dashboard-header p {
    color: var(--text-secondary);
    font-size: var(--text-base);
}

.quick-actions {
    margin-top: var(--space-8);
}

.quick-actions h2 {
    font-size: var(--text-lg);
    margin-bottom: var(--space-4);
    font-weight: var(--font-semibold);
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}

/* ===== Login Page ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: var(--space-6);
}

.login-box {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: var(--space-10);
    box-shadow: var(--shadow-xl);
}

.login-box h1 {
    text-align: center;
    color: var(--primary);
    margin-bottom: var(--space-2);
    font-size: var(--text-2xl);
}

.subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: var(--space-6);
}

/* ===== Invoice Specific ===== */
.invoice-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-4);
    margin-top: var(--space-5);
    padding-top: var(--space-5);
    border-top: 2px solid var(--text);
}

.invoice-summary div {
    text-align: right;
}

.invoice-summary .label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.invoice-summary .value {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
}

.invoice-summary .total {
    font-size: var(--text-2xl);
    color: var(--primary);
}

/* ===== TVA Warning ===== */
.tva-warning {
    background: var(--warning-light);
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: var(--space-5);
    margin-bottom: var(--space-5);
}

.tva-warning strong {
    color: #92400e;
}

/* ===== Invoice Lines ===== */
.invoice-line {
    margin-bottom: var(--space-3);
}

.invoice-line .card {
    padding: var(--space-3);
    margin-bottom: 0;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .sidebar.collapsed ~ .main-content {
        margin-left: 0;
    }

    .top-bar {
        display: flex;
    }

    .container {
        padding: var(--space-4);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .invoice-summary {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
