/* Family Hub · estilos base, móvil primero. */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #17201d;
  --muted: #5b6763;
  --border: #d5dcd9;
  --primary: #1f6f5c;
  --primary-text: #ffffff;
  --focus: #b35c00;
  --ok-bg: #e3f3ec;
  --ok-text: #14532d;
  --error-bg: #fdecea;
  --error-text: #8a1c12;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --radius: 12px;
  --tap: 44px;
  --tabbar-h: 60px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615;
    --surface: #1b2220;
    --text: #e7eeeb;
    --muted: #9fb0aa;
    --border: #33403c;
    --primary: #4fb89a;
    --primary-text: #0b1512;
    --focus: #ffb454;
    --ok-bg: #173327;
    --ok-text: #b9ecd2;
    --error-bg: #3a1a17;
    --error-text: #ffc2ba;
    --warn-bg: #3a2f10;
    --warn-text: #ffe39c;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

a { color: var(--primary); }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 10; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar-title { font-size: 1.15rem; margin: 0; overflow-wrap: anywhere; }

.page { max-width: 720px; margin: 0 auto; padding: 16px; }
.narrow .page { max-width: 420px; }
.page:focus { outline: none; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 1.05rem; margin: 0 0 12px; }

.muted { color: var(--muted); font-size: 0.9rem; }
.empty { color: var(--muted); }
.help { color: var(--muted); font-size: 0.875rem; margin: 4px 0 0; }

.alert { padding: 12px; border-radius: 8px; margin: 0 0 12px; }
.alert-success { background: var(--ok-bg); color: var(--ok-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }
.alert-warning { background: var(--warn-bg); color: var(--warn-text); }
.alert p { margin: 0; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font: inherit;
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
.field-error input, .field-error select, .field-error textarea { border-color: var(--error-text); }
.error { color: var(--error-text); font-size: 0.9rem; margin: 4px 0 0; }
.error::before { content: "⚠ "; }

.button, button.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 10px 18px; border-radius: 999px; border: 1px solid var(--primary);
  background: var(--primary); color: var(--primary-text); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.button-secondary { background: transparent; color: var(--primary); }

.link-button {
  background: none; border: 0; padding: 0 4px; min-height: var(--tap);
  color: var(--primary); font: inherit; text-decoration: underline; cursor: pointer;
}

.list, .menu { list-style: none; margin: 0; padding: 0; }
.list li, .menu li { border-bottom: 1px solid var(--border); }
.list li:last-child, .menu li:last-child { border-bottom: 0; }
.list li { padding: 10px 0; }
.menu li a { display: block; padding: 12px 0; min-height: var(--tap); font-weight: 600; }
.menu li .muted { display: block; margin-top: -8px; padding-bottom: 10px; }

.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.row-actions { display: flex; align-items: center; gap: 12px; }
.row-actions a { min-height: var(--tap); display: inline-flex; align-items: center; }
.row-actions form { margin: 0; }
.inactive .row-main { color: var(--muted); }
.badge {
  display: inline-block; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); margin-left: 4px;
}

.help-link { font-size: 0.9rem; white-space: nowrap; }
.breadcrumbs { margin-bottom: 12px; font-size: 0.9rem; }

.prose h1 { font-size: 1.3rem; }
.prose h2 { font-size: 1.1rem; margin-top: 1.5em; }
.prose table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); text-decoration: none; font-size: 0.8rem; min-height: var(--tap);
}
.tabbar a span { font-size: 1.2rem; }
.tabbar a[aria-current="page"] { color: var(--primary); font-weight: 700; }

/* ---- Fase 2: compra ---- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.searchbar { display: flex; gap: 8px; margin-bottom: 16px; }
.searchbar input {
  flex: 1; min-width: 0; min-height: var(--tap); padding: 10px 14px; font: inherit;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
}
.count { color: var(--muted); font-weight: 400; }
.items .item { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.item form { margin: 0; }
.item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; color: inherit; text-decoration: none; }
.item-name { font-weight: 600; overflow-wrap: anywhere; }
.item-actions { display: flex; align-items: center; gap: 8px; }
.item-actions a { min-height: var(--tap); display: inline-flex; align-items: center; }
.item.done .item-name { color: var(--muted); font-weight: 400; }
.check {
  width: var(--tap); height: var(--tap); flex: none; border-radius: 50%;
  border: 2px solid var(--primary); background: transparent; color: var(--primary);
  font-size: 1.2rem; cursor: pointer;
}
.check.checked { background: var(--primary); color: var(--primary-text); }
.big-check { width: 24px; height: 24px; flex: none; accent-color: var(--primary); }
.badge-ok { border-color: var(--ok-text); color: var(--ok-text); white-space: nowrap; }
details > summary { cursor: pointer; list-style: none; min-height: var(--tap); }
details > summary::-webkit-details-marker { display: none; }
details > summary h2 { display: inline; }
details > summary::before { content: "▸ "; color: var(--muted); }
details[open] > summary::before { content: "▾ "; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field.checkbox { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.field.checkbox input { width: 22px; height: 22px; accent-color: var(--primary); }
.field.checkbox label { display: inline; font-weight: 400; margin: 0; }
.field.checkbox .help { flex-basis: 100%; }
.label { display: block; font-weight: 600; margin-bottom: 4px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 16px; }
.stat { font-size: 1.6rem; font-weight: 700; margin: 0 0 8px; }

/* ---- Fase 3: tareas y saldo ---- */
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.amount.pos { color: var(--ok-text); }
.amount.neg { color: var(--error-text); }
.amount.big { font-size: 1.15rem; }
.amount.huge { font-size: 2.2rem; margin: 0; }
.balance-card { text-align: center; }
.balance-card p { margin: 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 8px 14px;
  border: 1px solid var(--primary); border-radius: 999px; text-decoration: none; font-weight: 600;
}
.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.actions-grid .button { width: 100%; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0; }
.stats div { background: var(--bg); border-radius: 8px; padding: 10px; }
.stats dt { color: var(--muted); font-size: 0.85rem; }
.stats dd { margin: 0; font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.row h2 { margin: 0; }
.alert-info { background: var(--bg); border: 1px solid var(--border); }
.button-danger { background: transparent; color: var(--error-text); border-color: var(--error-text); }

/* ---- Fase 4: agenda ---- */
.segmented { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px; margin-bottom: 12px; }
.segmented a { flex: 1; text-align: center; padding: 8px; border-radius: 999px; text-decoration: none; min-height: var(--tap); display: flex; align-items: center; justify-content: center; }
.segmented a[aria-current="page"] { background: var(--primary); color: var(--primary-text); font-weight: 700; }
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.filter-row select { min-height: var(--tap); padding: 8px; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; flex: 1; min-width: 0; }
.filter-row .button { margin-left: auto; }
.month { width: 100%; border-collapse: collapse; table-layout: fixed; }
.month th { color: var(--muted); font-size: 0.8rem; font-weight: 600; padding: 4px 0; }
.month td { padding: 2px; text-align: center; }
.month td a { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: var(--tap); border-radius: 8px; text-decoration: none; color: var(--text); }
.month td.out a { color: var(--muted); opacity: 0.6; }
.month td.today a { font-weight: 800; color: var(--primary); }
.month td.selected a { background: var(--primary); color: var(--primary-text); }
.month .dot { font-size: 0.7rem; line-height: 1; padding: 1px 5px; border-radius: 999px; background: var(--bg); color: var(--primary); font-weight: 700; }
.month td.selected .dot { background: var(--primary-text); color: var(--primary); }
.day-heading { font-size: 0.95rem; margin: 16px 0 4px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.day-heading.today { color: var(--primary); }
fieldset.field { border: 0; padding: 0; margin: 0 0 14px; }
[hidden] { display: none !important; }
.state-sent { border-color: var(--ok-text); color: var(--ok-text); }
.state-failed { border-color: var(--error-text); color: var(--error-text); }
.state-unknown { border-color: var(--warn-text); color: var(--warn-text); }
pre.message { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; background: var(--bg); padding: 12px; border-radius: 8px; margin: 0; }
.details { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
button.chip { background: transparent; color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; }
button.chip:active { background: var(--primary); color: var(--primary-text); }
.chips form { margin: 0; }
.undo-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.undo-bar form { margin: 0; }

/* Selector de fecha (flatpickr): mismo aspecto que el resto de campos. */
.field input.flatpickr-input[readonly], .field input.form-control.input { background: var(--bg); cursor: pointer; }
.flatpickr-day.selected, .flatpickr-day.selected:hover { background: var(--primary); border-color: var(--primary); }
.flatpickr-day.today { border-color: var(--primary); }
