:root {
  color-scheme: dark;
  --bg: #0f172a;
  --bg-soft: #16213b;
  --card: #1a2540;
  --border: #2a3856;
  --text: #e6ecff;
  --text-dim: #93a1c4;
  --accent: #38bdf8;
  --accent-dim: #1d4e63;
  --good: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0) 14px calc(env(safe-area-inset-bottom, 0) + 24px);
}

h1, h2, h3 { margin: 0; }

header.topbar {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 16px 0 10px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar .title { font-size: 20px; font-weight: 700; }

.icon-btn {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.95); }

nav.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
nav.tabs button {
  flex: 1;
  padding: 9px 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
nav.tabs button.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
}
.date-nav .date-label {
  flex: 1;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
}
.date-nav .date-label .sub { display: block; font-size: 12px; color: var(--text-dim); font-weight: 400; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.card h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.sleep-row {
  display: flex;
  gap: 10px;
}
.field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field label { font-size: 12px; color: var(--text-dim); }
.hint { font-size: 12px; color: var(--text-dim); margin: 6px 0 0; }
input, select, textarea {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 15px;
  width: 100%;
  font-family: inherit;
}
input[type="time"] { color-scheme: dark; }

.btn {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn.subtle {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border);
}
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.full { width: 100%; margin-top: 10px; }
.btn.small { padding: 6px 9px; font-size: 12px; }

.now-btn-row { display: flex; align-items: flex-end; }

.event-item, .med-row, .dose-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.event-item:last-child, .med-row:last-child, .dose-row:last-child { border-bottom: none; }

.dose-time {
  width: 64px;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 14px;
}
.dose-time .orig {
  display: block;
  font-size: 10.5px;
  color: var(--warn);
  font-weight: 400;
  text-decoration: line-through;
}
.dose-main { flex: 1; min-width: 0; }
.dose-main .name { font-weight: 600; font-size: 15px; }
.dose-main .meta { font-size: 12px; color: var(--text-dim); }
.badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(251,191,36,0.15);
  color: var(--warn);
  margin-left: 6px;
}
.dose-actions { display: flex; gap: 6px; flex-shrink: 0; }

.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.status-dot.taken { background: var(--good); }
.status-dot.skipped { background: var(--bad); }

.dose-row.taken .dose-main .name { color: var(--text-dim); text-decoration: line-through; }

.empty { color: var(--text-dim); font-size: 14px; padding: 8px 0; text-align: center; }

.event-item .name { flex: 1; font-size: 14px; }
.event-item .time { font-size: 12px; color: var(--text-dim); width: 100px; }

.week-strip { display: flex; gap: 6px; margin-bottom: 14px; }
.week-day {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 2px;
  text-align: center;
  cursor: pointer;
}
.week-day.today { border-color: var(--accent); }
.week-day .dow { font-size: 11px; color: var(--text-dim); }
.week-day .dnum { font-size: 15px; font-weight: 700; margin: 2px 0; }
.week-day .dots { display: flex; justify-content: center; gap: 2px; flex-wrap: wrap; }
.week-day .dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--text-dim); }
.week-day .dots span.taken { background: var(--good); }
.week-day .dots span.skipped { background: var(--bad); }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(env(safe-area-inset-bottom, 0) + 18px);
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal h2 { font-size: 17px; margin-bottom: 14px; }
.modal .row { display: flex; gap: 10px; margin-bottom: 10px; }
.modal .row .field { flex: 1; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

.autocomplete-wrap { position: relative; }
.suggestions-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 190px;
  overflow-y: auto;
  z-index: 60;
}
.suggestion-item {
  padding: 9px 10px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover, .suggestion-item:active {
  background: var(--accent-dim);
  color: var(--accent);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  margin: 4px 0 10px;
  cursor: pointer;
}
.checkbox-row input { width: auto; }

.day-toggle-group { display: flex; gap: 6px; }
.day-toggle {
  flex: 1;
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.day-toggle.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

.form-radio-group { display: flex; gap: 6px; }
.form-radio-group label {
  flex: 1;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}
.form-radio-group input { display: none; }
.form-radio-group input:checked + span { color: var(--accent); }
.form-radio-group label:has(input:checked) { border-color: var(--accent); background: var(--accent-dim); }

.color-swatches { display: flex; gap: 8px; }
.color-swatches button {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.color-swatches button.active { border-color: var(--text); }
