:root {
  --bg: #0e1a20;
  --surface: #142027;
  --surface-alt: #1a2c34;
  --surface-alt-2: #21394362;
  --border: #29424c;
  --text-primary: #e9f2f2;
  --text-muted: #82a0a8;
  --text-faint: #52717a;

  --accent-now: #f2a65a;
  --accent-now-glow: rgba(242, 166, 90, 0.35);
  --accent-future: #5fb0a6;
  --accent-past: #4c6572;
  --accent-live: #e8635d;

  --font-display: -apple-system, "Segoe UI", "Inter", system-ui, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;

  --topbar-h: 112px;
  --rail-w: 76px;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
}

button, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ---------- Login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 20%, rgba(95, 176, 166, 0.08), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(242, 166, 90, 0.08), transparent 40%),
    var(--bg);
}

.login-card {
  width: min(360px, 90vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-card h1 {
  margin: 0 0 2px;
  font-size: 1.4rem;
  letter-spacing: 0.01em;
}

.login-sub {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.login-card label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 10px;
}

.login-card input {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 4px;
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent-future);
}

.login-card button {
  margin-top: 20px;
}

.login-error {
  background: rgba(232, 99, 93, 0.12);
  border: 1px solid rgba(232, 99, 93, 0.4);
  color: #ffb3af;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn:hover { border-color: var(--accent-future); }

.btn-primary {
  background: var(--accent-future);
  border-color: var(--accent-future);
  color: #06211d;
  font-weight: 600;
}

.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost { background: transparent; }

.btn-danger {
  background: transparent;
  border-color: rgba(232, 99, 93, 0.4);
  color: #ff9b96;
}

.btn-danger:hover {
  background: rgba(232, 99, 93, 0.12);
  border-color: var(--accent-live);
}

/* ---------- Topbar ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 18px;
  z-index: 50;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 32px;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 10px;
  margin-left: 2px;
  border-left: 1px solid var(--border);
}

.zoom-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  line-height: 1;
}

.zoom-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.zoom-btn:disabled:hover {
  border-color: var(--border);
}

.zoom-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.brand-mark {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent-now);
  box-shadow: 0 0 0 4px var(--accent-now-glow);
}

.topbar h1 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}

.header-clock {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  padding-left: 12px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
  white-space: nowrap;
}

.user-chip {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 6px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* ---------- Agenda layout ---------- */
.agenda-wrap {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0; bottom: 0;
  overflow: hidden;
}

.edge-loader {
  position: absolute;
  left: 0; right: 0;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-faint);
  padding: 6px 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 20;
}
.edge-loader.visible { opacity: 1; }
.edge-loader-top { top: 0; background: linear-gradient(var(--bg), transparent); }
.edge-loader-bottom { bottom: 0; background: linear-gradient(transparent, var(--bg)); }

.agenda-scroll {
  height: 100%;
  overflow-y: scroll;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.agenda-track {
  position: relative;
  width: 100%;
}

.date-rail {
  position: absolute;
  top: 0; left: 0;
  width: var(--rail-w);
  height: 100%;
  border-right: 1px solid var(--border);
}

.rail-hour {
  position: absolute;
  left: 0; right: 10px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-faint);
  transform: translateY(-50%);
}

.rail-day {
  position: absolute;
  left: 0; right: 0;
  border-top: 1px solid var(--border);
  padding: 4px 10px 0 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.events-layer {
  position: absolute;
  top: 0;
  left: var(--rail-w);
  right: 16px;
  height: 100%;
}

.event-card {
  position: absolute;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-future);
  border-radius: 8px;
  padding: 6px 10px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.event-card:hover {
  background: var(--surface-alt-2);
  border-color: var(--accent-future);
}

.event-card.is-past {
  opacity: 0.6;
}

.event-card.is-live {
  box-shadow: 0 0 0 1px rgba(232, 99, 93, 0.4), 0 0 14px 0 rgba(232, 99, 93, 0.25);
}

.event-location-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.event-title {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-meta {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.event-live-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-live);
  margin-right: 5px;
  animation: pulse 1.6s ease-in-out infinite;
  vertical-align: middle;
}

/* ---------- Now line (signature element) ---------- */
.now-line {
  position: absolute;
  left: 0; right: 0;
  height: 0;
  border-top: 2px solid var(--accent-now);
  box-shadow: 0 0 10px 0 var(--accent-now-glow);
  z-index: 10;
}

.now-dot {
  position: absolute;
  left: calc(var(--rail-w) - 5px);
  top: -4px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent-now);
  box-shadow: 0 0 0 5px var(--accent-now-glow);
  animation: pulse 2s ease-in-out infinite;
}

.now-label {
  position: absolute;
  left: var(--rail-w);
  top: -9px;
  transform: translateY(-100%);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-now);
  background: var(--bg);
  padding: 1px 5px 2px;
  border-radius: 4px;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent-now-glow); }
  50% { box-shadow: 0 0 0 7px transparent; }
}

/* ---------- Dialog ---------- */
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(6, 12, 15, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.dialog-backdrop[hidden] { display: none; }

.dialog-card {
  width: min(560px, 94vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.dialog-card h2 {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.dialog-card label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 12px;
}

.dialog-card input {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  margin-top: 4px;
  outline: none;
  width: 100%;
}

.dialog-card input:focus { border-color: var(--accent-future); }

.optional { color: var(--text-faint); font-weight: 400; }

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

.location-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt);
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.location-chip input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.location-chip:hover {
  border-color: var(--accent-future);
}

.location-chip:has(input:checked) {
  border-color: var(--accent-future);
  background: var(--surface-alt-2);
  box-shadow: 0 0 0 1px var(--accent-future) inset;
}

.location-chip:has(input:focus-visible) {
  outline: 2px solid var(--accent-future);
  outline-offset: 2px;
}

.chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.chip-dot-none {
  background: transparent;
  border: 1px dashed var(--text-faint);
}

.dialog-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.dialog-row > div {
  min-width: 0;
}

.dialog-row input {
  width: 100%;
  min-width: 0;
}

.form-error {
  background: rgba(232, 99, 93, 0.12);
  border: 1px solid rgba(232, 99, 93, 0.4);
  color: #ffb3af;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  margin: 14px 0 0;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.dialog-actions-spacer {
  flex: 1;
}

@media (max-width: 600px) {
  :root { --rail-w: 56px; }
  .topbar h1 { display: none; }
  .header-clock { border-left: none; padding-left: 0; }
  .dialog-row { grid-template-columns: 1fr; }
}

@media (max-width: 460px) {
  .header-clock { display: none; }
}