/* ═══════════════════════════════════════════════════════════════════════
   Kavach — phone-first policy tracker.

   The idea the whole design rests on: a policy is a window of cover. Every
   row carries a cover bar showing how much of its term is left, and the page
   stays calm and green while you're covered, warming to ochre and rust as
   things approach lapse. Colour here is state, not decoration.
   ═══════════════════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'Bricolage';
  src: url('/fonts/bricolage.woff2') format('woff2');
  font-weight: 400 800;
  font-display: swap;
}
@font-face {
  font-family: 'Instrument';
  src: url('/fonts/instrument.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrainsMono';
  src: url('/fonts/jetbrains.woff2') format('woff2');
  font-weight: 400 500;
  font-display: swap;
}

:root {
  /* Paper and ink */
  --paper: #f3f5f1;
  --card: #ffffff;
  --mist: #e9efe9;
  --line: #e0e5dc;
  --line-soft: #eef1ec;
  --ink: #16211d;
  --ink-2: #5d6b64;
  --ink-3: #8b978f;

  /* The one brand hue: deep pine */
  --pine: #114a3b;
  --pine-soft: #dfeae3;

  /* Cover status — the only other colours in the app */
  --jade: #2f9469;
  --jade-soft: #e2f2e9;
  --ochre: #a97612;
  --ochre-soft: #f7eed8;
  --rust: #b0442f;
  --rust-soft: #f8e6e1;
  --slate: #7d8a83;
  --slate-soft: #eceeec;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-full: 999px;

  --shadow: 0 1px 2px rgba(22, 33, 29, 0.04), 0 6px 16px -8px rgba(22, 33, 29, 0.12);
  --shadow-lift: 0 2px 6px rgba(22, 33, 29, 0.06), 0 20px 40px -16px rgba(22, 33, 29, 0.22);

  --gutter: 18px;
  --tabbar-h: 68px;

  --font-display: 'Bricolage', 'Instrument', system-ui, sans-serif;
  --font-body: 'Instrument', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrainsMono', ui-monospace, SFMono-Regular, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.02em; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--pine);
  outline-offset: 2px;
  border-radius: 4px;
}

.mono { font-family: var(--font-mono); font-size: 0.88em; letter-spacing: -0.01em; }

.icon { width: 1em; height: 1em; display: block; }

/* ── Sign in ───────────────────────────────────────────────────────────── */

.gate {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px var(--gutter) calc(40px + env(safe-area-inset-bottom));
  max-width: 420px;
  margin: 0 auto;
}
.gate__mark {
  width: 52px; height: 52px;
  color: var(--pine);
  font-size: 52px;
  margin-bottom: 22px;
}
.gate__title { font-size: 40px; line-height: 1; letter-spacing: -0.04em; }
.gate__tag { color: var(--ink-2); margin: 10px 0 30px; max-width: 30ch; }
.gate__form { display: flex; flex-direction: column; gap: 14px; }
.gate__error {
  margin: 0; padding: 10px 12px;
  background: var(--rust-soft); color: var(--rust);
  border-radius: var(--r-sm); font-size: 14px;
}

/* ── Fields ────────────────────────────────────────────────────────────── */

.field { display: block; }
.field__label {
  display: block;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}
.field__input, .field__select, .field__textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-size: 16px; /* 16px stops iOS zooming the page on focus */
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field__input:focus, .field__select:focus, .field__textarea:focus {
  outline: none;
  border-color: var(--pine);
  box-shadow: 0 0 0 3px var(--pine-soft);
}
.field__textarea { min-height: 80px; resize: vertical; }
.field__select { appearance: none; background-image: none; }
.field__hint { display: block; margin-top: 6px; font-size: 12.5px; color: var(--ink-3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px;
  border: 1px solid transparent;
  border-radius: var(--r-full);
  font-weight: 600; font-size: 15px;
  cursor: pointer;
  background: none;
  transition: transform 0.12s ease, background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.975); }
.btn--primary { background: var(--pine); color: #fff; }
.btn--outline { background: var(--card); border-color: var(--line); color: var(--ink); }
.btn--quiet { color: var(--ink-2); }
.btn--danger { background: var(--rust-soft); color: var(--rust); }
.btn--block { width: 100%; }
.btn--sm { padding: 8px 14px; font-size: 14px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

/* ── App shell ─────────────────────────────────────────────────────────── */

.app { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) var(--gutter) 12px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.topbar.is-stuck { border-bottom-color: var(--line); }
.topbar__brand { display: flex; align-items: center; gap: 8px; }
.topbar__mark { color: var(--pine); font-size: 19px; display: block; }
.topbar__name { font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: -0.03em; }
.topbar__today { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.screens { padding: 0 var(--gutter); max-width: 560px; margin: 0 auto; }
.screen__title { font-size: 22px; margin-bottom: 2px; }
.screen__title--spaced { margin-top: 34px; }
.screen__lede { color: var(--ink-2); font-size: 14px; margin: 0 0 14px; }

/* ── Hero: the next thing that needs you ───────────────────────────────── */

.hero {
  position: relative;
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-top: 6px;
  overflow: hidden;
}
/* A hairline of the status colour down the leading edge. */
.hero::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--status, var(--jade));
}
.hero__eyebrow {
  display: flex; align-items: center; gap: 7px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--status, var(--jade));
}
.hero__count {
  font-family: var(--font-display);
  font-size: 62px; line-height: 0.9; letter-spacing: -0.05em;
  font-weight: 700;
  margin: 12px 0 2px;
  font-variant-numeric: tabular-nums;
}
.hero__count small { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; margin-left: 6px; color: var(--ink-2); }
.hero__title { font-size: 18px; margin-top: 10px; }
.hero__meta { color: var(--ink-2); font-size: 13.5px; margin-top: 3px; }
.hero__actions { display: flex; gap: 8px; margin-top: 16px; }
.hero__actions .btn { flex: 1; }

.hero--empty { text-align: left; }
.hero--empty::before { background: var(--slate); }
.hero__empty-title { font-size: 20px; margin-bottom: 6px; }

/* ── The cover bar — the signature element ─────────────────────────────── */

.cover {
  --fill: 0%;
  position: relative;
  height: 6px;
  border-radius: var(--r-full);
  background: var(--track, var(--slate-soft));
  overflow: hidden;
  margin-top: 14px;
}
.cover__fill {
  position: absolute; inset: 0 auto 0 0;
  width: var(--fill);
  background: var(--status, var(--jade));
  border-radius: var(--r-full);
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
/* Lapsed policies show a full, muted bar — the term is over, not part-way. */
.cover--lapsed .cover__fill { width: 100%; opacity: 0.35; }
.cover__scale {
  display: flex; justify-content: space-between;
  margin-top: 7px;
  font-size: 11.5px; color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* ── Tally: three counts that double as filters ────────────────────────── */

.tally { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 20px; }
.tally__item {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 11px 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.tally__item:active { transform: scale(0.98); }
.tally__item.is-on { border-color: var(--tally, var(--pine)); background: var(--tally-soft, var(--pine-soft)); }
.tally__n {
  font-family: var(--font-display); font-weight: 700;
  font-size: 22px; line-height: 1;
  color: var(--tally, var(--ink));
  font-variant-numeric: tabular-nums;
}
.tally__label { font-size: 11.5px; color: var(--ink-2); margin-top: 3px; }

/* ── Selector ──────────────────────────────────────────────────────────── */

.selector { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.selector__row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.selector__legend {
  flex: none; width: 34px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--ink-3);
}
.chips {
  /* flex:1 + min-width:0 is what actually lets this scroll. Without min-width
     the flex item sizes to its content and pushes the whole page sideways. */
  flex: 1 1 auto;
  min-width: 0;
  display: flex; gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  font-size: 13.5px; font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  scroll-snap-align: start;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.chip:active { transform: scale(0.96); }
.chip.is-on { background: var(--pine); border-color: var(--pine); color: #fff; }
.chip__icon { font-size: 12px; opacity: 0.75; }
.chip__n { font-size: 11.5px; opacity: 0.6; font-variant-numeric: tabular-nums; }

/* ── List ──────────────────────────────────────────────────────────────── */

.listhead { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.listhead__title { font-size: 15px; font-weight: 600; font-family: var(--font-body); letter-spacing: 0; color: var(--ink-2); }
.listhead__search {
  border: none; background: none; cursor: pointer;
  color: var(--ink-3); font-size: 15px; padding: 4px;
}
.searchbar { margin-bottom: 12px; }

.list { display: flex; flex-direction: column; gap: 9px; }

.row {
  position: relative;
  display: block; width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 14px 15px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.row:active { transform: scale(0.99); }
.row__top { display: flex; align-items: flex-start; gap: 11px; }

.avatar {
  flex: none;
  width: 34px; height: 34px;
  border-radius: var(--r-full);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 700; font-size: 13px;
  letter-spacing: -0.01em;
}
.accent-0 { background: var(--pine-soft); color: var(--pine); }
.accent-1 { background: #e6eef6; color: #2c5c86; }
.accent-2 { background: #f4ebf5; color: #7a4a86; }
.accent-3 { background: #f7eee2; color: #8a5f27; }
.accent-4 { background: #e8f1ee; color: #2f6f5e; }
.accent-5 { background: #f6e9ec; color: #8a3d4f; }

/* These are spans inside a <button> (a button may not contain block elements
   in valid HTML), so each one is explicitly made block-level here. */
.row__main { display: block; flex: 1; min-width: 0; }
.row__title {
  display: block;
  font-weight: 600; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row__meta {
  display: block;
  font-size: 12.5px; color: var(--ink-2);
  margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row__right { display: block; flex: none; text-align: right; }
.row__days {
  display: block;
  font-family: var(--font-display); font-weight: 700;
  font-size: 17px; line-height: 1.1;
  color: var(--status, var(--ink));
  font-variant-numeric: tabular-nums;
}
.row__date { display: block; font-size: 11.5px; color: var(--ink-3); margin-top: 2px; font-variant-numeric: tabular-nums; }
/* In a row the renewal date is already in the right-hand column, so the bar
   carries no labels — the bar alone. */
.row .cover { margin-top: 12px; }

.empty {
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  padding: 26px 20px;
  text-align: center;
}
.empty__title { font-size: 16px; margin-bottom: 5px; }
.empty__body { font-size: 13.5px; color: var(--ink-2); margin: 0 0 16px; }

/* ── Detail / panels ───────────────────────────────────────────────────── */

.panel {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  overflow: hidden;
}
.panel + .panel { margin-top: 9px; }
.panel__row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 15px;
  width: 100%;
  background: none; border: none; border-bottom: 1px solid var(--line-soft);
  text-align: left;
}
.panel__row:last-child { border-bottom: none; }
button.panel__row { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.panel__label { font-size: 14px; }
.panel__value { font-size: 13.5px; color: var(--ink-2); text-align: right; }
.panel__sub { display: block; font-size: 12px; color: var(--ink-3); margin-top: 2px; }

.deflist { display: grid; grid-template-columns: auto 1fr; gap: 9px 16px; margin: 0; }
.deflist dt { font-size: 12.5px; color: var(--ink-3); }
.deflist dd { margin: 0; font-size: 13.5px; text-align: right; word-break: break-word; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  font-size: 11.5px; font-weight: 600;
  background: var(--status-soft, var(--jade-soft));
  color: var(--status, var(--jade));
}

/* ── Tab bar ───────────────────────────────────────────────────────────── */

.tabbar {
  position: fixed; z-index: 30;
  left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  display: flex; align-items: center; gap: 2px;
  padding: 6px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(16px);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  box-shadow: var(--shadow-lift);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 64px;
  padding: 7px 10px;
  border: none; background: none;
  border-radius: var(--r-full);
  color: var(--ink-3);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tab__icon { font-size: 17px; display: block; }
.tab__label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em; }
.tab.is-on { color: var(--pine); background: var(--pine-soft); }
.tab--add {
  min-width: 0;
  width: 44px; height: 44px;
  background: var(--pine); color: #fff;
  justify-content: center;
  margin: 0 4px;
}
.tab--add .tab__icon { font-size: 15px; }
.tab--add:active { transform: scale(0.94); }

/* ── Sheet ─────────────────────────────────────────────────────────────── */

.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet__scrim {
  position: absolute; inset: 0;
  background: rgba(22, 33, 29, 0.32);
  animation: fade 0.2s ease;
}
.sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--paper);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-lift);
  animation: rise 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  max-width: 560px; margin: 0 auto;
}
.sheet__grip { padding: 10px 0 4px; display: grid; place-items: center; cursor: pointer; }
.sheet__grip::after { content: ''; width: 38px; height: 4px; border-radius: var(--r-full); background: var(--line); }
.sheet__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 4px var(--gutter) 12px;
}
.sheet__title { font-size: 19px; }
.sheet__close {
  border: none; background: var(--mist); color: var(--ink-2);
  width: 30px; height: 30px; border-radius: var(--r-full);
  display: grid; place-items: center; cursor: pointer; font-size: 13px;
}
.sheet__body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--gutter) calc(env(safe-area-inset-bottom) + 24px);
}
.form { display: flex; flex-direction: column; gap: 14px; }
.form__actions { display: flex; gap: 8px; margin-top: 6px; }
.form__actions .btn { flex: 1; }
.form__error { margin: 0; padding: 10px 12px; background: var(--rust-soft); color: var(--rust); border-radius: var(--r-sm); font-size: 13.5px; }
.form__section {
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--ink-3);
  margin: 8px 0 -4px;
}

.offsets { display: flex; flex-wrap: wrap; gap: 7px; }
.offset {
  padding: 7px 12px;
  border: 1px solid var(--line); background: var(--card);
  border-radius: var(--r-full);
  font-size: 13px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.offset.is-on { background: var(--pine); border-color: var(--pine); color: #fff; }

/* ── Toast ─────────────────────────────────────────────────────────────── */

.toast {
  position: fixed; z-index: 60;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 22px);
  max-width: calc(100vw - 32px);
  padding: 11px 17px;
  background: var(--ink); color: var(--paper);
  border-radius: var(--r-full);
  font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-lift);
  animation: rise 0.22s ease;
}
.toast--bad { background: var(--rust); }

@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet__panel { will-change: transform; }
.toast { animation-name: rise; }

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

/* Wider phones and small tablets: the app stays a single readable column. */
@media (min-width: 600px) {
  .screens { padding-left: 0; padding-right: 0; }
  .app { padding-left: var(--gutter); padding-right: var(--gutter); }
  .topbar { max-width: 560px; margin: 0 auto; padding-left: 0; padding-right: 0; }
}
