:root {
  /* Warm, personal palette: terracotta + cream, instead of the previous
     sage/minimal one — chosen for a friendlier, more human feel. */
  --bg: #fdf6ee;
  --surface: #fffcf8;
  --surface-muted: #f6e9db;
  --text: #3c2e24;
  --text-muted: #8a7566;
  --accent: #c1694f;
  --accent-dark: #9c4f39;
  --accent-soft: #f3ddd0;
  --border: #ecddc9;
  --danger: #b23b3b;
  --danger-soft: #f8e3e0;
  --success: #6f8f4e;
  --success-soft: #eaf0dd;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(60, 46, 36, 0.05), 0 4px 16px rgba(60, 46, 36, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #211711;
    --surface: #2b1f17;
    --surface-muted: #35271c;
    --text: #f3e6d8;
    --text-muted: #bda590;
    --accent: #e08a68;
    --accent-dark: #f0aa8a;
    --accent-soft: #4a3122;
    --border: #4a382c;
    --danger: #e08a7c;
    --danger-soft: #3d2620;
    --success: #a8c084;
    --success-soft: #33402a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Charter", serif;
  font-size: 16px;
  line-height: 1.55;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h1, h2, h3, h4 {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.5em;
  letter-spacing: -0.01em;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

p { margin: 0 0 1em; color: var(--text); }
a { color: var(--accent-dark); }

.muted { color: var(--text-muted); }

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.page.centered {
  max-width: 420px;
  padding-top: 12vh;
}

/* --- Nav --- */
.app-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-nav-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.brand {
  font-family: "Iowan Old Style", Georgia, serif;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--accent-dark);
  text-decoration: none;
  white-space: nowrap;
}
.nav-links {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
}
.nav-links a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 8px 10px;
  border-radius: 999px;
}
.nav-links a:hover { background: var(--surface-muted); color: var(--text); }
.nav-links a.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.nav-user { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.nav-user-name { font-size: 0.85rem; color: var(--text-muted); }

/* --- Buttons & forms --- */
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease;
}
.btn:hover { background: var(--accent-dark); }
.btn.btn-secondary {
  background: transparent;
  color: var(--accent-dark);
  border: 1px solid var(--border);
}
.btn.btn-secondary:hover { background: var(--surface-muted); }
.btn.btn-danger { background: var(--danger); }
.btn.btn-danger:hover { background: #8f2e2e; }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }

.link-button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.inline-form { display: inline; }

label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin: 18px 0 6px;
  color: var(--text);
}
label.first { margin-top: 0; }
.field-hint { font-size: 0.8rem; color: var(--text-muted); margin: -2px 0 6px; }

input[type=text], input[type=email], input[type=password], input[type=date],
textarea, select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-actions { margin-top: 26px; display: flex; gap: 10px; align-items: center; }

fieldset { border: none; padding: 0; margin: 0; }

.scale-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.scale-option {
  flex: 1;
  text-align: center;
}
.scale-option input { position: absolute; opacity: 0; pointer-events: none; }
.scale-option label {
  display: block;
  margin: 0;
  padding: 10px 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.scale-option input:checked + label {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 700;
}

/* --- Cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-row { display: flex; gap: 20px; flex-wrap: wrap; }
.card-row > .card { flex: 1; min-width: 240px; }

.prompt-box {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 14px 16px;
  font-style: italic;
  color: var(--accent-dark);
  margin: 4px 0 18px;
  font-size: 0.92rem;
}

/* --- Flash messages --- */
.flash {
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.9rem;
}
.flash-success { background: var(--success-soft); color: var(--success); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

/* --- Dashboard visuals --- */
.stat-number { font-size: 2.4rem; font-weight: 700; color: var(--accent-dark); line-height: 1; }
.stat-label { color: var(--text-muted); font-size: 0.85rem; margin-top: 6px; }

.mood-chart { width: 100%; height: auto; }
.chart-baseline { stroke: var(--border); stroke-width: 1; }
.chart-area { fill: var(--accent-soft); opacity: 0.7; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart-dot { fill: var(--accent-dark); }
.chart-axis-label { fill: var(--text-muted); font-size: 9px; }
.empty-chart { color: var(--text-muted); font-size: 0.88rem; padding: 30px 0; text-align: center; }

.streak-row { display: flex; gap: 6px; }
.streak-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  display: inline-block;
}
.streak-dot-on { background: var(--accent); border-color: var(--accent-dark); }

/* --- Entry list / history --- */
.entry-item {
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
}
.entry-item:last-child { border-bottom: none; }
.entry-meta { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge.badge-status-active { background: var(--accent-soft); color: var(--accent-dark); }
.badge.badge-status-achieved { background: var(--success-soft); color: var(--success); }
.badge.badge-status-paused { background: var(--surface-muted); color: var(--text-muted); }

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.filter-bar a {
  text-decoration: none;
  font-size: 0.82rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.filter-bar a.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }

.credentials-box {
  background: var(--accent-soft);
  border: 1px dashed var(--accent);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  margin: 12px 0;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
}

/* --- Weekly habit log --- */
/* One accent per day of the week, tuned to sit alongside the warm
   terracotta palette rather than clash with it. */
.day-grid,
.habit-review {
  --day1: #c1694f; /* Mon — terracotta */
  --day2: #b6894f; /* Tue — ochre */
  --day3: #6f8f4e; /* Wed — olive */
  --day4: #4f8f86; /* Thu — teal */
  --day5: #4f6f8f; /* Fri — dusty blue */
  --day6: #7a5a94; /* Sat — plum */
  --day7: #a24f70; /* Sun — rose */
}
@media (prefers-color-scheme: dark) {
  .day-grid,
  .habit-review {
    --day1: #e08a68;
    --day2: #d4a86e;
    --day3: #a8c084;
    --day4: #7bbdb3;
    --day5: #7ea3cc;
    --day6: #b090cf;
    --day7: #d381a0;
  }
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.day-card {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}
.day-card .day-head {
  margin: 0 -14px 8px;
  padding: 9px 14px;
  background: var(--accent);
}
.day-card h3 { margin: 0; font-size: 0.95rem; color: #fff; font-weight: 700; }
.day-card:nth-of-type(1) .day-head { background: var(--day1); }
.day-card:nth-of-type(2) .day-head { background: var(--day2); }
.day-card:nth-of-type(3) .day-head { background: var(--day3); }
.day-card:nth-of-type(4) .day-head { background: var(--day4); }
.day-card:nth-of-type(5) .day-head { background: var(--day5); }
.day-card:nth-of-type(6) .day-head { background: var(--day6); }
.day-card:nth-of-type(7) .day-head { background: var(--day7); }

@media (max-width: 560px) {
  .day-grid { grid-template-columns: 1fr; }
}

.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 10px;
}
.metric-row .lbl { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 500; color: var(--text); }
.metric-row input[type="time"],
.metric-row input[type="number"] {
  width: auto;
  padding: 5px 8px;
  font-size: 0.85rem;
}
.qty { display: flex; align-items: center; gap: 6px; }
.qty input[type="number"] { width: 58px; text-align: right; }
.qty .unit { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

.habit-review { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.habit-review-day {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
}
.habit-review-day:nth-of-type(1) { border-left-color: var(--day1); }
.habit-review-day:nth-of-type(2) { border-left-color: var(--day2); }
.habit-review-day:nth-of-type(3) { border-left-color: var(--day3); }
.habit-review-day:nth-of-type(4) { border-left-color: var(--day4); }
.habit-review-day:nth-of-type(5) { border-left-color: var(--day5); }
.habit-review-day:nth-of-type(6) { border-left-color: var(--day6); }
.habit-review-day:nth-of-type(7) { border-left-color: var(--day7); }
.habit-review-day-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.habit-review-metrics { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.85rem; }

@media (max-width: 640px) {
  .app-nav-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
  .nav-user { align-self: flex-end; }
}
