/* ============================================================
   HabitGrid — App Stylesheet
   Design tokens → layout → components → utilities → responsive
   ============================================================ */

/* ── Custom properties (light mode defaults) ───────────────────────────── */
:root {
  --bg:           #f4f4f5;
  --surface:      #ffffff;
  --surface-2:    #f9f9fa;
  --border:       #e4e4e7;
  --border-focus: #a1a1aa;
  --text:         #18181b;
  --text-2:       #52525b;
  --text-muted:   #a1a1aa;
  --accent:       #22c55e;
  --accent-dim:   #bbf7d0;
  --danger:       #ef4444;
  --danger-dim:   #fee2e2;
  --warning:      #f59e0b;

  /* Grid */
  --cell-size:    12px;
  --cell-gap:     3px;
  --cell-empty:   #e4e4e7;
  --cell-future:  #f1f1f2;

  /* Radius */
  --r-xs: 4px;
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 16px;
  --r-xl: 20px;

  /* Shadow */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 4px 16px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.04);

  /* Layout */
  --top-nav-h:    56px;
  --bottom-nav-h: 64px;
  --content-max:  900px;
  --page-pad:     20px;

  /* Animation */
  --ease: cubic-bezier(.4,0,.2,1);
  --dur:  180ms;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:         #09090b;
    --surface:    #18181b;
    --surface-2:  #1c1c1f;
    --border:     #27272a;
    --border-focus:#71717a;
    --text:       #fafafa;
    --text-2:     #a1a1aa;
    --text-muted: #52525b;
    --accent-dim: #14532d;
    --danger-dim: #450a0a;
    --cell-empty: #27272a;
    --cell-future:#1f1f22;
    --shadow-sm:  0 1px 3px rgba(0,0,0,.3);
    --shadow:     0 4px 16px rgba(0,0,0,.4);
  }
}

[data-theme="dark"] {
  --bg:         #09090b;
  --surface:    #18181b;
  --surface-2:  #1c1c1f;
  --border:     #27272a;
  --border-focus:#71717a;
  --text:       #fafafa;
  --text-2:     #a1a1aa;
  --text-muted: #52525b;
  --accent-dim: #14532d;
  --danger-dim: #450a0a;
  --cell-empty: #27272a;
  --cell-future:#1f1f22;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.3);
  --shadow:     0 4px 16px rgba(0,0,0,.4);
}

[data-theme="light"] {
  --bg:         #f4f4f5;
  --surface:    #ffffff;
  --surface-2:  #f9f9fa;
  --border:     #e4e4e7;
  --border-focus:#a1a1aa;
  --text:       #18181b;
  --text-2:     #52525b;
  --text-muted: #a1a1aa;
  --accent-dim: #bbf7d0;
  --danger-dim: #fee2e2;
  --cell-empty: #e4e4e7;
  --cell-future:#f1f1f2;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.06);
  --shadow:     0 4px 16px rgba(0,0,0,.08);
}

/* ── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

a { color: var(--accent); text-decoration: none; }
img, svg { display: block; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font: inherit; }

/* ── App shell ─────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Top navigation (desktop/tablet) ──────────────────────────────────── */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--top-nav-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 var(--page-pad);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.top-nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  white-space: nowrap;
  margin-right: 4px;
}

.top-nav-tabs {
  display: flex;
  gap: 2px;
  flex: 1;
}

.top-nav-tabs .nav-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.top-nav-tabs .nav-tab:hover {
  background: var(--surface-2);
  color: var(--text);
}

.top-nav-tabs .nav-tab.active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}

/* ── Theme toggle ──────────────────────────────────────────────────────── */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  flex-shrink: 0;
}

.theme-toggle:hover { background: var(--surface-2); color: var(--text); }

/* Show sun in dark mode, moon in light mode */
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"]   .theme-toggle .icon-sun  { display: none; }
[data-theme="dark"]   .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun  { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
}

/* ── Bottom navigation (mobile) ────────────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--bottom-nav-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: none;
  align-items: stretch;
  justify-content: space-around;
}

.bottom-nav .nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: .68rem;
  font-weight: 500;
  transition: color var(--dur) var(--ease);
  padding: 8px 4px;
}

.bottom-nav .nav-tab.active {
  color: var(--accent);
}

.bottom-nav .nav-tab svg {
  transition: transform var(--dur) var(--ease);
}

.bottom-nav .nav-tab.active svg {
  transform: translateY(-1px);
}

/* ── Main content ──────────────────────────────────────────────────────── */
.main {
  flex: 1;
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  padding: 24px var(--page-pad) calc(var(--bottom-nav-h) + 24px);
}

/* ── Tab panes ─────────────────────────────────────────────────────────── */
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Page header ───────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}

.page-title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.2;
}

.page-subtitle {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  font-size: .85rem;
  font-weight: 600;
  transition: all var(--dur) var(--ease);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--text);
  color: var(--bg);
}

.btn-primary:hover {
  opacity: .85;
  transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); opacity: .95; }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
}

.btn-danger:hover { opacity: .85; }

.btn-sm {
  padding: 5px 10px;
  font-size: .8rem;
}

.btn-icon {
  padding: 6px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
}

.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur) var(--ease);
}

/* ── Habit card ────────────────────────────────────────────────────────── */
.habit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow var(--dur) var(--ease);
}

.habit-card:hover { box-shadow: var(--shadow); }

.habit-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.habit-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--habit-color, var(--accent));
  flex-shrink: 0;
}

.habit-name {
  font-size: .95rem;
  font-weight: 650;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.habit-desc {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Badge ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
}

.badge-streak {
  background: color-mix(in srgb, var(--habit-color, var(--accent)) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--habit-color, var(--accent)) 25%, var(--border));
  color: var(--habit-color, var(--accent));
}

.badge-rate { /* neutral */ }

/* ── Contribution grid ─────────────────────────────────────────────────── */
.grid-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  margin: 4px -4px 0;
  padding: 4px 4px 6px;
}

.grid-scroll {
  display: inline-flex;
  flex-direction: column;
  gap: 0;
}

.grid-month-row {
  display: flex;
  margin-bottom: 4px;
  padding-left: 24px; /* offset for day labels */
  min-height: 14px;
  position: relative;
}

.grid-month-label {
  position: absolute;
  font-size: .68rem;
  color: var(--text-muted);
  white-space: nowrap;
  top: 0;
  /* left is set via JS */
}

.grid-body {
  display: flex;
  gap: 0;
}

.grid-day-labels {
  display: flex;
  flex-direction: column;
  gap: var(--cell-gap);
  margin-right: 6px;
  width: 18px;
}

.grid-day-labels span {
  height: var(--cell-size);
  font-size: .62rem;
  color: var(--text-muted);
  line-height: var(--cell-size);
  text-align: right;
  white-space: nowrap;
}

.habit-grid {
  display: grid;
  grid-template-rows: repeat(7, var(--cell-size));
  grid-auto-flow: column;
  grid-auto-columns: var(--cell-size);
  gap: var(--cell-gap);
}

/* ── Grid cells ────────────────────────────────────────────────────────── */
.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: var(--r-xs);
  background: var(--cell-empty);
  cursor: pointer;
  position: relative;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.grid-cell:hover {
  transform: scale(1.35);
  z-index: 2;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}

.grid-cell:active { transform: scale(1.1); }

.grid-cell[data-level="1"] {
  background: color-mix(in srgb, var(--habit-color) 25%, var(--cell-empty));
}
.grid-cell[data-level="2"] {
  background: color-mix(in srgb, var(--habit-color) 50%, var(--cell-empty));
}
.grid-cell[data-level="3"] {
  background: color-mix(in srgb, var(--habit-color) 75%, var(--cell-empty));
}
.grid-cell[data-level="4"] {
  background: var(--habit-color);
}

.grid-cell.today {
  box-shadow: 0 0 0 1.5px var(--text-2);
}

.grid-cell.future {
  background: var(--cell-future);
  opacity: .4;
  cursor: default;
  pointer-events: none;
}

.grid-cell.future:hover { transform: none; box-shadow: none; }

/* Cell click animation */
@keyframes cellPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.5); }
  100% { transform: scale(1); }
}
.grid-cell.popping { animation: cellPop 250ms var(--ease); }

/* ── Habit card footer ─────────────────────────────────────────────────── */
.habit-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  gap: 10px;
  flex-wrap: wrap;
}

.habit-footer-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: .78rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.habit-footer-meta strong {
  color: var(--text-2);
}

.today-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  font-size: .8rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  transition: all var(--dur) var(--ease);
  flex-shrink: 0;
}

.today-btn:hover {
  background: color-mix(in srgb, var(--habit-color) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--habit-color) 30%, var(--border));
  color: var(--text);
}

.today-btn.done {
  background: color-mix(in srgb, var(--habit-color) 15%, var(--surface));
  border-color: var(--habit-color);
  color: var(--habit-color);
}

.today-btn .checkmark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.today-btn.done .checkmark {
  background: var(--habit-color);
  border-color: var(--habit-color);
  color: #fff;
}

/* ── Habits list (management tab) ──────────────────────────────────────── */
.habit-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  margin-bottom: 8px;
  transition: box-shadow var(--dur) var(--ease);
}

.habit-list-item:hover { box-shadow: var(--shadow-sm); }

.habit-list-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.habit-list-info {
  flex: 1;
  min-width: 0;
}

.habit-list-name {
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-list-meta {
  font-size: .76rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.habit-list-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.form-label .optional {
  font-weight: 400;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: .88rem;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  -webkit-appearance: none;
}

.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--border-focus) 20%, transparent);
}

.form-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.form-hint {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Color picker */
.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
  -webkit-appearance: none;
  appearance: none;
  flex-shrink: 0;
}

.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: var(--text); transform: scale(1.1); }

/* Frequency toggle */
.freq-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}

.freq-toggle input[type="radio"] { display: none; }

.freq-toggle label {
  flex: 1;
  padding: 8px 12px;
  text-align: center;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  border-right: 1px solid var(--border);
}

.freq-toggle label:last-of-type { border-right: none; }

.freq-toggle input:checked + label {
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
}

/* Form actions */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn var(--dur) var(--ease);
}

.modal-overlay.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
  animation: slideUp var(--dur) var(--ease);
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
}

@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title { font-size: 1rem; font-weight: 700; }

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  transition: all var(--dur) var(--ease);
}

.modal-close:hover { background: var(--surface-2); color: var(--text); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

/* ── Stats view ────────────────────────────────────────────────────────── */
.stats-habit-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.stats-habit-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  transition: all var(--dur) var(--ease);
}

.stats-habit-btn .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.stats-habit-btn:hover {
  border-color: var(--border-focus);
  color: var(--text);
}

.stats-habit-btn.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 20px;
}

.stat-label {
  font-size: .74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.03em;
  color: var(--text);
}

.stat-value.accent { color: var(--habit-color, var(--accent)); }

.stat-sub {
  font-size: .76rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Progress bar */
.progress-bar-wrap {
  height: 6px;
  background: var(--cell-empty);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--habit-color, var(--accent));
  transition: width 600ms var(--ease);
}

/* Weekly performance bars */
.perf-chart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
}

.perf-chart-title {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 16px;
}

.perf-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 80px;
}

.perf-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
}

.perf-bar {
  width: 100%;
  min-width: 6px;
  background: var(--cell-empty);
  border-radius: var(--r-xs) var(--r-xs) 0 0;
  position: relative;
  overflow: hidden;
  flex: 1;
}

.perf-bar-inner {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: var(--r-xs) var(--r-xs) 0 0;
  background: var(--habit-color, var(--accent));
  transition: height 600ms var(--ease);
}

.perf-bar.met .perf-bar-inner { opacity: 1; }
.perf-bar:not(.met) .perf-bar-inner { opacity: .6; }

.perf-bar-label {
  font-size: .58rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Settings view ─────────────────────────────────────────────────────── */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: 16px;
  overflow: hidden;
}

.settings-section-title {
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  padding: 14px 18px 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  gap: 12px;
}

.settings-row:first-of-type { border-top: none; }

.settings-row-label {
  font-size: .88rem;
  font-weight: 500;
}

.settings-row-sub {
  font-size: .76rem;
  color: var(--text-muted);
  margin-top: 1px;
}

/* Theme selector buttons */
.theme-options {
  display: flex;
  gap: 4px;
}

.theme-option {
  padding: 5px 11px;
  border-radius: var(--r-sm);
  font-size: .8rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  transition: all var(--dur) var(--ease);
}

.theme-option:hover { background: var(--surface-2); }
.theme-option.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ── Tooltip ───────────────────────────────────────────────────────────── */
.tooltip {
  position: fixed;
  z-index: 300;
  padding: 5px 10px;
  border-radius: var(--r-sm);
  font-size: .75rem;
  font-weight: 500;
  background: var(--text);
  color: var(--bg);
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 100ms var(--ease), transform 100ms var(--ease);
}

.tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Toast notifications ────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 9px 16px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 600;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  animation: toastIn 250ms var(--ease) forwards;
  pointer-events: none;
  white-space: nowrap;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px) scale(.95); }
  to   { opacity: 1; transform: translateY(0)   scale(1);   }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(4px) scale(.95); }
}

.toast.out { animation: toastOut 200ms var(--ease) forwards; }

/* ── Empty state ───────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: var(--text-muted);
}

.empty-state h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.empty-state p {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ── Loading skeleton ──────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-2)   0%,
    var(--border)      50%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
}

@keyframes shimmer {
  0%   { background-position:  200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Divider ───────────────────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* ── Keyboard shortcut hint ────────────────────────────────────────────── */
.kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .7rem;
  font-family: monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* ── Utility classes ───────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.mt-8    { margin-top: 8px; }
.mt-16   { margin-top: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: .82rem; }
.fw-600     { font-weight: 600; }

/* ── Responsive — mobile ───────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root {
    --page-pad: 14px;
    --cell-size: 11px;
    --cell-gap: 2px;
  }

  .top-nav-tabs { display: none; }
  .top-nav-brand { flex: 1; }
  .bottom-nav { display: flex; }

  .main {
    padding-top: 16px;
    padding-bottom: calc(var(--bottom-nav-h) + 16px);
  }

  .page-header { flex-wrap: wrap; }

  .habit-card { padding: 14px; border-radius: var(--r); }
  .habit-card-header { margin-bottom: 10px; }

  .habit-badges { display: none; } /* shown in footer on mobile */

  .habit-card-footer { margin-top: 10px; padding-top: 10px; }

  .stats-grid { grid-template-columns: 1fr 1fr; }

  .modal { border-radius: var(--r-lg) var(--r-lg) 0 0; margin-top: auto; max-height: 92dvh; }
  .modal-overlay { align-items: flex-end; padding: 0; }

  #toast-container { bottom: calc(var(--bottom-nav-h) + 12px); }

  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; justify-content: center; }
}

@media (min-width: 641px) {
  .bottom-nav { display: none; }
  .main { padding-bottom: 40px; }
}
