:root {
  --forest-950: #031b14;
  --forest-900: #05271d;
  --forest-800: #073c2c;
  --forest-700: #0a5c42;
  --green: #1f9a6d;
  --green-soft: #e3f4ec;
  --gold: #c9962c;
  --gold-light: #f5d477;
  --red: #b3412f;
  --red-soft: #fbe9e5;
  --amber-soft: #fbf1d9;
  --ink: #0d1c17;
  --muted: #5d6f68;
  --paper: #f6f4ee;
  --card: #ffffff;
  --line: rgba(13, 54, 40, .12);
  --radius: 16px;
  --tabbar: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8efe9;
    --muted: #9db1a8;
    --paper: #04150f;
    --card: #0a241b;
    --line: rgba(232, 239, 233, .12);
    --green: #46c793;
    --green-soft: rgba(70, 199, 147, .14);
    --gold: #e8bd5a;
    --red: #ff8a75;
    --red-soft: rgba(255, 138, 117, .13);
    --amber-soft: rgba(232, 189, 90, .14);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--green); }
button, input, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; height: auto; }
h1, h2 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.skip-link { position: fixed; z-index: 50; top: 8px; inset-inline-start: 8px; padding: 8px 12px; border-radius: 8px; color: #fff; background: var(--forest-800); transform: translateY(-150%); }
.skip-link:focus { transform: none; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* Buttons */
button { cursor: pointer; }
.primary, .secondary {
  min-height: 48px; padding: 0 18px; border-radius: 12px; font-weight: 700; border: 1px solid transparent;
}
.primary { color: #10251b; background: linear-gradient(135deg, var(--gold-light), #d9a83f); }
.primary:disabled { opacity: .6; cursor: progress; }
.secondary { border-color: var(--line); background: var(--card); }
.secondary.danger { color: var(--red); }
.link { padding: 6px 0; border: 0; background: none; color: var(--green); font-weight: 600; text-decoration: underline; }
.icon-button { width: 40px; height: 40px; border: 1px solid rgba(255,255,255,.2); border-radius: 12px; color: #fff; background: rgba(255,255,255,.06); font-size: 20px; line-height: 1; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

/* Sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 70% 10%, rgba(31,144,102,.28), transparent 40%), linear-gradient(150deg, var(--forest-950), var(--forest-800)); }
/* Always dark: the logo's "T2" is white. */
.signin-card { --ink: #e8efe9; --muted: #9db1a8; --paper: #04150f; --line: rgba(232,239,233,.14); --green: #46c793; --gold: #e8bd5a; --red: #ff8a75;
  width: min(100%, 420px); padding: 28px 22px; border: 1px solid rgba(255,255,255,.08); border-radius: 22px; color: var(--ink); background: #0a241b; box-shadow: 0 24px 70px rgba(0,0,0,.35); color-scheme: dark; }
.signin-logo { width: 170px; margin-bottom: 18px; }
.signin h1 { font-size: 24px; margin-bottom: 8px; }
.eyebrow { margin: 0 0 6px; color: var(--gold); font-size: 11px; font-weight: 800; letter-spacing: .14em; }
.stack { display: grid; gap: 8px; margin-top: 18px; }
.stack label { font-weight: 700; font-size: 13px; }
.stack input { min-height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); font-size: 16px; }
#code { letter-spacing: .4em; font-size: 22px; text-align: center; direction: ltr; }
.error { min-height: 1.5em; margin: 10px 0 0; color: var(--red); font-weight: 600; }
.signin-foot { margin-top: 8px; text-align: center; }

/* Shell */
.shell { min-height: 100vh; padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--forest-950); }
.topbar-logo { width: 120px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.sync-state { color: rgba(255,255,255,.7); font-size: 12px; }
.content { width: min(100%, 980px); margin: 0 auto; padding: 18px 16px 28px; outline: none; }
.view-title { font-size: 22px; margin-bottom: 14px; }
.view-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.view-head .view-title { margin-bottom: 0; }
.section-title { margin: 22px 0 10px; font-size: 16px; }
.banner { margin: 0 0 14px; padding: 12px 14px; border-radius: 12px; font-weight: 600; }
.banner.warn { background: var(--amber-soft); }
.banner.bad { background: var(--red-soft); color: var(--red); }
.footnote { margin-top: 18px; color: var(--muted); font-size: 12px; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.card { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.card + .card { margin-top: 12px; }
.grid .card + .card { margin-top: 0; }
.card h2 { margin-bottom: 10px; font-size: 13px; color: var(--muted); font-weight: 700; letter-spacing: .02em; }
.big { margin: 0 0 8px; font-size: 28px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.more { display: inline-block; margin-top: 8px; font-weight: 700; font-size: 13px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: end; font-weight: 600; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--paper); border: 1px solid var(--line); white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok { background: var(--green-soft); }
.pill.ok::before { background: var(--green); }
.pill.warn { background: var(--amber-soft); }
.pill.warn::before { background: var(--gold); }
.pill.bad { background: var(--red-soft); color: var(--red); }
.pill.bad::before { background: var(--red); }

.device-list { display: grid; gap: 12px; }
.device-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.device-head strong { font-size: 16px; }
.device-reason { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--paper); font-size: 14px; }

.month-pick { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 700; }
.month-pick select { min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.summary-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.summary-row .pill::before { display: none; }
.list { display: grid; gap: 10px; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.row-title { font-weight: 700; }
.row-sub { color: var(--muted); font-size: 13px; }
.row-amount { font-weight: 800; text-align: end; font-variant-numeric: tabular-nums; }
.row-detail { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.empty { padding: 26px 16px; border: 1px dashed var(--line); border-radius: 14px; text-align: center; color: var(--muted); }

.message { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.message.unread { border-color: var(--gold); }
.message.important { border-inline-start: 5px solid var(--red); }
.message h2 { font-size: 16px; margin-bottom: 4px; }
.message-meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.message-body { white-space: pre-line; margin: 0 0 12px; }

.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.segmented button { min-height: 40px; padding: 0 16px; border: 0; border-radius: 9px; background: none; font-weight: 700; }
.segmented button[aria-pressed="true"] { background: var(--card); box-shadow: 0 1px 4px rgba(0,0,0,.12); }

.tabbar { position: fixed; z-index: 10; inset: auto 0 0; display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--line); background: var(--card); }
.tabbar a { position: relative; display: grid; place-items: center; align-content: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 700; text-decoration: none; }
.tabbar a[aria-current="page"] { color: var(--green); }
.tab-icon { font-size: 18px; line-height: 1; }
.badge { position: absolute; top: 8px; inset-inline-end: calc(50% - 22px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; color: #fff; background: var(--red); font-size: 11px; line-height: 18px; text-align: center; }
.noscript { padding: 24px; text-align: center; }

@media (min-width: 900px) {
  .shell { padding-bottom: 0; padding-inline-start: 200px; }
  .tabbar { inset: 0 auto 0 0; width: 200px; height: auto; grid-template-columns: 1fr; grid-auto-rows: 56px; align-content: start; padding-top: 80px; border-top: 0; border-inline-end: 1px solid var(--line); }
  html[dir="rtl"] .tabbar { inset: 0 0 0 auto; }
  .tabbar a { grid-auto-flow: column; justify-content: start; gap: 12px; padding-inline-start: 22px; font-size: 14px; }
  .badge { position: static; }
  .tabbar { padding-top: 76px; }
}

@media (prefers-reduced-motion: no-preference) {
  .view { animation: fade .18s ease-out; }
  @keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
