/* Last Hall app. Mobile first: base rules target a ~375 px phone; wider screens are enhanced with min-width queries. */
:root {
  --ink: #0f2420;
  --teal-950: #082b26;
  --teal-900: #0b3b34;
  --teal-800: #0d4a41;
  --teal-700: #0f5f53;
  --teal-100: #dcefe9;
  --lime: #d5f04a;
  --lime-hover: #e3f875;
  --paper: #f6f4ee;
  --card: #ffffff;
  --muted: #55655f;
  --line: #e3dfd4;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --warn: #7a4b00;
  --warn-bg: #fff3cd;
  --done-bg: #e3f1ec;
  --radius: 14px;
  --tap: 48px;
  --tabbar-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  min-height: 100vh;
}
body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); }
img { max-width: 100%; height: auto; display: block; }
a { color: var(--teal-700); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
.h3 { font-size: 1rem; margin-top: 1rem; }
p { margin: 0 0 1em; }
.sprite { display: none; }
.ico { width: 18px; height: 18px; vertical-align: -3px; }
.ico-lg { width: 28px; height: 28px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--teal-900); color: #fff;
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--lime); color: var(--teal-950); }
.brand-mark svg { width: 20px; height: 20px; }
.topnav { display: none; }
.signout { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.who { display: none; color: var(--teal-100); font-size: .875rem; }
.btn-link { background: none; border: 0; color: #fff; text-decoration: underline; font: inherit; font-size: .875rem; padding: 8px 4px; min-height: 40px; cursor: pointer; }

/* Bottom tab bar (phones) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff; border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; min-width: var(--tap);
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--teal-800); font-weight: 600; }
.tabbar .tab-primary svg { width: 44px; height: 44px; padding: 10px; border-radius: 50%; background: var(--lime); color: var(--teal-950); margin-top: -18px; box-shadow: 0 4px 12px rgba(8, 43, 38, .25); }
.tabbar .tab-primary { color: var(--teal-800); font-weight: 600; }

/* Page */
.page { width: 100%; max-width: 960px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.page-head h1 { margin: 0; }
.section { margin: 24px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.count { display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 8px; border-radius: 14px; background: var(--teal-900); color: #fff; font-weight: 700; font-size: .875rem; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 16px 0; }
.panel.narrow { max-width: 440px; margin: 32px auto; }
.hero-card { background: var(--teal-900); color: #fff; border-radius: var(--radius); padding: 20px 16px; }
.hero-card p { color: var(--teal-100); }
.empty { color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 16px; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 12px 14px; }
.flash { background: var(--done-bg); color: var(--teal-900); border-radius: 10px; padding: 12px 14px; font-weight: 600; }
.error, .field-error { color: var(--danger); }
.error:empty { display: none; }
.error ul { margin: 0; padding-left: 18px; }
.field-error { font-size: .875rem; }
.dev-note { margin-top: 16px; font-size: .875rem; color: var(--muted); }

/* Cards */
.cards { display: grid; gap: 10px; }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: inherit; text-decoration: none; }
.card-link:active { background: #fafaf7; }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-row + .card-row { margin-top: 6px; }
.card-title { font-size: 1.02rem; }
.card-note { margin: 8px 0 0; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.card.is-voided { opacity: .6; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.type { font-weight: 600; color: var(--teal-800); }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-done { background: var(--done-bg); color: var(--teal-800); }
.badge-muted { background: #ecebe6; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 18px; border-radius: 12px; border: 2px solid transparent;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; text-align: center;
}
.btn-sm { min-height: 40px; padding: 6px 12px; font-size: .875rem; }
.btn-block { display: flex; width: 100%; }
.btn-lime { background: var(--lime); color: var(--teal-950); }
.btn-lime:hover { background: var(--lime-hover); }
.btn-dark { background: var(--teal-900); color: #fff; }
.btn-outline { background: transparent; border-color: var(--teal-800); color: var(--teal-800); }
.btn-danger { background: var(--danger); color: #fff; }
.btn[disabled] { opacity: .6; cursor: progress; }
:focus-visible { outline: 3px solid var(--teal-700); outline-offset: 2px; }

/* Forms */
.form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; margin: 0; border: 0; padding: 0; min-width: 0; }
.field > span:first-child, .field legend, .field .label { font-weight: 600; }
.field legend { padding: 0; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=search], input[type=date], input:not([type]), select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid #c9c4b7; border-radius: 10px; background: #fff; color: var(--ink);
  font: inherit; font-size: 16px; /* 16px stops iOS from zooming into fields */
}
textarea { min-height: 110px; resize: vertical; }
.field-row { display: grid; gap: 16px; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); font-weight: 600; }
.check input { width: 22px; height: 22px; }
.form-actions { display: grid; gap: 10px; margin-top: 8px; }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; }
.choice-body { display: grid; gap: 2px; min-height: 64px; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; }
.choice-title { font-weight: 700; }
.choice-sub { font-size: .78rem; color: var(--muted); }
.choice input:checked + .choice-body { border-color: var(--teal-800); background: var(--teal-100); }
.choice input:focus-visible + .choice-body { outline: 3px solid var(--teal-700); outline-offset: 2px; }

.photo-drop { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 12px 16px; border: 2px dashed #b9c9c3; border-radius: 12px; background: #fff; color: var(--teal-800); font-weight: 600; cursor: pointer; }
.photo-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.photo-preview, .photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-preview img, .photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: #ddd; }

.filters { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 16px; margin-bottom: 16px; }
.filters summary { min-height: var(--tap); display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.filter-grid { display: grid; gap: 12px; padding-bottom: 16px; }
.filter-grid label { display: grid; gap: 4px; font-weight: 600; font-size: .9rem; }
.filter-actions { display: flex; gap: 8px; }
.search { display: grid; gap: 10px; margin-bottom: 16px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form select { width: auto; min-height: 40px; }

.facts { margin: 0; display: grid; gap: 12px; }
.facts div { display: grid; gap: 2px; }
.facts dt { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.note { white-space: pre-wrap; overflow-wrap: anywhere; }
.actions-panel { display: grid; gap: 12px; }
.danger-zone { background: var(--danger-bg); border-radius: var(--radius); padding: 0 16px; }
.danger-zone summary { min-height: var(--tap); display: flex; align-items: center; font-weight: 700; color: var(--danger); cursor: pointer; }
.danger-zone form { padding-bottom: 16px; }
.history { padding-left: 18px; }
.history li { margin-bottom: 6px; }
.stack-sm { margin-bottom: 8px; }

/* Searchable picker (js/picker.js). The native <select> stays in the form, hidden. */
.picker { position: relative; }
.picker-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }
.picker-button {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
  min-height: var(--tap); padding: 10px 12px; border: 1px solid #c9c4b7; border-radius: 10px;
  background: #fff; color: var(--ink); font: inherit; font-size: 16px; text-align: left; cursor: pointer;
}
.picker-button.is-empty .picker-value { color: var(--muted); }
.picker-button.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 2px var(--danger-bg); }
.picker-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-ico { width: 20px; height: 20px; flex: none; color: var(--muted); }
.picker.is-open .picker-button { border-color: var(--teal-800); box-shadow: 0 0 0 3px var(--teal-100); }
.picker-panel {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px);
  display: flex; flex-direction: column; max-height: min(60vh, 440px);
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 32px rgba(8, 43, 38, .18); overflow: hidden;
}
.picker-panel[hidden] { display: none; }
.picker-search { display: flex; align-items: center; gap: 8px; margin: 10px; padding: 0 10px; border: 2px solid var(--teal-800); border-radius: 10px; }
.picker-search input { flex: 1; min-height: 42px; border: 0; padding: 0; outline: none; background: transparent; font-size: 16px; }
.picker-search input:focus-visible { outline: none; }
.picker-list { list-style: none; margin: 0; padding: 4px 6px 8px; overflow-y: auto; overscroll-behavior: contain; flex: 1; }
.picker-heading { padding: 12px 10px 4px; font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.picker-option { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.picker-option.is-active { background: var(--teal-100); }
.picker-option[aria-selected="true"] { font-weight: 700; color: var(--teal-800); }
.picker-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.picker-hint { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.picker-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: #b8b2a3; }
.picker-dot.tone-payperiod { background: #e0a100; }
.picker-dot.tone-days30 { background: #e8590c; }
.picker-dot.tone-days90 { background: #c92a2a; }
.picker-dot.tone-none { background: #b8b2a3; }
.picker-empty { padding: 14px 10px; color: var(--muted); }
.picker-add {
  display: flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); margin: 0;
  border: 0; border-top: 1px solid var(--line); background: #fafaf7; color: var(--teal-800);
  font: inherit; font-weight: 700; cursor: pointer;
}
.picker-add .picker-ico { color: var(--teal-800); }
.picker-add:disabled { opacity: .6; cursor: progress; }
.picker-status { margin: 0; padding: 0 12px; color: var(--danger); font-size: .85rem; }
.picker-status:empty { display: none; }
.picker-added { margin: 6px 0 0; color: var(--teal-800); font-size: .9rem; font-weight: 600; }
.picker-error { margin: 6px 0 0; }
.inline-form .picker { min-width: 150px; }
.inline-form .picker-button { min-height: 40px; padding: 6px 10px; }

/* Tablets and up */
@media (min-width: 640px) {
  .field-row { grid-template-columns: 1fr 1fr; }
  .choice-grid { grid-template-columns: repeat(3, 1fr); }
  .filter-grid { grid-template-columns: repeat(3, 1fr); align-items: end; }
  .search { grid-template-columns: 1fr auto auto; align-items: center; }
  .form-actions { grid-template-columns: auto auto; justify-content: start; }
  .form-actions .btn-block { width: auto; }
  .photo-preview, .photo-grid { grid-template-columns: repeat(4, 1fr); }
  .facts { grid-template-columns: 1fr 1fr; }
}

/* Desktop: top navigation replaces the bottom tab bar */
@media (min-width: 900px) {
  body.has-tabbar { padding-bottom: 32px; }
  .tabbar { display: none; }
  .topbar { padding-left: max(24px, calc((100% - 960px) / 2 + 16px)); padding-right: max(24px, calc((100% - 960px) / 2 + 16px)); }
  .topnav { display: flex; gap: 4px; margin-left: 24px; }
  .topnav a { color: var(--teal-100); text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 600; }
  .topnav a.active, .topnav a:hover { background: var(--teal-800); color: #fff; }
  .who { display: inline; }
  .page { padding: 24px 16px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .hero-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 24px; }
  .hero-card h1, .hero-card p { grid-column: 1; }
  .hero-card .btn { grid-column: 2; grid-row: 1 / span 2; width: auto; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
