/* SitePulse UI.
   Rules: no borders (shapes come from fill + shadow), 6px corners, no pills, no all-caps,
   normal letter-spacing. The only gradient is the iridescent page background. */

:root {
  color-scheme: light dark;
  --bg: #f4f4f5;
  --surface: #ffffff;
  --hover: #f1f1f3;
  --field: #f1f1f3;
  --text: #18181b;
  --muted: #6b6b73;
  --line: #e4e4e7;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-weak: #e8effd;
  --accent-soft: var(--accent-weak); /* legacy alias */
  --bar: #e3ebfb;
  --danger: #dc2626;
  --success: #15803d;
  --tip-bg: #18181b;
  --tip-text: #fafafa;
  --radius: 16px;      /* tiles */
  --radius-ctl: 10px;  /* buttons, fields, code blocks */
  --radius-in: 7px;    /* elements nested inside controls/tiles */
  --tile-shadow: 0 1px 2px rgba(24,24,27,.06), 0 6px 20px rgba(24,24,27,.07);
  --tile-shadow-hover: 0 2px 4px rgba(24,24,27,.07), 0 14px 30px rgba(24,24,27,.12);
  --ease: cubic-bezier(.2,.7,.3,1);
  --iri-bg: linear-gradient(125deg, #dbeafe, #ede9fe 22%, #fce7f3 44%, #fef3c7 66%, #dcfce7 84%, #cffafe);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e10;
    /* tinted, slightly see-through tiles so the background hue carries through instead of flat black */
    --surface: rgba(44, 44, 56, .72);
    --hover: rgba(255, 255, 255, .09);
    --field: rgba(255, 255, 255, .07);
    --text: #ececee;
    --muted: #9b9ba3;
    --line: #2c2c31;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-weak: #1c2740;
    --bar: #1f2a42;
    --danger: #f87171;
    --success: #4ade80;
    --tip-bg: #ececee;
    --tip-text: #18181b;
    --tile-shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 8px 24px rgba(0,0,0,.25);
    --tile-shadow-hover: 0 2px 4px rgba(0,0,0,.5), 0 16px 34px rgba(0,0,0,.5);
    --iri-bg: linear-gradient(125deg, #0c2148, #26145a 22%, #4a1240 44%, #3d2a0a 66%, #0c3a28 84%, #0a3340);
  }
}

/* ───────── base ───────── */
@keyframes iri { from { background-position: 0% 30%; } to { background-position: 100% 70%; } }
* { box-sizing: border-box; }
body {
  margin: 0; color: var(--text); min-height: 100vh;
  background: var(--iri-bg) fixed; background-size: 220% 220%; animation: iri 40s ease-in-out infinite alternate;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.3; font-weight: 600; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 2px; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }
code, pre { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
code { background: var(--field); padding: 1px 5px; border-radius: 5px; }
strong, b { font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.5em; font-size: 13px; }
.error.ok { color: var(--success); }
.error.flash { animation: msg-in .25s var(--ease); }
.shake { animation: shake .35s var(--ease); }
@keyframes msg-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

/* ───────── header ───────── */
/* header sits directly on the page background; it only gains a surface once content scrolls under it */
.top { position: sticky; top: 0; z-index: 20; background: transparent; transition: background-color .2s, box-shadow .2s; }
.top.scrolled { background: var(--surface); box-shadow: var(--tile-shadow); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.top-inner { max-width: 1120px; margin: 0 auto; padding: 0 24px; height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.user { display: flex; align-items: center; gap: 12px; color: var(--muted); min-width: 0; font-size: 13px; }
.user .email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
@media (max-width: 560px) { .user .email { display: none; } }

main > * { animation: enter .25s var(--ease) both; }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } }
main { max-width: 1120px; margin: 0 auto; padding: 28px 24px 64px; display: grid; gap: 20px; align-content: start; }
@media (max-width: 560px) { main { padding: 20px 16px 48px; } .top-inner { padding: 0 16px; } }

/* ───────── controls ───────── */
.card { background: var(--surface); border-radius: var(--radius); padding: 20px; min-width: 0; box-shadow: var(--tile-shadow); }
.card, .seg { -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }

button, .btn, input, select {
  font: inherit; color: var(--text);
  border: none; border-radius: var(--radius-ctl); padding: 8px 13px; background: var(--field);
  transition: background-color .15s, color .15s, box-shadow .15s, transform .1s var(--ease);
}
button, .btn { position: relative; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 500; }
button:hover, .btn:hover { background: color-mix(in srgb, var(--field), var(--text) 8%); text-decoration: none; }
button:active, .btn:active { transform: scale(.97); }
button.primary, .btn.primary { background: var(--accent); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; }
/* disabled = busy: every disabled button in this app is waiting on a request */
button:disabled { cursor: progress; color: transparent !important; transform: none; }
button:disabled::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  border: 2px solid var(--muted); border-right-color: transparent; animation: spin .7s linear infinite;
}
button.primary:disabled::after { border-color: #fff; border-right-color: transparent; }
button.done, button.done:hover { background: var(--success); color: #fff; }
input, select { width: 100%; }
select { width: auto; }
input::placeholder { color: var(--muted); }
input:hover { background: color-mix(in srgb, var(--field), var(--text) 5%); }
input:focus, select:focus { outline: none; background: var(--surface); box-shadow: 0 0 0 2px var(--accent); }
input:user-invalid { box-shadow: 0 0 0 2px var(--danger); }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; }
.linkish, .linkish:hover { background: none; padding: 0; color: var(--accent); font-weight: 400; }
.linkish:hover { text-decoration: underline; }
.linkish:active { transform: none; }

.badge { font-size: 12px; font-weight: 600; color: var(--accent); }

.loading { display: flex; justify-content: center; padding: 64px 0; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--muted); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: var(--surface); border-radius: var(--radius); min-height: 72px; box-shadow: var(--tile-shadow); animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) {
  body, main > *, .skeleton, .caret, .shake, .error.flash { animation: none !important; }
  * { transition: none !important; }
}

/* ───────── sign in ───────── */
.hero { text-align: center; margin-top: 6vh; display: grid; justify-items: center; gap: 8px; }
.hero h1 { font-size: 28px; min-height: 1.3em; }
.caret { display: inline-block; width: 2px; height: 1em; margin-left: 3px; vertical-align: -.12em; background: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.hero p { color: var(--muted); max-width: 460px; margin: 0; font-size: 15px; }
.auth { max-width: 380px; width: 100%; margin: 8px auto 0; display: grid; gap: 14px; padding: 24px; }
.auth form { display: grid; gap: 14px; }
.or { text-align: center; color: var(--muted); font-size: 13px; }

/* ───────── page head + tabs ───────── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head .crumb { font-size: 13px; color: var(--muted); display: inline-block; margin-bottom: 4px; }
.page-head .crumb:hover { color: var(--text); }
.page-head h1 .domain { font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 8px; }

.tabs { display: flex; gap: 20px; }
.tab { position: relative; padding: 6px 0; color: var(--muted); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; transition: color .15s; }
.tab::after { content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 2px; background: var(--accent); transform: scaleX(0); transition: transform .2s var(--ease); }
.tab:hover::after { transform: scaleX(.35); }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); }
.tab.active::after { transform: scaleX(1); }

.controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.controls-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.seg { display: inline-flex; gap: 2px; background: var(--surface); border-radius: var(--radius-ctl); padding: 3px; box-shadow: var(--tile-shadow); }
.seg button { border: none; background: transparent; padding: 5px 12px; color: var(--muted); border-radius: var(--radius-in); }
.seg button:hover { color: var(--text); background: transparent; }
.seg button[aria-pressed="true"] { background: var(--accent-weak); color: var(--accent); }

.mini-tabs { display: inline-flex; gap: 14px; flex-wrap: wrap; }
.mini-tabs button { background: none; padding: 2px 0; font-size: 13px; color: var(--muted); border-radius: 0; box-shadow: inset 0 -2px 0 transparent; }
.mini-tabs button:hover { background: none; color: var(--text); }
.mini-tabs button[aria-selected="true"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.mini-tabs button:active, .seg button:active { transform: none; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.switch input { appearance: none; width: 32px; height: 18px; padding: 0; border: none; border-radius: 9px; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background-color .15s; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }

.live { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.live-chip { color: var(--text); }
.live-chip .live { color: var(--text); }

/* ───────── websites list ───────── */
.sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.site-card { display: block; color: var(--text); transition: transform .15s var(--ease), box-shadow .15s; }
.site-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--tile-shadow-hover); }
.site-card:active { transform: translateY(0) scale(.99); }
.site-card h3 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-card .meta span { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-card .today { margin-top: 8px; color: var(--text); }
.empty-state { grid-column: 1 / -1; padding: 32px 0; color: var(--muted); text-align: center; }
.inline-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; }
.inline-form.goal-form { grid-template-columns: 1fr auto; }
@media (max-width: 640px) { .inline-form, .inline-form.goal-form { grid-template-columns: 1fr; } }

/* ───────── setup ───────── */
pre.snippet { background: var(--field); border-radius: var(--radius-ctl); padding: 12px 14px; overflow-x: auto; white-space: pre; margin: 10px 0; }
.status-list { display: grid; gap: 12px; }
.status { display: flex; gap: 10px; align-items: flex-start; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--muted); }
.status.ok .dot { background: var(--success); }
.status.bad .dot { background: var(--danger); }
.status-list .loading { padding: 12px 0; justify-content: flex-start; }
.checklist summary { cursor: pointer; font-weight: 500; }
.checklist ul { margin: 8px 0 0; padding-left: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px 20px; margin: 12px 0; }
.chip { display: inline-flex; align-items: baseline; gap: 6px; font-size: 14px; }
.chip small { font-size: 12px; color: var(--muted); }
.chip .linkish { color: var(--muted); font-size: 16px; line-height: 1; }
.chip .linkish:hover { color: var(--danger); text-decoration: none; }

/* ───────── dashboard ───────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.stats-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1080px) { .stats-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) { .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .stats-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { padding: 16px; }
.stat .label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 600; margin-top: 2px; line-height: 1.2; font-variant-numeric: tabular-nums; }
button.card.stat { display: block; width: 100%; text-align: left; font-weight: 400; background: var(--surface); box-shadow: var(--tile-shadow); }
button.card.stat:hover { background: var(--surface); box-shadow: var(--tile-shadow-hover); }
button.card.stat:active { transform: scale(.98); }
button.card.stat.selected { box-shadow: inset 0 -3px 0 var(--accent), var(--tile-shadow); }
.stat.selected .label { color: var(--text); }
.stat-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; margin-top: 6px; min-height: 24px; }
.spark { width: 72px; height: 24px; flex: none; }
.delta { font-size: 12.5px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 16px; }

/* bar lists */
.row { position: relative; display: flex; justify-content: space-between; gap: 12px; padding: 6px 8px; margin-bottom: 2px; font-variant-numeric: tabular-nums; isolation: isolate; }
.row .fill { position: absolute; inset: 0 auto 0 0; background: var(--bar); border-radius: var(--radius-in); z-index: -1; transition: width .4s var(--ease); }
.row { border-radius: var(--radius-in); transition: background-color .12s; }
.row:hover { background: var(--hover); }
.row .name { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .num { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); flex: none; }
.row .num em { font-style: normal; font-size: 12px; width: 34px; text-align: right; visibility: hidden; }
.row:hover .num em { visibility: visible; }
.fav { width: 14px; height: 14px; flex: none; }
.flag { width: 18px; height: 13px; object-fit: cover; flex: none; vertical-align: -2px; margin-right: 6px; }
.chan { font-size: 12px; color: var(--muted); }
.meter { display: inline-block; width: 44px; height: 4px; background: var(--line); margin-right: 8px; vertical-align: middle; position: relative; }
.meter::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--v); background: var(--accent); }
.empty { color: var(--muted); padding: 8px 0; font-size: 13px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: right; color: var(--muted); font-weight: 500; font-size: 13px; padding: 6px 10px; white-space: nowrap; }
td { text-align: right; padding: 8px 10px; }
tr:hover td { background: var(--hover); }
th:first-child, td:first-child { text-align: left; }
td:first-child { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* charts */
svg text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart-wrap svg { display: block; overflow: visible; }
.chart-legend { display: flex; gap: 16px; align-items: center; margin-top: 10px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.chart-legend i { display: inline-block; width: 14px; border-top: 2px solid var(--accent); vertical-align: middle; margin-right: 6px; }
.chart-legend i.dash { border-top: 2px dashed var(--muted); }
.card-head .chart-legend { margin: 0; }
.guide { visibility: hidden; pointer-events: none; }
.guide.on { visibility: visible; }
rect.bar { fill: var(--accent); }
rect.bar:hover { fill: var(--accent-hover); }

#tip { position: fixed; pointer-events: none; background: var(--tip-bg); color: var(--tip-text); padding: 6px 10px; border-radius: var(--radius-in); font-size: 12.5px; display: none; white-space: nowrap; z-index: 30; font-variant-numeric: tabular-nums; }
#tip strong { display: block; margin-bottom: 2px; }
.tip-row { display: flex; align-items: center; gap: 8px; }
.tip-row i { width: 10px; border-top: 2px solid currentColor; }
.tip-row i.cmp { border-top-style: dashed; }
.tip-row b { margin-left: auto; padding-left: 16px; }

/* insights */
.insights ul { margin: 0; padding-left: 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 6px 32px; }

/* donut */
.donut { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; justify-content: center; }
.donut svg text { font-size: 10px; }
.donut .donut-big { font-size: 20px; font-weight: 600; fill: var(--text); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; min-width: 160px; flex: 1; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend b { font-variant-numeric: tabular-nums; }

.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 20px; }
.kv div { display: grid; gap: 2px; }
.kv span { font-size: 13px; color: var(--muted); }
.kv b { font-size: 18px; }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; } }

/* heatmap: opacity encodes the value */
.heat { overflow-x: auto; }
.heat-grid { display: grid; grid-template-columns: 36px repeat(24, minmax(16px, 1fr)); gap: 2px; min-width: 520px; }
.heat-day, .heat-hour { font-size: 11px; color: var(--muted); display: flex; align-items: center; }
.heat-cell { aspect-ratio: 1.6; border-radius: 4px; background: var(--hover); position: relative; overflow: hidden; }
.heat-cell::after { content: ""; position: absolute; inset: 0; background: var(--accent); opacity: var(--a); }
.heat-cell:hover { outline: 1px solid var(--text); }
.heat-scale { display: flex; align-items: center; gap: 4px; margin-top: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.heat-scale i { width: 14px; height: 10px; border-radius: 3px; position: relative; background: var(--hover); overflow: hidden; }
.heat-scale i::after { content: ""; position: absolute; inset: 0; background: var(--accent); opacity: var(--a); }

/* world map */
.geo { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(240px, 1fr); gap: 24px; align-items: start; }
@media (max-width: 820px) { .geo { grid-template-columns: 1fr; } }
.map { display: block; }
.map path { fill: var(--hover); stroke: var(--surface); stroke-width: .6; }
.map path.has { fill: color-mix(in srgb, var(--accent) calc(var(--a) * 100%), var(--hover)); }
.map path:hover { stroke: var(--text); stroke-width: 1; }
.map-loading { height: 300px; }

/* ───────── realtime ───────── */
.upsell { display: grid; gap: 10px; justify-items: start; }
.upsell h3 { font-size: 18px; }
.upsell ul { margin: 0; padding-left: 20px; }
.upsell .snippet { width: 100%; margin: 0; }
.feed { display: grid; gap: 2px; }
.feed-row { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; }
.feed-row .muted { flex: none; font-size: 13px; font-variant-numeric: tabular-nums; }
.feed-row.on span:first-child::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--success); margin-right: 8px; vertical-align: middle; }
@media (max-width: 640px) { .feed-row { flex-direction: column; gap: 0; } }
