:root, [data-theme="light"] {
  --bg: #fafafa;
  --fg: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --row: #ffffff;
  --card: #ffffff;
  --input-bg: #ffffff;

  --free: #16a34a;
  --busy: #dc2626;
  --tentative: #d97706;
  --unmarked: #d1d5db;

  --highlight-bg: #ecfdf5;
  --highlight-border: #34d399;

  --user-a: #2563eb;
  --user-b: #db2777;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
  --bg: #0b1220;
  --fg: #e5e7eb;
  --muted: #9ca3af;
  --border: #1f2937;
  --row: #111827;
  --card: #111827;
  --input-bg: #0f172a;

  --free: #22c55e;
  --busy: #ef4444;
  --tentative: #f59e0b;
  --unmarked: #374151;

  --highlight-bg: #064e3b;
  --highlight-border: #10b981;

  --user-a: #60a5fa;
  --user-b: #f472b6;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] button { background: var(--card); color: var(--fg); }
[data-theme="dark"] button:hover { background: #1f2937; }
[data-theme="dark"] button.primary { background: var(--user-a); border-color: var(--user-a); color: #fff; }
[data-theme="dark"] input, [data-theme="dark"] textarea, [data-theme="dark"] select {
  background: var(--input-bg); color: var(--fg); border-color: var(--border);
}
[data-theme="dark"] .day.weekend { background: #0f172a; }
[data-theme="dark"] .day.holiday { background: #422006; }
[data-theme="dark"] .banner { background: #1e3a8a; border-color: #3b82f6; color: #dbeafe; }
[data-theme="dark"] .banner.pulse { background: #064e3b; border-color: #10b981; color: #ecfdf5; }
[data-theme="dark"] .chip { background: #1e1b4b; color: #c7d2fe; }
[data-theme="dark"] .candidate.fits { background: #052e16; }
[data-theme="dark"] .candidate.partial-conflict { background: #3f1d04; }
[data-theme="dark"] .candidate.no-overlap { background: #450a0a; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
button:hover { background: #f3f4f6; }
button.primary {
  background: #111827;
  color: #fff;
  border-color: #111827;
}
button.primary:hover { background: #1f2937; }
button.danger { color: var(--busy); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="text"], input[type="password"], input[type="number"], input[type="date"], textarea, select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
}

/* ---------- layout ---------- */

.app {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

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

header.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

header.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

header.topbar .me { color: var(--muted); font-size: 13px; }

/* ---------- entry screens ---------- */

.entry {
  max-width: 360px;
  margin: 80px auto;
  background: #fff;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.entry h2 { margin: 0 0 16px 0; }
.entry .row { margin: 10px 0; }
.entry .row label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.entry .error {
  color: var(--busy);
  font-size: 13px;
  margin-top: 8px;
}
.entry input[type="password"], .entry input[type="text"] { width: 100%; }

.identity-picker { display: flex; gap: 12px; flex-wrap: wrap; }
.identity-picker button {
  flex: 1 1 120px;
  padding: 14px;
  font-weight: 600;
}

/* ---------- calendar ---------- */

.calendar {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 12px;
  user-select: none;
}

.cal-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.cal-controls .grow { flex: 1; }

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

.cal-grid .head {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.05em;
  padding: 4px 0;
}

.day {
  background: var(--row);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 56px;
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  position: relative;
}

.day.empty { background: transparent; border: none; cursor: default; }

.day.past { opacity: 0.45; cursor: not-allowed; }

.day .num {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.day .num .d {
  color: var(--fg);
  font-size: 13px;
}
.day .num .m {
  color: var(--muted);
  font-weight: 500;
}
.day .num .wk {
  color: var(--muted);
  font-weight: 400;
  font-size: 11px;
  margin-left: 2px;
}

.day.today .num {
  color: var(--user-a);
}

.day.weekend { background: #f9fafb; }

.day .marks {
  display: flex;
  gap: 3px;
  margin-top: 4px;
}

.mark {
  flex: 1;
  height: 8px;
  border-radius: 3px;
  background: var(--unmarked);
}
.mark.free { background: var(--free); }
.mark.busy { background: var(--busy); }
.mark.tentative { background: var(--tentative); }
.mark.stale {
  outline: 1px dashed #6b7280;
  outline-offset: 1px;
}

.day.mutual-free {
  background: var(--highlight-bg);
  border-color: var(--highlight-border);
}

.day.in-window {
  outline: 2px solid var(--highlight-border);
  outline-offset: -2px;
}

.day.drag-selected {
  outline: 2px dashed #6366f1;
  outline-offset: -2px;
}

.day.holiday {
  background: #fef3c7;          /* soft amber */
}
.day.holiday.mutual-free {
  /* still keep mutual-free visible if both happen */
  background: linear-gradient(to bottom, #fef3c7 0%, #fef3c7 60%, var(--highlight-bg) 60%);
}
.day .hbadge {
  color: #b45309;
  font-size: 10px;
  margin-left: 2px;
}

/* ---------- modal ---------- */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(17,24,39,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: #fff; border-radius: 10px; padding: 16px;
  width: 100%; max-width: 480px; max-height: 80vh; overflow: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; }
.modal-header button { font-size: 20px; line-height: 1; padding: 2px 8px; }

.tpl-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 4px; border-bottom: 1px solid var(--border);
}
.tpl-row:last-child { border-bottom: none; }
.tpl-row .title { font-weight: 500; }

.chip {
  display: inline-block;
  background: #e0e7ff;
  color: #3730a3;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
}
ul.agenda {
  margin: 6px 0 0 0;
  padding-left: 18px;
  font-size: 13px;
  color: #374151;
}
ul.agenda li { margin: 2px 0; }

/* past meeting ribbon on calendar */
.day.meeting {
  border-top: 3px solid #6366f1;
}
[data-theme="dark"] .day.meeting { border-top-color: #818cf8; }

/* follow-up rows */
.fu-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 0; border-bottom: 1px dashed var(--border);
  font-size: 13px;
}
.fu-row:last-child { border-bottom: none; }
.fu-row .text { flex: 1; }
.fu-row .text.done { text-decoration: line-through; color: var(--muted); }
.fu-row .del {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; padding: 0 4px;
}
.fu-row .del:hover { color: var(--busy); }

/* ---------- legend ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.legend .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}

/* ---------- sidebar / proposals ---------- */

aside.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.card h3 { margin: 0 0 8px 0; font-size: 14px; }
.card .muted { color: var(--muted); font-size: 13px; }

.proposal {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  background: #fff;
  cursor: pointer;
}
.proposal.active {
  border-color: #111827;
  box-shadow: 0 0 0 2px rgba(17, 24, 39, 0.06);
}
.proposal .title { font-weight: 600; }
.proposal .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

.candidate {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  margin-top: 6px;
  background: #fff;
}
.candidate .range { font-weight: 500; }
.candidate.fits { border-color: var(--free); background: #f0fdf4; }
.candidate.partial-conflict { border-color: var(--tentative); background: #fffbeb; }
.candidate.no-overlap { border-color: var(--busy); background: #fef2f2; }
.candidate .pill {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 6px;
}
.candidate.fits .pill { background: var(--free); color: #fff; }
.candidate.partial-conflict .pill { background: var(--tentative); color: #fff; }
.candidate.no-overlap .pill { background: var(--busy); color: #fff; }

.candidate .actions { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.candidate .conflicts { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ---------- proposal form ---------- */

.form .row { margin-bottom: 8px; }
.form label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.form input, .form textarea, .form select { width: 100%; }

.candidate-builder { display: flex; flex-direction: column; gap: 4px; }
.candidate-builder .cand-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
  align-items: center;
}

.toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ---------- banner ---------- */

.banner {
  background: #eff6ff;
  border: 1px solid #93c5fd;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 14px;
}
.banner.pulse {
  background: #f0fdf4;
  border-color: #86efac;
}
.banner button.muted {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

/* ---------- status palette key ---------- */

.statuskey {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  font-size: 11px;
}
.statuskey .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
