/* ==========================================================================
   Design system
   Tokens first; the agency brand colour (--brand) drives accents and primary
   buttons. Chart series keep the validated data-viz palette (see dataviz skill).
   ========================================================================== */

.viz-root {
  color-scheme: light;
  --page: #f4f5f8;
  --surface-1: #ffffff;
  --surface-2: #f8f9fb;
  --text-primary: #101828;
  --text-secondary: #475467;
  --text-muted: #667085;
  --grid: #eaecf0;
  --axis: #d0d5dd;
  --border: #e4e7ec;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 24px -6px rgba(16, 24, 40, .14);
  --accent: var(--brand, #2a78d6);
  --accent-text: var(--brand-text, #ffffff);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --series-1: #2a78d6;
  --good: #0ca30c;
  --good-text: #067647;
  --danger: #d03b3b;
  --danger-text: #b42318;
  --danger-soft: #fef3f2;
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: #0f1729;
  --sidebar-text: #c4cbd8;
  --sidebar-muted: #8b95a7;
  --mrr-new: #2a78d6; --mrr-expansion: #1baf7a; --mrr-reactivation: #6250d6; --mrr-contraction: #eda100; --mrr-churn: #e87ba4;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --page: #0c0e12; --surface-1: #16181d; --surface-2: #1c1f25;
    --text-primary: #f2f4f7; --text-secondary: #c2c7d0; --text-muted: #8f97a3;
    --grid: #262a31; --axis: #363b45; --border: #2a2e36;
    --shadow-sm: none; --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 16px 32px rgba(0, 0, 0, .5);
    --series-1: #3987e5; --good-text: #3ccb7f; --danger-text: #f97066; --danger-soft: #2a1414;
    --sidebar: #0a0c10;
    --mrr-new: #3987e5; --mrr-expansion: #199e70; --mrr-reactivation: #9085e9; --mrr-contraction: #c98500; --mrr-churn: #d55181;
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --page: #0c0e12; --surface-1: #16181d; --surface-2: #1c1f25;
  --text-primary: #f2f4f7; --text-secondary: #c2c7d0; --text-muted: #8f97a3;
  --grid: #262a31; --axis: #363b45; --border: #2a2e36;
  --shadow-sm: none; --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 16px 32px rgba(0, 0, 0, .5);
  --series-1: #3987e5; --good-text: #3ccb7f; --danger-text: #f97066; --danger-soft: #2a1414;
  --sidebar: #0a0c10;
  --mrr-new: #3987e5; --mrr-expansion: #199e70; --mrr-reactivation: #9085e9; --mrr-contraction: #c98500; --mrr-churn: #d55181;
}

/* --- Typeface: Inter (self-hosted, OFL licence in static/fonts) ------------- */
@font-face {
  font-family: "Inter";
  src: url("../fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

/* --- Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01", "ss03";
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; line-height: 1.25; letter-spacing: -.02em; margin: 0 0 .25rem; }
h2 { font-size: 1.02rem; letter-spacing: -.01em; margin: 0 0 .25rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
:not(pre) > code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: .05rem .3rem; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .9rem 1rem; overflow-x: auto; margin: .5rem 0; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--text-secondary); }
.small { font-size: .85rem; }
.center { text-align: center; }
.subtitle { color: var(--text-secondary); font-size: .88rem; margin: 0; }
.empty { color: var(--text-muted); font-size: .9rem; margin: .75rem 0 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- App shell ------------------------------------------------------------ */
.has-sidebar { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.app-main { min-width: 0; }
main { max-width: 1180px; margin: 0 auto; padding: 1.75rem 2rem 4rem; }
main.narrow { max-width: 440px; padding-top: 3rem; }

.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1rem;
  padding: 1.1rem .85rem; background: var(--sidebar); color: var(--sidebar-text); overflow-y: auto;
  border-right: 1px solid rgba(255, 255, 255, .06);
}
.sidebar-brand { color: #fff; padding: .3rem .5rem; text-decoration: none !important; }
.sidebar-brand .brand { font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.brand { display: inline-flex; align-items: center; gap: .6rem; }
.brand::before { content: ""; width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #000)); flex: none; }
.brand:has(.brand-logo)::before { display: none; }
.brand-logo { height: 28px; width: auto; max-width: 150px; object-fit: contain; }

.switcher { position: relative; border: 1px solid rgba(255, 255, 255, .1); border-radius: var(--radius-sm); background: rgba(255, 255, 255, .04); }
.switcher summary, .switcher.static { display: grid; grid-template-columns: 1fr auto; padding: .5rem .7rem; cursor: pointer; list-style: none; }
.switcher summary::-webkit-details-marker { display: none; }
.switcher-label { grid-column: 1; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--sidebar-muted); }
.switcher-name { grid-column: 1; color: #fff; font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher summary .icon { grid-column: 2; grid-row: 1 / 3; align-self: center; color: var(--sidebar-muted); }
.switcher-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 20; padding: .35rem;
  background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.switcher-menu form { margin: 0; }
.menu-item {
  display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: .45rem .6rem; border: 0; border-radius: 6px;
  background: none; color: var(--text-primary); font: inherit; font-size: .88rem; text-align: left; cursor: pointer;
}
.menu-item span { font-size: .75rem; color: var(--text-muted); }
.menu-item:hover { background: var(--surface-2); }
.menu-item[aria-current] { font-weight: 600; background: var(--accent-soft); }

.sidebar-nav { display: grid; gap: .15rem; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: var(--radius-sm);
  color: var(--sidebar-text); font-size: .92rem; font-weight: 500; text-decoration: none; position: relative;
}
.sidebar-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar-nav a[aria-current="page"] { background: rgba(255, 255, 255, .1); color: #fff; }
.sidebar-nav a[aria-current="page"]::before { content: ""; position: absolute; left: -.85rem; top: .45rem; bottom: .45rem; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }

.sidebar-user { margin-top: auto; display: flex; align-items: center; gap: .6rem; padding: .7rem .5rem 0; border-top: 1px solid rgba(255, 255, 255, .08); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: .85rem; flex: none; }
.sidebar-email { flex: 1; min-width: 0; font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user form { margin: 0; }
.btn-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm); border: 0; background: transparent; color: var(--sidebar-text); cursor: pointer; }
.btn-icon:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.public-header { display: flex; align-items: center; padding: .9rem 2rem; background: var(--surface-1); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.public-header .brand { font-weight: 700; font-size: 1.05rem; }

@media (max-width: 900px) {
  .has-sidebar { display: block; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem .8rem; }
  .sidebar-nav { display: flex; overflow-x: auto; gap: .2rem; order: 3; width: 100%; }
  .sidebar-nav a { white-space: nowrap; }
  .sidebar-nav a[aria-current="page"]::before { display: none; }
  .switcher { order: 2; }
  .sidebar-user { margin: 0 0 0 auto; border: 0; padding: 0; order: 1; }
  .sidebar-email { display: none; }
  main { padding: 1.25rem 1rem 3rem; }
}

/* --- Page & site headers ---------------------------------------------------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; margin: 0 0 .75rem; font-size: .85rem; color: var(--text-muted); }
.breadcrumb a { color: var(--text-secondary); }
.site-header { margin-bottom: 1.5rem; }
.site-title { display: flex; align-items: center; gap: .85rem; margin-bottom: 1rem; }
.site-title h1 { margin: 0; }
.site-favicon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; color: var(--accent); background: var(--accent-soft); flex: none; }
.tabs { display: flex; gap: .15rem; overflow-x: auto; border-bottom: 1px solid var(--border); scrollbar-width: thin; }
.tabs a {
  display: inline-flex; align-items: center; gap: .4rem; padding: .65rem .6rem; white-space: nowrap;
  color: var(--text-secondary); font-size: .87rem; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none;
}
.tabs a .icon { width: 16px; height: 16px; }
.tabs a:hover { color: var(--text-primary); }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.section-title { margin: 1.75rem 0 .75rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); }

/* --- Buttons ---------------------------------------------------------------- */
button, .button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  font: inherit; font-size: .88rem; font-weight: 600; line-height: 1.2; padding: .55rem .95rem;
  border-radius: var(--radius-sm); border: 1px solid var(--axis); background: var(--surface-1); color: var(--text-primary);
  box-shadow: var(--shadow-sm); cursor: pointer; text-decoration: none !important; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
button:hover, .button:hover, .btn:hover { background: var(--surface-2); border-color: var(--text-muted); }
button:active, .button:active, .btn:active { transform: translateY(1px); }
button .icon, .button .icon, .btn .icon { width: 16px; height: 16px; }
button.primary, .button.primary, .btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .1), inset 0 1px 0 rgba(255, 255, 255, .12);
}
button.primary:hover, .button.primary:hover, .btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); border-color: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-sm, button.link, .button.small { font-size: .8rem; padding: .35rem .65rem; }
/* "link" buttons are real buttons too: quiet, but clearly clickable. */
button.link { background: var(--surface-2); border-color: var(--border); color: var(--text-primary); box-shadow: none; }
button.link:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
button.link.danger, .btn-danger { color: var(--danger-text); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: var(--danger-soft); }
button.link.danger:hover, .btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.copy { font-size: .78rem; padding: .3rem .6rem; }

/* --- Cards, KPIs, grids ------------------------------------------------------ */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.35rem; box-shadow: var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 1rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpis + .kpis { margin-top: -.15rem; }
.kpi-label { display: flex; align-items: center; gap: .4rem; color: var(--text-secondary); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; margin-top: .35rem; line-height: 1.15; }
.kpi-value.money { font-size: clamp(1.25rem, 2.1vw, 1.65rem); white-space: nowrap; }
.kpis .subtitle { margin-top: .35rem; font-size: .8rem; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

/* --- Filters (segmented control) --------------------------------------------- */
.filters { display: inline-flex; gap: .2rem; padding: .2rem; margin-bottom: 1.25rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.filters a { padding: .35rem .8rem; border-radius: 7px; color: var(--text-secondary); font-size: .85rem; font-weight: 500; text-decoration: none; }
.filters a:hover { color: var(--text-primary); }
.filters a[aria-current="page"] { background: var(--surface-1); color: var(--text-primary); font-weight: 600; box-shadow: var(--shadow); }

/* --- Tables -------------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: bottom; }
td { padding: .6rem .5rem; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td, table tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td form, .path form { margin: 0; }

/* --- Forms -------------------------------------------------------------------- */
.field { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .35rem; }
.field label { font-size: .86rem; font-weight: 600; color: var(--text-primary); }
.field input:not([type="checkbox"]):not([type="file"]), .field select, .field textarea,
.inline-form input, .steps-table input:not([type="checkbox"]), .steps-table select {
  font: inherit; font-size: .92rem; padding: .6rem .75rem; border-radius: var(--radius-sm); border: 1px solid var(--axis);
  background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s; width: 100%;
}
.field input:focus, .field select:focus, .inline-form input:focus, .steps-table input:focus, .steps-table select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft);
}
.field input[type="file"] { font: inherit; font-size: .88rem; }
.field input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.field:has(> input[type="checkbox"]) { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: .55rem; }
.field ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.field ul label { font-weight: 400; display: flex; gap: .5rem; align-items: center; }
.help { color: var(--text-muted); font-size: .8rem; }
.help ul { margin: .25rem 0 0; padding-left: 1.1rem; list-style: disc; display: block; }
.errors, .errors ul { color: var(--danger-text); font-size: .84rem; margin: 0; padding-left: 0; list-style: none; }
form > button.primary, form > button[type="submit"]:last-child { margin-top: .25rem; }
.inline-form { display: flex; gap: .5rem; }

/* --- Messages ------------------------------------------------------------------ */
.messages { max-width: 1180px; margin: 1.25rem auto 0; padding: 0 2rem; display: grid; gap: .5rem; }
.message {
  margin: 0; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; padding: .75rem 1rem;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-1); box-shadow: var(--shadow-sm); font-size: .9rem;
}
.message.success { border-color: color-mix(in srgb, var(--good) 40%, var(--border)); background: color-mix(in srgb, var(--good) 8%, var(--surface-1)); }
.message.success::before { content: "✓"; color: var(--good-text); font-weight: 700; }
.message.error { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: var(--danger-soft); }
.message.error::before { content: "!"; color: var(--danger-text); font-weight: 700; }
.message.warning { background: #fff4d6; border-color: #fab219; color: #0b0b0b; }
.message.warning::before { content: "!"; color: #8a5a00; font-weight: 700; }
.message.warning span { flex: 1; }
.message.warning .btn { background: #fff; border-color: #e3a008; color: #6b4600; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .message.warning { background: #3a2c08; border-color: #c98500; color: #f0efec; }
  :root:where(:not([data-theme="light"])) .message.warning::before { color: #fab219; }
  :root:where(:not([data-theme="light"])) .message.warning .btn { background: #1c1f25; color: #fab219; border-color: #c98500; }
}
@media (max-width: 900px) { .messages { padding: 0 1rem; } }

/* --- Auth pages ------------------------------------------------------------------ */
body:not(.has-sidebar) main.narrow .card { padding: 2rem; box-shadow: var(--shadow-lg); }
body:not(.has-sidebar) main.narrow h1 { font-size: 1.45rem; margin-bottom: 1.25rem; }
body:not(.has-sidebar) main.narrow button.primary { width: 100%; padding: .7rem; margin-top: .5rem; }
body:not(.has-sidebar):not(:has(.public-header)) { background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent), var(--page); }
.auth-brand { display: flex; justify-content: center; margin-bottom: 1.5rem; font-size: 1.15rem; font-weight: 700; }
main.narrow > .center { margin-top: 1.25rem; color: var(--text-secondary); }

/* --- Charts ---------------------------------------------------------------------- */
.chart-card { margin-bottom: 1rem; }
.chart { position: relative; height: 270px; margin-top: .75rem; }
.chart svg { display: block; overflow: visible; }
.chart svg:focus-visible { outline: 2px solid var(--series-1); outline-offset: 4px; border-radius: 4px; }
.chart text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: .55rem .7rem; font-size: .8rem; box-shadow: var(--shadow-lg);
  white-space: nowrap; transform: translate(-50%, calc(-100% - 12px)); z-index: 5;
}
.tooltip[hidden] { display: none; }
.tooltip .tt-date { color: var(--text-secondary); margin-bottom: .25rem; }
.tooltip .tt-row { display: flex; align-items: center; gap: .4rem; }
.tooltip .tt-key { width: 12px; height: 2px; background: var(--series-1); border-radius: 1px; }
.tooltip .tt-key.none { background: transparent; }
details.table-view { margin-top: .75rem; font-size: .85rem; color: var(--text-secondary); }
details.table-view summary, details.definitions summary { cursor: pointer; font-weight: 600; color: var(--text-secondary); }
details.table-view table { margin-top: .5rem; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 1rem; padding: 0; margin: .5rem 0 0; font-size: .82rem; color: var(--text-secondary); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .45rem; vertical-align: baseline; }
.swatch-new { background: var(--mrr-new); } .swatch-expansion { background: var(--mrr-expansion); }
.swatch-reactivation { background: var(--mrr-reactivation); } .swatch-contraction { background: var(--mrr-contraction); }
.swatch-churn { background: var(--mrr-churn); }

/* --- Bar lists ---------------------------------------------------------------------- */
.barlist { list-style: none; margin: .85rem 0 0; padding: 0; display: grid; gap: .55rem; }
.barlist .row { display: flex; justify-content: space-between; gap: 1rem; font-size: .9rem; }
.barlist .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barlist .value { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.barlist .bar { height: 6px; margin-top: .3rem; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }

/* --- Workspace overview ------------------------------------------------------------- */
.client-group { margin-bottom: 1rem; }
.client-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.client-head .filters { margin: 0; }
.sites-table { margin-top: .75rem; table-layout: fixed; }
.sites-table th:first-child { width: 44%; }
.sites-table td:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sites-table td a { font-weight: 600; }
.delta { font-variant-numeric: tabular-nums; font-weight: 600; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--danger-text); }
.client-row { padding: .85rem 0; border-bottom: 1px solid var(--grid); display: grid; gap: .4rem; }
.client-row:last-child { border-bottom: 0; }
.client-row .row-actions { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.member { border-bottom: 1px solid var(--grid); padding: .75rem 0; }
.member summary { display: flex; justify-content: space-between; gap: 1rem; cursor: pointer; flex-wrap: wrap; font-weight: 500; }
.member form { margin-top: .75rem; }
.member .row-actions { display: flex; gap: .5rem; margin-top: .5rem; }

/* --- Install / sharing / misc blocks ------------------------------------------------ */
.install { margin-bottom: 1rem; }
.install-first { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: linear-gradient(180deg, var(--accent-soft), transparent 70%), var(--surface-1); }
.install .steps, ol.steps { margin: .75rem 0 0; padding-left: 1.25rem; display: grid; gap: 1rem; }
.install .steps > li { padding-left: .25rem; line-height: 1.55; }
.install .platforms { margin: .5rem 0 0; padding-left: 1.1rem; color: var(--text-secondary); font-size: .9rem; display: grid; gap: .2rem; }
.snippet { position: relative; margin-top: .5rem; }
.snippet pre { margin: 0; padding-right: 6.5rem; white-space: pre-wrap; word-break: break-all; }
.snippet .copy { position: absolute; top: .5rem; right: .5rem; }
.share-row { padding: .9rem 0; border-bottom: 1px solid var(--grid); display: grid; gap: .55rem; }
.share-row:last-child { border-bottom: 0; }
.share-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: baseline; }
.row-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.brand-preview { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; margin-top: .75rem; }
.brand-preview .public-header { padding: .8rem 1rem; }
.definitions summary { cursor: pointer; }
.definitions li { margin: .35rem 0; line-height: 1.5; }
details.card.definitions { margin-top: 1rem; }

/* --- Badges, roles, chips --------------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: .25rem; font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; margin: 0; white-space: nowrap; }
.badge-critical { background: #fbe4e4; color: #8f1d1d; }
.badge-serious { background: #fde9df; color: #8a3410; }
.badge-warning { background: #fff4d6; color: #6b4600; }
.badge-opportunity { background: #e3eefb; color: #184f95; }
.badge-good { background: #e2f5e2; color: #0a5a0a; }
.role { display: inline-block; font-size: .74rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; vertical-align: middle; }
.chip { font-size: .78rem; padding: .12rem .55rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); }
.chip-trial { border-color: var(--mrr-reactivation); }
.chip-paid { border-color: var(--good); font-weight: 600; }
.arrow { color: var(--text-muted); font-size: .8rem; }
.path { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }

/* --- Audit ------------------------------------------------------------------------------ */
.finding { margin-bottom: .75rem; border-left: 4px solid var(--axis); }
.finding h2 { margin: .45rem 0 .4rem; }
.finding p { margin: .3rem 0; line-height: 1.55; }
.recommendation { color: var(--text-secondary); }
.finding-critical { border-left-color: #d03b3b; } .finding-serious { border-left-color: #ec835a; }
.finding-warning { border-left-color: #fab219; } .finding-opportunity { border-left-color: var(--series-1); } .finding-good { border-left-color: #0ca30c; }
.score .kpi-value span { font-size: 1rem; font-weight: 400; }
.score-good { border-top: 4px solid #0ca30c; } .score-warning { border-top: 4px solid #fab219; } .score-critical { border-top: 4px solid #d03b3b; }

/* --- Attribution & journeys ------------------------------------------------------------- */
.attribution td { vertical-align: top; }
.cell-value { display: block; font-weight: 600; }
.cell-sub { display: block; font-size: .75rem; color: var(--text-muted); }
.mini-bar { display: block; height: 4px; margin: .3rem 0 0 auto; background: var(--series-1); border-radius: 2px; min-width: 1px; max-width: 100%; }
.journey-row { padding: .7rem 0; border-bottom: 1px solid var(--grid); display: grid; gap: .3rem; }
.journey-row:last-child { border-bottom: 0; }
.journey-row > a { font-weight: 600; }
.timeline { list-style: none; padding: 0; margin: .75rem 0 0 .4rem; border-left: 2px solid var(--grid); }
.timeline li { position: relative; padding: .5rem 0 .5rem 1.1rem; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: .85rem; width: 12px; height: 12px; border-radius: 50%; background: var(--axis); border: 2px solid var(--surface-1); }
.timeline .tl-visit::before { background: var(--series-1); }
.timeline .tl-trial::before { background: var(--mrr-reactivation); }
.timeline .tl-new::before, .timeline .tl-expansion::before, .timeline .tl-reactivation::before { background: var(--good); }
.timeline .tl-churn::before, .timeline .tl-contraction::before { background: var(--danger); }
.timeline .tl-after { opacity: .7; }
.tl-date { display: inline-block; min-width: 9.5rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; font-size: .85rem; }

/* --- Activation & cohorts (sequential blue ramp; dark text up to 400, white from 500) ------ */
.funnel-steps { list-style: none; padding: 0; margin: .85rem 0 0; display: grid; gap: 1rem; }
.funnel-steps .row { display: flex; justify-content: space-between; gap: 1rem; }
.funnel-steps .bar { height: 10px; margin: .4rem 0; background: var(--series-1); border-radius: 0 5px 5px 0; min-width: 2px; }
.heatmap-wrap { overflow-x: auto; margin-top: .75rem; }
.heatmap { border-collapse: separate; border-spacing: 3px; font-size: .8rem; }
.heatmap th, .heatmap td { border: 0; padding: .45rem .5rem; white-space: nowrap; background: none; }
.heatmap .heat { text-align: center; border-radius: 4px; color: #0b0b0b; font-variant-numeric: tabular-nums; min-width: 2.7rem; }
.heatmap .heat-dark { color: #ffffff; }
.heat-100 { background: #cde2fb !important; } .heat-200 { background: #9ec5f4 !important; } .heat-300 { background: #6da7ec !important; }
.heat-400 { background: #3987e5 !important; } .heat-500 { background: #256abf !important; } .heat-600 { background: #184f95 !important; } .heat-700 { background: #0d366b !important; }
.steps-table input[name$="position"] { width: 4.5rem; }

/* --- Health ---------------------------------------------------------------------------- */
.risk-card { border-top: 4px solid var(--axis); }
.risk-high { border-top-color: #d03b3b; } .risk-medium { border-top-color: #fab219; } .risk-low { border-top-color: #0ca30c; }
.risk-icon { font-weight: 700; }
.health-table td { vertical-align: top; }

/* --- Print (audit, board) ----------------------------------------------------------------- */
@media print {
  .no-print, .sidebar, .tabs, .messages, .breadcrumb, .page-actions { display: none !important; }
  .has-sidebar { display: block; }
  body { background: #fff; }
  .card { break-inside: avoid; box-shadow: none; }
  main { padding: 0; max-width: none; }
}

/* --- Premium finish ------------------------------------------------------------------------ */
.has-sidebar .app-main { background: radial-gradient(900px 320px at 85% -80px, var(--accent-soft), transparent 70%); }
.page-title { font-size: 1.2rem; margin: 0; letter-spacing: -.015em; }
.site-header + .page-head, .site-header + .page-title, .site-header + h2 { margin-top: 0; }
.site-header + .page-title { margin-bottom: 1rem; }
.kpis .card { position: relative; overflow: hidden; transition: transform .15s, box-shadow .15s; }
.kpis .card::after { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: linear-gradient(90deg, var(--accent), transparent); opacity: .55; }
.kpis .card.risk-card::after, .kpis .card.score::after { display: none; }
.kpis .card:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.card h2 { display: flex; align-items: center; gap: .5rem; }
.form-card { max-width: 640px; margin-top: 1rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; padding-top: 1rem; border-top: 1px solid var(--grid); }
.empty-state { text-align: center; padding: 2.5rem 1rem; }
.empty-state h2 { justify-content: center; font-size: 1.2rem; }
.empty-state .row-actions { justify-content: center; margin-top: 1.25rem; }
.auth-links { margin: 1rem 0 0; text-align: center; font-size: .9rem; }
.auth-alt { display: flex; justify-content: center; align-items: center; gap: .75rem; margin-top: 1.25rem; color: var(--text-secondary); font-size: .9rem; }
.auth-brand .brand { font-size: 1.2rem; }
.sites-table tr td:first-child a::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: .55rem; opacity: .8; }

/* --- Layout fixes ------------------------------------------------------------------------- */
html, body { min-height: 100%; }
body { min-height: 100vh; }
.card:has(> table), .card:has(> .attribution) { overflow-x: auto; }
h1 + .subtitle, .page-title + .subtitle { margin-bottom: 1.25rem; }
.card > h2 + .subtitle, .card > .subtitle { margin-bottom: .9rem; }
.card > h2 + form, .card > .subtitle + form { margin-top: .9rem; }
/* Checkbox lists (Django CheckboxSelectMultiple renders nested divs) */
.field > div > div > label, .field > div label:has(input[type="checkbox"]) { font-weight: 400; display: flex; gap: .55rem; align-items: center; padding: .15rem 0; }
.field input[type="checkbox"], input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }
/* Team members expand to edit: say so */
.member summary { list-style: none; align-items: center; }
.member summary::-webkit-details-marker { display: none; }
.member summary::after { content: "Modifier"; margin-left: auto; font-size: .76rem; font-weight: 600; padding: .25rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); color: var(--text-secondary); }
.member[open] summary::after { content: "Fermer"; }
.member summary > span:last-child { margin-left: auto; }
@media (max-width: 1500px) { .tabs a .icon { display: none; } .tabs a { padding: .65rem .7rem; } }
