:root {
  --bg: #f4f3f8;
  --surface: #ffffff;
  --surface-2: #ecebf2;
  --text: #17161d;
  --muted: #6b6878;
  --line: #e2e0ea;
  --accent: #5b4bdb;
  --accent-soft: #ebe8fd;
  --on-accent: #ffffff;
  --green: #1f9d55;
  --green-soft: #e3f5ea;
  --amber: #b26a00;
  --amber-soft: #fdf1dc;
  --blue: #2563c9;
  --blue-soft: #e4edfb;
  --red: #c4302b;
  --red-soft: #fbe6e5;
  --shadow: 0 1px 2px rgb(20 18 40 / 6%), 0 4px 16px rgb(20 18 40 / 5%);
  --radius: 16px;
  --tabbar-h: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121118;
    --surface: #1c1b24;
    --surface-2: #26252f;
    --text: #f1f0f6;
    --muted: #9c99aa;
    --line: #2e2d38;
    --accent: #8f82ff;
    --accent-soft: #2a2650;
    --on-accent: #ffffff;
    --green: #4cc982;
    --green-soft: #183326;
    --amber: #f0b44c;
    --amber-soft: #3a2b12;
    --blue: #79a7f5;
    --blue-soft: #1a2944;
    --red: #f07a74;
    --red-soft: #3d1c1b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* App-shell layout: the page itself never scrolls; only <main> does. The top bar and
   tab bar are ordinary flex rows, so mobile browsers (iOS Safari's collapsing toolbar,
   overscroll bounce) can't drag them off screen the way they can a position:fixed bar. */
html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */
.topbar {
  flex: none;
  z-index: 10;
  padding-top: var(--safe-top);
  background: var(--bg);
}
.topbar-inner {
  max-width: 600px;
  margin: 0 auto;
  padding: 14px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
}
.topbar h1 { margin: 0; font-size: 30px; font-weight: 750; letter-spacing: -0.02em; }

main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* full-width scroller (scrollbar at the window edge), content capped at 600px */
  padding: 4px max(16px, calc((100% - 568px) / 2)) 28px;
}
.view { animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.tabbar {
  flex: none;
  z-index: 20;
  display: flex;
  justify-content: center;
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  max-width: 200px;
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.tab svg { width: 25px; height: 25px; }
.tab[aria-current="page"] { color: var(--accent); }

/* ---------- home ---------- */
.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 4px 0 22px;
}
.hero-icon {
  width: 56px; height: 56px;
  border-radius: 15px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #e0469d));
  color: #fff;
}
.hero-icon svg { fill: currentColor; stroke: none; width: 28px; height: 28px; }
.hero-name { margin: 0; font-size: 19px; font-weight: 700; }
.hero-tagline { margin: 2px 0 0; color: var(--muted); }

.section-label {
  margin: 26px 4px 8px;
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.section-head { display: flex; align-items: baseline; justify-content: space-between; }
.section-head .link-btn { margin-right: 4px; }

.card-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.service {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: transform .1s;
}
.service:active, .cta:active, .request.tappable:active { transform: scale(.98); }
.service-logo {
  width: 46px; height: 46px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 20px;
  color: #fff;
}
.service-body { flex: 1; min-width: 0; }
.service-name { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.service-desc { color: var(--muted); font-size: 14px; margin-top: 1px; }
.chev { color: var(--muted); width: 20px; height: 20px; opacity: .7; }

.status-dot { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
.status-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-dot.up { color: var(--green); }
.status-dot.down { color: var(--red); }

.cta {
  margin-top: 14px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: inherit;
  text-decoration: none;
  transition: transform .1s;
}
.cta-icon {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
}
.cta-text { flex: 1; display: flex; flex-direction: column; }
.cta-text span { color: var(--muted); font-size: 14px; }

/* ---------- storage ---------- */
.storage { --meter: var(--accent); }
.storage.warn { --meter: var(--amber); }
.storage.full { --meter: var(--red); }
.storage-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.storage-name { font-weight: 650; }
.storage-pct { font-size: 14px; font-weight: 650; color: var(--muted); }
.storage.warn .storage-pct, .storage.full .storage-pct { color: var(--meter); }
.meter {
  display: block;
  height: 8px;
  margin: 10px 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.meter-fill { display: block; height: 100%; border-radius: inherit; background: var(--meter); }
.storage-detail { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; font-size: 14px; }

/* ---------- requests ---------- */
.segmented {
  display: flex;
  background: var(--surface-2);
  border-radius: 11px;
  padding: 3px;
  margin: 4px 0 16px;
}
.segmented button {
  flex: 1;
  padding: 7px 4px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.segmented button[aria-selected="true"], .segmented button[aria-checked="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(0 0 0 / 12%);
}
.segmented.big button { padding: 10px 4px; font-size: 15px; }

.request {
  display: flex;
  gap: 13px;
  align-items: flex-start;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  text-align: left;
  transition: transform .1s;
}
.kind-badge {
  width: 42px; height: 42px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted);
}
.kind-badge svg { width: 22px; height: 22px; }
.request-body { flex: 1; min-width: 0; }
.request-body > span, .service-body > span, .service-name { display: block; }
.service-name { display: flex; }
.request-title { font-weight: 650; overflow-wrap: anywhere; }
.request-title .year { color: var(--muted); font-weight: 500; }
.request-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.request-note { font-size: 14px; margin-top: 6px; color: var(--text); opacity: .85; overflow-wrap: anywhere; }

.chip {
  flex: none;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.chip.pending { background: var(--amber-soft); color: var(--amber); }
.chip.approved { background: var(--blue-soft); color: var(--blue); }
.chip.available { background: var(--green-soft); color: var(--green); }
.chip.declined { background: var(--red-soft); color: var(--red); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 20px;
  background: var(--surface);
  border-radius: var(--radius);
}
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

/* ---------- shared subscriptions ---------- */
.tip-small { font-size: 13px; color: var(--muted); }
.sub { display: block; }
.sub-top { display: flex; gap: 13px; align-items: flex-start; }
.service-logo.small { width: 42px; height: 42px; border-radius: 11px; font-size: 18px; }
.sub-detail { font-size: 14px; margin-top: 4px; }
.sub-interest { font-size: 13px; color: var(--muted); margin-top: 6px; overflow-wrap: anywhere; }
.sub-actions { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; }
.sub-actions:empty { display: none; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.chip.listed { background: var(--green-soft); color: var(--green); }
.chip.full { background: var(--surface-2); color: var(--muted); }
.sheet-lede { margin: 0 4px 12px; }

/* ---------- help ---------- */
.install-tip {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-size: 14px;
  margin-top: 4px;
}
.install-tip strong { font-size: 15px; }
.faq { display: grid; gap: 10px; }
.faq details {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0 16px;
}
.faq summary {
  list-style: none;
  padding: 15px 0;
  font-weight: 600;
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary svg { width: 18px; height: 18px; color: var(--muted); transition: transform .2s; }
.faq details[open] summary svg { transform: rotate(90deg); }
.faq p { margin: 0 0 15px; color: var(--muted); }

.admin-card p { margin: 0 0 12px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }

/* ---------- forms ---------- */
input, textarea {
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 11px 12px;
  width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }
textarea { resize: none; }

.field-group {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px 14px;
  margin-bottom: 14px;
}
.field { display: block; padding: 10px 0; }
.field + .field { border-top: 1px solid var(--line); }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field em { font-style: normal; font-weight: 500; opacity: .8; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 650;
}
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }
.link-btn { color: var(--accent); font-weight: 600; font-size: 15px; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; }
.icon-btn.accent { background: var(--accent); color: var(--on-accent); }
.icon-btn svg { width: 20px; height: 20px; stroke-width: 2.5; }

.form-error {
  color: var(--red);
  background: var(--red-soft);
  border-radius: 11px;
  padding: 10px 12px;
  margin: 0 0 14px;
  font-size: 14px;
}

/* ---------- sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgb(0 0 0 / 40%);
  animation: fadein .2s ease-out;
}
@keyframes fadein { from { opacity: 0; } }
.sheet {
  position: fixed;
  z-index: 50;
  left: 0; right: 0; bottom: 0;
  margin: 0 auto;
  max-width: 600px;
  max-height: calc(100dvh - var(--safe-top) - 24px);
  overflow-y: auto;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + var(--safe-bottom));
  animation: slideup .28s cubic-bezier(.2, .9, .3, 1);
  overscroll-behavior: contain;
}
@keyframes slideup { from { transform: translateY(100%); } }
.sheet-grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 6px; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-head .link-btn { justify-self: start; }

.action-title { text-align: center; font-size: 15px; color: var(--muted); font-weight: 600; margin: 6px 0 12px; overflow-wrap: anywhere; }
.action-list {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
}
.action-list button {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 15px 16px;
  font-weight: 600;
  text-align: left;
}
.action-list button + button { border-top: 1px solid var(--line); }
.action-list button.danger { color: var(--red); }
.action-list .tick { color: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 11px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
  animation: toastin .25s ease-out;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (min-width: 700px) {
  .topbar h1 { font-size: 32px; }
}
