/* Family Hub — design tokens from design.md §7.5, contrast-checked pairs. */
:root {
  --bg: #F7F8FA;
  --card: #FFFFFF;
  --text: #172033;
  --muted: #5B6578;
  --border: #E3E8EF;
  --primary: #2563EB;
  --primary-ink: #FFFFFF;
  --primary-soft: #EAF1FE;
  --success: #047857;
  --success-soft: #E7F6EF;
  --urgent: #C2410C;
  --urgent-strong: #DC2626;
  --urgent-soft: #FFF1EB;
  --warn: #92400E;
  --warn-soft: #FEF6E4;
  --violet-soft: #F2EEFE;
  --warm: #FFF8F1;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(23, 32, 51, .05), 0 4px 14px rgba(23, 32, 51, .05);
  --focus: 0 0 0 3px rgba(37, 99, 235, .45);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --accent: var(--primary);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; font-size: 16px; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }
img { max-width: 100%; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .55rem 1rem;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { border-color: #C9D2DE; background: #FBFCFD; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #1D4FD7; border-color: #1D4FD7; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { color: var(--urgent-strong); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 36px; padding: .3rem .7rem; font-size: .875rem; }
.btn[disabled], .btn.is-loading { opacity: .6; pointer-events: none; }
.link-btn { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

/* ---------- forms ---------- */
label { font-weight: 600; font-size: .92rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field .help { color: var(--muted); font-size: .82rem; font-weight: 400; }
.field .errorlist, .errorlist { color: var(--urgent-strong); font-size: .85rem; margin: 0; padding: 0; list-style: none; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number],
input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .7rem; border: 1px solid #CDD5E0; border-radius: var(--radius-sm);
  background: #fff; color: var(--text); font: inherit; }
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); }
.check { display: flex; gap: .55rem; align-items: center; font-weight: 500; }
.form-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
fieldset { border: 0; padding: 0; margin: 0; }
.choice-row { display: flex; flex-wrap: wrap; gap: .45rem; }
.choice-row label { font-weight: 500; }
.choice-chip input { position: absolute; opacity: 0; }
.choice-chip span { display: inline-flex; align-items: center; justify-content: center; min-width: 48px; min-height: 48px;
  padding: .3rem .7rem; border: 2px solid var(--border); border-radius: 12px; background: #fff; cursor: pointer; font-size: 1.4rem; }
.choice-chip input:checked + span { border-color: var(--primary); background: var(--primary-soft); }
.choice-chip input:focus-visible + span { box-shadow: var(--focus); }
.swatch { width: 28px; height: 28px; border-radius: 50%; display: inline-block; }

/* ---------- layout: parent ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: #fff; border-right: 1px solid var(--border); padding: 1.1rem .8rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: .6rem; align-items: center; padding: .2rem .5rem 1rem; font-weight: 700; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #2563EB, #7C3AED); color: #fff;
  display: grid; place-items: center; font-size: 1.1rem; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: .78rem; }
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: .65rem; padding: .6rem .7rem; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--bg); }
.nav a[aria-current=page] { background: var(--primary-soft); color: #1E40AF; font-weight: 650; }
.nav .ico { width: 1.4rem; text-align: center; }
.nav .badge { margin-left: auto; }
.nav-section { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 1rem .7rem .3rem; font-weight: 700; }
.nav-cta { margin: .4rem 0 .8rem; }
.main { padding: 1.6rem clamp(1rem, 3vw, 2.4rem) 3rem; max-width: 1240px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: 0; color: var(--muted); }
.topbar { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; transform: translateX(-105%); transition: transform .2s; z-index: 40; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: .6rem; padding: .6rem 1rem; background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .main { padding: 1rem 16px 3rem; }
}

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-bottom: .75rem; }
.card-head h2, .card-head h3 { margin: 0; }
.card.warm { background: var(--warm); }
.card.flush { padding: 0; overflow: hidden; }
.stat { display: flex; flex-direction: column; gap: .15rem; }
.stat .num { font-size: 1.9rem; font-weight: 750; line-height: 1; }
.stat .lbl { color: var(--muted); font-size: .88rem; }
.stat-link { text-decoration: none; color: inherit; }
.stat-link:hover .card { border-color: #C9D2DE; }
.empty { text-align: center; padding: 1.6rem 1rem; color: var(--muted); }
.empty .big { font-size: 2rem; display: block; margin-bottom: .3rem; }

/* ---------- badges & chips ---------- */
.badge { display: inline-flex; align-items: center; gap: .25rem; font-size: .76rem; font-weight: 650; padding: .15rem .5rem; border-radius: 999px;
  background: #EEF1F5; color: #334155; white-space: nowrap; }
.badge.urgent { background: var(--urgent-soft); color: var(--urgent); }
.badge.high { background: var(--warn-soft); color: var(--warn); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.info { background: var(--primary-soft); color: #1E40AF; }
.badge.ai { background: var(--violet-soft); color: #5B21B6; }
.badge.count { background: var(--urgent-strong); color: #fff; }
.kid-chip { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem .15rem .25rem; border-radius: 999px;
  background: color-mix(in srgb, var(--kid, #2563EB) 12%, white); color: #172033; font-weight: 600; font-size: .85rem; border: 1px solid color-mix(in srgb, var(--kid, #2563EB) 30%, white); }
.kid-chip .av { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: #fff; font-size: .85rem; }
.flag { display: flex; gap: .4rem; align-items: flex-start; font-size: .84rem; color: var(--warn); background: var(--warn-soft); padding: .3rem .55rem; border-radius: 8px; }
.flag + .flag { margin-top: .3rem; }

/* ---------- segmented filters ---------- */
.segmented { display: inline-flex; background: #EEF1F5; border-radius: 12px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented a, .segmented button { padding: .4rem .8rem; border-radius: 9px; text-decoration: none; color: var(--text); font-weight: 600; font-size: .9rem; border: 0; background: none; cursor: pointer; min-height: 36px; display: inline-flex; align-items: center; gap: .3rem; }
.segmented .on { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- task rows ---------- */
.task-list { list-style: none; margin: 0; padding: 0; }
.task-row { display: grid; grid-template-columns: auto 1fr auto; gap: .8rem; align-items: center; padding: .75rem 1rem; border-top: 1px solid var(--border); }
.task-list > .task-row:first-child { border-top: 0; }
.task-row .ic { font-size: 1.25rem; width: 2rem; text-align: center; }
.task-row .title { font-weight: 600; }
.task-row .meta { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: .84rem; margin-top: .15rem; }
.task-row.is-done .title { text-decoration: line-through; text-decoration-color: #9AA4B2; color: var(--muted); }
.task-row.is-overdue { background: linear-gradient(90deg, var(--urgent-soft), transparent 40%); }
.task-row .actions { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 640px) { .task-row { grid-template-columns: auto 1fr; } .task-row .actions { grid-column: 1 / -1; justify-content: flex-start; } }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table-wrap { overflow-x: auto; }

/* ---------- messages ---------- */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .5rem; }
.messages li { padding: .7rem 1rem; border-radius: var(--radius-sm); background: var(--primary-soft); border: 1px solid #C7D8FB; }
.messages .success { background: var(--success-soft); border-color: #B5E3CD; }
.messages .error { background: #FDECEC; border-color: #F6C1C1; }
.messages .warning { background: var(--warn-soft); border-color: #F3D9A4; }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .5rem; }
.cal-day { background: #fff; border: 1px solid var(--border); border-radius: 12px; min-height: 140px; padding: .5rem; display: flex; flex-direction: column; gap: .35rem; }
.cal-day.today { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.cal-day.out { background: #FAFBFC; opacity: .7; }
.cal-day .d { font-weight: 700; font-size: .85rem; display: flex; justify-content: space-between; }
.cal-item { font-size: .8rem; padding: .25rem .4rem; border-radius: 7px; border-left: 4px solid var(--kid, #94A3B8); background: color-mix(in srgb, var(--kid, #94A3B8) 9%, white); text-decoration: none; color: var(--text); display: block; }
.cal-item.done { opacity: .6; text-decoration: line-through; }
.cal.month .cal-day { min-height: 110px; }
@media (max-width: 900px) { .cal { grid-template-columns: 1fr; } .cal-day { min-height: 0; } .cal-day.out { display: none; } }

/* ---------- importer ---------- */
.dropzone { border: 2px dashed #B8C4D6; border-radius: var(--radius); padding: 1.6rem; text-align: center; background: #FBFCFE; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dropzone .big { font-size: 2.2rem; }
.file-list { list-style: none; padding: 0; margin: .6rem 0 0; display: grid; gap: .4rem; }
.file-list li { display: flex; gap: .6rem; align-items: center; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: .4rem .6rem; font-size: .9rem; }
.file-list img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: .6rem .9rem; font: inherit; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; min-height: 44px; }
.tabs button[aria-selected=true] { color: var(--text); border-color: var(--primary); }
.loading-overlay { position: fixed; inset: 0; background: rgba(247, 248, 250, .92); display: none; place-items: center; z-index: 100; text-align: center; padding: 1rem; }
.loading-overlay.on { display: grid; }
.spinner { width: 46px; height: 46px; border: 4px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 1rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- review ---------- */
.cand { border: 1px solid var(--border); border-radius: var(--radius); background: #fff; padding: 1rem; display: grid; gap: .8rem; }
.cand.off { opacity: .55; }
.cand.has-error { border-color: var(--urgent-strong); }
.cand-head { display: flex; gap: .7rem; align-items: flex-start; }
.cand-grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.excerpt { font-size: .85rem; color: var(--muted); border-left: 3px solid var(--border); padding-left: .6rem; font-style: italic; }
.source-thumb { width: 100%; max-height: 260px; object-fit: contain; border-radius: 10px; background: #F1F4F8; }
.sticky-bar { position: sticky; bottom: 0; background: rgba(255,255,255,.96); border-top: 1px solid var(--border); padding: .8rem 1rem; display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; margin: 1rem -1rem 0; backdrop-filter: blur(6px); z-index: 5; }

/* ---------- library ---------- */
.lib-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.lib-card { display: flex; flex-direction: column; text-decoration: none; color: inherit; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.lib-card:hover { border-color: #C9D2DE; }
.lib-thumb { height: 130px; background: #F1F4F8; display: grid; place-items: center; font-size: 2.6rem; overflow: hidden; }
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; }
.lib-body { padding: .8rem .9rem; display: grid; gap: .35rem; }
.lib-body .t { font-weight: 650; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.doc-text { white-space: pre-wrap; font-size: .92rem; background: #FBFCFD; border: 1px solid var(--border); border-radius: 10px; padding: .9rem; max-height: 420px; overflow: auto; }

/* ---------- chat ---------- */
.chat-layout { display: grid; grid-template-columns: 240px 1fr; gap: 1rem; }
@media (max-width: 900px) { .chat-layout { grid-template-columns: 1fr; } .chat-side { order: 2; } }
.chat-side a { display: block; padding: .5rem .6rem; border-radius: 8px; text-decoration: none; color: var(--text); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-side a.on, .chat-side a:hover { background: var(--primary-soft); }
.thread { display: flex; flex-direction: column; gap: .8rem; }
.bubble { max-width: 80%; padding: .7rem .95rem; border-radius: 16px; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.proposal-card { align-self: flex-start; max-width: 92%; border: 1px solid #D8CCFA; background: var(--violet-soft); border-radius: 14px; padding: .9rem 1rem; }
.composer { display: flex; gap: .5rem; margin-top: 1rem; position: sticky; bottom: 0; background: var(--bg); padding: .6rem 0; }
.composer textarea { min-height: 52px; height: 52px; }
.suggestions { display: flex; flex-wrap: wrap; gap: .4rem; }
.suggestions button { border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: .4rem .8rem; cursor: pointer; font: inherit; font-size: .88rem; min-height: 36px; }

/* ---------- weather card ---------- */
.wx { display: flex; gap: 1rem; align-items: center; }
.wx .icon { font-size: 2.6rem; line-height: 1; }
.wx .temps { font-size: 1.4rem; font-weight: 700; }
.stale { color: var(--warn); background: var(--warn-soft); padding: .2rem .5rem; border-radius: 6px; font-size: .82rem; font-weight: 600; display: inline-block; }

/* ---------- progress ---------- */
.progress { height: 10px; background: #EEF1F5; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }

/* ---------- code / pairing ---------- */
.code-display { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 2.6rem; letter-spacing: .18em; font-weight: 700; text-align: center; padding: 1rem; background: var(--primary-soft); border-radius: 14px; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 16px; }
.auth-card { width: 100%; max-width: 460px; }
