/* ==========================================================================
   Couleurs Opale Corse (bleu du logo #0071ce, noir, blanc)
   ========================================================================== */
:root {
  --brand: #0071ce;
  --brand-hover: #005ca8;
  --brand-soft: #e6f1fb;
  --brand-text: #00539a;
  --on-brand: #ffffff;
}

/* ==========================================================================
   Jetons de l'interface
   ========================================================================== */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef1f4;
  --text: #1a1a1a;
  --text-2: #5c5c57;
  --text-3: #8a8a84;
  --border: rgba(0, 0, 0, .10);
  --border-strong: rgba(0, 0, 0, .18);

  --danger: #c0392b;  --danger-bg: #fbeaea;  --danger-text: #8f2a20;
  --warning: #d4940f; --warning-bg: #fcf1dc; --warning-text: #7a5207;
  --success: #3b8a3e; --success-bg: #e8f3e3; --success-text: #2a6330;

  --radius: 8px;
  --radius-lg: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; font-weight: 600; margin: 0 0 16px; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; margin: 0; }
p { margin: 0; }
[hidden] { display: none !important; }

.muted { color: var(--text-3); }
.sub { font-size: 13px; color: var(--text-2); }
.strong { font-weight: 600; }
.mono { font-family: var(--mono); font-size: 13px; }
.pre { white-space: pre-line; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.text-danger { color: var(--danger); }
.inline { display: inline; margin: 0; }

/* ---------- Barre du haut ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text); font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: block; }
.brand-name { font-weight: 600; letter-spacing: .02em; }
.brand-name span { color: var(--brand); }
.brand-logo { display: block; width: 260px; max-width: 100%; height: auto; margin: 0 auto 8px; }
.brand-tag { text-align: center; color: var(--text-2); font-size: 14px; margin-bottom: 20px; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a { white-space: nowrap; padding: 6px 12px; border-radius: var(--radius); color: var(--text-2); font-size: 14px; }
.nav a:hover { background: var(--surface-soft); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.topbar-search { margin-left: auto; flex: 0 1 220px; min-width: 110px; }
.topbar-search input { width: 100%; }
@media (max-width: 1100px) {
  .topbar-inner { gap: 12px; }
  .topbar-user .btn-sm:not(.btn-ghost) { display: none; }
  .nav a { padding: 6px 9px; }
}
.topbar-user { display: flex; gap: 6px; align-items: center; }

.container { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }

/* ---------- Boutons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
  cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-soft); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Formulaires ---------- */
input[type=text], input[type=search], input[type=email], input[type=tel], input[type=password], input[type=date], input:not([type]),
select, textarea {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 0 10px; height: 36px; width: 100%; min-width: 0; }
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.filters select, .filters input { width: auto; }
.filters input.grow { flex: 1; min-width: 200px; }

.form h2 { margin: 24px 0 12px; font-size: 15px; color: var(--text-2); }
.form h2:first-of-type { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field label, .field .label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.req { color: var(--danger); }
.help { font-size: 12px; color: var(--text-3); }
.error { font-size: 12px; color: var(--danger); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px !important; font-weight: 400 !important; color: var(--text) !important; cursor: pointer; }
.check.small { font-size: 12px !important; color: var(--text-2) !important; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.form { max-width: 900px; }

/* ---------- Mise en page ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.count { font-size: 15px; font-weight: 400; color: var(--text-3); margin-left: 6px; }
.breadcrumb { font-size: 13px; color: var(--text-2); margin-bottom: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.breadcrumb span { color: var(--text-3); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--border); font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; }
.metric-label { font-size: 13px; color: var(--text-2); }
.metric-value { font-size: 26px; font-weight: 600; margin-top: 2px; letter-spacing: -.01em; }
.metric-value-sm { font-size: 20px; padding: 3px 0; }
.metric-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.segmented a { padding: 5px 12px; font-size: 13px; color: var(--text-2); border-left: 1px solid var(--border); }
.segmented a:first-child { border-left: 0; }
.segmented a:hover { background: var(--surface-soft); text-decoration: none; }
.segmented a.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius); background: var(--surface); font-size: 14px; cursor: pointer; }
.toggle input { accent-color: var(--brand); }
.toggle.active { background: var(--warning-bg); color: var(--warning-text); border-color: transparent; }

/* ---------- Listes ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); font-size: 14px; }
.list-row.inactive { opacity: .55; }
.list-indent .list-row { padding-left: 14px; }
.amount { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.date-col { width: 86px; flex: none; font-size: 13px; color: var(--text-2); }
.empty { color: var(--text-3); font-size: 14px; padding: 12px 0 4px; }
.empty-sm { padding: 6px 0 6px 14px; font-size: 13px; }
.empty-state { text-align: center; padding: 40px 20px; }
.empty-state h1, .empty-state h2 { margin-bottom: 8px; }
.empty-state p { color: var(--text-2); margin-bottom: 16px; }

.pill { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.pill-danger { background: var(--danger-bg); color: var(--danger-text); }
.pill-warning { background: var(--warning-bg); color: var(--warning-text); }
.pill-success { background: var(--success-bg); color: var(--success-text); }
.pill-accent { background: var(--brand-soft); color: var(--brand-text); }
.pill-muted { background: var(--surface-soft); color: var(--text-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.dot-danger { background: var(--danger); } .dot-warning { background: var(--warning); } .dot-success { background: var(--success); }
.legend { display: flex; gap: 16px; color: var(--text-2); font-size: 12px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Tableaux ---------- */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 500; color: var(--text-2); padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr:hover { background: #f7f9fb; }
.table tfoot td { border-top: 1px solid var(--border-strong); border-bottom: 0; font-size: 13px; }
.table tr.inactive td { opacity: .55; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.sort { color: inherit; }
.sort.active { color: var(--text); font-weight: 600; }
.actions-cell { text-align: right; white-space: nowrap; }

/* ---------- Fiche client ---------- */
.client-head { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.client-head h1 { margin: 0; }
.title-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-soft); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; color: var(--text-2); }
.avatar-lg { width: 56px; height: 56px; font-size: 18px; background: var(--brand-soft); color: var(--brand-text); }
.kv { margin: 0; }
.kv > div { display: flex; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); font-size: 14px; }
.kv dt { width: 120px; flex: none; color: var(--text-2); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.notes { margin-top: 12px; padding: 10px 12px; background: var(--surface-soft); border-radius: var(--radius); font-size: 13px; color: var(--text-2); }
.site { border-top: 1px solid var(--border); padding: 12px 0 4px; scroll-margin-top: 80px; }
.site:target { background: linear-gradient(var(--brand-soft), var(--brand-soft)) no-repeat; background-size: 4px 100%; padding-left: 12px; }
.site-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.acces { margin: 10px 0 4px; padding: 10px 12px; background: var(--surface-soft); border-radius: var(--radius); font-size: 13px; display: grid; gap: 6px; }
.acces .k { display: inline-block; width: 86px; color: var(--text-2); }
.note-form { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.note-form textarea { flex: 1; }
.danger-zone { display: flex; justify-content: flex-end; margin-top: 8px; }

/* ---------- Messages ---------- */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.flash-success { background: var(--success-bg); color: var(--success-text); }
.flash-error { background: var(--danger-bg); color: var(--danger-text); }
.flash-action { font-weight: 600; margin-left: 6px; color: inherit; text-decoration: underline; }
.flash-info { background: var(--brand-soft); color: var(--brand-text); }

/* ---------- Connexion ---------- */
.auth { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-card { display: grid; gap: 14px; padding: 24px; }
.auth-card h1 { font-size: 20px; margin: 0; }
.install-box { max-width: 560px; }
.auth-card-flat { padding: 0; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .topbar-inner { padding: 10px 16px; gap: 10px; }
  .topbar-search { order: 5; width: 100%; flex: 1 1 100%; margin: 0; }
  .topbar-search input { width: 100%; }
  .topbar-user { margin-left: auto; }
  .topbar-user .btn-sm:not(.btn-ghost) { display: none; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric { padding: 12px; }
  .metric-value { font-size: 21px; }
  .metric-value-sm { font-size: 17px; }
  h1 { font-size: 21px; }
  .nav { order: 4; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .container { padding: 16px 16px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 14px 16px; }
  .list-row { flex-wrap: wrap; row-gap: 6px; }
  .list-row > .grow { flex: 1 1 calc(100% - 50px); }
  .list-indent .list-row > .grow + .amount { margin-left: 0; }
  .nav { scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .client-head { gap: 12px; }
  .client-head .grow { flex: 1 1 calc(100% - 72px); }
  .client-head .actions { width: 100%; }
  .client-head .actions .btn { flex: 1; justify-content: center; }
  .avatar-lg { width: 48px; height: 48px; font-size: 16px; }
  .kv dt { width: 100px; }
  .date-col { width: auto; }
}

/* ---------- Lot 2 : factures et chiffres ---------- */
.output-value { display: flex; align-items: center; height: 36px; font-size: 18px; font-weight: 600; }
.metric-up { color: var(--success-text); }
.metric-down { color: var(--danger-text); }
.chart { width: 100%; height: auto; display: block; }
.chart .bar-current { fill: var(--brand); }
.chart .bar-prev { fill: #dcdcd6; }
.chart .axis { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart .val { fill: var(--text-2); font-size: 10px; font-family: var(--font); }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch-current { background: var(--brand); }
.swatch-prev { background: #dcdcd6; }
.metric-link { color: inherit; display: block; }
.metric-link:hover { text-decoration: none; border-color: var(--border-strong); }
.grid-2 { margin-bottom: 16px; }
.pill-outline { background: transparent; color: var(--text-2); box-shadow: inset 0 0 0 1px var(--border-strong); }
.field-sub { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; padding-left: 24px; }
.field-sub label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.notice { padding: 10px 14px; border-radius: var(--radius); background: var(--brand-soft); color: var(--brand-text); font-size: 14px; margin-bottom: 16px; }
.pills { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }
.forfait { margin-top: 20px; }
.forfait .help { margin: -6px 0 10px; }
.elements { display: grid; gap: 8px; margin-bottom: 10px; max-width: 640px; }
.element-row { display: grid; grid-template-columns: 180px 1fr 36px; gap: 8px; align-items: center; }
.pill-sm { font-size: 11px; padding: 1px 8px; }
.elements-inline { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
@media (max-width: 760px) { .element-row { grid-template-columns: 1fr 1fr 36px; } }
