:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e2e6ea;
  --text: #1c2733;
  --text-muted: #6b7684;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eaf1ff;
  --green: #15803d;
  --green-soft: #e7f6ec;
  --amber: #b45309;
  --amber-soft: #fef3e2;
  --red: #b91c1c;
  --red-soft: #fdeaea;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; flex-direction: column; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 700; }
.brand span { font-size: 12px; color: var(--text-muted); }

.stats-row { display: flex; gap: 10px; }
.stat-chip {
  background: var(--brand-soft);
  color: var(--brand-dark);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
  padding: 18px 24px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.list-panel { position: sticky; top: 74px; max-height: calc(100vh - 92px); display: flex; flex-direction: column; }

.list-header { display: flex; gap: 8px; margin-bottom: 12px; }

input[type="text"], input[type="search"], input[type="date"], input[type="tel"], input[type="email"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

textarea { resize: vertical; min-height: 60px; }

button {
  font-family: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 600;
}

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: #f2f4f6; }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: #fbdada; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; }

.household-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.household-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .12s;
}
.household-item:hover { border-color: var(--brand); }
.household-item.active { border-color: var(--brand); background: var(--brand-soft); }
.household-item h3 { margin: 0 0 4px; font-size: 14.5px; }
.household-item .meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-active { background: var(--green-soft); color: var(--green); }
.badge-waitlist { background: var(--amber-soft); color: var(--amber); }
.badge-inactive { background: #eee; color: #666; }

.empty-state { text-align: center; color: var(--text-muted); padding: 60px 20px; }
.empty-state h2 { color: var(--text); font-size: 17px; }

.detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.detail-header h2 { margin: 0; font-size: 21px; }
.detail-header .actions { display: flex; gap: 8px; }
.detail-address { color: var(--text-muted); font-size: 13.5px; margin-bottom: 18px; }

.section { margin-top: 22px; }
.section-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.section-title-row h3 { margin: 0; font-size: 15px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.record-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px; background: #fbfbfc; }
.record-card .rc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.record-card h4 { margin: 0 0 3px; font-size: 14px; }
.record-card .rc-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.record-card .rc-line { font-size: 12.5px; margin: 2px 0; }
.record-card .rc-actions { display: flex; gap: 6px; margin-top: 8px; }
.pill { font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 100;
}
.modal { background: #fff; border-radius: 12px; width: 560px; max-width: 100%; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: 760px; }
.modal h3 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.checkbox-field { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.checkbox-field input { width: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* New-household wizard */
.guardian-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 14px 6px;
  margin-bottom: 14px;
  background: #fbfbfc;
}
.guardian-block .eyebrow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}
.guardian-block .eyebrow .hint { text-transform: none; letter-spacing: 0; font-weight: 600; }
.guardian-block h4 { margin: 2px 0 10px; font-size: 15px; }
.addr-block { margin-top: 10px; }
.household-name-box {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--brand-soft);
  border-radius: 8px;
}
.household-name-box > label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 2px; }
.household-name-preview { font-size: 16px; font-weight: 700; color: var(--brand-dark); }
.name-override { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 8px; font-size: 12.5px; }
.name-override label { display: flex; align-items: center; gap: 4px; font-weight: 600; cursor: pointer; }
.name-override input { width: auto; }

/* Address autocomplete */
.addr-wrap { position: relative; }
.addr-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 10px 25px rgba(0,0,0,.15);
  z-index: 50;
}
.addr-suggestion-item { padding: 8px 10px; font-size: 12.5px; cursor: pointer; }
.addr-suggestion-item:hover { background: var(--brand-soft); }
.addr-suggestion-status { color: var(--text-muted); cursor: default; font-style: italic; }
.addr-suggestion-status:hover { background: none; }

/* Chip entry (Allergies / Medical notes) */
.chip-block { margin: 8px 0 4px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip-list:empty { margin-bottom: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
}
.chip-remove {
  background: none; border: none; color: inherit; font-size: 15px; line-height: 1;
  padding: 0 4px; cursor: pointer; border-radius: 999px; font-weight: 700;
}
.chip-remove:hover { background: rgba(0,0,0,.1); }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--text); color: #fff;
  padding: 10px 16px; border-radius: 8px; font-size: 13.5px; z-index: 200;
  opacity: 0; transform: translateY(8px); transition: all .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }

.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .list-panel { position: static; max-height: none; }
}

.hidden { display: none !important; }

.header-right { display: flex; align-items: center; gap: 16px; }
.user-menu { display: flex; align-items: center; gap: 8px; }
.user-chip { font-size: 13px; font-weight: 600; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }

.signed-out {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.signin-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 360px;
  max-width: 100%;
  text-align: center;
}
.signin-card h1 { font-size: 19px; margin: 0 0 8px; }
.signin-card p { color: var(--text-muted); font-size: 13.5px; margin: 0 0 18px; }
.signin-card .btn-primary { display: block; text-decoration: none; text-align: center; }
.signin-error {
  background: var(--red-soft); color: var(--red); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; text-align: left;
}
