:root {
  --blue-900: #0b2545;
  --blue-700: #14416b;
  --blue-600: #1e6fd9;
  --blue-500: #2f86e6;
  --blue-100: #e7f0fc;
  --green-600: #0f9d6e;
  --green-500: #16b585;
  --green-100: #e2f6ef;
  --ink: #1b2733;
  --muted: #64748b;
  --line: #e6ebf1;
  --bg: #f4f7fb;
  --card: #ffffff;
  --amber: #d99413;
  --amber-100: #fdf2dd;
  --red: #d9534f;
  --red-100: #fbe6e5;
  --gray-100: #eef2f7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 34, 60, .06), 0 8px 24px rgba(16, 34, 60, .06);
  --shadow-sm: 0 1px 2px rgba(16, 34, 60, .08);
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* Bandeau démo */
.demo-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 30px;
  z-index: 60;
  background: linear-gradient(90deg, var(--blue-900), var(--blue-700));
  color: #cfe2ff;
  font-size: 12.5px;
  letter-spacing: .2px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.demo-banner .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green-500);
  box-shadow: 0 0 0 3px rgba(22,181,133,.25);
}

/* Shell */
.app-shell {
  display: flex;
  padding-top: 30px;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--blue-900), var(--blue-700));
  color: #dbe7f5;
  position: fixed;
  top: 30px; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: transform .25s ease;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--blue-500), var(--green-500));
  display: grid; place-items: center;
  font-weight: 800; font-size: 20px; color: #fff;
}
.brand-text strong { display: block; font-size: 17px; color: #fff; }
.brand-text small { color: #9db8d6; font-size: 11.5px; }

.nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px;
  color: #789ac2; margin: 14px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px;
  color: #cddcef; font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background .15s, color .15s;
}
.nav-item .ic { width: 20px; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(47,134,230,.28); color: #fff; box-shadow: inset 3px 0 0 var(--green-500); }
.nav-item em {
  margin-left: auto; font-style: normal; font-size: 9.5px;
  background: rgba(255,255,255,.12); color: #a9c4e4;
  padding: 2px 7px; border-radius: 20px;
}
.nav-item.soon { opacity: .78; }

.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user { display: flex; align-items: center; gap: 11px; }
.user .avatar {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--green-600); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.user strong { display: block; font-size: 13px; color: #fff; }
.user small { color: #9db8d6; font-size: 11px; }

/* Main */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky; top: 30px; z-index: 30;
  background: rgba(244,247,251,.85);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 14px;
  padding: 14px 26px;
  border-bottom: 1px solid var(--line);
}
.page-title { font-size: 20px; margin: 0; font-weight: 700; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.search-mini {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; box-shadow: var(--shadow-sm);
}
.search-mini input { border: none; outline: none; font-size: 13.5px; width: 170px; background: transparent; }

.burger {
  display: none; flex-direction: column; gap: 4px;
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 8px; cursor: pointer;
}
.burger span { width: 20px; height: 2px; background: var(--ink); border-radius: 2px; }

.content { padding: 24px 26px 60px; }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 15px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: transform .05s, box-shadow .15s, background .15s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }
.btn-primary:hover { background: var(--blue-500); }
.btn-green { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.btn-green:hover { background: var(--green-500); }
.btn-ghost { background: transparent; box-shadow: none; }

/* Cards */
.grid { display: grid; gap: 18px; }
.kpi-grid { grid-template-columns: repeat(4, 1fr); }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.kpi { display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; }
.kpi .kpi-icon {
  position: absolute; right: 14px; top: 14px; font-size: 22px; opacity: .5;
}
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi .value { font-size: 27px; font-weight: 800; letter-spacing: -.5px; }
.kpi .trend { font-size: 12px; font-weight: 600; }
.kpi .trend.up { color: var(--green-600); }
.kpi .trend.down { color: var(--red); }
.kpi.accent-blue { border-top: 3px solid var(--blue-600); }
.kpi.accent-green { border-top: 3px solid var(--green-600); }
.kpi.accent-amber { border-top: 3px solid var(--amber); }
.kpi.accent-ink { border-top: 3px solid var(--blue-900); }

.section-title { font-size: 15px; font-weight: 700; margin: 0 0 4px; }
.section-sub { font-size: 12.5px; color: var(--muted); margin: 0 0 14px; }

.two-col { grid-template-columns: 1.6fr 1fr; align-items: start; }

/* Chart */
.chart { width: 100%; height: 240px; }
.bar { transition: opacity .15s; cursor: pointer; }
.bar:hover { opacity: .82; }

/* Table */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; color: var(--muted); font-weight: 600;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
table.data td { padding: 13px 14px; border-bottom: 1px solid var(--line); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #fafcff; }
.mono { font-variant-numeric: tabular-nums; font-family: "SF Mono", ui-monospace, Menlo, monospace; }
.amount { font-weight: 700; text-align: right; }
th.right, td.right { text-align: right; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-draft   { background: var(--gray-100); color: #64748b; }
.b-sent    { background: var(--blue-100); color: var(--blue-600); }
.b-paid    { background: var(--green-100); color: var(--green-600); }
.b-unpaid  { background: var(--red-100); color: var(--red); }
.tag {
  display: inline-block; padding: 3px 9px; border-radius: 7px;
  font-size: 11px; font-weight: 600; background: var(--blue-100); color: var(--blue-700);
}
.tag.g { background: var(--green-100); color: var(--green-600); }
.tag.a { background: var(--amber-100); color: var(--amber); }

/* Toolbar (filters) */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px;
}
.toolbar .search {
  flex: 1; min-width: 200px; display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 13px; box-shadow: var(--shadow-sm);
}
.toolbar .search input { border: none; outline: none; width: 100%; font-size: 13.5px; }
select, input[type="text"], input[type="number"], input[type="date"] {
  font-family: inherit;
}
.select {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 13px; font-size: 13.5px; box-shadow: var(--shadow-sm); cursor: pointer;
}

/* Retards list */
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: none; }
.list-row .who strong { display: block; font-size: 13.5px; }
.list-row .who small { color: var(--muted); font-size: 12px; }
.list-row .late { margin-left: auto; text-align: right; }
.list-row .late .n { font-weight: 700; }
.list-row .late small { color: var(--red); font-size: 11.5px; }

/* Invoice editor */
.editor { grid-template-columns: 1.15fr .85fr; align-items: start; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 14px; outline: none; background: #fff;
}
.field input:focus, .field select:focus { border-color: var(--blue-500); box-shadow: 0 0 0 3px var(--blue-100); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.lines th, .lines td { padding: 8px; }
.lines input, .lines select { width: 100%; padding: 8px 9px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.lines input.qty, .lines input.pu { text-align: right; }
.line-total { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.icon-btn { border: none; background: var(--red-100); color: var(--red); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-weight: 700; }

.totals { margin-top: 8px; margin-left: auto; width: 280px; }
.totals .row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; }
.totals .row.grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 12px; font-size: 18px; font-weight: 800; }
.totals .row .lbl { color: var(--muted); }

.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* PDF preview */
.pdf-preview {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 0; position: sticky; top: 96px; overflow: hidden;
}
.pdf-head { background: var(--gray-100); padding: 8px 14px; font-size: 11.5px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
.pdf-body { padding: 26px; font-size: 12.5px; }
.pdf-body .p-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.pdf-body h2 { margin: 0; font-size: 26px; letter-spacing: 3px; color: var(--blue-900); }
.pdf-logo { width: 40px; height: 40px; border-radius: 9px; background: linear-gradient(135deg, var(--blue-600), var(--green-500)); display: grid; place-items: center; color: #fff; font-weight: 800; }
.pdf-body .muted { color: var(--muted); }
.pdf-table { width: 100%; border-collapse: collapse; margin: 18px 0; }
.pdf-table th { text-align: left; font-size: 10.5px; color: var(--muted); border-bottom: 1px solid var(--line); padding: 6px 4px; }
.pdf-table td { padding: 7px 4px; border-bottom: 1px solid #f1f4f8; font-size: 12px; }
.pdf-table td.r, .pdf-table th.r { text-align: right; }
.pdf-tot { margin-left: auto; width: 200px; }
.pdf-tot .row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12px; }
.pdf-tot .row.g { font-weight: 800; font-size: 15px; border-top: 1.5px solid var(--ink); margin-top: 4px; padding-top: 8px; }

/* Documents / GED */
.ged { grid-template-columns: 230px 1fr; align-items: start; }
.folders { list-style: none; margin: 0; padding: 0; }
.folders li {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 10px; cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--ink);
}
.folders li:hover { background: var(--blue-100); }
.folders li.active { background: var(--blue-100); color: var(--blue-700); font-weight: 700; }
.folders li .count { margin-left: auto; font-size: 11px; color: var(--muted); background: var(--gray-100); padding: 1px 8px; border-radius: 20px; }

.doc-item { display: flex; align-items: center; gap: 14px; padding: 14px; border-bottom: 1px solid var(--line); }
.doc-item:last-child { border-bottom: none; }
.doc-ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 18px; flex-shrink: 0; }
.doc-ic.pdf { background: var(--red-100); }
.doc-ic.dev { background: var(--amber-100); }
.doc-ic.ctr { background: var(--green-100); }
.doc-meta strong { display: block; font-size: 14px; }
.doc-meta small { color: var(--muted); font-size: 12px; }
.doc-tags { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.doc-dl { margin-left: 8px; }

/* Placeholder screen */
.placeholder { text-align: center; padding: 70px 20px; color: var(--muted); }
.placeholder .big { font-size: 46px; margin-bottom: 10px; }

.overlay {
  display: none;
  position: fixed; inset: 30px 0 0 0; background: rgba(11,37,69,.45); z-index: 40;
}

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--blue-900); color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow); opacity: 0;
  transition: opacity .2s, transform .2s; z-index: 80; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Responsive */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col, .editor, .ged { grid-template-columns: 1fr; }
  .pdf-preview { position: static; }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .burger { display: flex; }
  .overlay.show { display: block; }
  .search-mini { display: none; }
  .topbar { padding: 12px 16px; }
  .content { padding: 18px 16px 60px; }
}
@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .topbar-actions .btn { display: none; }
  .page-title { font-size: 17px; }
}
