/* ============================================================
 * Design language
 * ------------------------------------------------------------
 * Single source of truth for visual tokens. Component styles
 * must compose from these vars — no raw hex/px/rem literals.
 *
 * Color roles
 *   Primary   brand green. Selection, focus ring, success.
 *   Danger    red. Remove hover, preview-remove, errors.
 *   Surface   white / soft-gray fills for cards and hints.
 *   Fg / Bg   page foreground + background.
 *   Muted     secondary text. Subtle: tertiary / disabled.
 *
 * Radius scale
 *   xs   1px   grid cells
 *   sm   2px   datepicker days, legend swatches
 *   md   3px   controls (buttons, inputs, hints, errors)
 *   pill 10px  chips
 *
 * Typography scale (monospace only)
 *   2xs 0.70rem   axis labels, legend
 *   xs  0.75rem   hints, fine print
 *   sm  0.80rem   chips, panel titles
 *   base 0.85rem  body default, buttons, inputs
 *   md  0.90rem   h3, .muted
 *   lg  1.15rem   h2
 *   xl  1.60rem   h1
 *   display 2rem  landing title
 * ============================================================ */
:root {
  /* Neutrals */
  --color-fg: #1a1a1a;
  --color-bg: #fafafa;
  --color-muted: #666;
  --color-subtle: #bbb;
  --color-surface: #ffffff;
  --color-surface-alt: #f0f0f0;
  --color-surface-alt-soft: #f4f4f4;
  --color-pill-bg: #eef2f7;
  --color-border: #d4d4d4;
  --color-cell-empty: #eee;

  /* Primary (brand) */
  --color-primary: #10b981;
  --color-primary-soft: #6ee7b7;
  --color-primary-rgb: 16, 185, 129;
  --color-on-primary: #ffffff;

  /* Danger (destructive) */
  --color-danger: #fca5a5;
  --color-danger-strong: #b91c1c;
  --color-danger-soft: #fef2f2;

  /* Radius */
  --radius-xs: 1px;
  --radius-sm: 2px;
  --radius-md: 3px;
  --radius-pill: 10px;

  /* Typography */
  --text-2xs: 0.7rem;
  --text-xs: 0.75rem;
  --text-sm: 0.8rem;
  --text-base: 0.85rem;
  --text-md: 0.9rem;
  --text-lg: 1.15rem;
  --text-xl: 1.6rem;
  --text-display: 2rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-fg: #e8e8ea;
    --color-bg: #0f0f11;
    --color-muted: #9a9a9f;
    --color-subtle: #4a4a4f;
    --color-surface: #1a1a1d;
    --color-surface-alt: #26262b;
    --color-surface-alt-soft: #1d1d20;
    --color-pill-bg: #252933;
    --color-border: #35353b;
    --color-cell-empty: #242428;

    --color-primary-soft: #0e5740;

    --color-danger: #7f1d1d;
    --color-danger-strong: #fca5a5;
    --color-danger-soft: #2b1113;
  }
}

* { box-sizing: border-box; }

body {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  max-width: 960px;
  margin: auto;
  padding: 24px;
  color: var(--color-fg);
  background: var(--color-bg);
  line-height: 1.5;
}

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: var(--text-xl); margin: 0 0 8px; }
h2 { font-size: var(--text-lg); margin: 16px 0 8px; }

a { color: var(--color-primary); }
.muted { color: var(--color-muted); font-size: var(--text-md); }
.error {
  color: var(--color-danger-strong);
  background: var(--color-danger-soft);
  border: 1px solid var(--color-danger);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  margin: 8px 0;
}

/* Landing */
.landing {
  max-width: 520px;
  margin: 48px auto;
  text-align: center;
}
.landing h1 { font-size: var(--text-display); margin-bottom: 4px; }
.landing .subtitle { color: var(--color-muted); margin-bottom: 32px; }
.landing form { text-align: left; margin-top: 24px; }

/* Forms */
form { display: flex; flex-direction: column; gap: 12px; }
label { font-size: var(--text-base); color: var(--color-muted); }
input[type="text"], input[type="date"], input[type="time"], input[type="number"], select, textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-fg);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
  border-color: var(--color-primary);
}
button, .btn {
  font: inherit;
  padding: 10px 16px;
  border: 1px solid var(--color-fg);
  background: var(--color-fg);
  color: var(--color-surface);
  border-radius: var(--radius-md);
  cursor: pointer;
}
button:hover, .btn:hover { opacity: 0.88; }
button.secondary, .btn.secondary {
  background: var(--color-surface);
  color: var(--color-fg);
}
button[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Datepicker */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: var(--text-base); color: var(--color-muted); }
.datepicker {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  padding: 10px 12px;
  user-select: none;
}
.dp-topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 10px;
}
.dp-mode-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-sm);
  color: var(--color-muted);
}
.dp-mode-label select {
  width: auto;
  padding: 4px 8px;
  font-size: var(--text-base);
}
.datepicker.mode-specific .dp-dow-wrap { display: none; }
.datepicker.mode-dow .dp-specific-wrap { display: none; }

.dp-weekdays {
  display: grid;
  grid-template-columns: 2.2em repeat(7, 1fr) 3em;
  gap: 2px;
  font-size: var(--text-2xs);
  color: var(--color-muted);
  text-align: center;
  margin-bottom: 4px;
}
.dp-spec-grid {
  display: grid;
  grid-template-columns: 2.2em repeat(7, 1fr) 3em;
  gap: 2px;
}
.dp-week-label, .dp-week-year {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-2xs);
  color: var(--color-muted);
}
.dp-day {
  aspect-ratio: 1;
  background: var(--color-cell-empty);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--color-fg);
  font: inherit;
  font-size: var(--text-base);
  padding: 0;
  cursor: pointer;
}
.dp-day.past { color: var(--color-subtle); cursor: not-allowed; background: transparent; }
.dp-day.selected { background: var(--color-primary); color: var(--color-on-primary); }
.dp-day:hover:not(.past):not(.selected) { background: var(--color-primary-soft); }
.dp-controls {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 10px;
}
.dp-controls button {
  padding: 4px 10px;
  font-size: var(--text-sm);
}

.dp-dow-hint { margin: 0 0 8px; font-size: var(--text-xs); }
.dp-dow-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.dp-dow-col {
  height: 120px;
  background: var(--color-cell-empty);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--color-fg);
  font: inherit;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8px;
}
.dp-dow-col .dp-dow-letter { font-weight: 600; font-size: var(--text-md); }
.dp-dow-col:hover:not(.selected) { background: var(--color-primary-soft); }
.dp-dow-col.selected { background: var(--color-primary); color: var(--color-on-primary); }

.dp-summary { margin-top: 10px; font-size: var(--text-xs); }

.window-hint { margin: 0 0 4px; font-size: var(--text-xs); }
.window-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.window-row label { display: flex; flex-direction: column; gap: 4px; }
@media (max-width: 480px) {
  .window-row { grid-template-columns: 1fr 1fr; }
  .window-row label:last-child { grid-column: 1 / -1; }
}

/* Event page */
body:has(.event-page) { max-width: 1120px; }
.event-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 32px;
  align-items: flex-start;
}
.new-event-edge {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 180px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding-left: 20px;
  text-decoration: none;
  color: var(--color-muted);
  background: linear-gradient(
    to right,
    rgba(var(--color-primary-rgb), 0) 0%,
    rgba(var(--color-primary-rgb), 0) 100%
  );
  transition: background 220ms ease, color 220ms ease;
}
.new-event-edge__plus {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
  line-height: 1;
  opacity: 0.35;
  transform-origin: center left;
  transition: font-size 220ms ease, opacity 220ms ease, color 220ms ease;
}
.new-event-edge__label {
  font-size: var(--text-sm);
  opacity: 0;
  transform: translateX(-8px);
  transition: opacity 220ms ease, transform 220ms ease, color 220ms ease;
  white-space: nowrap;
}
.new-event-edge:hover {
  color: var(--color-fg);
  background: linear-gradient(
    to right,
    rgba(var(--color-primary-rgb), 0.22) 0%,
    rgba(var(--color-primary-rgb), 0.08) 40%,
    rgba(var(--color-primary-rgb), 0) 100%
  );
}
.new-event-edge:hover .new-event-edge__plus {
  font-size: 34px;
  opacity: 1;
  color: var(--color-primary);
}
.new-event-edge:hover .new-event-edge__label {
  opacity: 1;
  transform: translateX(0);
  color: var(--color-fg);
}
@media (max-width: 1479px) {
  .new-event-edge { width: max(0px, calc((100vw - 1120px) / 2)); }
}
@media (max-width: 1279px) {
  .new-event-edge__label { display: none; }
}
@media (max-width: 1120px) {
  .new-event-edge {
    top: auto;
    bottom: 24px;
    left: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    padding: 0;
    justify-content: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }
  .new-event-edge__plus {
    font-size: 22px;
    opacity: 0.55;
  }
  .new-event-edge:hover {
    background: var(--color-surface);
    border-color: var(--color-primary);
  }
  .new-event-edge:hover .new-event-edge__plus {
    font-size: 22px;
    opacity: 1;
    color: var(--color-primary);
  }
}
.event-page > header.event-header {
  grid-column: 1 / -1;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.event-header__title { min-width: 0; flex: 1 1 auto; }
.event-header__title h1 { margin: 0; }
.event-header__title p { margin: 4px 0 0; }
.event-page > .panel { min-width: 0; }
.panel-title {
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  margin: 0 0 10px;
}

.share-link {
  font: inherit;
  font-size: var(--text-sm);
  color: var(--color-fg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  margin: 0;
  text-align: left;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 0 1 auto;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.share-link::before {
  content: "Copy link · ";
  font-weight: 600;
  color: var(--color-muted);
}
.share-link:hover {
  opacity: 1;
  background: var(--color-surface-alt);
  border-color: var(--color-muted);
}
.share-link.copied,
.share-link.copied:hover {
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-color: var(--color-primary);
}
.share-link.copied::before {
  content: "Copied · ";
  color: var(--color-on-primary);
}

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

/* Identify */
.identify {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
  margin: 0 0 12px;
}
.identify input { width: 100%; }
.identify button {
  padding: 10px 18px;
  background: var(--color-surface);
  color: var(--color-fg);
  border: 1px solid var(--color-border);
}
.identify button:hover {
  background: var(--color-fg);
  color: var(--color-surface);
  border-color: var(--color-fg);
  opacity: 1;
}
.me { font-size: var(--text-md); color: var(--color-muted); margin: 0 0 12px; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--color-muted); text-decoration: underline; cursor: pointer; }
.linkish:hover { color: inherit; }
.hint { font-size: var(--text-base); padding: 10px 12px; background: var(--color-surface-alt); border-radius: var(--radius-md); }

/* Grid (shared by personal + heatmap) */
.grid {
  display: grid;
  grid-template-columns: auto repeat(var(--cols), minmax(0, 1fr));
  gap: 2px;
  user-select: none;
}
.grid-corner { }
.grid-day-header {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-muted);
  text-align: center;
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  line-height: 1.15;
  min-width: 0;
}
.grid-day-dow, .grid-day-date { display: block; }
.grid-day-date { font-weight: 500; font-variant-numeric: tabular-nums; }
.grid-time-label {
  font-size: var(--text-2xs);
  color: var(--color-muted);
  padding: 0 6px 0 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  line-height: 1;
  white-space: nowrap;
}
.cell {
  min-height: 22px;
  background: var(--color-cell-empty);
  cursor: pointer;
  border-radius: var(--radius-xs);
}
.cell.selected { background: var(--color-primary); }

.grid:not(.heatmap):not(.disabled) .cell:hover:not(.selected) {
  background: var(--color-primary-soft);
}
.grid:not(.heatmap):not(.disabled) .cell.selected:hover { opacity: 0.88; }

/* Crosshair: highlight only the day header + time label of the hovered cell */
.grid-day-header.axis-hover,
.grid-time-label.axis-hover {
  color: var(--color-fg);
  font-weight: 700;
}
#grid.disabled .cell {
  cursor: not-allowed;
  opacity: 0.6;
}

/* Heatmap cells (read-only) */
.heatmap .cell { cursor: default; }
.heatmap .cell.heat[data-count="0"] { background: var(--color-cell-empty); }
.heatmap .cell.heat:not([data-count="0"]) {
  background: rgba(var(--color-primary-rgb), var(--intensity, 0.2));
}

/* Results */
.participant-list {
  font-size: var(--text-base);
  margin: 0 0 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.participant-list .pill {
  display: inline-block;
  background: var(--color-pill-bg);
  color: var(--color-fg);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 2px 10px;
  font: inherit;
  font-size: var(--text-sm);
  line-height: 1.4;
}
.participant-list .pill.selectable {
  cursor: pointer;
  user-select: none;
  transition: background 0.1s ease, color 0.1s ease, border-color 0.1s ease;
}
.participant-list .pill.selectable:hover {
  background: var(--color-primary-soft);
}
.participant-list .pill.selectable.selected {
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-color: var(--color-primary);
}
.participant-list .pill.selectable:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}
.participant-list .filter-clear {
  background: none;
  border: 0;
  padding: 2px 6px;
  font: inherit;
  font-size: var(--text-xs);
  color: var(--color-muted);
  text-decoration: underline;
  cursor: pointer;
}
.participant-list .filter-clear:hover { color: var(--color-fg); }
.results-legend {
  font-size: var(--text-2xs);
  color: var(--color-muted);
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.results-legend .legend-swatch {
  display: inline-block;
  width: 18px;
  height: 12px;
  border-radius: var(--radius-sm);
  background: rgba(var(--color-primary-rgb), var(--intensity, 0.2));
}
.best-slots { margin-top: 16px; }
.best-slots h3 { font-size: var(--text-md); margin: 0 0 6px; }
.best-slots ol { margin: 0; padding-left: 20px; font-size: var(--text-base); }
.best-slots li { margin-bottom: 2px; border-radius: var(--radius-md); }
.best-slots li[data-slot]:hover { background: var(--color-surface-alt); }
.best-slot-time { font-variant-numeric: tabular-nums; }
