/* FamilyTable design system — mobile-first, zero-build. */

:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #2b2620;
  --muted: #8a8377;
  --line: #e3dfd5;
  --accent: #c96f2f;         /* warm terracotta */
  --accent-soft: #f7e5d6;
  --green: #4e7a4e;
  --green-soft: #e2eede;
  --amber: #b07d20;
  --amber-soft: #f5ecd4;
  --red: #b04a3a;
  --red-soft: #f5ded9;
  --shadow: 0 1px 3px rgba(43, 38, 32, .08), 0 4px 16px rgba(43, 38, 32, .06);
  --radius: 14px;
  --dock-h: calc(60px + env(safe-area-inset-bottom));
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191712;
    --surface: #23201a;
    --surface-2: #2c2820;
    --text: #ede8de;
    --muted: #9a927f;
    --line: #353026;
    --accent: #e08a45;
    --accent-soft: #3a2c1e;
    --green: #7fae7f;
    --green-soft: #26301f;
    --amber: #d3a24a;
    --amber-soft: #35301c;
    --red: #d3705d;
    --red-soft: #38231e;
    --shadow: 0 1px 3px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 700; font-size: 18px; }
.topbar-side { font-size: 14px; color: var(--muted); }

/* ---- main + dock ---- */
main { padding: 14px 14px calc(var(--dock-h) + 18px); max-width: 720px; margin: 0 auto; }
.tabdock {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabdock a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 8px 0 6px; font-size: 11px; color: var(--muted); position: relative;
  min-height: 44px;
}
.tabdock a.active { color: var(--accent); font-weight: 600; }
.tab-icon { font-size: 20px; line-height: 1; }
.tab-badge {
  position: absolute; top: 4px; right: calc(50% - 22px);
  background: var(--red); color: #fff; border-radius: 9px;
  font-size: 10px; font-weight: 700; min-width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* ---- cards / lists ---- */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
.list-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 2px; border-bottom: 1px solid var(--line); min-height: 44px;
}
.list-row:last-child { border-bottom: none; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- buttons / chips / pills ---- */
.btn {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 12px; padding: 10px 16px; cursor: pointer;
  min-height: 44px; font-weight: 600;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border: none; color: var(--accent); }
.btn-danger { color: var(--red); border-color: var(--red-soft); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 13px; font-size: 14px;
  cursor: pointer; white-space: nowrap; min-height: 36px;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chiprow {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.chiprow::-webkit-scrollbar { display: none; }

.pill {
  border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 700;
  border: none; cursor: pointer; min-width: 58px; min-height: 34px;
}
.pill-in { background: var(--green-soft); color: var(--green); }
.pill-low { background: var(--amber-soft); color: var(--amber); }
.pill-out { background: var(--red-soft); color: var(--red); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; border-radius: 8px; padding: 3px 8px;
  background: var(--surface-2);
}
.badge-eatout { background: var(--accent-soft); color: var(--accent); }
.badge-family { background: var(--green-soft); color: var(--green); }
.badge-warn { background: var(--amber-soft); color: var(--amber); }

/* ---- forms ---- */
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); margin-bottom: 10px;
  min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
label.field { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }

/* ---- bottom sheet ---- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .4);
  opacity: 0; transition: opacity .18s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--surface); border-radius: 18px 18px 0 0;
  max-height: 86vh; overflow-y: auto; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .18s ease;
  max-width: 720px; margin: 0 auto;
}
.sheet-open .sheet { transform: translateY(0); }
.sheet-open.sheet-backdrop, .sheet-backdrop.sheet-open { opacity: 1; }
.sheet-handle {
  width: 38px; height: 4px; border-radius: 2px; background: var(--line);
  margin: 6px auto 12px;
}
.sheet h2 { font-size: 17px; }

/* ---- toast ---- */
.toast {
  position: fixed; bottom: calc(var(--dock-h) + 12px); left: 50%;
  transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); white-space: nowrap;
  animation: toast-in .2s ease, toast-out .3s ease 2.2s forwards;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, 8px); } }

/* ---- login ---- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 34px 26px; width: 100%; max-width: 360px; text-align: center;
}
.login-logo { font-size: 52px; margin-bottom: 6px; }
.login-card form { margin-top: 18px; }
.login-err { color: var(--red); font-size: 14px; }

/* ---- spinner ---- */
.spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { text-align: center; padding: 40px 0; color: var(--muted); }

/* ---- FAB ---- */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--dock-h) + 16px); z-index: 25;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none;
  font-size: 26px; box-shadow: var(--shadow); cursor: pointer;
}

/* ---- week screen ---- */
.day-card { padding: 10px 14px; }
.day-head { display: flex; align-items: center; gap: 8px; padding: 4px 0 6px; }
.day-name { font-weight: 700; font-size: 15px; }
.day-name.today { color: var(--accent); }
.day-date { color: var(--muted); font-size: 13px; }
.day-more { margin-left: auto; background: none; border: none; color: var(--muted); font-size: 18px; padding: 4px 8px; cursor: pointer; min-height: 36px; }
.slot-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0; border-top: 1px solid var(--line); min-height: 44px;
}
.slot-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); width: 66px; flex-shrink: 0; }
.slot-fill {
  flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0;
  background: none; border: none; text-align: left; padding: 4px 6px;
  border-radius: 8px; cursor: pointer; min-height: 36px; color: var(--text);
}
.slot-fill:active { background: var(--surface-2); }
.slot-empty { color: var(--muted); }
.slot-title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-title.done { text-decoration: line-through; color: var(--muted); }
.slot-x { background: none; border: none; color: var(--muted); font-size: 15px; padding: 6px 8px; cursor: pointer; }
.add-dessert { font-size: 13px; color: var(--muted); background: none; border: none; padding: 7px 0 4px; cursor: pointer; }
.week-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.week-nav .btn { min-width: 46px; }

/* safe options strip */
.safe-strip-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 4px 0 6px; }

/* ---- pantry ---- */
.cat-head { font-size: 13px; font-weight: 700; color: var(--muted); margin: 16px 4px 6px; text-transform: uppercase; letter-spacing: .04em; }

/* ---- recipes ---- */
.recipe-card { padding: 12px 14px; cursor: pointer; }
.recipe-title { font-weight: 700; font-size: 16px; }
.recipe-meta { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

/* ---- idea cards ---- */
.idea-chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
.idea-chip { font-size: 12px; border-radius: 7px; padding: 3px 8px; }
.idea-chip.have { background: var(--green-soft); color: var(--green); }
.idea-chip.need { background: var(--red-soft); color: var(--red); }

/* ---- receipts ---- */
.upload-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.upload-tile {
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 18px 6px; text-align: center; cursor: pointer; font-size: 14px; font-weight: 600;
}
.upload-tile .tab-icon { display: block; font-size: 26px; margin-bottom: 6px; }
.mismatch-banner {
  background: var(--amber-soft); color: var(--amber); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; margin-bottom: 10px;
}
.ritem-name { border: none; background: transparent; padding: 4px 2px; margin: 0; min-height: 32px; width: 100%; }
.ritem-name:focus { background: var(--surface-2); border-radius: 6px; outline: none; }
.ritem-price { width: 74px; text-align: right; border: none; background: transparent; margin: 0; padding: 4px 2px; min-height: 32px; }
.ritem-excluded { opacity: .45; }

@media (min-width: 720px) {
  .topbar { padding-left: 24px; padding-right: 24px; }
  main { padding-top: 20px; }
}
