/* Phil Morex — Solutions Numéria Inc.
   Interface professionnelle, sobre, lisible. */

:root {
    --color-primary: #0d2840;
    --color-primary-light: #1a4068;
    --color-accent: #0ea5e9;
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-info: #6366f1;
    --color-bg: #f7f8fa;
    --color-surface: #ffffff;
    --color-border: #e5e7eb;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --radius: 8px;
    --radius-sm: 4px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: var(--color-accent);
    text-decoration: none;
}
a:hover { text-decoration: underline; }

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

.sidebar {
    width: 240px;
    background: var(--color-primary);
    color: #fff;
    flex-shrink: 0;
    padding: 24px 0;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 0 24px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.sidebar-brand h1 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.sidebar-brand .tagline {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.sidebar-nav {
    list-style: none;
    padding: 16px 0;
    flex: 1;
}
.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}
.sidebar-nav li a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    text-decoration: none;
}
.sidebar-nav li a.active {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-left-color: var(--color-accent);
}
.sidebar-nav .nav-icon {
    width: 18px;
    height: 18px;
    opacity: 0.8;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
}
.sidebar-footer .user-name {
    color: #fff;
    font-weight: 500;
    margin-bottom: 4px;
}
.sidebar-footer a {
    color: rgba(255, 255, 255, 0.7);
    font-size: 11px;
}
.sidebar-footer a:hover { color: #fff; }

.main {
    flex: 1;
    padding: 32px 40px;
    max-width: 100%;
    overflow-x: auto;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 16px;
}
.topbar h1 {
    font-size: 22px;
    font-weight: 600;
    color: var(--color-primary);
}
.topbar-actions { display: flex; gap: 8px; }

/* ─── Cards ─── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 16px;
}
.card-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}
.card-header h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-primary);
}
.card-header .subtitle {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* ─── Stat cards ─── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}
.stat-card .stat-label {
    font-size: 12px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}
.stat-card .stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1.2;
}
.stat-card .stat-meta {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 6px;
}

/* ─── Tables ─── */
.table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow-x: auto;
    overflow-y: hidden;
    box-shadow: var(--shadow-sm);
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
th {
    background: #fafbfc;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: none; }
td.numeric { text-align: right; font-variant-numeric: tabular-nums; }
th.numeric { text-align: right; }

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.2;
}
.btn:hover {
    border-color: var(--color-text-muted);
    text-decoration: none;
}
.btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--color-primary-light);
    border-color: var(--color-primary-light);
    color: #fff;
}
.btn-accent {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #fff;
}
.btn-accent:hover {
    background: #0284c7;
    border-color: #0284c7;
    color: #fff;
}
.btn-danger {
    background: var(--color-surface);
    border-color: var(--color-danger);
    color: var(--color-danger);
}
.btn-danger:hover { background: var(--color-danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ─── Forms ─── */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--color-surface);
    color: var(--color-text);
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}
.form-help {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 4px;
}
.form-error {
    color: var(--color-danger);
    font-size: 12px;
    margin-top: 4px;
}

/* ─── Badges ─── */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-primary { background: #dbeafe; color: #1e40af; }
.badge-info { background: #e0e7ff; color: #3730a3; }
.badge-secondary { background: #f3f4f6; color: #374151; }

/* ─── Flash messages ─── */
.flash-list { margin-bottom: 20px; }
.flash {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: 13px;
    border-left: 4px solid;
}
.flash-success { background: #ecfdf5; border-color: var(--color-success); color: #065f46; }
.flash-warning { background: #fffbeb; border-color: var(--color-warning); color: #92400e; }
.flash-danger { background: #fef2f2; border-color: var(--color-danger); color: #991b1b; }
.flash-info { background: #eff6ff; border-color: var(--color-info); color: #1e40af; }

/* ─── Login page ─── */
.login-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0d2840 0%, #1a4068 100%);
    padding: 24px;
}
.login-card {
    background: var(--color-surface);
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}
.login-card h1 {
    color: var(--color-primary);
    font-size: 22px;
    margin-bottom: 8px;
    text-align: center;
}
.login-card .subtitle {
    color: var(--color-text-muted);
    text-align: center;
    margin-bottom: 28px;
    font-size: 13px;
}

/* ─── Timeline ─── */
.timeline {
    list-style: none;
    padding-left: 0;
}
.timeline li {
    position: relative;
    padding-left: 24px;
    padding-bottom: 16px;
    border-left: 2px solid var(--color-border);
    margin-left: 8px;
}
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
    content: "";
    position: absolute;
    left: -7px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-accent);
    border: 2px solid var(--color-surface);
    box-shadow: 0 0 0 2px var(--color-accent);
}
.timeline-time {
    font-size: 11px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.timeline-content {
    font-size: 13px;
    margin-top: 2px;
}
.timeline-meta {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* ─── Detail layout ─── */
.detail-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}
@media (max-width: 900px) {
    .detail-grid { grid-template-columns: 1fr; }
    .sidebar { width: 200px; }
    .main { padding: 20px; }
}

/* ─── Mobile (<= 768px) ─── */
@media (max-width: 768px) {
    /* Mise en page : sidebar en haut, contenu en dessous */
    .app-shell {
        flex-direction: column;
        min-height: 100vh;
    }
    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        padding: 12px 16px;
        gap: 8px;
    }
    .sidebar-brand {
        padding: 0;
        border-bottom: none;
        flex: 1;
    }
    .sidebar-brand h1 { font-size: 15px; }
    .sidebar-brand .tagline { font-size: 10px; }

    /* Menu hamburger : tout en dropdown via détails natifs */
    .sidebar-nav {
        order: 3;
        flex-basis: 100%;
        padding: 0;
        margin-top: 8px;
        display: none;
        background: rgba(0, 0, 0, 0.2);
        border-radius: 6px;
    }
    .sidebar-nav.is-open { display: block; }
    .sidebar-nav li a {
        padding: 14px 16px;
        font-size: 15px;
        border-left: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    }
    .sidebar-nav li:last-child a { border-bottom: none; }

    .sidebar-footer {
        order: 4;
        flex-basis: 100%;
        padding: 12px 0 0 0;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        margin-top: 8px;
        text-align: center;
    }

    /* Bouton hamburger (utilise un input checkbox caché ou un détail) */
    .sidebar::before {
        content: "☰ Menu";
        order: 2;
        padding: 8px 14px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 4px;
        cursor: pointer;
        font-size: 14px;
        font-weight: 500;
        color: white;
    }

    .main {
        padding: 16px 12px;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        margin-bottom: 20px;
    }
    .topbar h1 { font-size: 20px; }
    .topbar-actions {
        flex-wrap: wrap;
    }
    .topbar-actions .btn {
        flex: 1 1 auto;
        min-width: 0;
        justify-content: center;
    }

    /* Tableaux : scroll horizontal */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    table {
        font-size: 13px;
    }
    th, td {
        padding: 10px 12px;
        white-space: nowrap;
    }

    /* Stats cards en colonne */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .stat-card { padding: 16px; }
    .stat-card .stat-value { font-size: 22px; }

    /* Boutons touch-friendly (minimum 44px de hauteur) */
    .btn {
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px;
    }
    .btn-sm {
        padding: 8px 12px;
        font-size: 13px;
        min-height: 36px;
    }

    /* Forms */
    .form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .form-group input[type="text"],
    .form-group input[type="email"],
    .form-group input[type="password"],
    .form-group input[type="number"],
    .form-group input[type="file"],
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Évite le zoom automatique iOS */
        padding: 12px;
    }

    /* Cards */
    .card { padding: 16px; }
    .card-header h2 { font-size: 16px; }

    /* Toolbar (filtres) */
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar input, .toolbar select {
        width: 100%;
        padding: 12px;
        font-size: 14px;
    }

    /* KV list */
    .kv-list {
        grid-template-columns: 1fr;
        gap: 4px 0;
    }
    .kv-list dt {
        margin-top: 8px;
    }

    /* Documents */
    .doc-list li {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .doc-list .doc-actions {
        flex-wrap: wrap;
    }
    .doc-list .doc-actions .btn,
    .doc-list .doc-actions form {
        flex: 1;
    }

    /* Modal OCR : pleine largeur */
    #ocr-modal > div {
        margin: 8px !important;
        max-height: calc(100vh - 16px) !important;
        padding: 16px !important;
    }
}

.kv-list {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 8px 16px;
    font-size: 13px;
}
.kv-list dt {
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.04em;
    align-self: center;
}
.kv-list dd { color: var(--color-text); }

/* ─── Doc list ─── */
.doc-list {
    list-style: none;
    padding: 0;
}
.doc-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    background: #fafbfc;
}
.doc-list li:last-child { margin-bottom: 0; }
.doc-list .doc-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.doc-list .doc-name { font-weight: 500; font-size: 13px; }
.doc-list .doc-meta { font-size: 11px; color: var(--color-text-muted); }
.doc-list .doc-actions { display: flex; gap: 4px; }

/* ─── Filters / search bar ─── */
.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}
.toolbar input, .toolbar select {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: var(--color-surface);
}
.toolbar .spacer { flex: 1; }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
}
.empty-state h3 { color: var(--color-text); margin-bottom: 8px; font-size: 16px; }
.empty-state p { font-size: 13px; margin-bottom: 16px; }

/* ─── Utilities ─── */
.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }

/* ─── Print (pour reçus) ─── */
@media print {
    .sidebar, .topbar-actions, .btn, form { display: none !important; }
    .main { padding: 0; }
}
