:root {
  --bg: #f1f0eb;
  --surface: #faf9f5;
  --surface-2: #f5f3ed;
  --surface-3: #ebe9e2;
  --ink: #1f2421;
  --muted: #6f746f;
  --line: #d8d6cf;
  --deep: #222824;
  --deep-2: #303833;
  --accent: #68796d;
  --accent-soft: #dce2dc;
  --gold: #9b8052;
  --gold-soft: #e6ddcb;
  --good: #415e4c;
  --good-text: #f8fbf8;
  --partial: #9a7a3f;
  --partial-text: #fffaf0;
  --bad: #7a4944;
  --bad-text: #fff8f7;
  --skip: #a9aaa5;
  --skip-text: #242824;
  --shadow: 0 12px 34px rgba(35, 40, 36, .08);
  --radius-lg: 24px;
  --radius-md: 17px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -10%, rgba(104,121,109,.12), transparent 34%),
    linear-gradient(180deg, #f6f5f1 0%, var(--bg) 55%, #eceae3 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans", "Yu Gothic", sans-serif;
  padding-bottom: calc(82px + var(--safe-bottom));
}

button, input, textarea, select { font: inherit; }
button, .file-label { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
input, textarea, select { color: var(--ink); }

.app-shell { max-width: 760px; margin: 0 auto; padding: 16px 14px 28px; }
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px 18px;
}
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--deep); color: #f8f5eb; font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem; box-shadow: 0 8px 18px rgba(34,40,36,.16);
}
.app-header h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.7rem; letter-spacing: .01em; }
.app-header p { margin: 3px 0 0; color: var(--muted); font-size: .82rem; }
.date-pill { display: inline-flex; align-items: center; min-height: 34px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: rgba(250,249,245,.75); color: var(--muted); font-size: .76rem; white-space: nowrap; }

.page { display: none; animation: pageIn .22s ease; }
.page.active { display: block; }
@keyframes pageIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.card, .kpi-card {
  background: rgba(250,249,245,.96);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card { padding: 18px; margin-bottom: 14px; }
.card h2 { margin: 0 0 12px; font-size: 1.12rem; letter-spacing: .01em; }
.card-heading-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.card-heading-row h2 { margin: 0; }
.eyebrow { margin: 0 0 4px; color: var(--gold); font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.helper { margin: 8px 0 14px; color: var(--muted); font-size: .8rem; line-height: 1.55; }
.source-badge, .compact-count { display: inline-flex; align-items: center; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 6px 9px; font-size: .7rem; white-space: nowrap; }
.quiet-card { background: rgba(235,233,226,.72); }
.theme-card { background: linear-gradient(145deg, #e8ebe5, #f7f5ee); }

.primary-btn, .secondary-btn, .ghost-btn, .text-btn, .danger-btn, .file-label {
  border: 0; border-radius: 14px; min-height: 48px; padding: 12px 15px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.primary-btn { width: 100%; background: var(--deep); color: #f9f7ef; box-shadow: 0 8px 18px rgba(34,40,36,.14); }
.secondary-btn, .file-label { width: 100%; background: var(--accent-soft); color: var(--deep); border: 1px solid #c8d0c9; }
.ghost-btn { width: 100%; background: var(--surface-3); color: var(--ink); border: 1px solid var(--line); }
.danger-btn { width: 100%; background: #e7d8d6; color: #633d39; }
.text-btn { min-height: auto; padding: 7px 10px; background: transparent; color: var(--accent); }
.secondary-btn.compact { width: auto; min-width: 66px; min-height: 44px; }
.primary-btn:active, .secondary-btn:active, .ghost-btn:active, .text-btn:active, .file-label:active { transform: scale(.985); }
button:disabled { opacity: .45; cursor: not-allowed; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.stacked-buttons { display: grid; gap: 9px; }

.health-input-grid { display: grid; gap: 14px; }
.input-block { display: block; margin-bottom: 14px; }
.input-block > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.input-block input, .input-block textarea, .input-block select,
.action-entry-row input, .action-entry-row select {
  width: 100%; border: 1px solid #cfcfc8; border-radius: 13px; background: #fffef9; padding: 12px 13px; outline: none;
}
.input-block textarea { resize: vertical; min-height: 88px; line-height: 1.55; }
.input-block input:focus, .input-block textarea:focus, .input-block select:focus,
.action-entry-row input:focus, .action-entry-row select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(104,121,109,.12); }
.unit-input { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; }
.unit-input input { font-size: 1.35rem; font-weight: 800; }
.unit-input strong, .bp-inputs strong { color: var(--muted); font-size: .76rem; }
.bp-inputs { display: grid; grid-template-columns: minmax(62px,1fr) auto minmax(62px,1fr) auto; align-items: center; gap: 7px; }
.bp-inputs input { min-width: 0; font-size: 1.25rem; font-weight: 800; text-align: center; }
.bp-inputs b { color: var(--muted); }

.chart-grid { display: grid; gap: 10px; }
.mini-chart-card { border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius-md); padding: 13px; min-width: 0; }
.metric-line { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.metric-line span { color: var(--muted); font-size: .76rem; }
.metric-line strong { font-size: 1rem; }
.chart-wrap { min-height: 108px; overflow: hidden; }
.chart-wrap.large { min-height: 132px; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.status-note { min-height: 1.2em; margin: 9px 0 0; color: var(--muted); font-size: .74rem; }

.focus-editor { display: grid; gap: 11px; margin-bottom: 14px; }
.focus-entry {
  display: grid; grid-template-columns: 34px 1fr; gap: 10px; border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px; background: var(--surface-2);
}
.focus-entry.primary-focus { border-left: 5px solid var(--gold); }
.focus-index { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--deep); color: white; font-weight: 900; font-size: .78rem; }
.primary-focus .focus-index { background: var(--gold); }
.focus-fields { min-width: 0; display: grid; gap: 8px; }
.focus-fields input { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 7px 2px; outline: none; }
.focus-fields input:first-child { font-weight: 800; font-size: .95rem; }
.focus-fields input:last-child { color: var(--muted); font-size: .8rem; }
.carry-candidates { margin-bottom: 12px; border: 1px solid #d8d1bf; background: #f4efe3; border-radius: 15px; padding: 11px; }
.carry-candidates h3 { margin: 0 0 7px; font-size: .85rem; }
.carry-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid rgba(155,128,82,.18); }
.carry-item:first-of-type { border-top: 0; }
.carry-item span { font-size: .78rem; line-height: 1.35; }
.carry-item button { flex: 0 0 auto; border: 0; border-radius: 10px; background: var(--deep); color: white; padding: 7px 9px; font-size: .72rem; font-weight: 800; }

.night-focus-list { display: grid; gap: 11px; }
.night-focus-card { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px; background: var(--surface-2); }
.night-focus-title { display: grid; grid-template-columns: 30px 1fr; gap: 9px; align-items: start; }
.night-focus-title .marker { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--deep); color: white; font-weight: 900; font-size: .75rem; }
.night-focus-title strong { display: block; font-size: .9rem; line-height: 1.35; }
.night-focus-title small { display: block; color: var(--muted); margin-top: 4px; line-height: 1.35; }
.status-segment { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 10px; }
.status-segment button { min-height: 40px; border: 1px solid var(--line); border-radius: 12px; background: #fffef9; color: var(--muted); font-weight: 800; }
.status-segment button.selected.done { background: var(--good); border-color: var(--good); color: white; }
.status-segment button.selected.yet { background: var(--partial); border-color: var(--partial); color: white; }
.yet-fields { display: grid; gap: 8px; margin-top: 10px; }
.yet-fields select { width: 100%; border: 1px solid var(--line); border-radius: 11px; background: white; padding: 10px; }
.toggle-inline { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .77rem; }
.empty-state { padding: 18px 10px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); text-align: center; font-size: .82rem; }

.habit-grid-wrap { overflow-x: auto; padding-bottom: 4px; }
.habit-grid { min-width: 350px; display: grid; grid-template-columns: 48px repeat(7, minmax(34px, 1fr)); gap: 5px; align-items: stretch; }
.habit-grid .grid-head, .habit-grid .habit-label, .habit-cell { min-height: 38px; border-radius: 10px; display: grid; place-items: center; }
.habit-grid .grid-head { color: var(--muted); font-size: .7rem; font-weight: 800; }
.habit-grid .grid-head.today { color: var(--gold); background: var(--gold-soft); }
.habit-grid .habit-label { justify-items: start; padding-left: 5px; color: var(--ink); font-size: .76rem; font-weight: 900; }
.habit-cell { border: 1px solid var(--line); background: #fffef9; color: transparent; font-weight: 900; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.habit-cell.today { box-shadow: inset 0 0 0 2px var(--gold); }
.habit-cell.status-o { background: var(--good); color: var(--good-text); border-color: var(--good); }
.habit-cell.status-triangle { background: var(--partial); color: var(--partial-text); border-color: var(--partial); }
.habit-cell.status-x { background: var(--bad); color: var(--bad-text); border-color: var(--bad); }
.habit-cell.status-s { background: var(--skip); color: var(--skip-text); border-color: var(--skip); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-top: 12px; color: var(--muted); font-size: .68rem; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; border: 1px solid var(--line); background: white; }
.legend-dot.status-o { background: var(--good); border-color: var(--good); }
.legend-dot.status-triangle { background: var(--partial); border-color: var(--partial); }
.legend-dot.status-x { background: var(--bad); border-color: var(--bad); }
.legend-dot.status-s { background: var(--skip); border-color: var(--skip); }

.kpi-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 14px; }
.kpi-card { padding: 13px 10px; min-width: 0; }
.kpi-card span { display: block; min-height: 2.35em; color: var(--muted); font-size: .66rem; line-height: 1.2; }
.kpi-card strong { display: block; margin-top: 6px; font-size: 1.35rem; font-family: Georgia, "Times New Roman", serif; }
.kpi-card small { display: block; margin-top: 3px; color: var(--muted); font-size: .62rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dashboard-habits { display: grid; gap: 9px; }
.dashboard-habit-row { display: grid; grid-template-columns: 44px 1fr auto; gap: 9px; align-items: center; }
.dashboard-habit-row strong { font-size: .76rem; }
.week-dots { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.week-dot { height: 18px; border-radius: 6px; border: 1px solid var(--line); background: white; display: grid; place-items: center; font-size: .55rem; font-weight: 900; color: transparent; }
.week-dot.status-o { background: var(--good); border-color: var(--good); color: white; }
.week-dot.status-triangle { background: var(--partial); border-color: var(--partial); color: white; }
.week-dot.status-x { background: var(--bad); border-color: var(--bad); color: white; }
.week-dot.status-s { background: var(--skip); border-color: var(--skip); color: var(--skip-text); }
.dashboard-habit-rate { min-width: 38px; text-align: right; color: var(--muted); font-size: .72rem; }
.goal-list { display: grid; gap: 9px; }
.goal-item { border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; background: var(--surface-2); }
.goal-item strong { display: block; font-size: .84rem; }
.goal-item small { display: block; margin-top: 4px; color: var(--muted); line-height: 1.45; }
.goal-empty { color: var(--muted); font-size: .8rem; }

.review-summary-card { background: linear-gradient(145deg, #27302a, #3a453d); color: white; border: 0; }
.review-summary-card .eyebrow { color: #d6c49f; }
.review-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.review-metrics > div { background: rgba(255,255,255,.1); border-radius: 14px; padding: 11px; }
.review-metrics span { display: block; font-size: .7rem; opacity: .75; }
.review-metrics strong { display: block; margin-top: 4px; font-size: 1.2rem; }
.step-label { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; margin: 0 0 8px; background: var(--gold); color: white; font-weight: 900; font-size: .78rem; }
.action-entry-row { display: grid; grid-template-columns: 1fr 105px auto; gap: 7px; align-items: center; }
.weekly-action-list { display: grid; gap: 8px; margin-top: 11px; }
.weekly-action-item { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-2); }
.bucket-badge { border-radius: 999px; padding: 5px 7px; font-size: .65rem; font-weight: 900; white-space: nowrap; }
.bucket-do { background: var(--accent-soft); color: var(--deep); }
.bucket-later { background: var(--gold-soft); color: #6e572f; }
.bucket-drop { background: #dedbd4; color: #65645f; }
.weekly-action-item span:nth-child(2) { font-size: .8rem; line-height: 1.35; }
.weekly-action-item button { border: 0; background: transparent; color: var(--bad); font-size: 1rem; }
.top-gap { margin-top: 16px; }
.weekly-priorities { display: grid; gap: 8px; margin: 10px 0 14px; }
.weekly-priority-row { display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: center; }
.weekly-priority-row span { width: 27px; height: 27px; border-radius: 50%; display: grid; place-items: center; background: var(--deep); color: white; font-size: .7rem; font-weight: 900; }
.weekly-priority-row input { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: white; padding: 11px; }

.toggle-row { display: flex; align-items: flex-start; gap: 10px; padding: 12px 0 14px; }
.toggle-row input { width: 22px; height: 22px; accent-color: var(--good); }
.toggle-row strong { display: block; font-size: .86rem; }
.toggle-row small { display: block; margin-top: 3px; color: var(--muted); font-size: .72rem; line-height: 1.4; }
.goal-editor { display: grid; gap: 9px; margin-bottom: 10px; }
.goal-edit-item { border: 1px solid var(--line); border-radius: 14px; padding: 11px; background: var(--surface-2); }
.goal-edit-top { display: grid; grid-template-columns: 92px 1fr auto; gap: 7px; }
.goal-edit-item select, .goal-edit-item input, .goal-edit-item textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: white; padding: 9px; }
.goal-edit-item textarea { margin-top: 7px; min-height: 66px; resize: vertical; }
.goal-edit-item button { border: 0; background: transparent; color: var(--bad); padding: 4px; }
.simple-list { margin: 0; }
.simple-list div { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.simple-list div:last-child { border-bottom: 0; }
.simple-list dt { color: var(--muted); }
.simple-list dd { margin: 0; font-weight: 900; }

.bottom-nav {
  position: fixed; z-index: 50; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(760px, 100%); display: grid; grid-template-columns: repeat(5,1fr);
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: rgba(247,246,241,.94); border-top: 1px solid var(--line);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.nav-item { border: 0; background: transparent; color: #8b8e89; min-height: 54px; border-radius: 14px; display: grid; place-items: center; align-content: center; gap: 2px; }
.nav-item span { font-size: 1.08rem; line-height: 1; }
.nav-item small { font-size: .66rem; font-weight: 800; }
.nav-item.active { color: var(--deep); background: var(--accent-soft); }

.sheet-backdrop { position: fixed; z-index: 100; inset: 0; background: rgba(24,28,25,.5); display: flex; align-items: flex-end; justify-content: center; padding: 14px; }
.choice-sheet { width: min(520px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 18px; box-shadow: 0 24px 70px rgba(0,0,0,.22); margin-bottom: var(--safe-bottom); }
.choice-sheet h2 { margin: 0 0 12px; font-size: 1rem; }
.choice-sheet-buttons { display: grid; grid-template-columns: repeat(5,1fr); gap: 7px; margin-bottom: 10px; }
.choice-sheet-buttons button { min-height: 52px; border: 1px solid var(--line); border-radius: 13px; background: white; font-weight: 900; }
.choice-sheet-buttons button.status-o { background: var(--good); color: white; border-color: var(--good); }
.choice-sheet-buttons button.status-triangle { background: var(--partial); color: white; border-color: var(--partial); }
.choice-sheet-buttons button.status-x { background: var(--bad); color: white; border-color: var(--bad); }
.choice-sheet-buttons button.status-s { background: var(--skip); color: var(--skip-text); border-color: var(--skip); }

.toast { position: fixed; z-index: 120; left: 50%; bottom: calc(92px + var(--safe-bottom)); transform: translate(-50%, 16px); max-width: calc(100% - 36px); padding: 11px 14px; border-radius: 999px; background: var(--deep); color: white; box-shadow: 0 12px 28px rgba(0,0,0,.18); font-size: .78rem; opacity: 0; pointer-events: none; transition: .2s ease; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 640px) {
  .health-input-grid, .chart-grid { grid-template-columns: 1fr 1fr; }
  .card { padding: 21px; }
}

@media (max-width: 390px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .app-header h1 { font-size: 1.5rem; }
  .brand-mark { width: 38px; height: 38px; }
  .date-pill { font-size: .68rem; padding: 6px 8px; }
  .card { padding: 15px; border-radius: 21px; }
  .kpi-card { padding: 11px 8px; }
  .kpi-card strong { font-size: 1.18rem; }
  .action-entry-row { grid-template-columns: 1fr 96px; }
  .action-entry-row .secondary-btn { grid-column: 1 / -1; width: 100%; }
  .button-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
