/* EffaFinance — responsive UI (phone / tablet / desktop), light & dark */
:root {
  --ink: #0d1b2a; --ink-2: #13263a; --ink-text: #c9d4e3; --ink-muted: #7f90a8;
  --bg: #f3f5f9; --surface: #ffffff; --surface-2: #f8fafc; --text: #142032; --muted: #5f6f86; --line: #e2e7ef; --line-2: #eef1f6;
  --accent: #0f766e; --accent-soft: #e3f4f1; --accent-text: #0b5c56; --act: #b45309; --act-soft: #fdf1e3;
  --pos: #15803d; --neg: #b42318; --warn: #b7791f; --info: #2563eb;
  --radius: 12px; --radius-sm: 8px; --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sidebar: 252px; --topbar: 56px; --bottom: 62px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0b1320; --surface: #111c2d; --surface-2: #0f1828; --text: #e5ecf5; --muted: #93a3ba; --line: #22324a; --line-2: #1a283c;
  --accent: #2dd4bf; --accent-soft: #0f2f33; --accent-text: #5eead4; --act: #f59e0b; --act-soft: #33240e;
  --pos: #4ade80; --neg: #f87171; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14.5px/1.5 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent-text); }
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 15.5px; } h3 { font-size: 16px; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); } .pos { color: var(--pos); } .neg { color: var(--neg); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------------------------------------------------------------- shell */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar { width: var(--sidebar); background: var(--ink); color: var(--ink-text); display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 40; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 12px; }
.brand strong { color: #fff; display: block; font-size: 16px; } .brand small { color: var(--ink-muted); font-size: 12px; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #14b8a6, #0f766e 60%, #b45309); color: #fff; display: grid; place-items: center; font-weight: 700; letter-spacing: -.02em; }
.company-box { padding: 0 14px 10px; }
.company-select { width: 100%; background: var(--ink-2); color: #fff; border: 1px solid #22384f; border-radius: 8px; padding: 8px 10px; }
.nav-scroll { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
.nav-group { margin-top: 10px; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-muted); padding: 8px 10px 4px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-text); text-decoration: none; font-size: 14px; }
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: rgba(45, 212, 191, .14); color: #fff; box-shadow: inset 3px 0 0 #2dd4bf; }
.sidebar-foot { border-top: 1px solid #1d3047; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; gap: 10px; align-items: center; } .user-chip strong { color: #fff; display: block; font-size: 13.5px; } .user-chip small { color: var(--ink-muted); font-size: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #1f3a52; color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 13px; text-transform: uppercase; }
.foot-actions { display: flex; gap: 6px; } .sidebar .icon-btn { color: var(--ink-text); border-color: #22384f; }
.main-col { flex: 1; margin-left: var(--sidebar); min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 24px 28px 40px; max-width: 1400px; width: 100%; margin: 0 auto; outline: none; }
.bottom-nav { display: none; }
.scrim { display: none; }

/* ---------------------------------------------------------------- generic */
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: transparent; cursor: pointer; color: var(--text); }
.icon-btn:hover { background: var(--line-2); } .sidebar .icon-btn:hover { background: rgba(255, 255, 255, .06); }
.lang { font-size: 12px; font-weight: 700; letter-spacing: .04em; }
.btn { display: inline-flex; align-items: center; gap: 7px; justify-content: center; padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 550; white-space: nowrap; min-height: 38px; }
.btn:hover { background: var(--surface-2); border-color: #cfd6e2; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; } .btn.primary:hover { filter: brightness(1.07); }
[data-theme="dark"] .btn.primary { color: #062421; }
.btn.danger { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 35%, var(--line)); } .btn.danger:hover { background: color-mix(in srgb, var(--neg) 8%, transparent); }
.btn.ghost { border-color: transparent; background: transparent; } .btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.card.act { border-top: 3px solid var(--act); } .card.acc { border-top: 3px solid var(--accent); }
.grid { display: grid; gap: 16px; } .grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); align-items: start; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 12.5px; } .kpi-value { font-size: 21px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; } .kpi-sub { font-size: 12px; color: var(--muted); }
.kpi.pos .kpi-value { color: var(--pos); } .kpi.neg .kpi-value { color: var(--neg); } .kpi.act { border-left: 3px solid var(--act); } .kpi.acc { border-left: 3px solid var(--accent); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--pos) 14%, transparent); color: var(--pos); }
.badge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge.err { background: color-mix(in srgb, var(--neg) 14%, transparent); color: var(--neg); }
.badge.act { background: var(--act-soft); color: var(--act); } .badge.acc { background: var(--accent-soft); color: var(--accent-text); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tab { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 550; }
.tab.active { color: var(--accent-text); border-color: var(--accent); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); display: grid; place-items: center; gap: 6px; }
.loading { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 48px; color: var(--muted); }
.spin { width: 20px; height: 20px; border: 2.5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toolbar { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .field { margin: 0; min-width: 130px; }
.notice { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-text); margin-bottom: 14px; font-size: 13.5px; }
.notice.warn { background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn); }
.notice.err { background: color-mix(in srgb, var(--neg) 10%, transparent); color: var(--neg); }
.split { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------------------------------------------------------------- forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; } .field.wide { grid-column: 1 / -1; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 550; } .req { color: var(--neg); }
.field .hint { color: var(--muted); font-size: 12px; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); min-height: 40px; }
textarea { min-height: 120px; resize: vertical; font-family: var(--mono); font-size: 13px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .icon-btn:focus-visible, .tab:focus-visible, a:focus-visible, tr.clickable:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px; border-color: var(--accent); }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.field.error input, .field.error select { border-color: var(--neg); }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); cursor: pointer; background: var(--surface); font-size: 13.5px; user-select: none; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: middle; }
th { background: var(--surface-2); font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 650; position: sticky; top: 0; z-index: 1; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--surface-2); }
tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--line); }
tr.subtotal td { font-weight: 650; background: var(--surface-2); } tr.group td { font-weight: 700; color: var(--accent-text); background: var(--accent-soft); }
tr.selected td { background: var(--accent-soft) !important; }
td.wrap { white-space: normal; min-width: 180px; }
.tri td, .tri th { padding: 6px 9px; font-size: 12.5px; } .tri td.proj { color: var(--act); font-style: italic; background: var(--act-soft); }
.tri td.ldf { font-weight: 650; } .tri input { min-height: 30px; padding: 4px 6px; text-align: right; font-variant-numeric: tabular-nums; min-width: 84px; }

/* ---------------------------------------------------------------- entry editor */
.lines-editor .line { display: grid; grid-template-columns: minmax(180px, 2.2fr) minmax(140px, 1.4fr) minmax(140px, 1.6fr) minmax(100px, 1fr) minmax(100px, 1fr) 40px; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.lines-editor .line.head { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line); }
.lines-editor input.amt { text-align: right; font-variant-numeric: tabular-nums; }
.balance-bar { display: flex; gap: 18px; justify-content: flex-end; align-items: center; flex-wrap: wrap; padding: 12px 0 0; font-variant-numeric: tabular-nums; }
.balance-bar .state { font-weight: 700; }

/* ---------------------------------------------------------------- charts */
.chart-box { position: relative; height: 280px; } .chart-box.small { height: 220px; } .chart-box.tall { height: 340px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 110px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 10px; border-radius: 99px; background: var(--line-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--accent); } .bar-fill.act { background: var(--act); } .bar-fill.neg { background: var(--neg); }
.gauge { display: flex; align-items: baseline; gap: 8px; } .gauge strong { font-size: 34px; letter-spacing: -.03em; }

/* ---------------------------------------------------------------- modal & toasts */
.modal-back { position: fixed; inset: 0; background: rgba(9, 15, 25, .5); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 14px; width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal.wide { width: min(980px, 100%); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; overflow-y: auto; } .modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 11px 16px; border-radius: 10px; color: #fff; background: #13263a; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); font-size: 14px; transition: opacity .4s, transform .4s; }
.toast.ok { background: #0f766e; } .toast.err { background: #b42318; } .toast.out { opacity: 0; transform: translateY(6px); }

/* ---------------------------------------------------------------- auth */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-art { background: radial-gradient(1200px 500px at -10% 110%, rgba(180, 83, 9, .35), transparent 60%), radial-gradient(900px 600px at 110% -10%, rgba(20, 184, 166, .35), transparent 55%), var(--ink); color: #dbe5f2; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-art h2 { font-size: 34px; color: #fff; max-width: 460px; letter-spacing: -.02em; line-height: 1.15; }
.auth-art ul { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; color: #b7c4d6; }
.auth-art li::before { content: "—  "; color: #2dd4bf; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: min(420px, 100%); } .auth-card h1 { font-size: 26px; } .auth-card .sub { color: var(--muted); margin: 6px 0 22px; }
.auth-card form { display: grid; gap: 12px; } .auth-card .btn.primary { width: 100%; min-height: 44px; margin-top: 4px; }
.auth-foot { margin-top: 18px; color: var(--muted); font-size: 14px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- offline banner */
body.is-offline::after { content: "Offline / Hors ligne"; position: fixed; top: 0; left: 50%; transform: translateX(-50%); background: var(--warn); color: #fff; padding: 4px 14px; border-radius: 0 0 8px 8px; font-size: 12px; z-index: 300; }

/* ---------------------------------------------------------------- tablet */
@media (max-width: 1100px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  body.drawer-open .sidebar { transform: none; }
  body.drawer-open .scrim { display: block; position: fixed; inset: 0; background: rgba(9, 15, 25, .45); z-index: 35; }
  .main-col { margin-left: 0; }
  .topbar { display: flex; align-items: center; gap: 10px; height: var(--topbar); padding: 0 14px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .top-title { font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .content { padding: 20px 18px 36px; }
  .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.side { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; } .auth-art { display: none; }
}

/* ---------------------------------------------------------------- phone */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .menu-btn { display: none; }
  .content { padding: 14px 12px calc(var(--bottom) + 24px + env(safe-area-inset-bottom)); }
  h1 { font-size: 20px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; height: calc(var(--bottom) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); z-index: 30; }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; color: var(--muted); text-decoration: none; background: none; border: 0; padding: 4px 2px; cursor: pointer; }
  .bottom-nav a.active { color: var(--accent-text); }
  .bottom-nav span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } .kpi { padding: 12px; } .kpi-value { font-size: 17px; }
  .card { padding: 14px; border-radius: 10px; }
  .page-head { align-items: flex-start; } .page-actions { width: 100%; } .page-actions .btn { flex: 1; }
  .toolbar .field { flex: 1 1 140px; }
  /* tables → cards */
  .table-wrap.cards { border: 0; overflow: visible; }
  .table-wrap.cards table, .table-wrap.cards tbody, .table-wrap.cards tr, .table-wrap.cards td { display: block; width: 100%; }
  .table-wrap.cards thead { display: none; }
  .table-wrap.cards tr { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; padding: 8px 12px; }
  .table-wrap.cards td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table-wrap.cards td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; text-align: left; flex-shrink: 0; }
  .table-wrap.cards td:empty { display: none; }
  .table-wrap.cards tfoot tr { background: var(--surface-2); }
  .lines-editor .line { grid-template-columns: 1fr 1fr; padding: 10px 0; }
  .lines-editor .line.head { display: none; }
  .lines-editor .line > :first-child, .lines-editor .line > :nth-child(3) { grid-column: 1 / -1; }
  .balance-bar { justify-content: space-between; }
  .bar-row { grid-template-columns: 90px 1fr 90px; }
  .modal-back { padding: 0; align-items: end; } .modal { border-radius: 16px 16px 0 0; max-height: 92dvh; }
  .chart-box { height: 230px; }
  #toasts { bottom: calc(var(--bottom) + 12px); left: 12px; right: 12px; }
}

/* ---------------------------------------------------------------- print */
@media print {
  .sidebar, .topbar, .bottom-nav, .page-actions, .toolbar, .card-actions, .tabs, #toasts { display: none !important; }
  .main-col { margin: 0; } .content { padding: 0; max-width: none; } .card { box-shadow: none; border: 0; padding: 0; }
  body { background: #fff; color: #000; } .table-wrap { border: 0; overflow: visible; } th { position: static; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------------------------------------------------------------- layout fixes */
.grid > *, .main-col, .content > div { min-width: 0; }
.grid.side .form-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.table-wrap { max-width: 100%; }
@media (max-width: 760px) {
  .table-wrap:not(.cards) th, .table-wrap:not(.cards) td { padding: 7px 8px; font-size: 12.5px; }
  .table-wrap:not(.cards) td.wrap { min-width: 120px; }
  .table-wrap:not(.cards) .mono { font-size: 11.5px; }
}
