:root {
  --bg: #F2F4F4; --surface: #FFFFFF; --ink: #142120; --muted: #587068; --line: #D8E0DE;
  --accent: #0E5A4B; --accent-ink: #FFFFFF; --soft: #E2EEEA; --warn: #8A5A00; --warn-bg: #FFF3D6; --err: #A32424;
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "Instrument Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1415; --surface: #152022; --ink: #E5EDEB; --muted: #93A8A3; --line: #26393B;
    --accent: #4FC2A5; --accent-ink: #06201A; --soft: #1B2F2F; --warn: #F2C86B; --warn-bg: #2E2610; --err: #FF8E8E;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 16px; line-height: 1.45;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-left)) calc(84px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-right));
}
.wrap { max-width: 920px; margin: 0 auto; }
h1, h2 { font-family: var(--font-display); letter-spacing: -0.01em; text-wrap: balance; margin: 0; }
h1 { font-size: 24px; line-height: 1.1; }
h2 { font-size: 19px; }
button, input, select, textarea { font: inherit; color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
[hidden] { display: none !important; }

/* top bar */
header.top { position: sticky; top: env(safe-area-inset-top); z-index: 5; background: var(--bg); padding: 14px 0 10px; border-bottom: 1px solid var(--line); }
.hrow { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.stats { display: flex; gap: 8px; margin-top: 10px; }
.stat { flex: 1 1 0; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.stat b { display: block; font-family: var(--font-display); font-size: 21px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px; background: transparent; cursor: pointer; font-size: 14px; font-weight: 500; white-space: nowrap; touch-action: manipulation; }
.chip .n { color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip[aria-pressed="true"] .n { color: inherit; opacity: .8; }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding-top: 8px; }
input[type=text], input[type=search], input[type=password], input[type=email], input[type=number], input[type=date], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-height: 44px; width: 100%; min-width: 0;
}
textarea { resize: vertical; line-height: 1.45; }
.tools input[type=search] { flex: 1 1 220px; }
.chk { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14.5px; cursor: pointer; }
.chk input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

/* buttons */
.btn { min-height: 44px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 8px; background: transparent; font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; touch-action: manipulation; color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--err); }
.btn[disabled], .btn.off { opacity: .45; pointer-events: none; }
.btn:hover { border-color: var(--accent); }
.btn.sm { min-height: 40px; padding: 6px 12px; font-size: 14px; }

/* list */
ul.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
li.row { padding: 14px 0; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
li.row.done { opacity: .55; }
li.row.nocontact .name { text-decoration: line-through; }
.name { margin: 0; font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--accent); margin-left: 6px; vertical-align: 1px; }
.pill.legacy { background: var(--warn-bg); color: var(--warn); }
.acts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.marks { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.more { display: flex; justify-content: center; padding: 20px 0; }
.empty { color: var(--muted); padding: 32px 0; text-align: center; }

/* panels / forms */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-top: 16px; display: grid; gap: 12px; }
.field { display: grid; gap: 4px; }
.field > label, .lbl { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: 14px; overflow-wrap: anywhere; }
.note.ok { background: var(--soft); color: var(--accent); }
.note.err { background: var(--warn-bg); color: var(--err); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .4s; }

/* bottom nav */
nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--line); display: flex; padding-bottom: env(safe-area-inset-bottom); }
nav.bottom button { flex: 1; min-height: 56px; border: 0; background: transparent; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; display: grid; place-items: center; gap: 2px; padding: 6px 2px; touch-action: manipulation; }
nav.bottom button[aria-current="page"] { color: var(--accent); }
nav.bottom svg { width: 22px; height: 22px; }

/* sheet */
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(8, 16, 15, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: 94dvh; overflow-y: auto; background: var(--bg); border-radius: 16px 16px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 12px; }
.sheet header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { min-height: 44px; border: 1px solid var(--line); background: transparent; border-radius: 8px; font-weight: 600; font-size: 14px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.login { max-width: 400px; margin: 12vh auto 0; display: grid; gap: 14px; }
.cand { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }

#toast { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 50; max-width: 90vw; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 720px) {
  li.row { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 20px; }
  .overlay { align-items: center; }
  .sheet { border-radius: 16px; }
}
@media (prefers-reduced-motion: reduce) { #toast, .bar > i { transition: none; } }
#sheet-body { display: grid; gap: 12px; }
