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

/* ─── Theme tokens ─── */
:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #2e2e2e;
  --text: #f0f0f0;
  --text2: #c0c0c0;
  --muted: #6b6b6b;
  --accent: #7c6af7;
  --accent-dim: rgba(124,106,247,0.15);
  --danger: #f75a5a;
  --success: #4caf7d;
  --shadow: rgba(0,0,0,0.4);
  --radius: 14px;
  --nav-height: 64px;
}
[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface2: #f0f0f2;
  --border: #e0e0e5;
  --text: #111111;
  --text2: #444444;
  --muted: #999999;
  --accent: #6558e8;
  --accent-dim: rgba(101,88,232,0.1);
  --danger: #e03535;
  --shadow: rgba(0,0,0,0.1);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}

/* ─── Layout ─── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px calc(var(--nav-height) + 20px);
  scrollbar-width: none;
}
.page::-webkit-scrollbar { display: none; }
.page.active { display: block; }

/* ─── Nav ─── */
nav {
  position: fixed;
  bottom: 0;
  left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  height: var(--nav-height);
  background: var(--surface);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
  transition: background 0.2s, border-color 0.2s;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 16px;
  background: none; border: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s;
  font-size: 11px; font-weight: 500; letter-spacing: 0.3px;
}
.nav-btn.active { color: var(--accent); }
.nav-btn svg { width: 22px; height: 22px; }

/* ─── FAB ─── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  right: max(16px, calc(50vw - 240px + 16px));
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  border: none; color: white;
  font-size: 28px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(124,106,247,0.4);
  z-index: 99;
  transition: transform 0.15s, box-shadow 0.15s;
}
.fab:active { transform: scale(0.93); box-shadow: 0 2px 10px rgba(124,106,247,0.3); }

/* ─── Typography ─── */
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.section-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.8px;
  text-transform: uppercase; color: var(--muted);
  margin-bottom: 10px; margin-top: 24px;
}

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  transition: background 0.2s, border-color 0.2s;
}

/* ─── Summary chips ─── */
.summary-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.summary-chip {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 12px; text-align: center;
  transition: background 0.2s;
}
.summary-chip .val { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.summary-chip .lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ─── Heatmap ─── */
.heatmap-wrap { overflow-x: auto; margin-bottom: 8px; padding-bottom: 4px; scrollbar-width: none; }
.heatmap-wrap::-webkit-scrollbar { display: none; }
.heatmap-goal { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.heatmap-goal-name {
  font-size: 12px; font-weight: 600; width: 90px; flex-shrink: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.heatmap-grid { display: flex; gap: 3px; }
.heatmap-cell { width: 12px; height: 12px; border-radius: 2px; background: var(--surface2); flex-shrink: 0; }

/* ─── Chart ─── */
.chart-container { position: relative; height: 200px; }

/* ─── Modal ─── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  z-index: 200; align-items: flex-end; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  width: 100%; max-width: 480px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(32px + env(safe-area-inset-bottom));
  animation: slideUp 0.25s ease;
  max-height: 90vh;
  overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 20px; }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 20px; }

/* ─── Autocomplete ─── */
.autocomplete-wrap { position: relative; margin-bottom: 16px; }
.autocomplete-input {
  width: 100%;
  background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: 12px; color: var(--text);
  font-size: 15px; padding: 13px 16px;
  outline: none; font-family: inherit;
  transition: border-color 0.15s;
}
.autocomplete-input:focus { border-color: var(--accent); }
.autocomplete-dropdown {
  display: none;
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  z-index: 10;
  box-shadow: 0 8px 24px var(--shadow);
  max-height: 220px;
  overflow-y: auto;
}
.autocomplete-dropdown.open { display: block; }
.ac-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.1s;
  font-size: 14px; font-weight: 500;
}
.ac-item:hover, .ac-item.focused { background: var(--surface2); }
.ac-item .ac-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.ac-item .ac-new { font-size: 11px; color: var(--accent); font-weight: 600; background: var(--accent-dim); border-radius: 6px; padding: 2px 7px; margin-left: auto; }

/* ─── Selected branch chip ─── */
.selected-branch-chip {
  display: none; align-items: center; gap: 8px;
  background: var(--accent-dim); border: 1.5px solid var(--accent);
  border-radius: 10px; padding: 8px 12px;
  margin-bottom: 16px; font-weight: 600; font-size: 14px; color: var(--accent);
}
.selected-branch-chip.show { display: flex; }
.selected-branch-chip button {
  background: none; border: none; color: var(--accent);
  font-size: 16px; cursor: pointer; margin-left: auto; line-height: 1; padding: 0;
}
.chip-dot { width: 10px; height: 10px; border-radius: 50%; }

/* ─── Form elements ─── */
.form-group { margin-bottom: 16px; }
.form-label {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 8px; display: block;
}
input[type="number"],
input[type="text"],
input[type="time"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text);
  font-size: 15px; padding: 12px 14px;
  outline: none; font-family: inherit;
  transition: border-color 0.15s, background 0.2s;
  appearance: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear { display: none; }
textarea { resize: none; height: 80px; }
.time-presets { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.time-preset {
  padding: 6px 14px; border-radius: 20px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--muted); font-size: 13px; cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.time-preset:active { background: var(--accent-dim); color: var(--accent); }

/* ─── Buttons ─── */
.btn {
  width: 100%; padding: 15px; border-radius: 12px; border: none;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-danger { background: rgba(247,90,90,0.12); color: var(--danger); }

/* ─── Log items ─── */
.log-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.log-item:last-child { border-bottom: none; }
.log-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.log-meta { flex: 1; min-width: 0; }
.log-goal { font-weight: 600; font-size: 14px; }
.log-note { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.log-duration { font-size: 13px; font-weight: 600; color: var(--accent); white-space: nowrap; }

/* ─── Branches page ─── */
.branch-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 8px;
  transition: background 0.2s;
}
.branch-color-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.branch-info { flex: 1; min-width: 0; }
.branch-name { font-weight: 600; font-size: 15px; }
.branch-stats { font-size: 12px; color: var(--muted); margin-top: 2px; }
.branch-delete {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 4px; display: flex; align-items: center; border-radius: 6px;
  transition: color 0.15s;
}
.branch-delete:hover { color: var(--danger); }

/* ─── Add branch form ─── */
.add-branch-form {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-top: 16px;
  transition: background 0.2s;
}
.color-picker-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: transform 0.1s, border-color 0.1s;
}
.color-swatch.selected { border-color: var(--text); transform: scale(1.15); }

/* ─── Settings ─── */
.settings-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-top: 24px;
  transition: background 0.2s;
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; padding-bottom: 0; }
.settings-label { font-size: 14px; font-weight: 500; }
.settings-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.time-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.time-row input[type="time"] { font-size: 14px; padding: 10px 12px; }
.day-chip {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; cursor: pointer;
  background: var(--surface2); color: var(--muted);
  border: 1px solid var(--border); user-select: none;
  transition: background 0.15s, color 0.15s;
}
.day-chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ─── Toggle switch ─── */
.toggle { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--border);
  border-radius: 13px; cursor: pointer; transition: background 0.2s;
}
.toggle-slider:before {
  content: ''; position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: white; border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider:before { transform: translateX(18px); }

/* ─── Theme toggle ─── */
.theme-btn {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 12px;
  cursor: pointer; font-size: 14px; color: var(--text);
  transition: background 0.2s;
  display: flex; align-items: center; gap: 5px;
}

/* ─── Empty states ─── */
.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14px; }
.empty span { font-size: 32px; display: block; margin-bottom: 12px; }

/* ─── Streak ─── */
.streak-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; font-weight: 600; color: #f0a500;
  background: rgba(240,165,0,0.12); border-radius: 20px; padding: 4px 10px;
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 80px);
  left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  font-size: 13px; font-weight: 600;
  padding: 10px 18px; border-radius: 20px;
  opacity: 0; transition: opacity 0.2s;
  pointer-events: none; white-space: nowrap; z-index: 300;
}
.toast.show { opacity: 1; }

/* ─── Notification banner ─── */
.notif-banner {
  background: var(--accent-dim); border: 1px solid var(--accent);
  border-radius: 12px; padding: 12px 14px;
  font-size: 13px; color: var(--accent);
  margin-bottom: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.notif-banner button {
  background: var(--accent); color: white; border: none;
  border-radius: 8px; padding: 6px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
