:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #20242c;
  background: #f7f8fb;
  --card: #ffffff;
  --line: #e7e9ef;
  --text-muted: #6d7480;
  --accent: #2767d7;
  --accent-soft: #eaf1ff;
  --danger: #c43b3b;
  --warning: #fff5d8;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #f7f8fb; }
body { padding: env(safe-area-inset-top, 0px) 0 0; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
#appShell { max-width: 760px; margin: 0 auto; min-height: 100dvh; }
.topbar { padding: 18px 18px 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 10; background: rgba(247,248,251,.94); backdrop-filter: blur(18px); }
h1 { margin: 2px 0 0; font-size: 22px; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 0 0 8px; font-size: 17px; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .09em; font-size: 10px; color: var(--text-muted); font-weight: 700; }
.muted { color: var(--text-muted); margin: 6px 0 0; line-height: 1.5; }
.fine-print { font-size: 12px; color: var(--text-muted); }
.child-switcher { max-width: 46%; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 10px 12px; display: flex; gap: 8px; align-items: center; font-size: 13px; }
#activeChildName { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
main { padding: 0 16px 104px; }
.view { display: none; }
.view.active { display: block; }
.hero-card { background: linear-gradient(145deg, #ffffff, #edf4ff); border: 1px solid #dfe9fb; border-radius: 24px; padding: 20px; display: flex; justify-content: space-between; gap: 20px; box-shadow: 0 10px 30px rgba(56,76,120,.08); }
.hero-card h2 { margin-top: 4px; font-size: 24px; }
.hero-icon { font-size: 42px; align-self: center; }
.label { color: var(--accent); font-size: 12px; font-weight: 700; margin: 0; }
section + section { margin-top: 24px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 12px; }
.sticky-heading { position: sticky; top: 76px; z-index: 8; background: rgba(247,248,251,.96); padding: 8px 0; backdrop-filter: blur(16px); }
.stack { display: grid; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 15px; box-shadow: 0 3px 16px rgba(47,55,72,.04); }
.card-row { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.card h3 { margin: 0; font-size: 16px; }
.meta { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--text-muted); font-size: 12px; }
.badge { display: inline-flex; align-items: center; padding: 5px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; }
.badge.warn { background: #fff1cc; color: #8a5d00; }
.badge.done { background: #e8f7eb; color: #26773b; }
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.quick-card { border: 1px solid var(--line); background: var(--card); border-radius: 18px; padding: 14px 8px; min-height: 110px; display: grid; place-items: center; align-content: center; gap: 5px; }
.quick-card span { font-size: 25px; }
.quick-card strong { font-size: 14px; }
.quick-card small { font-size: 10px; color: var(--text-muted); }
.empty { border: 1px dashed #ccd1db; border-radius: 18px; padding: 20px; text-align: center; color: var(--text-muted); background: rgba(255,255,255,.5); }
.banner { border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; font-size: 13px; }
.warning { background: var(--warning); color: #795500; }
.hidden { display: none !important; }
.primary-btn, .secondary-btn, .danger-btn { border-radius: 12px; padding: 10px 13px; font-weight: 700; border: 0; font-size: 13px; }
.primary-btn { background: var(--accent); color: #fff; }
.secondary-btn { background: #eff1f5; color: #303640; }
.danger-btn { background: #fff0f0; color: var(--danger); }
.icon-btn { border: 0; background: transparent; font-size: 28px; line-height: 1; padding: 4px 8px; color: #5f6570; }
.bottom-nav { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: min(760px, 100%); z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); padding: 8px 8px calc(8px + var(--safe-bottom)); background: rgba(255,255,255,.96); backdrop-filter: blur(18px); border-top: 1px solid var(--line); }
.nav-item { border: 0; background: transparent; display: grid; justify-items: center; gap: 3px; color: #8a909a; padding: 6px 2px; }
.nav-item span { font-size: 20px; }
.nav-item small { font-size: 10px; }
.nav-item.active { color: var(--accent); }
.settings-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 12px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-list { display: grid; gap: 8px; margin-top: 12px; }
.settings-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.settings-item:first-child { border-top: 0; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.file-label { display: inline-flex; align-items: center; }
.info-grid { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 14px; font-size: 13px; }
.info-grid span { color: var(--text-muted); }
.card-button { border: 0; width: 100%; text-align: left; padding: 0; background: transparent; color: inherit; }
dialog { width: min(680px, calc(100% - 24px)); max-height: 88dvh; border: 0; border-radius: 22px; padding: 0; box-shadow: 0 24px 80px rgba(28,34,47,.25); }
dialog::backdrop { background: rgba(18,22,31,.38); backdrop-filter: blur(3px); }
dialog form { padding: 18px; }
.compact-dialog { padding: 18px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.form-fields { display: grid; gap: 14px; max-height: 62dvh; overflow-y: auto; padding-right: 2px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 12px; font-weight: 700; color: #555c68; }
.field input, .field textarea, .field select { width: 100%; border: 1px solid #d9dde5; border-radius: 12px; padding: 12px; background: #fff; color: #20242c; }
.field textarea { min-height: 92px; resize: vertical; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 18px; }
.grow { flex: 1; }
.toast { position: fixed; z-index: 40; left: 50%; transform: translateX(-50%) translateY(20px); bottom: calc(86px + var(--safe-bottom)); background: #20242c; color: #fff; padding: 10px 14px; border-radius: 999px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 460px) {
  .topbar { padding-left: 14px; padding-right: 14px; }
  main { padding-left: 12px; padding-right: 12px; }
  .quick-grid { gap: 8px; }
  .quick-card { padding-left: 4px; padding-right: 4px; }
  .field-grid { grid-template-columns: 1fr; }
  dialog { width: calc(100% - 16px); }
}

/* v0.2 image/OCR */
.quick-card.accent { background: linear-gradient(145deg, #f3f7ff, #e8f0ff); border-color: #cddcff; }
.photo-mark { font-size: 13px; opacity: .75; }
.image-picker { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; border: 1px dashed #aeb9ca; border-radius: 14px; background: #f7f9fc; color: #344052; font-weight: 700; font-size: 13px; padding: 12px; cursor: pointer; }
.image-picker.secondary { background: #eff3f8; border-style: solid; border-color: #dce2eb; }
.image-preview-wrap { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: #f1f3f6; }
.image-preview { display: block; width: 100%; max-height: 320px; object-fit: contain; background: #f1f3f6; }
.image-field { padding-top: 4px; border-top: 1px solid var(--line); }
.ocr-note { padding: 12px 14px; border-radius: 14px; background: #eef4ff; color: #30405d; font-size: 13px; line-height: 1.5; }
.ocr-note p { margin: 6px 0 0; color: #62708a; font-size: 12px; }
.ocr-progress { display: grid; gap: 7px; }
.progress-track { width: 100%; height: 8px; overflow: hidden; border-radius: 999px; background: #e7eaf0; }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .2s ease; }
.detected-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; }
.detected-row strong { margin-right: auto; }
#ocrRawText { width: 100%; border: 1px solid #d9dde5; border-radius: 12px; padding: 12px; background: #fafbfc; color: #303640; resize: vertical; }
.ocr-details { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; background: #fafbfc; }
.ocr-details summary { cursor: pointer; font-size: 12px; font-weight: 700; color: #586170; }
.ocr-details pre { white-space: pre-wrap; word-break: break-word; font: inherit; font-size: 12px; line-height: 1.5; color: #555c68; max-height: 220px; overflow: auto; }
#ocrDialog { padding: 18px; }
#ocrDialog .form-fields { max-height: 58dvh; }
#startOcr:disabled, #useOcrResult:disabled { opacity: .45; cursor: default; }
@media (max-width: 520px) {
  .quick-grid { grid-template-columns: repeat(2, 1fr); }
  .quick-card { min-height: 104px; }
}


/* v0.2.3 OCR candidate preview / diagnostics */
.ocr-candidates {
  display: grid;
  gap: 10px;
  margin: 8px 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}
.candidate-head strong { font-size: 14px; }
.candidate-head p { margin: 4px 0 0; font-size: 12px; line-height: 1.5; color: #697386; }
.candidate-type-field { margin: 0; }
.candidate-list { display: grid; gap: 8px; }
.candidate-item {
  display: grid;
  grid-template-columns: minmax(88px, .8fr) minmax(0, 1.8fr);
  gap: 10px;
  align-items: start;
  padding: 9px 10px;
  border-radius: 12px;
  background: #f7f9fc;
}
.candidate-item span { font-size: 12px; color: #6b7483; }
.candidate-item strong { font-size: 13px; line-height: 1.45; word-break: break-word; }
.candidate-empty { padding: 10px; border-radius: 12px; background: #fff7e8; color: #765e2c; font-size: 12px; line-height: 1.55; }
.raw-ocr-details { margin-top: 8px; }
.raw-ocr-details #ocrRawText { margin-top: 10px; }
@media (max-width: 520px) {
  .candidate-item { grid-template-columns: 1fr; gap: 3px; }
}

.ocr-outcome {
  padding: 11px 12px;
  border-radius: 12px;
  background: #eef4ff;
  color: #30405d;
  font-size: 12px;
  line-height: 1.55;
}
.ocr-outcome.warn { background: #fff7e8; color: #765e2c; }
.ocr-outcome.error { background: #fff0f0; color: #963c3c; }

/* v0.3 high-accuracy OCR */
.ocr-quality-info {
  margin: -4px 0 10px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.45;
}
#startOcr { width: 100%; }

/* v0.4 voice entry + family sync */
.quick-card.voice { grid-column: span 2; min-height: 90px; background: linear-gradient(145deg, #eefaf3, #e3f5ea); border-color: #c7e8d3; }
#voiceDialog { padding: 18px; }
#voiceDialog .form-fields { max-height: 58dvh; }
.voice-note { padding: 12px 14px; border-radius: 14px; background: #eefaf3; color: #315744; font-size: 13px; line-height: 1.55; }
.voice-note p { margin: 6px 0 0; color: #5d7868; font-size: 12px; }
#voiceRawText { min-height: 140px; font-size: 16px; line-height: 1.55; }
.sync-details { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.sync-details summary { cursor: pointer; font-size: 12px; font-weight: 700; color: #596477; }
.sync-form { margin-top: 12px; max-height: none; overflow: visible; }
.sync-section { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.sync-section h4 { margin: 0 0 10px; }
.family-box { display: grid; grid-template-columns: auto 1fr; gap: 7px 12px; align-items: center; background: #f7f9fc; border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 10px 0 14px; }
.family-box span { color: var(--text-muted); font-size: 12px; }
.family-box code { user-select: all; font-size: 13px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 5px 7px; word-break: break-all; }
#syncStatusBadge.warn { background: #fff2cf; color: #81631b; }
@media (max-width: 520px) {
  .quick-card.voice { grid-column: span 2; }
}
