:root {
  --bg: #f6f3ff;
  --surface: #ffffff;
  --surface2: #ede8ff;
  --primary: #6c47b8;
  --primary-light: #9b7dd4;
  --primary-dark: #4d2f96;
  --accent: #2dbfb0;
  --accent-light: #6de0d5;
  --warn: #f87171;
  --text: #1a1a2e;
  --text-mid: #4a4a6a;
  --text-muted: #9090b0;
  --border: #e2daf5;
  --shadow: 0 4px 20px rgba(108,71,184,0.10);
  --shadow-sm: 0 2px 8px rgba(108,71,184,0.07);
  --radius: 16px;
  --radius-sm: 10px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 90px;
}

/* ── HEADER ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 660px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.app-title { font-size: 19px; font-weight: 800; color: var(--primary); letter-spacing: -0.3px; }
.date-nav { display: flex; align-items: center; gap: 10px; }
.date-nav button {
  background: var(--surface2);
  border: none;
  border-radius: 50%;
  width: 32px; height: 32px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
  font-size: 18px;
  transition: background 0.2s;
}
.date-nav button:hover { background: var(--border); }
.date-display {
  font-size: 14px; font-weight: 700; color: var(--text-mid);
  min-width: 110px; text-align: center;
}

/* ── TABS ── */
.tabs {
  display: flex;
  max-width: 660px;
  margin: 14px auto 0;
  padding: 0 14px;
  gap: 8px;
}
.tab-btn {
  flex: 1;
  padding: 10px 4px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px; font-weight: 700;
  cursor: pointer;
  transition: all 0.18s;
}
.tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 10px rgba(108,71,184,0.25);
}

/* ── MAIN ── */
main { max-width: 660px; margin: 0 auto; padding: 14px; }

/* ── CARD ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.card-title {
  font-size: 12px; font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.7px;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 7px;
}

/* ── SLEEP ── */
.quality-row { display: flex; align-items: center; gap: 14px; }
.quality-num {
  font-size: 32px; font-weight: 900; color: var(--primary);
  min-width: 44px; text-align: center; line-height: 1;
}
input[type="range"] {
  flex: 1; height: 6px;
  border-radius: 3px;
  accent-color: var(--primary);
  cursor: pointer;
}
.quality-labels {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-muted);
  margin-top: 6px; padding: 0 58px;
}
.fields-row { display: flex; gap: 10px; margin-top: 14px; }
.field { flex: 1; }
.field label {
  display: block;
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.4px;
  margin-bottom: 5px;
}
.field input {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus { border-color: var(--primary-light); }

/* ── MOOD ── */
.mood-period { margin-bottom: 18px; }
.mood-period:last-child { margin-bottom: 0; }
.mood-period-label { font-size: 13px; font-weight: 600; color: var(--text-mid); margin-bottom: 8px; }
.mood-emojis { display: flex; gap: 8px; }
.emoji-btn {
  flex: 1;
  padding: 10px 2px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 24px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  line-height: 1;
}
.emoji-btn:hover { border-color: var(--primary-light); transform: scale(1.07); }
.emoji-btn.sel {
  border-color: var(--primary);
  background: var(--surface2);
  transform: scale(1.07);
  box-shadow: 0 2px 8px rgba(108,71,184,0.18);
}

/* ── RATING BUTTONS (energy, novelty, etc.) ── */
.energy-row { display: flex; gap: 8px; flex-wrap: wrap; }
.energy-btn {
  padding: 7px 16px;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  color: var(--text-mid);
  transition: all 0.15s;
}
.energy-btn:hover { border-color: var(--primary-light); }
.energy-btn.sel { border-color: var(--primary); background: var(--surface2); color: var(--primary-dark); }

/* ── ACTIVITIES ── */
.acts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.act-card {
  border: 2px solid var(--border);
  border-radius: 13px;
  padding: 13px 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.act-card:hover { border-color: var(--primary-light); }
.act-card.on { border-color: var(--primary); background: var(--surface2); }
.act-top { display: flex; align-items: center; justify-content: space-between; }
.act-name { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.act-ico { font-size: 20px; }
.act-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: transparent;
  transition: all 0.15s;
  flex-shrink: 0;
}
.act-card.on .act-check { background: var(--primary); border-color: var(--primary); color: #fff; }
.act-detail { display: none; margin-top: 9px; }
.act-card.on .act-detail { display: block; }
.act-detail input {
  width: 100%;
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}
.act-detail input:focus { border-color: var(--primary-light); }

/* ── CUSTOM / TAG INPUTS ── */
.custom-section { margin-top: 14px; }
.custom-label {
  font-size: 12px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.custom-tags { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 8px; }
.ctag {
  background: var(--surface2);
  border: 1.5px solid var(--primary-light);
  border-radius: 20px;
  padding: 4px 12px 4px 13px;
  font-size: 12px; color: var(--primary-dark);
  display: flex; align-items: center; gap: 6px;
}
.ctag button {
  background: none; border: none;
  cursor: pointer; color: var(--primary);
  font-size: 15px; line-height: 1; padding: 0;
}
.add-custom { display: flex; gap: 8px; }
.add-custom input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}
.add-custom input:focus { border-color: var(--primary-light); }
.add-custom button {
  padding: 8px 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 700;
  cursor: pointer;
}

/* ── CARD SUBTITLE ── */
.card-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: -10px;
  margin-bottom: 14px;
}

/* ── SLEEP AUTO LABEL ── */
.auto-lbl {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  margin-left: 4px;
}

/* ── NOTES ── */
textarea {
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px; line-height: 1.6;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  min-height: 96px;
  outline: none;
  transition: border-color 0.2s;
}
textarea:focus { border-color: var(--primary-light); }

.notes-list { display: flex; flex-direction: column; gap: 14px; }
.note-block {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.note-block-head {
  display: flex;
  gap: 8px;
  align-items: center;
}
.note-title-input {
  flex: 1;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.2s;
}
.note-title-input:focus { border-color: var(--primary-light); }
.note-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.note-delete-btn:hover { background: #fbe9e9; color: var(--warn); }
.note-body {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  min-height: 200px;
  outline: none;
  transition: border-color 0.2s;
}
.note-body:focus { border-color: var(--primary-light); }
.add-note-btn {
  margin-top: 14px;
  width: 100%;
  padding: 10px;
  border: 1.5px dashed var(--primary-light);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.add-note-btn:hover { background: var(--surface2); border-style: solid; }

/* Rendered markdown inside detail sheet */
.note-render { font-size: 14px; line-height: 1.65; color: var(--text-mid); }
.note-render h1, .note-render h2, .note-render h3, .note-render h4 {
  color: var(--text); margin: 10px 0 6px; line-height: 1.25;
}
.note-render h1 { font-size: 18px; }
.note-render h2 { font-size: 16px; }
.note-render h3 { font-size: 15px; }
.note-render h4 { font-size: 14px; }
.note-render p { margin: 6px 0; }
.note-render ul, .note-render ol { margin: 6px 0 6px 22px; }
.note-render li { margin: 2px 0; }
.note-render code {
  background: var(--surface2);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: var(--primary-dark);
}
.note-render pre {
  background: var(--surface2);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.note-render pre code {
  background: none; padding: 0; font-size: 12px;
}
.note-render a { color: var(--primary); text-decoration: underline; }
.note-render strong { color: var(--text); }
.sheet-note + .sheet-note,
.sheet-note-title + .note-render { margin-top: 4px; }
.sheet-note-title {
  font-size: 14px; font-weight: 700;
  color: var(--primary-dark);
  margin: 14px 0 4px;
}
.sheet-note-title:first-child { margin-top: 0; }

/* ── SAVE BAR ── */
.save-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(108,71,184,0.08);
}
.save-btn {
  display: block; width: 100%;
  max-width: 660px; margin: 0 auto;
  padding: 14px;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 800;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.save-btn:hover { background: var(--primary-dark); }
.save-btn:active { transform: scale(0.98); }
.save-btn.done { background: var(--accent); }

/* ── HISTORY ── */
.hist-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}
.hist-item:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.hist-date { font-size: 14px; font-weight: 800; color: var(--text); margin-bottom: 8px; }
.hist-stats { display: flex; gap: 14px; font-size: 13px; color: var(--text-mid); flex-wrap: wrap; }
.hist-stat { display: flex; align-items: center; gap: 4px; }
.hist-stat strong { color: var(--primary); }
.hist-acts { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.badge {
  background: var(--surface2);
  border-radius: 6px;
  padding: 2px 9px;
  font-size: 11px; color: var(--primary-dark); font-weight: 600;
}

/* ── DETAIL SHEET ── */
.overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(26,26,46,0.55);
  z-index: 200;
  align-items: flex-end; justify-content: center;
}
.overlay.open { display: flex; }
.sheet {
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 22px 22px 30px;
  width: 100%; max-width: 660px;
  max-height: 82vh; overflow-y: auto;
}
.sheet-handle {
  width: 38px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 18px;
}
.sheet-title { font-size: 17px; font-weight: 800; margin-bottom: 18px; }
.sheet-section { margin-bottom: 16px; }
.sheet-section-title {
  font-size: 11px; font-weight: 800;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px;
  margin-bottom: 8px;
}
.sheet-moods { display: flex; gap: 14px; flex-wrap: wrap; }
.sheet-mood-item { text-align: center; }
.sheet-mood-period { font-size: 10px; color: var(--text-muted); margin-bottom: 4px; }
.sheet-mood-emoji { font-size: 26px; }
.sheet-acts { display: flex; flex-wrap: wrap; gap: 6px; }
.sheet-note { font-size: 14px; line-height: 1.65; color: var(--text-mid); }
.sheet-btn {
  margin-top: 18px; width: 100%;
  padding: 12px;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700;
  cursor: pointer;
}

/* ── INSIGHTS ── */
.insight-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.insight-title {
  font-size: 12px; font-weight: 800;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.7px;
  margin-bottom: 14px;
}
.stat-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text-mid); }
.stat-val { font-weight: 800; color: var(--primary); }

/* Bar chart */
.bar-chart { display: flex; align-items: flex-end; gap: 5px; height: 90px; margin-top: 6px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.bar { width: 100%; border-radius: 4px 4px 0 0; min-height: 3px; transition: height 0.35s; }
.bar-lbl { font-size: 10px; color: var(--text-muted); margin-top: 5px; }

/* Correlation */
.corr-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.corr-item:last-child { border-bottom: none; }
.corr-ico { font-size: 20px; flex-shrink: 0; }
.corr-info { flex: 1; min-width: 0; }
.corr-name { font-size: 14px; font-weight: 700; }
.corr-detail { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.corr-right { text-align: right; flex-shrink: 0; }
.corr-delta { font-size: 13px; font-weight: 800; }
.corr-track { width: 72px; height: 7px; background: var(--border); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.corr-fill { height: 100%; border-radius: 3px; }
.pos { color: var(--accent); }
.neg { color: var(--warn); }
.fill-pos { background: var(--accent); }
.fill-neg { background: var(--warn); }

/* Export */
.export-row { display: flex; gap: 10px; margin-top: 4px; }
.export-btn {
  flex: 1; padding: 11px;
  border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 700;
  cursor: pointer; transition: opacity 0.15s;
}
.export-btn:hover { opacity: 0.85; }
.btn-json { background: var(--primary); color: #fff; }
.btn-csv  { background: var(--accent);  color: #fff; }
.btn-vault { background: var(--primary-light); color: #fff; }

/* Empty state */
.empty { text-align: center; padding: 44px 20px; color: var(--text-muted); }
.empty .eico { font-size: 50px; margin-bottom: 12px; }
.empty p { font-size: 14px; line-height: 1.65; }

/* Toast */
.toast {
  position: fixed;
  bottom: 94px; left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #1a1a2e; color: #fff;
  padding: 10px 22px;
  border-radius: 22px;
  font-size: 13px; font-weight: 700;
  opacity: 0; transition: all 0.28s;
  z-index: 400; white-space: nowrap;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  .acts-grid { grid-template-columns: 1fr; }
  .fields-row { flex-direction: column; }
}
