/* =====================================================================
   ComptaFlow : feuille de style principale
   Theme clair et professionnel aux couleurs Sysgate.
   Blanc dominant, bleu nuit rgb(2,3,129), typographie soignee.
   ===================================================================== */

/* ---------- Jetons de design (variables) ---------------------------- */
:root {
    --bg:            #F4F6FB;
    --bg-2:          #FAFBFE;
    --surface:       #FFFFFF;
    --surface-2:     #FFFFFF;
    --surface-3:     #F0F3FA;
    --border:        #E2E7F1;
    --border-soft:   #EDF0F7;

    --navy:          #020381;
    --navy-700:      #0A0C6E;
    --navy-600:      #14179A;
    --navy-500:      #2A2EB8;
    --primary:       #020381;
    --primary-2:     #14179A;
    --primary-soft:  rgba(2, 3, 129, 0.07);
    --primary-tint:  rgba(2, 3, 129, 0.12);
    --secondary:     #14179A;
    --accent:        #3B4BE0;

    --success:       #0F8B5F;
    --success-soft:  rgba(15, 139, 95, 0.10);
    --warning:       #B26B00;
    --warning-soft:  rgba(178, 107, 0, 0.10);
    --danger:        #C42B3A;
    --danger-soft:   rgba(196, 43, 58, 0.09);
    --info:          #1F5FD0;
    --info-soft:     rgba(31, 95, 208, 0.10);

    --text:          #14182B;
    --text-soft:     #3A4056;
    --muted:         #6B7285;
    --faint:         #9AA1B3;

    --radius:        14px;
    --radius-sm:     10px;
    --radius-lg:     20px;
    --shadow:        0 12px 32px -20px rgba(2, 3, 60, 0.28);
    --shadow-soft:   0 6px 18px -12px rgba(2, 3, 60, 0.18);
    --shadow-nav:    0 18px 44px -28px rgba(2, 3, 80, 0.45);

    --sidebar-w:     266px;
    --font-display:  'Space Grotesk', 'Segoe UI', system-ui, sans-serif;
    --font-body:     'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font-body);
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--text-soft);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(760px 460px at 8% -10%, rgba(2, 3, 129, 0.05), transparent 60%),
        radial-gradient(620px 420px at 96% 2%, rgba(59, 75, 224, 0.045), transparent 58%);
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--navy-500); text-decoration: underline; }
h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
    color: var(--text);
}
::selection { background: rgba(2, 3, 129, 0.15); color: var(--navy); }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D3D9E6; border-radius: 8px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #BFC7D9; }

.app { position: relative; z-index: 1; display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(184deg, var(--navy) 0%, #06075C 100%);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    padding: 22px 16px 16px;
    overflow-y: auto;
}
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.16); border-color: transparent; }
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px 20px;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}
.brand-mark {
    width: 42px; height: 42px;
    border-radius: 11px;
    display: grid; place-items: center;
    background: rgba(255, 255, 255, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.14);
    flex: 0 0 auto;
    overflow: hidden;
}
.brand-mark img { width: 30px; height: 30px; object-fit: contain; display: block; }
.brand-mark svg { width: 22px; height: 22px; display: block; }
.brand-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 19px;
    letter-spacing: -0.01em;
    color: #fff;
    line-height: 1;
}
.brand-name span { color: #B9C0FF; font-weight: 500; }
.brand-sub {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.55);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    margin-top: 5px;
}
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
.nav-group-label {
    font-size: 10.5px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.42);
    padding: 16px 10px 7px;
    font-weight: 600;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.80);
    font-size: 14px;
    font-weight: 500;
    position: relative;
    transition: background 0.15s ease, color 0.15s ease;
}
.nav-link:hover { text-decoration: none; }
.nav-link svg { width: 18px; height: 18px; flex: 0 0 auto; opacity: 0.85; }
.nav-link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-link.active { background: rgba(255, 255, 255, 0.13); color: #fff; }
.nav-link.active::before {
    content: "";
    position: absolute;
    left: -16px; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 22px;
    border-radius: 0 3px 3px 0;
    background: #fff;
}
.nav-link.active svg { opacity: 1; color: #fff; }
.sidebar-foot { margin-top: auto; padding-top: 16px; }
.userbox {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.10);
}
.userbox .user-link {
    display: flex;
    align-items: center;
    gap: 11px;
    flex: 1 1 auto;
    min-width: 0;
    padding: 6px 8px;
    border-radius: 8px;
    text-decoration: none;
    transition: background 0.15s ease;
}
.userbox .user-link:hover { background: rgba(255, 255, 255, 0.10); text-decoration: none; }
.userbox .user-link.active { background: rgba(255, 255, 255, 0.13); }
.userbox .avatar {
    width: 34px; height: 34px;
    border-radius: 9px;
    display: grid; place-items: center;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 14px;
    flex: 0 0 auto;
}
.userbox .u-name { font-size: 13.5px; font-weight: 600; color: #fff; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.userbox .u-role { font-size: 11px; color: rgba(255, 255, 255, 0.55); }
.userbox .user-link:hover .u-role, .userbox .user-link.active .u-role { color: rgba(255, 255, 255, 0.75); }
.userbox .logout {
    flex: 0 0 auto;
    color: rgba(255, 255, 255, 0.65);
    display: grid; place-items: center;
    width: 34px; height: 34px;
    border-radius: 8px;
}
.userbox .logout:hover { color: #fff; background: rgba(255, 255, 255, 0.14); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 15px 30px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}
.topbar .page-title { font-size: 18px; }
.topbar .crumb { font-size: 12px; color: var(--muted); margin-top: 2px; }
.topbar .spacer { flex: 1 1 auto; }
.menu-toggle {
    display: none;
    width: 40px; height: 40px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    place-items: center;
}
.content { padding: 28px 30px 56px; max-width: 1320px; width: 100%; }

.flash-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
.flash {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 12px 15px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 13.5px;
    box-shadow: var(--shadow-soft);
}
.flash svg { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; }
.flash-success { border-color: rgba(15,139,95,0.28); background: var(--success-soft); color: #0a5c3f; }
.flash-success svg { color: var(--success); }
.flash-danger  { border-color: rgba(196,43,58,0.28); background: var(--danger-soft); color: #8f1f2a; }
.flash-danger svg { color: var(--danger); }
.flash-warning { border-color: rgba(178,107,0,0.28); background: var(--warning-soft); color: #7a4900; }
.flash-warning svg { color: var(--warning); }
.flash-info    { border-color: rgba(31,95,208,0.26); background: var(--info-soft); color: #17458f; }
.flash-info svg { color: var(--info); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    position: relative;
}
.card-pad { padding: 20px 22px; }
.card-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border-soft);
}
.card-head h3 { font-size: 15.5px; }
.card-head .sub { font-size: 12px; color: var(--muted); }
.card-head .spacer { flex: 1; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 22px; }
.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-soft);
    transition: transform 0.12s ease, box-shadow 0.15s ease;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--navy);
    opacity: 0.85;
}
.kpi .k-top { display: flex; align-items: center; gap: 10px; position: relative; }
.kpi .k-ico {
    width: 38px; height: 38px;
    border-radius: 11px;
    display: grid; place-items: center;
    background: var(--primary-soft);
    border: 1px solid var(--primary-tint);
}
.kpi .k-ico svg { width: 19px; height: 19px; }
.kpi .k-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi .k-value {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 28px;
    letter-spacing: -0.02em;
    margin-top: 13px;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1.05;
    position: relative;
}
.kpi .k-value .cur { font-size: 15px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.kpi .k-foot { font-size: 12px; color: var(--muted); margin-top: 7px; position: relative; }
.kpi .k-foot .up { color: var(--success); font-weight: 600; }
.kpi .k-foot .down { color: var(--danger); font-weight: 600; }
.k-ico.violet { color: var(--navy); }
.k-ico.navy   { color: var(--navy); }
.k-ico.green  { color: var(--success); background: var(--success-soft); border-color: rgba(15,139,95,0.2); }
.k-ico.amber  { color: var(--warning); background: var(--warning-soft); border-color: rgba(178,107,0,0.2); }
.k-ico.blue   { color: var(--info); background: var(--info-soft); border-color: rgba(31,95,208,0.2); }
.k-ico.red    { color: var(--danger); background: var(--danger-soft); border-color: rgba(196,43,58,0.2); }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: 2fr 1fr; }
.grid-2e { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.mt-18 { margin-top: 18px; }
.mt-22 { margin-top: 22px; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data thead th {
    text-align: left;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 11.5px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: var(--bg-2);
}
table.data tbody td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border-soft);
    color: var(--text-soft);
    vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background 0.12s ease; }
table.data tbody tr:hover { background: var(--primary-soft); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .strong { color: var(--text); font-weight: 600; }
table.data .mono { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--faint); margin-bottom: 12px; }
.empty h4 { color: var(--text-soft); font-size: 15px; margin-bottom: 6px; }
.empty p { font-size: 13px; margin: 0 0 16px; }

.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em;
    border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { color: var(--success); background: var(--success-soft); border-color: rgba(15,139,95,0.25); }
.badge-danger  { color: var(--danger);  background: var(--danger-soft);  border-color: rgba(196,43,58,0.25); }
.badge-warning { color: var(--warning); background: var(--warning-soft); border-color: rgba(178,107,0,0.25); }
.badge-info    { color: var(--info);    background: var(--info-soft);    border-color: rgba(31,95,208,0.25); }
.badge-muted   { color: var(--muted);   background: var(--surface-3);    border-color: var(--border); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 16px; border-radius: var(--radius-sm);
    font-family: var(--font-body); font-size: 13.5px; font-weight: 600;
    cursor: pointer; border: 1px solid transparent;
    transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    white-space: nowrap; line-height: 1;
}
.btn:hover { text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--navy); color: #fff; box-shadow: 0 10px 22px -14px rgba(2, 3, 129, 0.9); }
.btn-primary:hover { color: #fff; background: var(--navy-600); box-shadow: 0 12px 26px -12px rgba(2, 3, 129, 1); }
.btn-ghost { background: var(--surface); color: var(--text-soft); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-3); color: var(--navy); border-color: #D2D8E6; }
.btn-soft { background: var(--primary-soft); color: var(--navy); border-color: var(--primary-tint); }
.btn-soft:hover { background: var(--primary-tint); color: var(--navy); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(196,43,58,0.28); }
.btn-danger:hover { background: rgba(196,43,58,0.16); color: var(--danger); }
.btn-success { background: var(--success-soft); color: var(--success); border-color: rgba(15,139,95,0.28); }
.btn-success:hover { background: rgba(15,139,95,0.16); color: var(--success); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-icon { padding: 8px; width: 34px; height: 34px; }
.btn-icon.btn-sm { width: 30px; height: 30px; padding: 6px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .ph-text h2 { font-size: 23px; letter-spacing: -0.02em; }
.page-head .ph-text p { color: var(--muted); font-size: 13.5px; margin: 5px 0 0; }
.page-head .ph-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg a { padding: 6px 13px; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.seg a:hover { color: var(--navy); text-decoration: none; }
.seg a.active { background: var(--navy); color: #fff; }
.seg a.active:hover { color: #fff; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search-box input { padding-left: 38px; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field.col-2 { grid-column: span 2; }
label.lbl { font-size: 12.5px; font-weight: 600; color: var(--text-soft); }
label.lbl .opt { color: var(--faint); font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=url], input[type=tel], select, textarea {
    width: 100%; padding: 10px 13px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text);
    font-family: var(--font-body); font-size: 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    appearance: none;
}
textarea { resize: vertical; min-height: 86px; line-height: 1.55; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--navy);
    box-shadow: 0 0 0 3px var(--primary-soft); background: #fff;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%236B7285' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
    padding-right: 36px; cursor: pointer;
}
input[type=date] { cursor: pointer; }
.hint { font-size: 11.5px; color: var(--muted); }
.hint a { font-weight: 600; }
.form-foot { display: flex; gap: 10px; align-items: center; margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--border-soft); }
.form-foot .spacer { flex: 1; }
.input-prefix { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; }
.input-prefix span { display: grid; place-items: center; padding: 0 12px; color: var(--muted); font-size: 13px; background: var(--bg-2); border-right: 1px solid var(--border); }
.input-prefix input { border: none; border-radius: 0; }
.input-prefix:focus-within { border-color: var(--navy); box-shadow: 0 0 0 3px var(--primary-soft); }
.radio-seg { display: inline-flex; gap: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.radio-seg label { padding: 9px 16px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; background: var(--surface); }
.radio-seg label:not(:last-child) { border-right: 1px solid var(--border); }
.radio-seg input { display: none; }
.radio-seg input:checked + label, .radio-seg label.on { background: var(--navy); color: #fff; }

.items-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.items-table th { text-align: left; font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); padding: 0 10px 9px; font-weight: 600; }
.items-table th.r, .items-table td.r { text-align: right; }
.items-table td { padding: 5px 6px; vertical-align: top; }
.items-table input { padding: 8px 10px; font-size: 13.5px; }
.items-table .col-desc { width: 42%; }
.items-table .col-qty  { width: 90px; }
.items-table .col-pu   { width: 130px; }
.items-table .col-tva  { width: 92px; }
.items-table .col-tot  { width: 120px; }
.items-table .col-del  { width: 42px; }
.line-total { font-family: var(--font-display); font-variant-numeric: tabular-nums; color: var(--text); padding-top: 9px; display: block; text-align: right; font-size: 13.5px; }
.row-del { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; display: grid; place-items: center; margin-top: 1px; }
.row-del:hover { color: var(--danger); border-color: rgba(196,43,58,0.4); background: var(--danger-soft); }
.row-del svg { width: 15px; height: 15px; }
.totals-box { margin-left: auto; width: 320px; margin-top: 18px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; color: var(--text-soft); }
.totals-box .row .v { font-variant-numeric: tabular-nums; font-family: var(--font-display); }
.totals-box .row.grand { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 17px; font-weight: 600; color: var(--text); }
.totals-box .row.grand .v { color: var(--navy); }

.doc-preview { background: #fff; color: #1f2430; border-radius: var(--radius); padding: 40px 44px; max-width: 820px; margin: 0 auto; box-shadow: var(--shadow); border: 1px solid var(--border); font-size: 13.5px; }
.doc-preview h1, .doc-preview h2, .doc-preview h3 { color: var(--navy); }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding-bottom: 24px; border-bottom: 2px solid var(--navy); }
.doc-logo img { max-height: 70px; max-width: 220px; }
.doc-company { font-size: 12.5px; color: #5b6472; line-height: 1.6; }
.doc-company .cname { font-size: 16px; font-weight: 700; color: var(--navy); font-family: var(--font-display); }
.doc-meta { text-align: right; }
.doc-meta .doc-type { font-family: var(--font-display); font-size: 26px; font-weight: 700; color: var(--navy); letter-spacing: 0.02em; }
.doc-meta .doc-num { font-size: 14px; font-weight: 600; margin-top: 2px; color: #14182b; }
.doc-meta .doc-dates { font-size: 12px; color: #5b6472; margin-top: 8px; line-height: 1.7; }
.doc-parties { display: flex; justify-content: space-between; gap: 24px; margin: 24px 0; }
.doc-party-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #9aa3b2; font-weight: 700; margin-bottom: 6px; }
.doc-client { font-size: 13px; color: #2b3240; line-height: 1.6; }
.doc-client .pname { font-weight: 700; font-size: 14.5px; color: var(--navy); }
table.doc-items { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.doc-items thead th { background: var(--navy); color: #fff; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; padding: 10px 12px; text-align: left; }
table.doc-items thead th.r { text-align: right; }
table.doc-items tbody td { padding: 10px 12px; border-bottom: 1px solid #e6e9ee; vertical-align: top; }
table.doc-items tbody td.r { text-align: right; font-variant-numeric: tabular-nums; }
table.doc-items tbody tr:nth-child(even) { background: #f6f7fc; }
.doc-totals { margin-left: auto; width: 290px; margin-top: 18px; }
.doc-totals .row { display: flex; justify-content: space-between; padding: 7px 12px; font-size: 13px; }
.doc-totals .row.grand { background: var(--navy); color: #fff; font-weight: 700; border-radius: 8px; font-size: 15px; margin-top: 4px; }
.doc-note { margin-top: 26px; font-size: 12px; color: #5b6472; line-height: 1.65; border-top: 1px solid #e6e9ee; padding-top: 16px; }
.doc-actions { display: flex; gap: 10px; justify-content: center; margin: 22px 0 4px; flex-wrap: wrap; }

.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 14px; }
.legend .it { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; }
.bar-list { display: flex; flex-direction: column; gap: 14px; }
.bar-item .bar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.bar-item .bar-top .v { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.bar-track { height: 8px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--navy), var(--navy-500)); }

.month-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.month-cell { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 13px 15px; transition: border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease; }
.month-cell:hover { border-color: var(--navy); transform: translateY(-2px); box-shadow: var(--shadow-soft); }
.month-cell .m-name { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.month-cell .m-val { font-family: var(--font-display); font-size: 18px; font-weight: 600; color: var(--text); margin-top: 7px; font-variant-numeric: tabular-nums; }
.month-cell.has .m-val { color: var(--navy); }
.month-cell .m-cur { font-size: 11px; color: var(--muted); }

.pill-amount { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.text-muted { color: var(--muted); }
.text-soft { color: var(--text-soft); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.divider { height: 1px; background: var(--border-soft); margin: 20px 0; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--surface-3); color: var(--muted); border: 1px solid var(--border); font-weight: 600; }
.stat-line { display: flex; gap: 26px; flex-wrap: wrap; }
.stat-line .s .lbl { font-size: 12px; color: var(--muted); }
.stat-line .s .val { font-family: var(--font-display); font-size: 20px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; color: var(--text); }
.actions-cell { display: flex; gap: 6px; justify-content: flex-end; }
.inline-form { display: inline; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 16px; font-size: 13.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; color: var(--text-soft); }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; z-index: 1; background: radial-gradient(900px 500px at 50% -10%, rgba(2,3,129,0.08), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 412px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 38px 34px; box-shadow: 0 40px 90px -50px rgba(2,3,80,0.5); position: relative; overflow: hidden; }
.auth-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--navy); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 26px; }
.auth-brand .brand-mark { width: 150px; height: auto; border-radius: 0; background: none; border: none; padding: 0; overflow: visible; }
.auth-brand .brand-mark img { width: 100%; height: auto; }
.auth-brand .brand-mark svg { width: 28px; height: 28px; }
.auth-brand h1 { font-size: 25px; letter-spacing: -0.02em; }
.auth-brand h1 span { color: var(--navy-500); font-weight: 500; }
.auth-brand p { color: var(--muted); font-size: 13px; margin: 0; text-align: center; }
.auth-card .field { margin-bottom: 16px; }
.auth-err { background: var(--danger-soft); border: 1px solid rgba(196,43,58,0.28); color: #8f1f2a; border-radius: var(--radius-sm); padding: 11px 14px; font-size: 13px; margin-bottom: 18px; display: flex; gap: 9px; align-items: center; }
.auth-err svg { width: 17px; height: 17px; flex: 0 0 auto; color: var(--danger); }
.auth-foot { text-align: center; margin-top: 22px; font-size: 11.5px; color: var(--faint); }
.pw-wrap { position: relative; }
.pw-toggle { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; display: grid; place-items: center; }
.pw-toggle:hover { color: var(--navy); }
.pw-toggle svg { width: 18px; height: 18px; }
.pw-meter { height: 5px; border-radius: 4px; background: var(--surface-3); overflow: hidden; margin-top: 9px; }
.pw-meter i { display: block; height: 100%; width: 0; border-radius: 4px; transition: width 0.25s ease, background 0.25s ease; }
.pw-label { font-size: 11.5px; margin-top: 6px; color: var(--muted); }

.code-input { font-family: var(--font-display); font-size: 30px; text-align: center; letter-spacing: 0.5em; padding: 14px 10px 14px 20px; font-variant-numeric: tabular-nums; }
.twofa-qr { display: grid; place-items: center; padding: 16px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); width: fit-content; margin: 0 auto 4px; }
.twofa-qr img, .twofa-qr canvas { display: block; width: 190px; height: 190px; }
.twofa-secret { font-family: var(--font-display); font-size: 15px; letter-spacing: 0.12em; background: var(--bg-2); border: 1px dashed var(--border); border-radius: 8px; padding: 9px 14px; text-align: center; color: var(--navy); word-break: break-all; user-select: all; }

.agent-layout { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
.agent-threads { display: flex; flex-direction: column; gap: 6px; }
.thread-link { display: block; padding: 11px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); font-size: 13px; color: var(--text-soft); transition: border-color 0.12s ease, background 0.12s ease; }
.thread-link:hover { border-color: var(--navy); text-decoration: none; background: var(--primary-soft); }
.thread-link.active { border-color: var(--navy); background: var(--primary-soft); color: var(--navy); font-weight: 600; }
.thread-link .t-title { font-weight: 600; color: var(--text); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-link.active .t-title { color: var(--navy); }
.thread-link .t-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.chat-window { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 460px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-soft); overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border-soft); background: var(--bg-2); }
.chat-head .ch-ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--navy); color: #fff; }
.chat-head .ch-ico svg { width: 18px; height: 18px; }
.chat-head h3 { font-size: 14.5px; }
.chat-head .ch-sub { font-size: 11.5px; color: var(--muted); }
.chat-body { flex: 1 1 auto; overflow-y: auto; padding: 20px 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 82%; }
.msg .bubble { padding: 11px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .bubble { background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--surface-3); color: var(--text); border-bottom-left-radius: 4px; }
.msg .m-ico { width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.msg.assistant .m-ico { background: var(--primary-soft); color: var(--navy); }
.msg.user .m-ico { background: var(--navy); color: #fff; }
.chat-foot { border-top: 1px solid var(--border-soft); padding: 12px 14px; background: var(--bg-2); }
.chat-input-row { display: flex; gap: 10px; align-items: flex-end; }
.chat-input-row textarea { min-height: 44px; max-height: 160px; resize: none; }
.chat-empty { text-align: center; color: var(--muted); margin: auto; padding: 30px; }
.chat-empty svg { width: 44px; height: 44px; color: var(--faint); margin-bottom: 12px; }
.chat-empty h4 { color: var(--text-soft); margin-bottom: 6px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.suggestion { padding: 8px 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 12.5px; color: var(--text-soft); cursor: pointer; transition: border-color 0.12s ease, background 0.12s ease; }
.suggestion:hover { border-color: var(--navy); background: var(--primary-soft); color: var(--navy); }
.typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: typing 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }
.agent-inline { border: 1px solid var(--primary-tint); background: linear-gradient(180deg, var(--primary-soft), transparent); border-radius: var(--radius); padding: 16px 18px; }
.agent-inline .ai-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.agent-inline .ai-head .ai-ico { width: 30px; height: 30px; border-radius: 8px; background: var(--navy); color: #fff; display: grid; place-items: center; }
.agent-inline .ai-head .ai-ico svg { width: 16px; height: 16px; }
.agent-inline .ai-head h4 { font-size: 14px; }
.agent-inline .ai-out { font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; color: var(--text-soft); margin-top: 8px; }

@media (max-width: 1080px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2, .grid-2e, .grid-3 { grid-template-columns: 1fr; }
    .month-grid { grid-template-columns: repeat(3, 1fr); }
    .agent-layout { grid-template-columns: 1fr; }
    .agent-threads { flex-direction: row; overflow-x: auto; }
    .thread-link { min-width: 180px; }
}
@media (max-width: 860px) {
    .sidebar { position: fixed; z-index: 60; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.25s ease; box-shadow: 30px 0 60px -30px rgba(2,3,60,0.4); }
    .app.nav-open .sidebar { transform: translateX(0); }
    .menu-toggle { display: grid; }
    .content { padding: 22px 18px 48px; }
    .topbar { padding: 14px 18px; }
    .nav-scrim { display: none; position: fixed; inset: 0; background: rgba(5,7,20,0.4); z-index: 55; backdrop-filter: blur(2px); }
    .app.nav-open .nav-scrim { display: block; }
    .form-grid { grid-template-columns: 1fr; }
    .field.col-2 { grid-column: auto; }
    .totals-box { width: 100%; }
    .doc-preview { padding: 26px 22px; }
    .doc-head, .doc-parties { flex-direction: column; }
    .doc-meta { text-align: left; }
    .chat-window { height: auto; min-height: 400px; }
}
@media (max-width: 560px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .month-grid { grid-template-columns: repeat(2, 1fr); }
    .page-head .ph-actions { width: 100%; }
    .items-table { display: block; }
    .msg { max-width: 92%; }
}
:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.year-pick { width: auto; min-width: 110px; }
.seg-gap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
table.data tfoot td { padding: 11px 14px; font-size: 13.5px; }
.export-list { display: flex; flex-direction: column; gap: 10px; }
.export-row { display: flex; align-items: center; gap: 14px; padding: 13px 15px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm); transition: border-color 0.15s ease, transform 0.1s ease, background 0.15s ease; }
.export-row:hover { border-color: var(--navy); transform: translateY(-1px); text-decoration: none; }
.export-row .ex-ic { flex: 0 0 auto; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.export-row .ex-ic svg { width: 18px; height: 18px; color: var(--navy); }
.export-row .ex-txt { display: flex; flex-direction: column; gap: 2px; }
.export-row .ex-t { font-weight: 600; font-size: 14px; color: var(--text); }
.export-row .ex-s { font-size: 12px; color: var(--muted); }
