:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #1f2937;
  --accent: #2563eb;
  --ok: #059669;
  --soon: #d97706;
  --overdue: #dc2626;
  --today: #7c3aed;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--brand); color: #fff;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand span { vertical-align: middle; }
.search { flex: 1; }
.search input {
  width: 100%; padding: 8px 12px; border-radius: 999px; border: none;
  background: rgba(255,255,255,.15); color: #fff; font-size: 16px;
}
.search input::placeholder { color: rgba(255,255,255,.7); }
.topbar-meta { display: flex; align-items: center; gap: 8px; }
.chip { background: rgba(255,255,255,.18); padding: 3px 8px; border-radius: 999px; font-size: .72rem; }
.linkbtn { background: none; border: none; color: #fff; cursor: pointer; font-size: .85rem; opacity: .9; }
.inline { display: inline; margin: 0; }

/* ---- Side nav (desktop) ---- */
.sidenav { display: none; }
@media (min-width: 900px) {
  .sidenav {
    display: flex; flex-direction: column; gap: 2px;
    position: fixed; top: 56px; left: 0; width: 210px; bottom: 0;
    padding: 14px 10px; background: #fff; border-right: 1px solid var(--line);
    overflow-y: auto;
  }
  .sidenav a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    border-radius: 10px; color: var(--ink); font-weight: 500;
  }
  .sidenav a.active { background: #eef2ff; color: var(--accent); }
  .sidenav a.emergency-link { color: var(--overdue); }
  .content { margin-left: 210px; }
}

/* ---- Content ---- */
.content { padding: 16px; max-width: 900px; margin: 0 auto; padding-bottom: 90px; }
h1 { font-size: 1.4rem; margin: .2em 0 .6em; }
h2 { font-size: 1.05rem; margin: 1.2em 0 .5em; }
.muted { color: var(--muted); }

/* ---- Cards ---- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; font-size: .95rem; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.stat { text-align: left; }
.stat .num { font-size: 1.6rem; font-weight: 700; }
.stat a { color: inherit; display: block; }

/* ---- List rows ---- */
.rowlist { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; box-shadow: var(--shadow); min-height: 52px;
}
.row .main { min-width: 0; }
.row .main .t { font-weight: 600; }
.row .main .s { color: var(--muted); font-size: .85rem; }
.row .side { text-align: right; white-space: nowrap; }
.row .rowmain {
  flex: 1; min-width: 0; display: flex; align-items: center;
  justify-content: space-between; gap: 10px; color: inherit; text-decoration: none;
}

/* Tap-to-open contact card (a person under a vendor / provider). The whole card
   is the link; actions (Add to iPhone, Edit, Remove) live on the full card, so
   the row stays clean instead of cramming buttons beside squished text. */
.row.contact-card { color: inherit; text-decoration: none; }
.row.contact-card .main .t { font-size: 1.02rem; }
.row.contact-card .side { font-size: 1.4rem; color: var(--muted); flex: 0 0 auto; }
.row.contact-card:hover { border-color: var(--accent); }

/* One-tap done / reopen toggle */
.donebtn {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; color: var(--accent);
  font-size: 1.15rem; line-height: 1; cursor: pointer; padding: 0;
}
.donebtn:hover { background: #eef2ff; }
.donebtn.is-done { color: var(--muted); }
.table .donebtn { width: 34px; height: 34px; font-size: 1rem; }

/* ---- Badges ---- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .72rem; font-weight: 600; background: #eef2ff; color: #3730a3;
  border: 1px solid #e0e7ff;
}
.badge.overdue { background: #fef2f2; color: var(--overdue); border-color: #fecaca; }
.badge.today   { background: #f5f3ff; color: var(--today);   border-color: #ddd6fe; }
.badge.soon    { background: #fffbeb; color: var(--soon);    border-color: #fde68a; }
.badge.ok      { background: #ecfdf5; color: var(--ok);      border-color: #a7f3d0; }
.badge.sensitive { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.badge.secret_reference { background: #f0f9ff; color: #075985; border-color: #bae6fd; }

/* ---- Buttons ---- */
.btn {
  display: inline-block; padding: 11px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-weight: 600; cursor: pointer; font-size: .95rem;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { background: var(--overdue); color: #fff; border-color: var(--overdue); }
.btn.block { display: block; width: 100%; text-align: center; }
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.fab {
  position: fixed; right: 18px; z-index: 25;
  /* Sit clear of the mobile bottom nav, which grows by the safe-area inset on
     phones with a home indicator. */
  bottom: calc(84px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 1.8rem; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(37,99,235,.4);
}
/* Desktop: no bottom nav, so drop it back to the corner. */
@media (min-width: 900px) { .fab { bottom: 24px; } }

/* ---- Forms ---- */
form.stack label { display: block; font-weight: 600; font-size: .85rem; margin: 12px 0 4px; }
form.stack input, form.stack select, form.stack textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; background: #fff; color: var(--ink);
}
/* Checkboxes / radios (e.g. assigned people) shouldn't stretch full width. */
form.stack input[type="checkbox"], form.stack input[type="radio"] {
  width: auto; margin: 0 10px 0 0; padding: 0; transform: scale(1.25);
  flex: none;
}
form.stack ul { list-style: none; padding: 0; margin: 6px 0; }
form.stack ul li { margin: 0; }
form.stack ul li label {
  display: flex; align-items: center; font-weight: 400; font-size: 1rem;
  margin: 8px 0; padding: 11px 12px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
form.stack .helptext { color: var(--muted); font-size: .78rem; margin-top: 3px; }
form.stack .errorlist { color: var(--overdue); font-size: .82rem; margin: 4px 0 0; padding-left: 18px; }

/* ---- Detail ---- */
.kv { display: grid; grid-template-columns: 40% 60%; gap: 6px 10px; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

/* ---- Messages ---- */
.messages { list-style: none; padding: 0; margin: 0 0 12px; }
.msg { padding: 10px 14px; border-radius: 10px; margin-bottom: 8px; font-weight: 500; }
.msg.success { background: #ecfdf5; color: #065f46; }
.msg.error { background: #fef2f2; color: #991b1b; }
.msg.info, .msg.warning { background: #eff6ff; color: #1e40af; }

/* ---- Table (desktop lists) ---- */
.table { width: 100%; border-collapse: collapse; display: none; }
@media (min-width: 720px) {
  .table { display: table; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
  .table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: .9rem; }
  .table th { background: #f9fafb; color: var(--muted); font-weight: 600; }
  .table tr:last-child td { border-bottom: none; }
  .rowlist.mobile-only { display: none; }
}

/* ---- Bottom nav (mobile) ---- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around; background: #fff;
  border-top: 1px solid var(--line); padding: 6px 0;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
}
.bottomnav a { color: var(--muted); font-size: 1.3rem; text-align: center; display: flex; flex-direction: column; }
.bottomnav a span { font-size: .65rem; }
.bottomnav a.emergency-link { color: var(--overdue); }
@media (min-width: 900px) { .bottomnav { display: none; } }

/* ---- Auth ---- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 360px; }
.auth-card h1 { text-align: center; }

/* ---- Emergency ---- */
.emergency-hero { background: #fef2f2; border: 1px solid #fecaca; }
.emergency-hero h1 { color: var(--overdue); }

/* ---- Loading spinner (AI quick-add submit) ---- */
.spinner {
  display: inline-block; width: 1em; height: 1em; vertical-align: -0.15em;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn.is-loading { opacity: 0.8; cursor: progress; }
.working-note { margin-top: 10px; display: flex; align-items: center; gap: 8px; }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

