:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1c2433; --muted: #6b7587; --line: #e3e7ee;
  --nav: #13233a; --nav-ink: #c7d2e3; --accent: #1b6ef3;
  --in: #16875c; --in-bg: #e7f5ee; --out: #c93c4f; --out-bg: #fbecee; --warn: #b7791f; --warn-bg: #fdf4e3;
  --future: #f7f9fc; --current: #eef4ff;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--in); } .neg { color: var(--out); }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--nav); color: var(--nav-ink); padding: 18px 0; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 0 18px 18px; border-bottom: 1px solid #22385a; margin-bottom: 10px; }
.sidebar .brand img { max-width: 150px; background: #fff; border-radius: 6px; padding: 4px 8px; }
.sidebar .brand div { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; margin-top: 8px; color: #8fa3c2; }
.sidebar a { display: block; color: var(--nav-ink); padding: 9px 18px; border-left: 3px solid transparent; }
.sidebar a:hover { background: #1a2f4d; text-decoration: none; }
.sidebar a.active { background: #1d3659; color: #fff; border-left-color: #4d9bff; }
.sidebar .sep { height: 1px; background: #22385a; margin: 10px 0; }
.sidebar .foot { padding: 12px 18px; font-size: 12px; color: #8fa3c2; }
.sidebar .foot a { display: inline; padding: 0; border: 0; }
.sidebar .foot a:hover { background: none; text-decoration: underline; }
.main { flex: 1; padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

/* Components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(4, 1fr); margin-bottom: 18px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 600; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 1100px) { .two { grid-template-columns: 1fr; } }
.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.btn:hover { background: #f0f3f8; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #135bd0; }
.btn.danger { color: var(--out); }
.btn.small { padding: 3px 8px; font-size: 12px; }
input, select { font: inherit; padding: 6px 8px; border: 1px solid #cfd6e1; border-radius: 6px; background: #fff; }
input:focus, select:focus { outline: 2px solid #b8d3ff; border-color: var(--accent); }
form.inline { display: inline; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; background: #eef1f6; color: var(--muted); white-space: nowrap; }
.tag.reel { background: var(--in-bg); color: var(--in); }
.tag.engage { background: var(--warn-bg); color: var(--warn); }
.tag.late { background: var(--out-bg); color: var(--out); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.ok { background: var(--in-bg); color: #0d5c3e; }
.flash.error { background: var(--out-bg); color: #8c1d2c; }
.flash.warn { background: var(--warn-bg); color: #7a4d0a; }

/* Tables */
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; background: #fafbfd; }
tbody tr:hover { background: #fafcff; }
.table-wrap { overflow-x: auto; }

/* Plan de trésorerie */
.plan { font-size: 13px; }
.plan th, .plan td { border-right: 1px solid var(--line); }
.plan th.m { text-align: right; min-width: 104px; }
.plan .lbl { position: sticky; left: 0; background: #fff; min-width: 230px; z-index: 1; }
.plan th.lbl { background: #fafbfd; }
.plan .past { }
.plan .current { background: var(--current); }
.plan .future { background: var(--future); }
.plan tr.section td { background: #eef1f6; font-weight: 700; }
.plan tr.section td.lbl { text-transform: uppercase; font-size: 12px; letter-spacing: .04em; }
.plan tr.section td.lbl { background: #eef1f6; }
.plan tr.total td { font-weight: 700; background: #f6f8fb; }
.plan tr.total td.lbl { background: #f6f8fb; }
.plan tr.balance td { font-weight: 700; font-size: 14px; }
.plan tr.balance.end td { border-top: 2px solid var(--ink); }
.plan tr.cat td.lbl { font-weight: 600; }
.plan tr.cat.sub td.lbl { font-weight: 400; }
.plan td.cell { text-align: right; cursor: pointer; font-variant-numeric: tabular-nums; }
.plan td.cell:hover { outline: 2px solid #b8d3ff; outline-offset: -2px; }
.plan .main-v { font-weight: 600; }
.plan .sub-v { display: block; font-size: 11px; color: var(--muted); white-space: nowrap; }
.plan .ecart-pos { color: var(--in); } .plan .ecart-neg { color: var(--out); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border: 1px solid var(--line); margin-right: 5px; vertical-align: -2px; }
.legend .l-past::before { background: #fff; } .legend .l-cur::before { background: var(--current); } .legend .l-fut::before { background: var(--future); }

/* Budget */
.budget input { width: 86px; text-align: right; padding: 4px 6px; }
.budget td.lbl { min-width: 220px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(15, 25, 40, .45); display: none; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 50; }
.modal.open { display: flex; }
.modal .box { background: #fff; border-radius: 12px; max-width: 1200px; width: 100%; max-height: 80vh; overflow: auto; padding: 18px 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }

/* Login */
.login { max-width: 360px; margin: 12vh auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login img { max-width: 180px; display: block; margin: 0 auto 16px; }
.login input { width: 100%; margin-bottom: 12px; padding: 9px 10px; }
.login .btn { width: 100%; padding: 10px; }

.chart-box { position: relative; height: 320px; }
.bar-mini { height: 6px; background: #e8ecf3; border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar-mini span { display: block; height: 100%; background: var(--accent); }
@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; display: flex; flex-wrap: wrap; padding: 8px; }
  .sidebar .brand, .sidebar .sep, .sidebar .foot { display: none; }
  .sidebar a { padding: 6px 10px; border-left: 0; }
  .main { padding: 16px; }
}

.modal td { word-break: break-word; }
select.cat-sel { max-width: 200px; }
