:root {
  --bg: #0a0e14;
  --bg-2: #10151d;
  --panel: #141b25;
  --panel-2: #1a2230;
  --border: #232c3b;
  --border-strong: #2d384a;
  --text: #f0f4f8;
  --text-dim: #98a4b6;
  --text-mute: #6b7787;
  --accent: #8b7cff;
  --accent-2: #3ec2b7;
  --danger: #ff6a75;
  --ok: #58e2a5;
  --focus: #ffd166;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --bg-2: #edf1f8;
    --panel: #ffffff;
    --panel-2: #f7f9fd;
    --border: #dbe1ec;
    --border-strong: #c0c9d9;
    --text: #1a2030;
    --text-dim: #4b5a72;
    --text-mute: #7a8598;
    --accent: #5a4bcc;
    --accent-2: #17948a;
    --shadow-md: 0 6px 20px rgba(20, 30, 50, 0.08);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); }
button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* -------- Buttons -------- */
.btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  background: var(--panel-2);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 60ms ease, background 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--panel); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0e14;
  border-color: transparent;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.05); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }

.btn-icon {
  min-width: 44px;
  padding: 0;
  border-color: var(--border);
  background: var(--panel);
  font-size: 22px;
  line-height: 1;
  color: var(--text-dim);
}
.btn-icon:hover { color: var(--text); }

.btn-inline { text-decoration: none; margin-top: 12px; display: inline-flex; }

/* -------- Auth page -------- */
.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: radial-gradient(ellipse at top, rgba(139, 124, 255, 0.15), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(62, 194, 183, 0.12), transparent 60%),
    var(--bg);
}
.auth-shell {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-md);
}
.auth-shell h1 {
  margin: 12px 0 6px;
  font-size: 26px;
  letter-spacing: -0.01em;
}
.auth-shell .lede {
  color: var(--text-dim);
  margin: 0 0 20px;
  font-size: 15px;
}
.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: 14px; color: var(--text-dim); }
.field input {
  height: 48px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
.field input:focus-visible {
  border-color: var(--accent);
  outline: 2px solid rgba(139, 124, 255, 0.3);
}
.footnote {
  margin-top: 22px;
  color: var(--text-mute);
  font-size: 13px;
}
.status {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  min-height: 0;
  font-size: 14px;
  background: transparent;
}
.status:empty { padding: 0; }
.status-error { background: rgba(255, 106, 117, 0.12); color: var(--danger); }
.status-ok { background: rgba(88, 226, 165, 0.1); color: var(--ok); }

/* -------- Top bar / brand -------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0e14;
  font-size: 18px;
}
.brand-word { font-size: 16px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-actions { display: flex; gap: 8px; }

/* -------- Month bar -------- */
.month-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}
.month-title {
  flex: 1;
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
  text-align: center;
}
.btn-today { margin-left: 4px; }

.sync-status {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  min-height: 0;
  color: var(--text-dim);
  font-size: 14px;
}
.sync-status:empty { padding: 0; }
.sync-status.err { color: var(--danger); }
.sync-status.ok { color: var(--ok); }

/* -------- Calendar shell -------- */
.calendar-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 40px;
}
.dow {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  padding: 0;
  margin: 8px 0;
  list-style: none;
  color: var(--text-mute);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.dow li { text-align: center; padding: 6px 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

/* -------- Day cell -------- */
.day-stack {
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  perspective: 700px;
}
.cell {
  min-height: 120px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: background 120ms ease, border-color 120ms ease;
  position: relative;
  z-index: 2;
  box-shadow:
    0 1px 0 color-mix(in oklab, var(--panel) 72%, white),
    0 5px 14px rgba(0, 0, 0, 0.16);
}
.cell.other-month { opacity: 0.42; }
.cell.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cell.drop-target { background: color-mix(in oklab, var(--accent) 18%, var(--panel)); border-color: var(--accent); }
.cell-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.cell-date {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  min-height: 22px;
}
.cell-date-long { display: none; }
.cell.today .cell-date { color: var(--accent); }
.cell-add {
  border: none;
  background: transparent;
  color: var(--text-mute);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 6px;
  min-width: 32px;
  min-height: 32px;
  opacity: 0;
  transition: opacity 120ms ease;
}
.cell:hover .cell-add,
.cell:focus-within .cell-add { opacity: 1; }
.cell-add:hover { background: var(--panel-2); color: var(--text); }

.cell-empty {
  color: var(--text-mute);
  font-size: 12px;
  padding: 2px 4px;
}

.notes {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 4px;
}
.note {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 50px 6px 22px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  position: relative;
  cursor: grab;
  word-break: break-word;
  touch-action: none;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16);
  transform: translateY(-1px);
}
.note:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: 0 5px 9px rgba(0, 0, 0, 0.2);
}
.note.dragging {
  opacity: 0.35;
  cursor: grabbing;
}
.note.imported {
  border-color: color-mix(in oklab, var(--accent-2) 60%, var(--border));
  background: color-mix(in oklab, var(--accent-2) 6%, var(--panel-2));
}
.note.layer-linked {
  padding-right: 64px;
  border-left-width: 3px;
}
.note.layer-linked.event-start { border-left-color: #e6b96c; }
.note.layer-linked.event-end { border-left-color: #6bc5d2; }
.note-layer-edge {
  position: absolute;
  right: -1px;
  top: -1px;
  bottom: -1px;
  width: 17px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-left: 1px solid color-mix(in oklab, var(--accent-2) 45%, var(--border));
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: color-mix(in oklab, var(--accent-2) 18%, var(--panel-2));
  color: var(--accent-2);
  cursor: pointer;
}

/* The itinerary underlay: travel lives beneath the day sheet. */
.layer-rack {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 3px;
  margin: -5px 5px 0;
  padding-top: 6px;
}
.travel-layer {
  --layer-color: #b98645;
  width: 100%;
  height: 26px;
  min-height: 26px;
  min-width: 0;
  padding: 3px 18px 3px 8px;
  border: 1px solid color-mix(in oklab, var(--layer-color) 70%, #18130d);
  border-top: 0;
  border-radius: 0 0 6px 6px;
  background:
    linear-gradient(95deg, color-mix(in oklab, var(--layer-color) 78%, #31271b),
      color-mix(in oklab, var(--layer-color) 48%, var(--panel)));
  color: #fffaf0;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  line-height: 1;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.22);
  transform: translateZ(-2px);
  transition: transform 140ms ease, filter 140ms ease;
}
.travel-layer:hover {
  filter: brightness(1.12);
  transform: translateY(2px);
}
.travel-layer.layer-flight { --layer-color: #3d8795; }
.travel-layer-glyph { flex: none; font-size: 12px; }
.travel-layer-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}
.travel-layer.layer-middle .travel-layer-label { opacity: 0.68; }
.travel-layer-edge {
  position: absolute;
  right: 0;
  top: 0;
  width: 11px;
  height: 100%;
  border-left: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.13);
}

/* -------- Travel detail sheet -------- */
.travel-detail {
  width: min(430px, calc(100vw - 28px));
  border: 1px solid color-mix(in oklab, #b98645 50%, var(--border));
  border-radius: 2px 14px 14px 2px;
  padding: 28px 28px 26px 34px;
  background:
    linear-gradient(90deg, rgba(185, 134, 69, 0.15) 0 8px, transparent 8px),
    var(--panel);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}
.travel-detail.detail-flight {
  border-color: color-mix(in oklab, #3d8795 60%, var(--border));
  background:
    linear-gradient(90deg, rgba(61, 135, 149, 0.2) 0 8px, transparent 8px),
    var(--panel);
}
.travel-detail::backdrop {
  background: rgba(3, 6, 10, 0.66);
  backdrop-filter: blur(4px);
}
.travel-detail-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
}
.travel-detail-kicker {
  color: #d5a65e;
  font: 700 11px/1 var(--mono);
  letter-spacing: 0.14em;
}
.detail-flight .travel-detail-kicker { color: #6bc5d2; }
.travel-detail h2 {
  margin: 12px 42px 4px 0;
  font-size: 25px;
  line-height: 1.15;
}
.travel-detail-range { margin: 0; color: var(--text-dim); }
.travel-detail-copy {
  white-space: pre-line;
  margin: 22px 0;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.travel-detail-ref {
  color: var(--text-mute);
  font: 12px/1.4 var(--mono);
}
.note-drag {
  position: absolute;
  left: 6px;
  top: 4px;
  color: var(--text-mute);
  font-size: 10px;
  line-height: 1;
  letter-spacing: -1px;
  user-select: none;
}
.note-content { white-space: pre-wrap; }
.note-content[contenteditable="true"] {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: var(--bg-2);
  border-radius: 4px;
  padding: 2px 4px;
  cursor: text;
}
.note-meta {
  margin-top: 4px;
  color: var(--text-mute);
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}
.note-meta .prov-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: color-mix(in oklab, var(--accent-2) 20%, transparent);
  color: color-mix(in oklab, var(--accent-2) 80%, var(--text));
  font-family: var(--font);
  font-size: 11px;
}
.note-edit,
.note-delete {
  position: absolute;
  top: 4px;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-mute);
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  min-width: 0;
  min-height: 0;
}
.note-edit { right: 26px; }
.note-delete { right: 4px; }
.note-edit:hover { background: var(--border-strong); color: var(--text); }
.note-delete:hover { background: var(--danger); color: #fff; }

.add-form {
  display: grid;
  gap: 6px;
  padding: 6px;
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
}
.add-form textarea {
  width: 100%;
  min-height: 44px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}
.add-form-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.add-form .btn {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

/* -------- Responsive -------- */
@media (max-width: 720px) {
  .month-title { font-size: 18px; }
  .calendar-shell { padding: 0 12px 32px; }
  .dow { display: none; }
  .grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }
  .cell {
    min-height: 52px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
  }
  .day-stack.other-month { display: none; }
  .cell-date { font-size: 14px; }
  .cell-date-short { display: none; }
  .cell-date-long { display: inline; }
  .cell-add { opacity: 1; }
  .cell-empty { display: none !important; }
  .notes { min-width: 0; }
  .note {
    min-width: 0;
    padding: 9px 72px 9px 26px;
    font-size: 14px;
    line-height: 1.45;
    word-break: normal;
    overflow-wrap: anywhere;
  }
  .layer-rack {
    margin: -5px 10px 0;
  }
  .travel-layer {
    height: 32px;
    min-height: 32px;
    padding-left: 12px;
    font-size: 12px;
  }
  .travel-layer.layer-middle .travel-layer-label { opacity: 1; }
  .note-edit,
  .note-delete {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }
  .note-edit { right: 38px; }
  .note-delete { right: 4px; }
  .brand-word { display: none; }
  .topbar { padding: 10px 12px; }
  #logout-btn { padding: 0 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
@media (max-width: 480px) {
  .grid { gap: 6px; }
  .topbar-actions .btn span:last-child { display: none; }
  .btn-today { padding: 0 10px; }
  .month-bar { padding: 12px 8px; gap: 4px; }
  .calendar-shell { padding: 0 8px 24px; }
}

/* Ensure no horizontal scroll at 360px minimum viewport */
@media (max-width: 360px) {
  body { font-size: 15px; }
  .cell { min-height: 50px; }
  .cell-add { font-size: 14px; }
}
