:root {
  --bg: #0b1020;
  --panel: #141a2e;
  --panel-2: #1b2238;
  --text: #e6e9f2;
  --muted: #9aa4bf;
  --accent: #5b8cff;
  --good: #34d399;
  --bad: #f87171;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* The `hidden` attribute must always win, even over id selectors that set
   `display` (e.g. #login). Without this, hidden screens stay visible. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen { min-height: 100vh; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); margin: 8px 0 0; font-size: 14px; }

/* --- Login --- */
#login { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.brand-mark {
  width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--accent), #8a6bff);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 26px; color: #fff;
}
.login-card h1 { margin: 0; font-size: 24px; }
.login-card form { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.passkey-btn {
  margin-top: 24px; width: 100%;
  background: linear-gradient(135deg, #5b8cff, #8a6bff);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 16px 0 0; font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: #283150; }
input {
  background: var(--panel); border: 1px solid #283150; color: var(--text);
  padding: 14px 16px; border-radius: 12px; font-size: 16px;
}
input:focus { outline: none; border-color: var(--accent); }
button {
  background: var(--accent); color: #fff; border: none; border-radius: 12px;
  padding: 14px; font-size: 16px; font-weight: 600;
}
button:disabled { opacity: .6; }

/* --- Dashboard --- */
#dashboard { padding: 16px 16px 40px; max-width: 720px; margin: 0 auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.topbar h2 { margin: 0; font-size: 22px; }
.topbar-actions { display: flex; gap: 8px; }
.ghost {
  background: var(--panel); width: 40px; height: 40px; padding: 0;
  border-radius: 12px; font-size: 17px; color: var(--text);
}

.banner {
  background: linear-gradient(135deg, #2a3358, #20284a);
  border: 1px solid #34406b; border-radius: 12px;
  padding: 12px 14px; margin-bottom: 14px; display: flex;
  align-items: center; justify-content: space-between; gap: 10px; font-size: 14px;
}
.banner button { padding: 8px 14px; font-size: 14px; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.card {
  background: var(--panel); border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 4px; border: 1px solid #1f2740;
}
.card .label { color: var(--muted); font-size: 12px; }
.card .value { font-size: 26px; font-weight: 700; }
.card .sub { color: var(--muted); font-size: 12px; }
.card.good { border-color: rgba(52,211,153,.4); }
.card.bad { border-color: rgba(248,113,113,.5); }
.card.bad .value { color: var(--bad); }
.card.good .value { color: var(--good); }

.panel {
  background: var(--panel); border-radius: var(--radius); padding: 16px;
  margin-bottom: 16px; border: 1px solid #1f2740;
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.panel-head h3 { margin: 0; font-size: 16px; }
/* Fixed-height container so Chart.js (maintainAspectRatio:false) has a bounded
   height to fill. Without this the canvas grows taller every frame. */
.chart-wrap { position: relative; height: 200px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* --- Funnel --- */
.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-row { display: grid; grid-template-columns: 96px 1fr 44px; align-items: center; gap: 10px; }
.funnel-label { font-size: 13px; color: var(--muted); }
.funnel-bar { background: var(--panel-2); border-radius: 6px; height: 12px; overflow: hidden; }
.funnel-bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), #8a6bff); }
.funnel-n { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }

/* --- Segmented toggle --- */
.seg { display: inline-flex; background: var(--panel-2); border-radius: 7px; padding: 2px; gap: 2px; }
.seg-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 5px; line-height: 1;
}
.seg-btn.is-active { background: var(--accent); color: #fff; }

/* --- Feeds --- */
.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.feed li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  padding: 10px 0; border-bottom: 1px solid #1f2740; align-items: center;
}
.feed li:last-child { border-bottom: none; }
.feed-main { grid-column: 1; grid-row: 1; font-weight: 600; }
.feed-time { grid-column: 2; grid-row: 1 / span 2; align-self: center; text-align: right; }

.foot { text-align: center; margin-top: 8px; }
