/* carissaco.com — Habit Tracker
   Clean & minimal design */

:root {
  /* base structure variables — themes override the color tokens */
  --radius: 14px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.04);
}

/* ============ THEMES ============ */
/* SERENITY (default — sunset meditation: peach, coral, seafoam) */
body[data-theme="serenity"] {
  --bg: #fdf2e9;
  --surface: #ffffff;
  --surface-2: #fbe1d3;
  --text: #2d3e54;
  --text-muted: #997b75;
  --border: #f7d5c5;
  --accent: #e58978;
  --accent-soft: #fbd9d0;
  --success: #6cb5a3;
  --danger: #c5352b;
}

/* MINT (spa green) */
body[data-theme="mint"] {
  --bg: #f3faf6;
  --surface: #ffffff;
  --surface-2: #e6f3ec;
  --text: #1d3a2c;
  --text-muted: #6b8579;
  --border: #d4ebde;
  --accent: #4a9d7a;
  --accent-soft: #d8ede1;
  --success: #4a9d7a;
  --danger: #c5352b;
}

/* OCEAN (calm blue) */
body[data-theme="ocean"] {
  --bg: #f1f7fb;
  --surface: #ffffff;
  --surface-2: #e3eff7;
  --text: #1c3954;
  --text-muted: #6a8499;
  --border: #d1e3ef;
  --accent: #3d7ea6;
  --accent-soft: #d6e8f3;
  --success: #3d8aa6;
  --danger: #c5352b;
}

/* LAVENDER (soft purple) */
body[data-theme="lavender"] {
  --bg: #f8f5fb;
  --surface: #ffffff;
  --surface-2: #ede5f3;
  --text: #3a2c54;
  --text-muted: #847a99;
  --border: #ddd1eb;
  --accent: #7e62a8;
  --accent-soft: #e1d6ef;
  --success: #4a9d7a;
  --danger: #c5352b;
}

/* SUNSET (warm peach) */
body[data-theme="sunset"] {
  --bg: #fdf6f1;
  --surface: #ffffff;
  --surface-2: #f7e8dd;
  --text: #4a2c1d;
  --text-muted: #9a7868;
  --border: #ecd9c8;
  --accent: #d97a4d;
  --accent-soft: #f3dcc9;
  --success: #4a9d7a;
  --danger: #c5352b;
}

/* MINIMAL (original black & cream) */
body[data-theme="minimal"] {
  --bg: #fafaf7;
  --surface: #ffffff;
  --surface-2: #f3f2ed;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --border: #ebe9e2;
  --accent: #1a1a1a;
  --accent-soft: #e8e6df;
  --success: #2f7d4f;
  --danger: #c5352b;
}

/* Dark variants — applied only when user hasn't overridden and prefers dark */
@media (prefers-color-scheme: dark) {
  body[data-theme="serenity"]:not([data-mode="light"]) {
    --bg: #1a1f2a;
    --surface: #232a37;
    --surface-2: #2c3543;
    --text: #fbe1d3;
    --text-muted: #b89890;
    --border: #3a4456;
    --accent: #f0a89a;
    --accent-soft: #3a2e2a;
    --success: #8ed1bc;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
  }
  body[data-theme="mint"]:not([data-mode="light"]) {
    --bg: #0f1a14;
    --surface: #182520;
    --surface-2: #1f3028;
    --text: #d8ede1;
    --text-muted: #8aa89a;
    --border: #2a4036;
    --accent: #6ec0a0;
    --accent-soft: #2a4036;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
  }
  body[data-theme="ocean"]:not([data-mode="light"]) {
    --bg: #0e1822;
    --surface: #18242f;
    --surface-2: #1f3140;
    --text: #d6e8f3;
    --text-muted: #89a3b8;
    --border: #2a4258;
    --accent: #6ba8cc;
    --accent-soft: #2a4258;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
  }
  body[data-theme="lavender"]:not([data-mode="light"]) {
    --bg: #161122;
    --surface: #22192f;
    --surface-2: #2d2240;
    --text: #e1d6ef;
    --text-muted: #9b8eb3;
    --border: #3a2c54;
    --accent: #a890c7;
    --accent-soft: #3a2c54;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
  }
  body[data-theme="sunset"]:not([data-mode="light"]) {
    --bg: #1f140e;
    --surface: #2b1d14;
    --surface-2: #3a281c;
    --text: #f3dcc9;
    --text-muted: #b89789;
    --border: #4a3528;
    --accent: #e89870;
    --accent-soft: #4a3528;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
  }
  body[data-theme="minimal"]:not([data-mode="light"]) {
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text: #f0efe9;
    --text-muted: #9a9a93;
    --border: #2c2c2a;
    --accent: #f0efe9;
    --accent-soft: #2c2c2a;
    --success: #6ec48a;
    --danger: #ef6b62;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

body {
  padding-bottom: calc(96px + var(--safe-bottom));
}

.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.danger { color: var(--danger); }

/* HEADER */
.app-header {
  padding: calc(20px + var(--safe-top)) 20px 12px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid transparent;
}
.app-header.scrolled { border-bottom-color: var(--border); }

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  max-width: 600px;
  margin: 0 auto;
}

.brand {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

h1 {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 2px;
  letter-spacing: -0.02em;
}

#dateSub {
  margin: 0;
  font-size: 14px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }

/* VIEWS */
main { max-width: 600px; margin: 0 auto; padding: 8px 20px 20px; }
.view { display: none; }
.view.active { display: block; }

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 28px 0 12px;
}

/* AFFIRMATION BANNER */
.affirmation {
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 8px 0 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid var(--border);
}
.affirmation-text {
  flex: 1;
  font-size: 15px;
  line-height: 1.5;
  font-style: italic;
  color: var(--text);
}
.affirmation-text::before { content: "“"; opacity: 0.5; margin-right: 1px; }
.affirmation-text::after { content: "”"; opacity: 0.5; margin-left: 1px; }
.affirmation-refresh {
  background: none;
  border: none;
  color: var(--accent);
  padding: 4px;
  cursor: pointer;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.4s ease;
  flex-shrink: 0;
}
.affirmation-refresh:hover { background: var(--surface); }
.affirmation-refresh.spinning { transform: rotate(360deg); }

/* CUSTOM AFFIRMATIONS */
.affirmation-add {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}
.affirmation-add input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
}
.custom-list {
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.custom-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}
.custom-list li .text { flex: 1; font-style: italic; }
.custom-list li button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 18px;
}
.custom-list li button:hover { color: var(--danger); background: var(--surface-2); }
.custom-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

/* THEME PICKER */
.theme-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
  margin: 8px 0 12px;
}
.theme-swatch {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  cursor: pointer;
  text-align: center;
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
  transition: transform 0.1s ease;
}
.theme-swatch:active { transform: scale(0.97); }
.theme-swatch.selected { border-color: var(--accent); }
.theme-swatch-colors {
  display: flex;
  justify-content: center;
  gap: 3px;
  margin-bottom: 6px;
}
.theme-swatch-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.08);
}

/* CATEGORY FILTERS */
.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.filter-row::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 7px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.chip.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* HABIT LIST */
.habit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.habit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, opacity 0.2s ease;
}
.habit-card.done { opacity: 0.55; }
.habit-card:active { transform: scale(0.98); }

.habit-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.habit-info {
  flex: 1;
  min-width: 0;
}
.habit-name {
  font-weight: 500;
  font-size: 16px;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.habit-card.done .habit-name { text-decoration: line-through; }

.habit-meta {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 500;
}

.check-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  transition: all 0.2s ease;
}
.habit-card.done .check-btn {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.habit-edit {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px 8px;
  font-size: 18px;
  cursor: pointer;
  border-radius: 8px;
}
.habit-edit:hover { background: var(--surface-2); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
}
.empty-state p { margin: 4px 0; }

/* STATS */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 8px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-num {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.heatmap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.heatmap-grid {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  gap: 3px;
  min-width: 100%;
}
.heatmap-cell {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--surface-2);
}
.heatmap-cell[data-level="1"] { background: #cfe8d6; }
.heatmap-cell[data-level="2"] { background: #87c69a; }
.heatmap-cell[data-level="3"] { background: #4fa86e; }
.heatmap-cell[data-level="4"] { background: var(--success); }
@media (prefers-color-scheme: dark) {
  .heatmap-cell[data-level="1"] { background: #1f3a26; }
  .heatmap-cell[data-level="2"] { background: #2d5d3a; }
  .heatmap-cell[data-level="3"] { background: #46895a; }
  .heatmap-cell[data-level="4"] { background: var(--success); }
}

.per-habit-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.per-habit-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.per-habit-name { font-weight: 500; }
.per-habit-num { color: var(--text-muted); font-size: 14px; }

/* SETTINGS */
.setting-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 16px;
}
.setting-label { font-weight: 500; }
.setting-sub { font-size: 13px; margin-top: 2px; }

input[type="time"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 14px;
  color: var(--text);
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 26px;
  transition: 0.2s;
}
.slider::before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 2px;
  top: 2px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .slider {
  background: var(--success);
  border-color: var(--success);
}
.switch input:checked + .slider::before { transform: translateX(20px); }

.footer-note {
  text-align: center;
  margin-top: 32px;
  padding-bottom: 20px;
}

/* BUTTONS */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn.primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.btn.ghost { background: transparent; }
.btn.danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

/* FAB */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(80px + var(--safe-bottom) + 12px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-size: 28px;
  font-weight: 300;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,0.18);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* BOTTOM NAV */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 6px 0 calc(6px + var(--safe-bottom));
  z-index: 15;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 4px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 500;
}
.nav-btn.active { color: var(--accent); }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-card {
  background: var(--surface);
  width: 100%;
  max-width: 600px;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h3 { margin: 0; font-size: 18px; font-weight: 600; }

.field {
  display: block;
  margin-bottom: 16px;
}
.field > span {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input[type="text"], .field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
}

.icon-picker, .color-picker {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}
.icon-option, .color-option {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
}
.icon-option.selected { border-color: var(--accent); }
.color-option.selected { border-color: var(--text); transform: scale(1.05); }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: calc(100px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
