:root {
  --bg: #f6f4f0;
  --panel: #ffffff;
  --ink: #22221f;
  --ink-soft: #6b6a63;
  --line: #e2e0d8;
  --accent: #2f5d50;
  --accent-ink: #ffffff;

  --overdue: #b23b2e;
  --due-soon: #a06a10;
  --ok: #2f7a4f;
  --neutral: #6b6a63;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171712;
    --panel: #201f1a;
    --ink: #f2f1ea;
    --ink-soft: #a8a69c;
    --line: #35342c;
    --accent: #6fae9a;
    --accent-ink: #14231e;

    --overdue: #e06a5a;
    --due-soon: #d6a13a;
    --ok: #5fbf85;
    --neutral: #a8a69c;
  }
}
:root[data-theme="dark"] {
  --bg: #171712; --panel: #201f1a; --ink: #f2f1ea; --ink-soft: #a8a69c; --line: #35342c;
  --accent: #6fae9a; --accent-ink: #14231e;
  --overdue: #e06a5a; --due-soon: #d6a13a; --ok: #5fbf85; --neutral: #a8a69c;
}
:root[data-theme="light"] {
  --bg: #f6f4f0; --panel: #ffffff; --ink: #22221f; --ink-soft: #6b6a63; --line: #e2e0d8;
  --accent: #2f5d50; --accent-ink: #ffffff;
  --overdue: #b23b2e; --due-soon: #a06a10; --ok: #2f7a4f; --neutral: #6b6a63;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body { padding-bottom: env(safe-area-inset-bottom); }

button, input, textarea { font-family: inherit; }

.wrap { max-width: 640px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.25rem 0 1.1rem;
}
.topbar h1 { font-size: 1.3rem; font-weight: 650; margin: 0; flex: 1; }
.topbar .back {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; min-width: 44px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); text-decoration: none; font-size: 1.2rem;
}
.topbar-icon {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; min-width: 32px;
  color: var(--ink-soft);
}
.topbar-icon svg { width: 100%; height: 100%; fill: currentColor; }
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; min-width: 44px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); cursor: pointer; font-size: 1.1rem;
}
.icon-btn:active { border-color: var(--accent); }
.icon-btn svg { display: block; }

/* Search */
.search-box {
  display: block; width: 100%; padding: 0.85rem 1rem;
  border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); font-size: 1rem; margin-bottom: 1rem;
}
.search-box:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Dashboard rows */
.zone-heading {
  font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 700; color: var(--ink); margin: 2rem 0 0.75rem; padding: 0 0.1rem;
}
/* The first zone's heading gets this from app.js (class="zone-heading first"),
   since :first-of-type matches the first .zone-heading in EACH zone's own
   wrapper div, not just the first one on the whole page — every zone's
   heading matched it and lost its top margin. */
.zone-heading.first { margin-top: 0; }

.row-list {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem;
}
/* Compact horizontal tile: icon left, name/status right. Half the height of
   the old square tiles, so twice as many appliances fit on screen — this is
   a list you scan for red, not a gallery. */
.appliance-row {
  display: flex; align-items: center;
  gap: 0.75rem; width: 100%; min-height: 64px;
  background: var(--panel); border: 2px solid var(--line);
  border-radius: 16px; padding: 0.7rem 0.85rem;
  text-decoration: none; color: var(--ink); text-align: left;
  cursor: pointer;
}
.appliance-row.status-overdue { border-color: var(--overdue); background: color-mix(in srgb, var(--overdue) 12%, var(--panel)); }
.appliance-row.status-due-soon { border-color: var(--due-soon); background: color-mix(in srgb, var(--due-soon) 12%, var(--panel)); }
.appliance-row.status-ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--panel)); }
.appliance-row.status-as-needed { border-color: var(--line); }
.appliance-row.status-never-logged { border-color: var(--line); }
/* Unscheduled = a recurring rule with nothing to measure from. Not an
   urgency color (nothing is provably late), but dashed so it reads as an
   open question rather than a settled, healthy state. */
.appliance-row.status-unscheduled { border-color: var(--neutral); border-style: dashed; }

.row-icon {
  display: flex; align-items: center; justify-content: center;
  width: 44px; aspect-ratio: 1; flex: none;
  color: var(--ink-soft);
}
.row-icon svg { width: 100%; height: 100%; fill: currentColor; }

.row-main { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 0.2rem; }
.row-name { font-weight: 650; font-size: 1rem; }
.row-status { font-size: 0.82rem; display: flex; align-items: baseline; gap: 0.35rem; }
.row-status.status-overdue { color: var(--overdue); font-weight: 650; }
.row-status.status-due-soon { color: var(--due-soon); font-weight: 650; }
.row-status.status-ok { color: var(--ok); }
.row-status.status-as-needed,
.row-status.status-never-logged { color: var(--ink-soft); }
.row-status.status-unscheduled { color: var(--neutral); font-weight: 650; }
.row-status .dot { font-size: 0.6rem; }

/* Cards */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 1.1rem 1.2rem; margin-bottom: 1rem;
}
.card h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); margin: 0 0 0.75rem; font-weight: 650; }

/* Service rule cards: a faded fill of the status color, same idea as the
   dashboard tiles, so an overdue/due-soon rule is scannable at a glance
   without reading the text. as-needed/never-logged stay untinted — neutral
   states, not urgency signals. */
.rule-card { border-left: 4px solid var(--line); padding: 0.9rem 1rem; }
.rule-card.status-overdue { border-left-color: var(--overdue); background: color-mix(in srgb, var(--overdue) 12%, var(--panel)); }
.rule-card.status-due-soon { border-left-color: var(--due-soon); background: color-mix(in srgb, var(--due-soon) 12%, var(--panel)); }
.rule-card.status-ok { border-left-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--panel)); }
.rule-card.status-unscheduled { border-left-color: var(--neutral); border-left-style: dashed; }

/* Log service button */
.btn-primary {
  display: block; width: 100%; text-align: center;
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: 12px; padding: 1rem; font-size: 1.05rem; font-weight: 650;
  cursor: pointer; min-height: 52px; margin-bottom: 1.1rem;
}
.btn-primary:active { opacity: 0.85; }
.btn-secondary {
  display: block; width: 100%; text-align: center;
  background: transparent; color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; padding: 0.85rem; font-size: 0.95rem; font-weight: 600;
  cursor: pointer; min-height: 48px;
}

.consumable-name { font-weight: 600; font-size: 0.92rem; }
.consumable-spec { font-size: 0.85rem; color: var(--ink-soft); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.consumable-spec a { color: var(--accent); word-break: break-all; }
.sec-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.65rem 0; border-bottom: 1px solid var(--line);
}
.sec-row:last-child { border-bottom: none; }

.data-tools { display: flex; gap: 0.5rem; justify-content: center; margin: 1.75rem 0 0.5rem; }

.history-edit {
  border: none; background: none; color: var(--accent);
  font-size: 0.76rem; cursor: pointer; padding: 0 0.2rem;
}
.sec-edit-row {
  display: flex; flex-direction: column; gap: 0.4rem;
  padding: 0.6rem 0; border-bottom: 1px solid var(--line);
}
.sec-edit-row:last-child { border-bottom: none; }
.sec-edit-row input[type="text"], .sec-edit-row input[type="url"] { flex: 1; min-width: 0; }
.sec-edit-copy {
  display: flex; gap: 0.35rem; align-items: center;
  font-size: 0.85rem; color: var(--ink-soft); white-space: nowrap;
}
.copy-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 0.5rem 0.7rem; font-size: 0.8rem; min-height: 36px;
  cursor: pointer; white-space: nowrap;
}
.copy-btn.copied { border-color: var(--ok); color: var(--ok); }

.req-text, .notes-text { font-size: 0.92rem; line-height: 1.55; white-space: pre-wrap; margin: 0; }

.history-item { padding: 0.65rem 0; border-bottom: 1px solid var(--line); }
.history-item:last-child { border-bottom: none; }
.history-date {
  font-size: 0.76rem; font-weight: 650; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.history-title { font-weight: 650; font-size: 0.95rem; color: var(--ink); margin-top: 0.15rem; }
.history-details { font-size: 0.9rem; color: var(--ink-soft); margin-top: 0.15rem; }
.history-cost { font-size: 0.85rem; color: var(--ink-soft); margin-top: 0.15rem; }
.empty-state { color: var(--ink-soft); font-size: 0.9rem; font-style: italic; }

/* Purchase record / vendors */
.line-item { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.4rem 0; font-size: 0.88rem; border-bottom: 1px dashed var(--line); }
.line-item:last-child { border-bottom: none; }
.line-item-desc { color: var(--ink-soft); }
.line-item-total { font-variant-numeric: tabular-nums; white-space: nowrap; }
.total-row { display: flex; justify-content: space-between; font-weight: 650; padding-top: 0.6rem; margin-top: 0.3rem; border-top: 1px solid var(--line); }

/* Modal (log service) */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}
.modal {
  background: var(--panel); width: 100%; max-width: 520px;
  border-radius: 16px 16px 0 0; padding: 1.25rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
}
@media (min-width: 640px) {
  .modal { border-radius: 16px; }
}
.modal h2 { margin: 0 0 1rem; font-size: 1.15rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 0.4rem; }
.field input, .field textarea, .field select {
  width: 100%; padding: 0.75rem 0.85rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: 1rem; font-family: inherit;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.chip {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 999px; padding: 0.5rem 0.9rem; font-size: 0.85rem; cursor: pointer; min-height: 36px;
}
.chip.selected { border-color: var(--accent); color: var(--accent); font-weight: 650; }
.modal-actions { display: flex; gap: 0.6rem; margin-top: 1.2rem; }
.modal-actions .btn-primary, .modal-actions .btn-secondary { margin-bottom: 0; }

/* Password gate */
.gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.gate-box { width: 100%; max-width: 340px; text-align: center; }
.gate-box h1 { font-size: 1.3rem; margin-bottom: 1.5rem; }
.gate-error { color: var(--overdue); font-size: 0.85rem; margin-top: 0.6rem; min-height: 1.2em; }

.offline-banner {
  background: var(--due-soon); color: #1a1400; text-align: center; font-size: 0.82rem;
  font-weight: 600; padding: 0.5rem; border-radius: 8px; margin-bottom: 1rem;
}

.toast {
  position: fixed; bottom: calc(1.25rem + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 0.7rem 1.1rem; border-radius: 10px;
  font-size: 0.88rem; z-index: 100; max-width: 90vw; text-align: center;
}

.hidden { display: none !important; }

a { color: inherit; }
