:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #262b36;
  --text: #eef1f6;
  --text-dim: #9aa3b2;
  --accent: #5b8cff;
  --accent-dim: #34497e;
  --success: #37c98b;
  --danger: #f0576b;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --maxw: 640px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

body {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px;
}

.hidden { display: none !important; }

/* ---- Header ---- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 16px;
}
.header h1 { font-size: 20px; margin: 0; font-weight: 700; }
.header .date { color: var(--text-dim); font-size: 13px; }

/* ---- KPI cards ---- */
.kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 8px;
  text-align: center;
}
.kpi .num { font-size: 24px; font-weight: 700; }
.kpi .label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

/* ---- Section titles ---- */
.section-title {
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 24px 4px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ---- Cards / list items ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.todo {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.todo .check {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 2px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  display: grid;
  place-items: center;
  margin-top: 1px;
  transition: all 0.15s;
}
.todo .check.done {
  background: var(--success);
  border-color: var(--success);
}
.todo .check.done::after { content: "✓"; color: #06231a; font-size: 15px; font-weight: 800; }
.todo .body { flex: 1; min-width: 0; }
.todo .title { font-weight: 500; word-wrap: break-word; }
.todo.done .title { color: var(--text-dim); text-decoration: line-through; }
.todo .meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.del { color: var(--text-dim); background: none; border: none; font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px; flex: 0 0 auto; }
.del:active { color: var(--danger); }
.todo-actions { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 0 0 auto; }
.iconbtn { background: none; border: none; color: var(--text-dim); font-size: 16px; cursor: pointer; padding: 0 4px; line-height: 1; }
.iconbtn:active { color: var(--accent); }
.todo .body { cursor: pointer; }

/* ---- Goal tree ---- */
.goal-annual { margin-bottom: 16px; }
.goal-annual > .card { border-left: 3px solid var(--accent); }
.goal-node { }
.goal-node .row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.goal-node .row .t { flex: 1; font-weight: 500; }
.goal-monthly { margin: 6px 0 6px 14px; }
.goal-weekly { margin: 4px 0 4px 14px; }
.goal-monthly .card, .goal-weekly .card { padding: 10px 12px; margin-bottom: 6px; }
.goal-monthly .card { border-left: 3px solid var(--accent-dim); }
.goal-weekly .card { border-left: 3px solid var(--border); background: var(--surface-2); }
.chip { font-size: 11px; color: var(--text-dim); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; }
.muted { color: var(--text-dim); }
.desc { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  width: 100%;
}
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.small { width: auto; padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.ghost { background: none; color: var(--accent); width: auto; padding: 6px 8px; }
.btn:active { transform: scale(0.98); }

/* ---- Forms / inputs ---- */
input, textarea, select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  font-family: var(--font);
  margin-bottom: 10px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
label { font-size: 13px; color: var(--text-dim); display: block; margin-bottom: 4px; }

/* ---- Bottom nav ---- */
.nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(20, 23, 29, 0.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 50;
}
.nav button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  flex: 1;
}
.nav button .ico { font-size: 20px; }
.nav button.active { color: var(--accent); }

/* ---- Lock screen ---- */
.lock {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.lock .logo { font-size: 48px; margin-bottom: 8px; }
.lock h2 { margin: 0 0 4px; }
.lock p { color: var(--text-dim); margin: 0 0 24px; }
.lock .form { width: 100%; max-width: 320px; }
.lock input { text-align: center; font-size: 22px; letter-spacing: 0.3em; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin-bottom: 8px; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: var(--maxw);
  box-shadow: 0 -6px 24px rgba(0,0,0,0.5);
  max-height: 88vh;
  overflow-y: auto;
}
.modal h3 { margin: 0 0 14px; }
.modal .actions { display: flex; gap: 10px; margin-top: 6px; }

/* ---- Empty states ---- */
.empty { text-align: center; color: var(--text-dim); padding: 32px 16px; }
.empty .big { font-size: 32px; margin-bottom: 8px; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: calc(84px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: grid; place-items: center; padding: 48px; }

/* ---- AI breakdown review tree ---- */
.bd-tree { margin-top: 8px; }
.bd-month { margin-bottom: 12px; }
.bd-week { margin: 4px 0 4px 20px; }
.bd-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 14px; cursor: pointer; }
.bd-row input { width: auto; margin: 0; flex: 0 0 auto; accent-color: var(--accent); }
.bd-todo { margin-left: 20px; color: var(--text-dim); }
