/* MyAi design system -- one look for every MyAi surface: the chat app, the
   connector sign-in, onboarding / billing, and the operator portal.

   Self-contained (no web fonts, no external assets) so it works under the
   strict Content-Security-Policy the cloud pages send. Served as a file by
   the springboard (static/myai-theme.css) and inlined by the other apps via
   springboard/ui_theme.py.

   Colour modes: follows the OS (prefers-color-scheme) unless the user picks
   one -- <html data-theme="light|dark">, set by the toggle (ui_theme.TOGGLE_JS)
   before first paint so there is no flash. */

:root {
  color-scheme: light;
  /* surfaces */
  --bg: #f5f6f8;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #dff3f6 0%, rgba(223,243,246,0) 60%),
             radial-gradient(900px 500px at -10% 110%, #efe9fb 0%, rgba(239,233,251,0) 55%);
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e7eaef;
  --overlay: rgba(15, 23, 42, .45);
  /* text */
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e6ec;
  --line-strong: #cbd2dc;
  /* brand: deep teal with an iris companion */
  --accent: #0e7490;
  --accent-hover: #0b5e75;
  --accent-ink: #ffffff;
  --accent-soft: #e2f4f8;
  --accent-2: #6d4fd8;
  --accent-2-soft: #efeafe;
  /* status */
  --ok: #15803d;   --ok-soft: #e7f6ec;
  --warn: #b45309; --warn-soft: #fdf2e3;
  --bad: #b91c1c;  --bad-soft: #fdeaea;
  --info: #1d4ed8; --info-soft: #e8efff;
  /* chart series -- fixed order (never cycled), validated with the dataviz
     palette checks: light on #fff passes lightness band, chroma floor, CVD
     (worst adjacent dE 10.9), normal-vision (20.2) and 3:1 contrast */
  --c1: #0a86a8; --c2: #e0662f; --c3: #6a4fd6; --c4: #c98500; --c5: #d44f86; --c6: #2e8b1f;
  /* shape */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow-1: 0 1px 2px rgba(15,23,42,.06), 0 1px 1px rgba(15,23,42,.04);
  --shadow-2: 0 8px 24px rgba(15,23,42,.08), 0 2px 6px rgba(15,23,42,.05);
  --focus: 0 0 0 3px rgba(14,116,144,.35);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Code", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0f16;
    --bg-grad: radial-gradient(1200px 600px at 100% -10%, rgba(34,184,207,.10) 0%, rgba(34,184,207,0) 60%),
               radial-gradient(900px 500px at -10% 110%, rgba(139,112,255,.10) 0%, rgba(139,112,255,0) 55%);
    --surface: #111822;
    --surface-2: #17202c;
    --surface-3: #1e2936;
    --overlay: rgba(0,0,0,.6);
    --ink: #e6edf5;
    --ink-2: #c1cbd7;
    --muted: #8a97a8;
    --line: #223041;
    --line-strong: #2f3f53;
    --accent: #2cc3d8;
    --accent-hover: #5ad3e3;
    --accent-ink: #03161b;
    --accent-soft: #0e2b33;
    --accent-2: #a28bff;
    --accent-2-soft: #221c3d;
    --ok: #4ade80;   --ok-soft: #0f2a1a;
    --warn: #fbbf24; --warn-soft: #2d2208;
    --bad: #f87171;  --bad-soft: #2f1414;
    --info: #7aa2ff; --info-soft: #141f3b;
    --c1: #1596b6; --c2: #d95926; --c3: #9085e9; --c4: #c98500; --c5: #d55181; --c6: #008300;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 10px 30px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.35);
    --focus: 0 0 0 3px rgba(44,195,216,.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0f16;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, rgba(34,184,207,.10) 0%, rgba(34,184,207,0) 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(139,112,255,.10) 0%, rgba(139,112,255,0) 55%);
  --surface: #111822;
  --surface-2: #17202c;
  --surface-3: #1e2936;
  --overlay: rgba(0,0,0,.6);
  --ink: #e6edf5;
  --ink-2: #c1cbd7;
  --muted: #8a97a8;
  --line: #223041;
  --line-strong: #2f3f53;
  --accent: #2cc3d8;
  --accent-hover: #5ad3e3;
  --accent-ink: #03161b;
  --accent-soft: #0e2b33;
  --accent-2: #a28bff;
  --accent-2-soft: #221c3d;
  --ok: #4ade80;   --ok-soft: #0f2a1a;
  --warn: #fbbf24; --warn-soft: #2d2208;
  --bad: #f87171;  --bad-soft: #2f1414;
  --info: #7aa2ff; --info-soft: #141f3b;
  --c1: #1596b6; --c2: #d95926; --c3: #9085e9; --c4: #c98500; --c5: #d55181; --c6: #008300;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 10px 30px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.35);
  --focus: 0 0 0 3px rgba(44,195,216,.4);
}

/* ---------------------------------------------------------------- base --- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.55 var(--font);
  color: var(--ink);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
code, pre { font-family: var(--mono); font-size: .9em; }
pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
      padding: .75rem 1rem; overflow-x: auto; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
::selection { background: var(--accent-soft); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------- layout --- */
.shell { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .spacer { flex: 1; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 15px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: var(--shadow-1);
}
/* dark mode: the bright accents would put white text at ~2:1 -- use the
   deep ends of both hues so the mark stays legible */
:root[data-theme="dark"] .brand-mark { background: linear-gradient(135deg, #0b5e75 0%, #4b36a8 100%); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-mark { background: linear-gradient(135deg, #0b5e75 0%, #4b36a8 100%); }
}
.brand-svg { width: 32px; height: 32px; flex: none; display: block; }
.brand-name { font-weight: 800; letter-spacing: -.02em; }
.brand-ai { background: linear-gradient(90deg, #0a86a8, #5b3fd0); -webkit-background-clip: text;
            background-clip: text; color: transparent; }
:root[data-theme="dark"] .brand-ai { background-image: linear-gradient(90deg, #2cc3d8, #a28bff); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-ai { background-image: linear-gradient(90deg, #2cc3d8, #a28bff); }
}
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; margin-top: -2px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
                            .shell { padding: 0 16px; } }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* -------------------------------------------------------------- cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 18px 20px;
}
.card-hero { border-radius: var(--radius-lg); box-shadow: var(--shadow-2); padding: 28px; }
.card h2, .card h3 { margin-top: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }

/* KPI tile */
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 13px; font-weight: 600; }
.delta.up { color: var(--ok); } .delta.down { color: var(--bad); } .delta.flat { color: var(--muted); }

/* ------------------------------------------------------------ buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 16px;
  font: 600 14px/1 var(--font);
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 10px;
  cursor: pointer; transition: background .15s, border-color .15s, transform .05s;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-block { display: flex; width: 100%; }
.btn-danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-solid:hover { background: color-mix(in srgb, var(--bad) 85%, #000); }
.icon-btn { width: 36px; padding: 0; }

/* ------------------------------------------------------------- forms ---- */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--ink-2); }
.input, input[type=text], input[type=email], input[type=url], input[type=password], input[type=search], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px;
  font: 15px/1.4 var(--font); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.help { font-size: 13px; color: var(--muted); margin-top: 4px; }
.field + .field { margin-top: 14px; }

/* ------------------------------------------------------ badges/alerts --- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 20px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.plain::before { display: none; }
.alert { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); }
.alert.ok { background: var(--ok-soft); border-color: transparent; }
.alert.warn { background: var(--warn-soft); border-color: transparent; }
.alert.bad { background: var(--bad-soft); border-color: transparent; }

/* ------------------------------------------------------------- tables --- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { font-size: 12px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted);
            background: var(--surface-2); position: sticky; top: 0; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------- theme toggle - */
.theme-toggle { position: relative; }
.theme-toggle .ic-sun, .theme-toggle .ic-moon { width: 18px; height: 18px; }
:root[data-theme="dark"] .theme-toggle .ic-sun { display: none; }
:root:not([data-theme="dark"]) .theme-toggle .ic-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .ic-sun { display: none; }
  :root:not([data-theme]) .theme-toggle .ic-moon { display: inline; }
}

/* ------------------------------------------------------------ motion ---- */
@keyframes myai-fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.fade-up { animation: myai-fade-up .35s ease both; }
@keyframes myai-pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
.dots span { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%;
             background: var(--accent); animation: myai-pulse 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: .2s; } .dots span:nth-child(3) { animation-delay: .4s; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
