:root {
  --sage: #5F7A5A;
  --sage-light: #E4EBE1;
  --beige: #F4EEE3;
  --terracotta: #C77B58;
  --terracotta-light: #F3DCCF;
  --ink: #2E2A24;
  --muted: #8A8172;
  --card-bg: #FFFFFF;
  --danger: #C0554A;
  --ok: #5F8F5B;
  --warn: #C99A3E;
  --radius: 14px;
  --nav-height: 64px;
  --header-height: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--beige);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.config-banner {
  background: var(--warn);
  color: #fff;
  font-size: 12.5px;
  padding: 8px 14px;
  text-align: center;
}
.config-banner code { background: rgba(0,0,0,.15); padding: 1px 5px; border-radius: 4px; }
.hidden { display: none !important; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--sage);
  color: #fff;
  padding: 10px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.header-title { display: flex; align-items: center; gap: 10px; }
.header-emoji { font-size: 28px; }
.app-header h1 { margin: 0; font-size: 17px; font-weight: 700; }
.countdown { margin: 2px 0 0; font-size: 12.5px; color: var(--sage-light); }

main#views {
  padding: 14px 14px calc(var(--nav-height) + 20px);
  max-width: 560px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; animation: fadein .15s ease-out; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none; } }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card h2 { margin: 0 0 8px; font-size: 15.5px; color: var(--sage); }
.card p { margin: 0 0 8px; font-size: 14px; line-height: 1.5; }
.card details { margin-top: 8px; border-top: 1px solid #eee; padding-top: 8px; }
.card summary { font-weight: 600; font-size: 14px; color: var(--terracotta); cursor: pointer; }
.card details p, .card details ul { font-size: 13.5px; margin-top: 6px; }
.card details ul { padding-left: 18px; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.stat-value { font-size: 24px; font-weight: 800; color: var(--terracotta); }
.stat-label { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.schedule-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.schedule-table td { padding: 6px 4px; border-bottom: 1px solid #f0ece2; vertical-align: top; }
.schedule-table td:first-child { color: var(--terracotta); font-weight: 700; white-space: nowrap; width: 30%; }

.view-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.view-toolbar input[type="search"] {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #ddd4c4;
  font-size: 14px;
  background: #fff;
}
.btn-primary {
  background: var(--sage);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}
.btn-primary:active { opacity: .85; }

.filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 6px;
}
.chip {
  border: 1px solid #ddd4c4;
  background: #fff;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  white-space: nowrap;
  color: var(--ink);
}
.chip.active { background: var(--sage); color: #fff; border-color: var(--sage); }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 700; font-size: 14.5px; margin-bottom: 2px; }
.list-item-sub { font-size: 12.5px; color: var(--muted); }
.list-item-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.tag {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.tag-green { background: #E4EFE1; color: var(--ok); }
.tag-yellow { background: #FBF0D8; color: var(--warn); }
.tag-red { background: #F6DEDA; color: var(--danger); }
.tag-gray { background: #ECE7DC; color: var(--muted); }
.tag-blue { background: #DCE7EF; color: #4A7699; }
.tag-purple { background: #E9E1F0; color: #7A5A9E; }
.tag-pink { background: #F5E1E9; color: #B15D82; }
.tag-orange { background: #F6E4D3; color: var(--terracotta); }

.list-item-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.icon-btn {
  border: none;
  background: none;
  font-size: 17px;
  padding: 4px;
  color: var(--muted);
}
.checkbox-btn { font-size: 22px; border: none; background: none; padding: 0; line-height: 1; }

.total-card { }
.total-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14.5px; }
.total-row:not(:last-child) { border-bottom: 1px solid #f0ece2; }

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: #fff;
  border-top: 1px solid #e8e0d0;
  display: flex;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10.5px;
  color: var(--muted);
  font-weight: 600;
}
.nav-btn span { font-size: 19px; }
.nav-btn.active { color: var(--sage); }

.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet.hidden { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.sheet-content {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 10px 10px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
.sheet-item {
  border: none;
  background: none;
  text-align: left;
  padding: 14px 12px;
  font-size: 15px;
  border-bottom: 1px solid #f0ece2;
}
.sheet-item:last-child { border-bottom: none; color: var(--muted); }

/* Modal (add/edit forms) */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; z-index: 50;
}
.modal-box {
  background: #fff;
  width: 100%;
  border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
}
.modal-box h3 { margin: 0 0 12px; color: var(--sage); }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #ddd4c4;
  font-size: 14px;
  font-family: inherit;
  background: #fdfbf7;
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.btn-secondary {
  flex: 1;
  background: #ECE7DC;
  color: var(--ink);
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-weight: 600;
}
.btn-danger {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 13px;
  padding: 10px;
}
.modal-actions .btn-primary { flex: 2; padding: 12px; }

.empty-state { text-align: center; color: var(--muted); font-size: 13.5px; padding: 30px 10px; }
