/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Dark palette (default) */
:root {
  --bg:          #0f0f1a;
  --bg-card:     #1a1a2e;
  --bg-card2:    #222240;
  --border:      rgba(255,255,255,0.07);
  --text:        #f0f0f5;
  --text-muted:  #8888aa;
  --accent:      #6c63ff;
  --danger:      #ff4757;
  --shadow:      rgba(0,0,0,0.3);
  --topbar-h:    52px;
  --tabbar-h:    72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Light palette — applied when OS is light AND no manual override */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:         #f2f2f7;
    --bg-card:    #ffffff;
    --bg-card2:   #e8e8f0;
    --border:     rgba(0,0,0,0.08);
    --text:       #1a1a2e;
    --text-muted: #666688;
    --shadow:     rgba(0,0,0,0.08);
  }
}

/* Manual overrides */
:root[data-theme="light"] {
  --bg:         #f2f2f7;
  --bg-card:    #ffffff;
  --bg-card2:   #e8e8f0;
  --border:     rgba(0,0,0,0.08);
  --text:       #1a1a2e;
  --text-muted: #666688;
  --shadow:     rgba(0,0,0,0.08);
}
:root[data-theme="dark"] {
  --bg:          #0f0f1a;
  --bg-card:     #1a1a2e;
  --bg-card2:    #222240;
  --border:      rgba(255,255,255,0.07);
  --text:        #f0f0f5;
  --text-muted:  #8888aa;
  --shadow:      rgba(0,0,0,0.3);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { background: none; border: none; cursor: pointer; font: inherit; color: inherit; }
svg { display: block; }

/* ── Top bar ──────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  padding-top: env(safe-area-inset-top, 0px);
}

.topbar-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

/* ── Theme toggle ─────────────────────────────────────────────────────────── */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.theme-toggle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: color 0.2s, background 0.2s;
}
.theme-toggle:active { background: var(--bg-card2); }
.theme-toggle svg { width: 18px; height: 18px; }
/* show correct icon */
.icon-sun  { display: none; }
.icon-moon { display: block; }
:root[data-theme="light"]  .icon-sun  { display: block; }
:root[data-theme="light"]  .icon-moon { display: none; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .icon-sun  { display: block; }
  :root:not([data-theme="dark"]) .icon-moon { display: none; }
}

.topbar-user {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Content area ─────────────────────────────────────────────────────────── */
.content {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Panels ───────────────────────────────────────────────────────────────── */
.panel { display: none; padding: 12px 0 24px; }
.panel.active { display: block; }

/* ── Day groups (Week / Up Next) ──────────────────────────────────────────── */
.day-group { padding: 0 16px 4px; margin-bottom: 4px; }

.day-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 14px 0 6px;
}
.day-name   { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.day-date   { font-size: 13px; color: var(--text-muted); }

/* ── Event cards ──────────────────────────────────────────────────────────── */
.event-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  margin-bottom: 6px;
  box-shadow: 0 1px 3px var(--shadow);
}

.event-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Timed reminder cards */
.reminder-card {
  border-style: dashed;
  border-color: rgba(108,99,255,0.35);
}
:root[data-theme="light"] .reminder-card { border-color: rgba(108,99,255,0.45); }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .reminder-card { border-color: rgba(108,99,255,0.45); }
}

.reminder-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--accent);
  opacity: 0.85;
}
.reminder-icon svg { width: 20px; height: 20px; }


.event-body { flex: 1; min-width: 0; }
.event-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-meta  { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

/* Expandable event card */
.event-card[data-expandable] { cursor: pointer; }
.event-card[data-expandable]:active { opacity: 0.75; }

/* Linked reminders nested under an event card */
.linked-reminders {
  margin: -2px 0 6px 18px;
  border-left: 2px solid var(--border);
  padding-left: 10px;
}
.linked-reminder-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 4px;
  font-size: 13px;
  color: var(--text-muted);
  transition: opacity 0.3s;
}
.linked-rem-icon { width: 14px; height: 14px; flex-shrink: 0; color: var(--accent); opacity: 0.7; }
.linked-rem-icon svg { width: 14px; height: 14px; }
.linked-rem-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linked-rem-time { font-size: 12px; font-weight: 500; flex-shrink: 0; }
.linked-rem-check {
  background: none; border: none; cursor: pointer; padding: 2px;
  color: var(--text-muted); opacity: 0.5; flex-shrink: 0;
}
.linked-rem-check svg { width: 16px; height: 16px; display: block; }

.event-time {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.event-time.badge {
  background: var(--bg-card2);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
}

.empty-day {
  font-size: 13px;
  color: var(--text-muted);
  padding: 6px 0 10px;
}

/* ── Task cards ───────────────────────────────────────────────────────────── */
.task-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 6px;
  box-shadow: 0 1px 3px var(--shadow);
}
.task-card.overdue { border-color: rgba(255,71,87,0.3); background: rgba(255,71,87,0.07); }
.task-card.timed  { border-style: dashed; border-color: rgba(108,99,255,0.35); }

.task-clock { width: 11px; height: 11px; display: inline; vertical-align: middle; margin-right: 2px; color: var(--accent); }

.task-check {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: color 0.15s;
}
.task-check svg { width: 22px; height: 22px; }
.task-check:active { color: var(--accent); }

.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 14px; font-weight: 500; display: block; }
.task-due   { font-size: 12px; color: var(--text-muted); margin-top: 1px; display: block; }
.task-card.overdue .task-due { color: var(--danger); }

/* Inline task (in week view) */
.task-card > .task-title { font-size: 14px; font-weight: 500; flex: 1; }
.task-card > .task-list  { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }

/* ── Tasks panel ──────────────────────────────────────────────────────────── */
.tasks-group { padding: 0 16px 8px; }
.tasks-list-header {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  padding: 14px 0 6px;
}

/* ── Calendar panel ───────────────────────────────────────────────────────── */
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
}
.cal-month-label { font-size: 16px; font-weight: 700; }
.cal-arrow {
  font-size: 24px;
  line-height: 1;
  padding: 4px 10px;
  color: var(--text-muted);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  padding: 0 12px;
}

.cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 4px 0;
  text-transform: uppercase;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  gap: 2px;
  cursor: pointer;
  position: relative;
  padding-bottom: 4px;
}
.cal-day.other { color: var(--text-muted); opacity: 0.4; }
.cal-day.today {
  background: var(--accent);
  font-weight: 700;
  color: #fff;
}
.cal-day:not(.today):active { background: var(--bg-card2); }

.cal-dots {
  display: flex;
  gap: 2px;
  position: absolute;
  bottom: 3px;
}
.cal-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  display: inline-block;
}

.cal-detail {
  padding: 12px 16px 0;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.cal-detail-date {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 10px 0 6px;
}

/* ── Parse panel ──────────────────────────────────────────────────────────── */
.parse-intro {
  padding: 12px 16px 16px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.upload-zone {
  margin: 0 16px 20px;
  border: 1.5px dashed rgba(108,99,255,0.4);
  border-radius: 16px;
  background: rgba(108,99,255,0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 36px 16px;
  position: relative;
  cursor: pointer;
}
.upload-zone:active { background: rgba(108,99,255,0.12); }
.upload-icon { width: 40px; height: 40px; color: var(--accent); margin-bottom: 4px; }
.upload-label { font-size: 15px; font-weight: 600; color: var(--accent); }
.upload-hint  { font-size: 12px; color: var(--text-muted); }
.upload-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.parse-results { padding: 0 16px 24px; }
.parse-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 10px;
}
.parse-results-header span { font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.btn-text { font-size: 14px; font-weight: 600; color: var(--accent); }
.btn-text:active { opacity: 0.7; }

.parsed-event-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  margin-bottom: 6px;
}

.parsed-event-check {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: transparent;
  transition: all 0.15s;
}
.parsed-event-check.checked {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.parsed-event-check svg { width: 14px; height: 14px; }

.parsed-event-body { flex: 1; min-width: 0; }
.parsed-event-title { font-size: 14px; font-weight: 500; }
.parsed-event-meta  { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.btn-primary {
  display: block;
  width: 100%;
  margin-top: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 14px;
  border-radius: 12px;
  text-align: center;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.8; }

/* ── Tab bar ──────────────────────────────────────────────────────────────── */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  padding: 6px 4px 0;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tab.active { color: var(--accent); }

.tab-icon { width: 22px; height: 22px; }
.tab-label { font-size: 10px; font-weight: 600; }

.tab-admin { color: rgba(136,136,170,0.5); }
.tab-admin.active { color: var(--accent); }

/* ── Event expand drawer ──────────────────────────────────────────────────── */
.drawer-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
}
.drawer-scrim.open { display: block; }

.event-drawer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-card);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding: 0 20px 40px;
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
}
.event-drawer.open { transform: translateY(0); }

.event-drawer-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 20px;
}
.event-drawer-title { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.event-drawer-meta  { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.event-drawer-actions { display: flex; flex-direction: column; gap: 8px; }

.drawer-action {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card2);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 15px;
  font-weight: 500;
  color: var(--accent);
  width: 100%;
  text-align: left;
}
.drawer-action svg { width: 20px; height: 20px; flex-shrink: 0; }
.drawer-action:active { opacity: 0.7; }

.reminder-form { margin-top: 16px; }
.reminder-form-label { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.4px; }
.reminder-time-options { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.time-chip {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  background: var(--bg-card2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.time-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.time-chip:active { opacity: 0.8; }

.reminder-list-row { display: flex; align-items: center; justify-content: space-between; }
.reminder-list-label { font-size: 14px; font-weight: 500; }
.reminder-list-select {
  font-size: 14px;
  background: var(--bg-card2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: inherit;
}

/* ── Settings panel ───────────────────────────────────────────────────────── */
.settings-section {
  padding: 16px 16px 8px;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: none; }
.settings-section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
}
.settings-hint {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 14px;
}

/* Calendar / list mapping */
.cal-map-group { margin-bottom: 12px; }
.cal-map-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.cal-map-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.cal-map-row:last-child { border-bottom: none; }
.cal-map-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  min-width: 0;
}
.cal-map-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.reminder-dot { background: var(--text-muted); }
.cal-map-chips { display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end; }

/* Person / shared chips */
.chip {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 12px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--bg-card2);
  cursor: pointer;
  transition: all 0.15s;
}
.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.chip:active { opacity: 0.7; }
