/* ===== Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --accent: #1f4e79;
  --accent-light: #2e74b5;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #dde3ea;
  --text: #24292f;
  --muted: #6b7280;
  --green: #1a7f37;
  --green-bg: #dafbe1;
  --orange: #b35900;
  --orange-bg: #fff1e0;
  --red: #cf222e;
  --red-bg: #ffebe9;
  --grey-bg: #eaeef2;
}
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
#app { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
#sidebar { width: 220px; background: var(--accent); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { padding: 18px 16px 14px; border-bottom: 1px solid rgba(255,255,255,.15); }
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11px; opacity: .7; margin-top: 2px; }
#sidebar nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.nav-link { display: block; padding: 10px 16px; color: rgba(255,255,255,.85); text-decoration: none; font-size: 13.5px; border-left: 3px solid transparent; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.14); color: #fff; border-left-color: #fff; font-weight: 600; }
.sidebar-footer { padding: 10px 16px; font-size: 11px; opacity: .6; }

/* ===== Main ===== */
#main { flex: 1; padding: 24px 28px; max-width: 1200px; }
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.view-header h1 { font-size: 21px; color: var(--accent); }
.view-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Cards / sections ===== */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 15px; color: var(--accent); margin-bottom: 12px; }
.card h3 { font-size: 13.5px; color: var(--accent-light); margin: 10px 0 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ===== Stat tiles ===== */
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; cursor: pointer; }
.stat:hover { border-color: var(--accent-light); }
.stat .stat-label { font-size: 12px; color: var(--muted); }
.stat .stat-value { font-size: 22px; font-weight: 700; color: var(--accent); margin-top: 4px; }
.stat .stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stat.warn .stat-value { color: var(--orange); }
.stat.danger .stat-value { color: var(--red); }

/* ===== Tables ===== */
table.list { width: 100%; border-collapse: collapse; background: var(--card); }
table.list th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--border); white-space: nowrap; }
table.list td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover { background: #f0f6ff; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 24px; text-align: center; color: var(--muted); font-style: italic; }

/* ===== Badges (pastilles) ===== */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.grey { background: var(--grey-bg); color: var(--muted); }
.badge.blue { background: #ddf4ff; color: #0969da; }

/* ===== Buttons ===== */
.btn { display: inline-block; padding: 7px 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--text); font-size: 13px; cursor: pointer; text-decoration: none; font-family: inherit; }
.btn:hover { border-color: var(--accent-light); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-light); color: #fff; }
.btn.danger { color: var(--red); border-color: #f1b8bc; }
.btn.danger:hover { background: var(--red-bg); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== Forms ===== */
label.field { display: block; margin-bottom: 12px; }
label.field span.lbl { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13.5px; font-family: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(46,116,181,.3); border-color: var(--accent-light); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }
.search-bar { margin-bottom: 14px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search-bar input[type=text] { max-width: 300px; }
.search-bar select { width: auto; }
.checkbox-line { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 13.5px; }
.checkbox-line input { width: auto; }

/* ===== Modal ===== */
#modal-root:empty { display: none; }
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; padding: 22px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal h2 { font-size: 17px; color: var(--accent); margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ===== Toast ===== */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #24292f; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.25); animation: toastin .2s ease; max-width: 380px; }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Divers ===== */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.amount.pos { color: var(--green); }
.amount.neg { color: var(--red); }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.right { text-align: right; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.client-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.kpi-inline { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 8px; }
.kpi-inline .kpi { font-size: 13px; }
.kpi-inline .kpi b { font-size: 17px; display: block; }
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.alert.warn { background: var(--orange-bg); color: var(--orange); border: 1px solid #f0cfa0; }
.alert.info { background: #ddf4ff; color: #0969da; border: 1px solid #b6e3ff; }
.alert.error { background: var(--red-bg); color: var(--red); border: 1px solid #f1b8bc; }
.breadcrumb { font-size: 12.5px; margin-bottom: 12px; }
.breadcrumb a { color: var(--accent-light); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.lines-editor table { width: 100%; border-collapse: collapse; }
.lines-editor th { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 6px 6px; }
.lines-editor td { padding: 4px 6px; }
.lines-editor input, .lines-editor select { padding: 6px 8px; font-size: 13px; }
.totals-box { margin-top: 12px; margin-left: auto; width: 260px; font-size: 13.5px; }
.totals-box .tr { display: flex; justify-content: space-between; padding: 4px 0; }
.totals-box .tr.total { font-weight: 700; font-size: 15px; border-top: 2px solid var(--border); margin-top: 4px; padding-top: 8px; color: var(--accent); }
.drop-zone { border: 2px dashed var(--border); border-radius: 10px; padding: 30px; text-align: center; color: var(--muted); cursor: pointer; }
.drop-zone:hover, .drop-zone.drag { border-color: var(--accent-light); background: #f0f6ff; }
.import-report { max-height: 300px; overflow-y: auto; font-size: 12.5px; }
.import-report li { margin-left: 18px; margin-bottom: 3px; }
/* ===== Statistiques : barres CA ===== */
.bar-row { display: grid; grid-template-columns: 90px 1fr 110px; align-items: center; gap: 10px; padding: 4px 0; }
.bar-row .bar-label { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.bar-row .bar-track { position: relative; height: 18px; }
.bar-row .bar-fill { position: absolute; left: 0; top: 2px; height: 14px; background: var(--accent-light); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .bar-value { font-size: 12.5px; text-align: right; font-variant-numeric: tabular-nums; }
.bar-row:hover .bar-fill { background: var(--accent); }

@media print { #sidebar, .view-header .actions, .no-print { display: none !important; } #main { padding: 0; } }
