/* IGSender Growth Engine.
   Themes are CSS variables on html[data-theme]: lavender (default, owner's choice D4), light and dark.
   Palette = prototype/index.html with a few text colours darkened so every text pair has contrast >= 4.5:1
   (docs/08 §6; tests/test_theme.py checks it). Font: Montserrat, self-hosted (SIL OFL, see fonts/OFL.txt). */

@font-face {
  font-family: "Montserrat"; font-style: normal; font-weight: 400 800; font-display: swap;
  src: url("/static/fonts/montserrat-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Montserrat"; font-style: normal; font-weight: 400 800; font-display: swap;
  src: url("/static/fonts/montserrat-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- themes ---------- */
:root, [data-theme="lavender"] {
  color-scheme: light;
  --bg: #efeafd; --bg-fx: linear-gradient(160deg, #f3effe 0%, #e9e2fd 45%, #dfe7ff 100%);
  --panel: rgba(255,255,255,.86); --panel-2: #f5f1ff; --panel-3: #ebe4ff;
  --line: #e3dbfb; --line-2: #cfc3f6;
  --text: #1b1446; --muted: #5a5387; --muted2: #655c96;
  --accent: #5b3df5; --accent-2: #3b2bb8; --grad: linear-gradient(135deg, #7553ff, #4f3ae0);
  --good: #0f7a58; --warn: #9b5d00; --bad: #c32d2d; --info: #4a3ad6;
  --side: rgba(255,255,255,.7); --input: #ffffff; --shadow: 0 14px 32px -16px rgba(70,45,200,.35);
  --pill-good: #e3f6ee; --pill-warn: #fff1dc; --pill-bad: #fde6e6; --pill-info: #ebe6ff;
  --ring-inner: #fbf9ff; --drawer: #fbf9ff; --dialog: #fbf9ff;
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7fa; --bg-fx: none;
  --panel: #ffffff; --panel-2: #f3f3f8; --panel-3: #eaeaf2;
  --line: #e6e6ee; --line-2: #d4d4e0;
  --text: #15151f; --muted: #5d5d73; --muted2: #6c6c86;
  --accent: #6c49ff; --accent-2: #4f46e5; --grad: linear-gradient(135deg, #6d4aff, #4f46e5);
  --good: #0c7b55; --warn: #946219; --bad: #cc2121; --info: #4f46e5;
  --side: #ffffff; --input: #ffffff; --shadow: 0 8px 24px -14px rgba(30,30,60,.25);
  --pill-good: #e6f7f0; --pill-warn: #fdf3e1; --pill-bad: #fde8e8; --pill-info: #ecebff;
  --ring-inner: #ffffff; --drawer: #ffffff; --dialog: #ffffff;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #06060a; --bg-fx: radial-gradient(900px 500px at 85% -10%, rgba(139,92,246,.18), transparent 60%), radial-gradient(700px 400px at -10% 110%, rgba(34,211,238,.10), transparent 60%);
  --panel: rgba(255,255,255,.035); --panel-2: rgba(255,255,255,.06); --panel-3: rgba(255,255,255,.09);
  --line: rgba(255,255,255,.08); --line-2: rgba(255,255,255,.15);
  --text: #ececf3; --muted: #9d9db3; --muted2: #8989a2;
  --accent: #9e77f8; --accent-2: #6366f1; --grad: linear-gradient(135deg, #8250f5 0%, #5d60f0 100%);
  --good: #34d399; --warn: #fbbf24; --bad: #f87171; --info: #a5b4fc;
  --side: rgba(10,10,16,.55); --input: rgba(255,255,255,.04); --shadow: 0 10px 30px -12px rgba(124,92,255,.55);
  --pill-good: rgba(52,211,153,.14); --pill-warn: rgba(251,191,36,.14); --pill-bad: rgba(248,113,113,.14); --pill-info: rgba(165,180,252,.14);
  --ring-inner: #0d0d14; --drawer: rgba(14,14,22,.96); --dialog: rgba(16,16,24,.97);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); background-image: var(--bg-fx); background-attachment: fixed; color: var(--text);
  font: 16px/1.6 "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}
[data-theme="lavender"] h1, [data-theme="lavender"] .kpi b { font-weight: 800; letter-spacing: -.01em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
h1 { font-size: 30px; margin: 0; line-height: 1.25; }
h2 { font-size: 22px; margin: 0 0 .5em; line-height: 1.3; }
h3 { font-size: 18px; margin: 1.3em 0 .4em; line-height: 1.4; }
.card > h3:first-child, .card > h2:first-child { margin-top: 0; }
.note { color: var(--muted); font-size: 14px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--panel-3); color: var(--text); padding: 8px 14px; border-radius: 8px; }
.skip:focus { left: 12px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
aside {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 22px 16px; background: var(--side);
  border-right: 1px solid var(--line); backdrop-filter: blur(18px); display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; background: var(--grad); display: grid; place-items: center; color: #fff; font-weight: 800; flex: none; }
.brand b { display: block; font-size: 17px; line-height: 1.3; }
.brand small { display: block; color: var(--muted); font-size: 13.5px; line-height: 1.3; }
.navlabel { color: var(--muted2); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; padding: 12px 10px 4px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 10px 12px; font-size: 15.5px; border-radius: 10px; color: var(--text); }
.nav:hover { background: var(--panel-2); text-decoration: none; }
.nav.on { background: var(--panel-3); box-shadow: inset 2px 0 0 var(--accent); }
.nav .n { margin-left: auto; font-size: 12px; background: var(--grad); color: #fff; border-radius: 99px; padding: 0 8px; }
.side-foot { margin-top: auto; color: var(--muted2); font-size: 13px; padding: 10px; }
.side-foot a { color: var(--muted); text-decoration: underline; }
.inline-form { display: inline; margin: 0; }
.link-button { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: var(--muted); text-decoration: underline; cursor: pointer; }
main { padding: 30px 38px 70px; max-width: 1320px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.sub { color: var(--muted); margin: 2px 0 0; }
.top .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ---------- components ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px 22px; box-shadow: var(--shadow); }
.card.flush { padding: 4px 8px; }
.empty { text-align: center; padding: 34px 22px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { padding: 18px 20px; }
.kpi b { font-size: 30px; display: block; line-height: 1.2; }
.kpi span { color: var(--muted); font-size: 14px; }
.kpi small { color: var(--good); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.gap-top { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
.stack > * + * { margin-top: 14px; }

.btn {
  display: inline-block; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); padding: 9px 16px;
  border-radius: 10px; cursor: pointer; font: inherit; font-size: 15px; font-weight: 500; line-height: 1.4; text-align: center;
}
.btn:hover { background: var(--panel-3); text-decoration: none; }
.btn.primary { background: var(--grad); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 13.5px; }
.btn.wide { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

.pill { white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; font-size: 13px; padding: 3px 11px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.pill.good { background: var(--pill-good); color: var(--good); border-color: transparent; }
.pill.warn { background: var(--pill-warn); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--pill-bad); color: var(--bad); border-color: transparent; }
.pill.info { background: var(--pill-info); color: var(--info); border-color: transparent; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-2); border-radius: 99px; padding: 5px 13px; font-size: 14.5px; background: var(--panel-2); }
.chip.off { opacity: .6; text-decoration: line-through; }

.bar { height: 10px; border-radius: 99px; background: var(--panel-3); overflow: hidden; }
td .bar { display: inline-block; width: 72%; vertical-align: middle; margin-right: 8px; }
.bar i { display: block; height: 100%; background: var(--grad); }

/* Today: one question card with its score ring */
.q { display: grid; grid-template-columns: 64px 1fr; gap: 14px; margin-bottom: 14px; }
.ring {
  --s: 80; width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; position: relative;
  background: conic-gradient(var(--accent) calc(var(--s) * 1%), var(--panel-3) 0);
}
.ring::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--ring-inner); }
.ring span { position: relative; z-index: 1; font-size: 16px; }
.q h3 { margin: 6px 0 4px; font-size: 18px; line-height: 1.4; }
.q .meta { color: var(--muted); font-size: 14px; }
.q .why { color: var(--muted); font-size: 15px; margin: 6px 0 12px; }

/* forms */
textarea, input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select {
  width: 100%; background: var(--input); color: var(--text); border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 11px; font: inherit;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 18px; height: 18px; vertical-align: middle; }
textarea { min-height: 140px; resize: vertical; line-height: 1.6; }
::placeholder { color: var(--muted2); opacity: 1; }
input[readonly] { background: var(--panel-2); }
label.f { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 5px; }
.count { font-size: 12.5px; color: var(--muted2); float: right; }
.count.over { color: var(--bad); font-weight: 600; }
.rule { border-left: 3px solid var(--accent); padding: 8px 12px; background: var(--panel-2); border-radius: 0 10px 10px 0; font-size: 14px; color: var(--muted); margin: 12px 0; }
.flash { border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 15px; border: 1px solid transparent; }
.flash.ok { background: var(--pill-good); color: var(--good); }
.flash.err { background: var(--pill-bad); color: var(--bad); }
.alert { background: var(--pill-bad); color: var(--bad); border-radius: 10px; padding: 9px 14px; margin-bottom: 10px; font-size: 15px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--line); font-size: 15px; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 13.5px; }
tr.click:hover td { background: var(--panel-2); cursor: pointer; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* segmented switch (buttons or links) */
.switch { display: inline-flex; border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; }
.switch button, .switch a { border: 0; padding: 8px 14px; background: transparent; color: var(--muted); cursor: pointer; font: inherit; font-size: 14px; }
.switch a:hover { text-decoration: none; background: var(--panel-2); }
.switch .on { background: var(--grad); color: #fff; }

/* overlays */
.drawer {
  position: fixed; top: 0; right: 0; width: min(600px, 100vw); height: 100vh; overflow: auto; background: var(--drawer); padding: 22px; z-index: 20;
  border-left: 1px solid var(--line-2); box-shadow: -20px 0 60px -30px rgba(0,0,0,.5); backdrop-filter: blur(22px);
  transform: translateX(105%); visibility: hidden; transition: transform .25s ease, visibility 0s linear .25s;
}
.drawer.open { transform: translateX(0); visibility: visible; transition: transform .25s ease; }
dialog { border: 1px solid var(--line-2); border-radius: 16px; background: var(--dialog); color: var(--text); padding: 24px; width: min(520px, calc(100vw - 32px)); font-size: 16px; }
dialog::backdrop { background: rgba(10,8,30,.5); }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(30px); opacity: 0; pointer-events: none; transition: .2s;
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px; font-size: 15px; z-index: 30;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); }
.login-card .brand { padding: 0 0 18px; }

@media (max-width: 1180px) { .grid3 { grid-template-columns: 1fr; } }
@media (max-width: 1000px) {
  .grid2 { grid-template-columns: 1fr; }
  main { padding: 24px 22px 60px; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  aside { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .q { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
