/* melslab emergency access — household information, calmly organised. */

:root {
  --paper: #f4f1e8;
  --card: #fffdf7;
  --ink: #1b2b2a;
  --muted: #66716d;
  --line: #ded8c8;
  --accent: #0e5b52;
  --accent-dark: #0a453e;
  --accent-soft: #e3ede9;
  --warn: #8a5a12;
  --warn-soft: #f8efdc;
  --danger: #a02e26;
  --danger-soft: #f8e7e4;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(27, 43, 42, 0.06), 0 6px 18px rgba(27, 43, 42, 0.05);
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
}

* { 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: 16px;
  line-height: 1.55;
  padding-bottom: 84px;
}

body.no-nav { padding-bottom: 32px; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 0.4em;
  letter-spacing: -0.01em;
}

h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

img { max-width: 100%; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  z-index: 100;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 241, 232, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 17px;
}

.brand-text { min-width: 0; }

.brand-name {
  font-family: var(--font-display);
  font-size: 1.02rem;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
}

.brand-sub {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.emergency-timer {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid #e7d6b3;
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

/* ---------- layout ---------- */

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.page-head p { color: var(--muted); margin: 4px 0 0; font-size: 0.92rem; }

.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}

@media (min-width: 720px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  h1 { font-size: 2rem; }
  .wrap { padding: 28px 24px 48px; }
  body { padding-bottom: 32px; }
}

/* ---------- cards ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card-tight { padding: 14px; }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-head h2, .card-head h3 { margin: 0; }

.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.card-link:hover { border-color: #c9bfa8; }
.card-link:active { transform: translateY(1px); }

.card-link h3 { margin-bottom: 4px; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.75rem; }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ---------- stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (min-width: 620px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.5rem;
  line-height: 1.1;
  display: block;
}

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* ---------- pills and badges ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border: 1px solid #cfe2dc;
  white-space: nowrap;
}

.pill-private { background: #efe9f6; color: #4a3a68; border-color: #ddd2ee; }
.pill-shared { background: var(--accent-soft); color: var(--accent-dark); border-color: #cfe2dc; }
.pill-off { background: #f0ece2; color: var(--muted); border-color: var(--line); }
.pill-warn { background: var(--warn-soft); color: var(--warn); border-color: #e7d6b3; }
.pill-emergency { background: #fdeee6; color: #8a3a12; border-color: #f3d6c4; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.94rem;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover { border-color: #c9bfa8; }
.btn:active { background: #f2ede1; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-primary:active { background: #083a34; }

.btn-ghost { background: transparent; }

.btn-danger { color: var(--danger); border-color: #e6c7c2; background: var(--danger-soft); }
.btn-danger:hover { background: #f4dad5; }

.btn-sm { min-height: 34px; padding: 5px 11px; font-size: 0.82rem; }

.btn-block { width: 100%; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- forms ---------- */

form { margin: 0; }

.field { margin-bottom: 16px; }

.field label,
.field .label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.field .hint {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 5px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="number"], input[type="search"],
select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

textarea { min-height: 150px; resize: vertical; line-height: 1.5; }

input:focus-visible, select:focus-visible, textarea:focus-visible,
.btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="file"] {
  width: 100%;
  padding: 12px;
  border: 1px dashed #c9bfa8;
  border-radius: var(--radius-sm);
  background: #fffdf8;
  font: inherit;
  font-size: 0.9rem;
}

.radio-row { display: flex; flex-wrap: wrap; gap: 8px; }

.radio-card {
  position: relative;
  flex: 1 1 160px;
  display: block;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffdf8;
  cursor: pointer;
  font-size: 0.9rem;
}

.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.radio-card strong { display: block; font-size: 0.92rem; }
.radio-card span { color: var(--muted); font-size: 0.8rem; }

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffdf8;
}
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); }
.check span { font-size: 0.86rem; color: var(--muted); }

.search-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.search-row input { flex: 1 1 200px; }
.search-row select { flex: 0 1 160px; }

/* ---------- flash / error ---------- */

.flash {
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  border: 1px solid #cfe2dc;
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.flash-error {
  border-color: #e6c7c2;
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- lists ---------- */

.list { list-style: none; margin: 0; padding: 0; }

.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.list li:last-child { border-bottom: 0; }
.list li > :first-child { min-width: 0; flex: 1; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.item-title {
  font-weight: 600;
  font-size: 0.98rem;
  display: block;
  color: inherit;
  text-decoration: none;
}
.item-title:hover { text-decoration: underline; }

.item-sub { font-size: 0.82rem; color: var(--muted); }

.prose {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.97rem;
  line-height: 1.6;
}

.empty {
  text-align: center;
  padding: 26px 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255, 253, 247, 0.6);
}
.empty p { margin-bottom: 12px; }

.section-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 22px 0 8px;
}

/* ---------- bottom navigation ---------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: rgba(255, 253, 247, 0.97);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-inner {
  max-width: 980px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 9px 2px 8px;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-decoration: none;
  border-top: 2px solid transparent;
  min-height: 58px;
}

.nav-item svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.nav-item.active { color: var(--accent); border-top-color: var(--accent); }
.nav-item:hover { color: var(--accent-dark); }

@media (min-width: 720px) {
  .bottom-nav { position: static; border-top: 0; background: transparent; backdrop-filter: none; }
  .bottom-nav-inner {
    margin: 0 auto 0 0;
    display: flex;
    gap: 4px;
    padding: 0 24px 0;
    max-width: 980px;
  }
  .nav-item {
    flex-direction: row;
    gap: 7px;
    padding: 6px 12px;
    font-size: 0.82rem;
    border-top: 0;
    border-bottom: 2px solid transparent;
    min-height: 34px;
  }
  .nav-item.active { border-bottom-color: var(--accent); }
  .nav-item svg { width: 16px; height: 16px; }
}

/* ---------- emergency mode ---------- */

.emergency-band {
  background: var(--warn-soft);
  border-bottom: 1px solid #e7d6b3;
  color: var(--warn);
  font-size: 0.84rem;
}
.emergency-band .topbar-inner { padding-top: 6px; padding-bottom: 6px; }

.emergency-hero {
  text-align: center;
  padding: 34px 20px 28px;
}

.emergency-hero h1 { font-size: 1.8rem; }

.pin-input {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 1.5rem;
  letter-spacing: 0.45em;
  padding: 14px 12px 14px 18px;
}

.auth-shell {
  max-width: 460px;
  margin: 0 auto;
  padding: 32px 16px 60px;
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px 22px;
  box-shadow: var(--shadow);
}

.auth-foot {
  text-align: center;
  margin-top: 20px;
  font-size: 0.86rem;
  color: var(--muted);
}

/* ---------- print ---------- */

.print-sheet { max-width: 780px; margin: 0 auto; padding: 24px 16px 60px; }

.print-header {
  border-bottom: 2px solid var(--ink);
  padding-bottom: 10px;
  margin-bottom: 18px;
}
.print-header h1 { margin-bottom: 2px; }
.print-header .meta { font-size: 0.8rem; }

.print-section { margin-bottom: 22px; page-break-inside: avoid; }
.print-section h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
  margin-bottom: 10px;
}
.print-record { margin-bottom: 16px; page-break-inside: avoid; }
.print-record h3 { margin-bottom: 4px; font-size: 1rem; }
.print-record .prose { font-size: 0.92rem; }

.print-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.print-table th, .print-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.print-table th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

@media print {
  body { background: #fff; color: #000; padding: 0; font-size: 11pt; }
  .topbar, .bottom-nav, .no-print, .btn, .flash { display: none !important; }
  .wrap, .print-sheet { max-width: none; padding: 0; }
  .card { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  a { color: #000; text-decoration: none; }
  .print-section h2 { color: #000; }
  .print-table th, .print-table td { border-color: #bbb; }
  @page { margin: 16mm 14mm; }
}

/* ---------- misc ---------- */

.divider { height: 1px; background: var(--line); border: 0; margin: 20px 0; }

.split {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.offline-banner {
  display: none;
  background: var(--warn-soft);
  color: var(--warn);
  text-align: center;
  font-size: 0.82rem;
  padding: 6px 12px;
  border-bottom: 1px solid #e7d6b3;
}
body.is-offline .offline-banner { display: block; }

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(14, 91, 82, 0.08);
  padding: 1px 5px;
  border-radius: 5px;
  word-break: break-all;
}
