:root {
  --bg: #f6f7f9; --card: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --primary: #2563eb; --primary-d: #1d4ed8; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }

.topbar { background: #111827; color: #fff; display: flex; align-items: center; gap: 14px; padding: 0 16px; height: 52px; position: sticky; top: 0; z-index: 10; }
.topbar .brand { font-weight: 700; letter-spacing: .3px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: #cbd5e1; padding: 6px 9px; font-size: 14px; border-radius: 6px; white-space: nowrap; }
.topbar nav a:hover { background: #1f2937; text-decoration: none; }
.topbar nav a.active { background: #374151; color: #fff; }
.topbar select { width: auto; max-width: 220px; flex: none; background: #1f2937; color: #fff; border: 1px solid #374151; border-radius: 6px; padding: 5px 8px; }
.topbar .logout { color: #9ca3af; cursor: pointer; background: none; border: 0; }

main { width: 100%; max-width: none; margin: 0; padding: 24px 28px 60px; }   /* every page uses the full width of the screen */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.stat .value.bad { color: var(--danger); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid #f0f1f3; vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f9fafb; }
.num, th.num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.empty { color: var(--muted); text-align: center; padding: 28px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; font: inherit; }
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; background: #e5e7eb; color: #374151; white-space: nowrap; }
.badge.draft { background: #f3f4f6; color: #6b7280; }
.badge.validated, .badge.sent, .badge.accepted { background: #dbeafe; color: #1d4ed8; }
.badge.paid, .badge.active, .badge.success, .badge.invoiced { background: #dcfce7; color: #15803d; }
.badge.partially_paid, .badge.paused { background: #fef3c7; color: #b45309; }
.badge.declined, .badge.cancelled, .badge.failed, .badge.overdue, .badge.expired { background: #fee2e2; color: #b91c1c; }
.badge.ended { background: #e5e7eb; color: #6b7280; }

.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; color: var(--text); width: 100%; }
/* Checkboxes and radios keep their natural size (the rule above would stretch them to the full width of a flex row). */
input[type=checkbox], input[type=radio] { width: auto; flex: none; padding: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.filters input, .filters select { width: auto; min-width: 160px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 22px; color: var(--text); font-size: 14px; }
.check input { width: auto; }

.lines input { padding: 6px 8px; }
.lines td { padding: 4px; }
.lines .del { color: var(--danger); background: none; border: 0; cursor: pointer; font-size: 18px; }
.totals { margin-left: auto; width: 320px; max-width: 100%; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { font-size: 17px; font-weight: 700; border-top: 2px solid var(--text); margin-top: 6px; padding-top: 8px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.muted { color: var(--muted); }
.error { background: #fee2e2; color: #991b1b; padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 50; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.toast.err { background: var(--danger); }

.login { max-width: 360px; margin: 12vh auto; }
.login h1 { margin-bottom: 18px; text-align: center; }
.modal-back { position: fixed; inset: 0; background: rgba(17,24,39,.5); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; z-index: 40; }
.modal { background: #fff; border-radius: 10px; padding: 20px 22px; width: 640px; max-width: 100%; }
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; } main { padding: 16px 12px 50px; } }

.dropzone { text-align: center; padding: 28px; border: 2px dashed #cbd5e1; background: #f8fafc; }
.dropzone.over { border-color: var(--primary, #2563eb); background: #eff6ff; }
.dropzone .link { color: var(--primary, #2563eb); cursor: pointer; text-decoration: underline; }
.bad { color: var(--danger); }
tr .actions { text-align: right; white-space: nowrap; }
.page-head select { max-width: 320px; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs a { padding: 6px 16px; border-radius: 6px; background: #e5e7eb; color: #374151; text-decoration: none; }
.tabs a.active { background: #111827; color: #fff; }

.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(150px, 40%) 1fr minmax(110px, auto); gap: 10px; align-items: center; font-size: 13px; }
.hbar .hl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .hb { background: #eef2f7; border-radius: 4px; height: 12px; }
.hbar .hb span { display: block; height: 100%; background: #2563eb; border-radius: 4px; }
.hbar .hv { text-align: right; white-space: nowrap; } .hbar .hv small { color: #6b7280; }
.vbars { display: flex; gap: 6px; align-items: flex-end; height: 230px; padding-top: 6px; }
.vbar { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.vbar .vv { font-size: 11px; color: #6b7280; height: 16px; white-space: nowrap; }
.vbar .vcol { flex: 1; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.vbar .vl { font-size: 12px; margin-top: 4px; }
.vb, .va { display: block; width: 100%; } .vb { background: #93c5fd; } .va { background: #2563eb; border-radius: 3px 3px 0 0; }
.legend { font-size: 12px; font-weight: 400; color: #6b7280; margin-left: 12px; } .legend i { display: inline-block; width: 10px; height: 10px; margin: 0 4px 0 10px; border-radius: 2px; }
.legend i.va { background: #2563eb; } .legend i.vb { background: #93c5fd; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 16px; }

.loading { display: flex; align-items: center; gap: 12px; padding: 48px; justify-content: center; color: #6b7280; font-size: 15px; }
.spinner { width: 22px; height: 22px; border: 3px solid #dbeafe; border-top-color: #2563eb; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.filters:has(button) { align-items: center; flex-wrap: wrap; }
.filters .check { display: inline-flex; align-items: center; gap: 6px; width: auto; flex: none; }
.filters .check input { width: auto; }
.topbar nav a { padding: 6px 7px; font-size: 13.5px; }
.topbar select { max-width: 160px; }
.topbar .logout { font-size: 13px; }
.filters .check { margin: 0; } .filters .check input { min-width: 0; }

/* lists: pagination, sortable headers, late invoices */
.pager { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 4px 4px; font-size: 13px; }
.pager .btn { padding: 4px 10px; } .pager .btn[disabled] { opacity: .4; cursor: default; }
.pager .page-input { width: 64px; min-width: 0; padding: 4px 6px; display: inline-block; } .pager .per-page { width: auto; margin-left: auto; padding: 4px 8px; }
th.sortable { cursor: pointer; user-select: none; } th.sortable:hover { color: #111827; } th.sorted { color: #111827; }
.busy { opacity: .55; transition: opacity .15s; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--text); } label.inline input { width: auto; min-width: 0; }
tr.late-soft > td { background: #ffedd5; } tr.late-soft:hover > td { background: #fed7aa; }
tr.late-hard > td { background: #991b1b; color: #fff; } tr.late-hard:hover > td { background: #7f1d1d; }
tr.late-soft a { color: #111827; } tr.late-hard a { color: #fff; }
tr.late-hard .badge { background: #fff; } tr.late-hard small, tr.late-hard .muted { color: #fecaca; }
.legend-late { font-size: 12px; color: #6b7280; margin: -4px 0 10px; display: flex; align-items: center; gap: 8px; }
.legend-late .chip { width: 14px; height: 14px; border-radius: 3px; display: inline-block; } .legend-late .chip.late-soft { background: #ffedd5; border: 1px solid #fdba74; } .legend-late .chip.late-hard { background: #991b1b; margin-left: 12px; }

.inst-table { width: 100%; margin-top: 10px; } .inst-table td { padding: 3px 6px 3px 0; } .inst-table input { min-width: 0; padding: 5px 8px; } .inst-table input[data-f=amount] { width: 120px; text-align: right; display: inline-block; }
.inst-foot { display: flex; align-items: center; gap: 14px; margin-top: 8px; flex-wrap: wrap; } .ok { color: #15803d; font-weight: 700; } .bad { color: #b91c1c; font-weight: 700; }
.inst-controls { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.modal.wide { max-width: 860px; width: 92vw; }
.mail-head { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; margin: 8px 0 12px; font-size: 13px; } .mail-head dt { color: #6b7280; } .mail-head dd { margin: 0; word-break: break-word; }
.mail-body { width: 100%; height: 380px; border: 1px solid #e5e7eb; border-radius: 6px; background: #fff; }
.send.warn { color: #d97706; } tr.late-hard .send.warn { color: #fed7aa; }

table.doc-lines tr.section td { background: #f1f5f9; padding: 8px 10px; border-top: 1px solid #cbd5e1; }
table.doc-lines td.num, table.doc-lines th.num { white-space: nowrap; }
tr.section-row td { background: #f1f5f9; }

td.due.owed { font-weight: 700; } table tfoot td { font-weight: 700; border-top: 2px solid #cbd5e1; padding-top: 10px; }
table.dense th, table.dense td { padding-left: 6px; padding-right: 6px; }
tr.late-hard tfoot td { color: inherit; }

main.wide { max-width: none; }
table.dense { font-size: 13px; } table.dense th, table.dense td { padding: 8px 7px; white-space: nowrap; }
table.dense td.clip { max-width: 28vw; overflow: hidden; text-overflow: ellipsis; }

/* Drop-down menus of the top bar (open on hover, and on click for touch screens) */
.topbar .menu { position: relative; }
.topbar .menu-btn { color: #cbd5e1; background: none; border: 0; cursor: pointer; padding: 6px 9px; font-size: 14px; border-radius: 6px; white-space: nowrap; font-family: inherit; }
.topbar .menu-btn:hover, .topbar .menu.open .menu-btn { background: #1f2937; }
.topbar .menu-btn.active { background: #374151; color: #fff; }
.topbar .caret { font-size: 10px; opacity: .7; }
.topbar .menu-list { display: none; position: absolute; top: 100%; left: 0; min-width: 210px; background: #1f2937; border: 1px solid #374151; border-radius: 8px; padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.3); z-index: 20; flex-direction: column; gap: 2px; }
.topbar .menu:hover .menu-list, .topbar .menu.open .menu-list { display: flex; }
.topbar .menu-list a { display: block; padding: 8px 10px; font-size: 14px; }
@media (max-width: 760px) { .topbar { height: auto; min-height: 52px; flex-wrap: wrap; padding: 6px 12px; } }

/* Drawer: side panel sliding in from the right (App.drawer in app.js) */
.drawer-veil { position: fixed; inset: 0; background: rgba(17,24,39,.28); opacity: 0; transition: opacity .18s; z-index: 50; }
.drawer-veil.open { opacity: 1; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); background: #fff; box-shadow: -12px 0 32px rgba(0,0,0,.18); transform: translateX(100%); transition: transform .18s ease-out; z-index: 51; display: flex; flex-direction: column; outline: none; }
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: flex-start; gap: 10px; padding: 14px 18px 10px; border-bottom: 1px solid #e5e7eb; }
.drawer-titles { flex: 1; min-width: 0; } .drawer-title { margin: 0; font-size: 18px; overflow-wrap: anywhere; } .drawer-sub { font-size: 13px; margin-top: 2px; }
.drawer-close { border: 0; background: none; font-size: 28px; line-height: 1; cursor: pointer; color: #6b7280; padding: 0 6px; } .drawer-close:hover { color: #111827; }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 18px 24px; }
@media (max-width: 640px) { .drawer { width: 100vw !important; } }

/* CA et charges sur le même graphique : deux colonnes par période */
.vbar .vpair { flex: 1; width: 100%; display: flex; gap: 2px; align-items: flex-end; }
.vbar .vpair span { flex: 1; display: block; border-radius: 3px 3px 0 0; min-height: 0; }
.vbar .vpair .vca { background: #2563eb; } .vbar .vpair .vch { background: #f59e0b; }
.vbar .vv2 { font-size: 11px; height: 16px; white-space: nowrap; color: #6b7280; }
.vbar .vv2.neg { color: #b91c1c; } .vbar .vv2.pos { color: #15803d; }
.legend i.vca { background: #2563eb; } .legend i.vch { background: #f59e0b; }
