:root {
  --bg: #fcfcfc;
  --surface: #ffffff;
  --text: #353535;
  --text-muted: #6b6b6b;
  --border: #e3e3e3;
  --accent: #43aa8b;
  --accent-text: #ffffff;
  --success-bg: #e3f6e8;
  --success-text: #1e7a34;
  --error-bg: #fdeaea;
  --error-text: #b00020;
  --badge-bg: #eeeeee;
  --badge-text: #444444;
  --locked-bg: #f0f1f4;
  --locked-text: #888888;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --star-color: #fdca02;
}

[data-theme='dark'] {
  --bg: #1e1e1e;
  --surface: #262626;
  --text: #fcfcfc;
  --text-muted: #a3a3a3;
  --border: #3d3d3d;
  --accent: #55c2a0;
  --accent-text: #ffffff;
  --success-bg: #123a24;
  --success-text: #4ade80;
  --error-bg: #3a1620;
  --error-text: #f87171;
  --badge-bg: #333333;
  --badge-text: #d0d0d0;
  --locked-bg: #2b2b2b;
  --locked-text: #8a8a8a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  --star-color: #fdca02;
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

a { color: inherit; }

header.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--accent);
  color: var(--accent-text);
  padding: 1rem 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
header.app-header h1 { font-size: 1.1rem; margin: 0; }
header.app-header a { color: var(--accent-text); font-size: 0.85rem; text-decoration: underline; }
header.app-header .header-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }

main.app-main { max-width: 900px; margin: 2rem auto; padding: 0 1.5rem 3rem; }
main.app-main.narrow { max-width: 480px; }
main.app-main.wide { max-width: 1100px; }

.btn, button, header.app-header button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1.1rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}
.btn--ghost, button.btn--ghost {
  background: transparent;
  color: var(--accent-text);
  border: 1px solid var(--accent-text);
}
.btn--secondary { background: var(--badge-bg); color: var(--text); }
.btn--sm { padding: 0.3rem 0.7rem; font-size: 0.78rem; }

.card {
  background: var(--surface);
  padding: 1.25rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card h2 { font-size: 1rem; margin: 0 0 1rem; }

.banner { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1.25rem; font-size: 0.9rem; }
.banner--success { background: var(--success-bg); color: var(--success-text); }
.banner--error { background: var(--error-bg); color: var(--error-text); }
.banner--info { background: var(--badge-bg); color: var(--text); }

.badge { display: inline-block; font-size: 0.72rem; padding: 0.15rem 0.55rem; border-radius: 999px; background: var(--badge-bg); color: var(--badge-text); }
.badge--locked { background: var(--locked-bg); color: var(--locked-text); }
.badge--open { background: #dbeafe; color: #1d4ed8; }
[data-theme='dark'] .badge--open { background: #1e3a5f; color: #93c5fd; }
.badge--completed { background: var(--success-bg); color: var(--success-text); }

label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 1rem; color: var(--text); }
label > span, label .label-text { display: block; font-weight: 600; margin-bottom: 0.3rem; }
input, textarea, select {
  width: 100%;
  padding: 0.55rem;
  margin-top: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
}
textarea { resize: vertical; }
.hint { font-size: 0.78rem; color: var(--text-muted); margin: 0.3rem 0 0.9rem; }
fieldset { border: none; padding: 0; margin: 0 0 1.1rem; }
legend { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.5rem; padding: 0; }

.form-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.form-row > label { flex: 1; min-width: 180px; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: left; padding: 0.6rem 0.75rem; font-size: 0.83rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--bg); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
tr:last-child td { border-bottom: none; }
td.empty { color: var(--text-muted); font-style: italic; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.9rem; margin-bottom: 1.25rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; box-shadow: var(--shadow); }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-card .stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin-top: 0.2rem; }

/* Progress bar */
.progress-track { background: var(--badge-bg); border-radius: 999px; height: 10px; overflow: hidden; }
.progress-fill { background: var(--accent); height: 100%; border-radius: 999px; transition: width 0.2s ease; }

/* Wizard step indicator */
.step-indicator { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.25rem; }
.step-pill { padding: 0.35rem 0.8rem; border-radius: 999px; font-size: 0.78rem; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); }
.step-pill--done { background: var(--success-bg); color: var(--success-text); border-color: transparent; }
.step-pill--current { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }

/* Timeline */
.timeline { border-left: 2px solid var(--border); margin-left: 0.6rem; padding-left: 1.2rem; }
.timeline-item { position: relative; padding-bottom: 1.4rem; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
  content: '';
  position: absolute;
  left: -1.55rem;
  top: 0.15rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.timeline-item.is-completed::before { background: var(--success-text); }
.timeline-item.is-open::before { background: var(--accent); }
.timeline-item .timeline-title { font-weight: 600; font-size: 0.9rem; }
.timeline-item .timeline-meta { font-size: 0.78rem; color: var(--text-muted); }

/* Calendar strip */
.calendar-strip { display: flex; gap: 0.6rem; overflow-x: auto; padding-bottom: 0.3rem; }
.calendar-day { flex: 0 0 auto; min-width: 68px; text-align: center; border: 1px solid var(--border); border-radius: 8px; padding: 0.55rem 0.4rem; background: var(--surface); }
.calendar-day .cal-dow { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; }
.calendar-day .cal-num { font-size: 1.1rem; font-weight: 700; margin: 0.15rem 0; }
.calendar-day .cal-day-label { font-size: 0.68rem; color: var(--text-muted); }
.calendar-day.is-today { border-color: var(--accent); border-width: 2px; }
.calendar-day.is-completed { background: var(--success-bg); }
.calendar-day.is-locked { opacity: 0.55; }

/* Star rating: radios in reverse DOM order + row-reverse flex so the
   checked-input-to-following-label sibling selector lights up all stars
   at-or-below the chosen value while reading left-to-right. */
.star-rating { display: inline-flex; flex-direction: row-reverse; gap: 0.2rem; font-size: 1.6rem; }
.star-rating input { display: none; }
.star-rating label { display: inline-block; margin: 0; cursor: pointer; }
.star-rating .star { color: var(--border); }
.star-rating input:checked ~ label .star { color: var(--star-color); }
.star-rating label:hover .star,
.star-rating label:hover ~ label .star { color: var(--star-color); }

.theme-toggle {
  background: transparent;
  border: 1px solid var(--accent-text);
  color: var(--accent-text);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
}

@media (max-width: 640px) {
  main.app-main { margin: 1rem auto; padding: 0 1rem 2rem; }
  header.app-header { padding: 0.85rem 1rem; }
  .form-row { flex-direction: column; }
}
