@import url("./rose-pine.css");

/* ==========================================================================
   Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--rp-base);
  color: var(--rp-text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
button:disabled { cursor: default; opacity: 0.6; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--rp-overlay);
  color: var(--rp-gold);
  font: 600 0.72rem/1.6 "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
}

.icon { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon svg { display: block; }

* { scrollbar-width: thin; scrollbar-color: var(--rp-hl-high) transparent; }

/* Calendar colors: names from the palette, resolved per theme. */
.cal-pine { --cal: var(--rp-pine); }
.cal-foam { --cal: var(--rp-foam); }
.cal-iris { --cal: var(--rp-iris); }
.cal-rose { --cal: var(--rp-rose); }
.cal-love { --cal: var(--rp-love); }
.cal-gold { --cal: var(--rp-gold); }

/* ==========================================================================
   Controls
   ========================================================================== */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--rp-subtle);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.button:hover { background: var(--rp-overlay); color: var(--rp-text); }
.button.primary, .button.danger { border-color: transparent; color: var(--on-accent); font-weight: 600; }
.button.primary { background: var(--accent); }
.button.danger { background: var(--danger); }
.button.primary:hover:not(:disabled), .button.danger:hover:not(:disabled) { filter: brightness(1.08); }
.button.wide { width: 100%; height: 38px; }
.button.ghost { border-color: transparent; }
.button.ghost.danger-text { color: var(--danger); }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 6px;
  color: var(--rp-muted);
  font-size: 1.1rem;
  line-height: 1;
  transition: background-color 0.15s, color 0.15s;
}
.icon-button:hover, .icon-button.is-open { background: var(--rp-overlay); color: var(--rp-text); }

.input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--rp-overlay);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--rp-muted); }
textarea.input { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
select.input { cursor: pointer; }
.input[type="date"], .input[type="time"] { min-width: 0; font-variant-numeric: tabular-nums; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field-label {
  color: var(--rp-subtle);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.checkbox { display: inline-flex; align-items: center; gap: 8px; color: var(--rp-subtle); font-size: 0.84rem; cursor: pointer; user-select: none; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); }

.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 7px;
}
.segmented button {
  height: 26px;
  padding: 0 10px;
  border-radius: 5px;
  color: var(--rp-subtle);
  font-size: 0.8rem;
  font-weight: 500;
}
.segmented button:hover { color: var(--rp-text); }
.segmented button.active { background: var(--rp-overlay); color: var(--rp-text); font-weight: 600; }

.swatches { display: flex; gap: 8px; }
.swatch {
  width: 22px;
  height: 22px;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--cal);
}
.swatch.selected { border-color: var(--rp-text); box-shadow: inset 0 0 0 2px var(--rp-surface); }

/* ==========================================================================
   Layout
   ========================================================================== */

.app { display: flex; flex: 1; min-height: 0; }
.main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.view { position: relative; flex: 1; min-height: 0; }

/* ==========================================================================
   Sidebar
   ========================================================================== */

.sidebar {
  display: flex;
  flex-direction: column;
  width: 248px;
  flex-shrink: 0;
  padding: 0 10px 10px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--rp-surface);
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 4px 0 8px;
}
.brand { font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }
.sidebar-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 4px 8px;
  color: var(--rp-muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.sidebar-section .icon-button { width: 26px; height: 26px; }
.calendar-list { display: flex; flex-direction: column; gap: 1px; }
.calendar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 4px 4px 4px 8px;
  border-radius: 6px;
  font-size: 0.86rem;
  cursor: pointer;
  user-select: none;
}
.calendar-row:hover { background: var(--rp-overlay); }
.calendar-row.hidden-cal { color: var(--rp-muted); }
.calendar-dot {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border: 2px solid var(--cal);
  border-radius: 4px;
  background: var(--cal);
}
.calendar-row.hidden-cal .calendar-dot { background: transparent; }
.calendar-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calendar-row .icon-link { color: var(--rp-muted); }
.calendar-row .calendar-error { color: var(--danger); font-size: 0.8rem; }
.calendar-row .icon-button { width: 26px; height: 26px; opacity: 0; }
.calendar-row:hover .icon-button, .calendar-row .icon-button.is-open { opacity: 1; }
.connect-button {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 10px 8px;
  border-radius: 6px;
  color: var(--rp-subtle);
  font-size: 0.82rem;
  text-align: left;
}
.connect-button:hover { background: var(--rp-overlay); color: var(--rp-text); }
.sidebar-backdrop { display: none; }

/* ==========================================================================
   Header
   ========================================================================== */

.main-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  flex-shrink: 0;
  padding: 0 16px 0 20px;
  border-bottom: 1px solid var(--border);
}
.menu-toggle { display: none; }
.view-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.view-title .muted { color: var(--rp-muted); font-weight: 500; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.nav-buttons { display: flex; }

/* ==========================================================================
   Time grid (day and week)
   ========================================================================== */

.grid {
  --gutter: 56px;
  --hour: 48px;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.grid-head, .grid-allday, .grid-body { scrollbar-gutter: stable; }
.grid-head { overflow: hidden; }
.grid-head {
  display: grid;
  grid-template-columns: var(--gutter) repeat(var(--days), 1fr);
  flex-shrink: 0;
}
.day-head {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  padding: 8px 4px 6px;
  color: var(--rp-subtle);
  font-size: 0.78rem;
  cursor: pointer;
}
.day-head .day-number { color: var(--rp-text); font-size: 1.05rem; font-weight: 600; }
.day-head.today { color: var(--accent); }
.day-head.today .day-number {
  padding: 0 7px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--on-accent);
}
.day-head.anchor:not(.today) .day-number { text-decoration: underline 2px var(--rp-hl-high); text-underline-offset: 4px; }

.grid-allday {
  display: grid;
  grid-template-columns: var(--gutter) repeat(var(--days), 1fr);
  grid-auto-rows: 24px;
  row-gap: 2px;
  flex-shrink: 0;
  min-height: 28px;
  max-height: 30%;
  padding-bottom: 4px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
}
.allday-label {
  grid-column: 1;
  grid-row: 1;
  align-self: center;
  padding-right: 8px;
  color: var(--rp-muted);
  font-size: 0.68rem;
  text-align: right;
}
.allday-cell { grid-row: 1 / -1; border-left: 1px solid var(--border); }

.grid-body { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.grid-hours {
  display: grid;
  grid-template-columns: var(--gutter) repeat(var(--days), 1fr);
  height: calc(24 * var(--hour));
  position: relative;
}
.hour-labels { position: relative; }
.hour-label {
  position: absolute;
  right: 8px;
  color: var(--rp-muted);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  transform: translateY(-50%);
}
.day-col {
  position: relative;
  border-left: 1px solid var(--border);
  background-image: repeating-linear-gradient(to bottom, var(--border) 0 1px, transparent 1px var(--hour));
  touch-action: pan-y;
}
.day-col.today { background-color: color-mix(in srgb, var(--accent) 4%, transparent); }
.day-col.weekend { background-color: color-mix(in srgb, var(--rp-overlay) 35%, transparent); }

.now-line {
  position: absolute;
  left: -1px;
  right: 0;
  z-index: 4;
  height: 2px;
  background: var(--rp-love);
  pointer-events: none;
}
.now-line::before {
  content: "";
  position: absolute;
  left: -5px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--rp-love);
}

/* ==========================================================================
   Events
   ========================================================================== */

.event {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  min-height: 14px;
  padding: 2px 6px;
  overflow: hidden;
  border-left: 3px solid var(--cal);
  border-radius: 6px;
  background: color-mix(in srgb, var(--cal) 24%, var(--rp-base));
  color: var(--rp-text);
  font-size: 0.74rem;
  line-height: 1.3;
  cursor: pointer;
  user-select: none;
  touch-action: pan-y;
}
.event:hover { background: color-mix(in srgb, var(--cal) 32%, var(--rp-base)); }
.event-title { overflow: hidden; font-weight: 600; text-overflow: ellipsis; }
.event-time, .event-location { overflow: hidden; color: var(--rp-subtle); font-size: 0.68rem; text-overflow: ellipsis; white-space: nowrap; }
.event.short { flex-direction: row; gap: 6px; padding-block: 0; align-items: center; }
.event.short .event-title { white-space: nowrap; }
.event.past { opacity: 0.6; }
.event.cancelled .event-title { text-decoration: line-through; }
.event.readonly { border-left-style: dashed; }
.event.selected {
  z-index: 3;
  box-shadow: 0 0 0 2px var(--rp-text), var(--shadow);
  opacity: 1;
}
.event.dragging { opacity: 0.35; }
.event.ghost {
  z-index: 5;
  opacity: 0.9;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.event.ghost.copy::after {
  content: "+";
  position: absolute;
  top: 2px;
  right: 6px;
  color: var(--rp-text);
  font-weight: 800;
}
.event .resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 7px;
  cursor: ns-resize;
}
.event.draft { background: color-mix(in srgb, var(--cal) 40%, var(--rp-base)); }

/* All-day bars */
.bar {
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0 3px;
  padding: 0 8px;
  overflow: hidden;
  border-radius: 5px;
  background: color-mix(in srgb, var(--cal) 30%, var(--rp-base));
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.bar:hover { background: color-mix(in srgb, var(--cal) 40%, var(--rp-base)); }
.bar > span { overflow: hidden; text-overflow: ellipsis; }
.bar.past { opacity: 0.6; }
.bar.selected { box-shadow: 0 0 0 2px var(--rp-text); }

/* ==========================================================================
   Month
   ========================================================================== */

.month { display: flex; flex-direction: column; height: 100%; }
.month-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.month-head span { padding: 6px 8px; color: var(--rp-muted); font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.month-grid {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, minmax(0, 1fr));
  min-height: 0;
}
.month-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  min-height: 0;
  padding: 4px 4px 2px;
  overflow: hidden;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.month-cell:nth-child(7n) { border-right: none; }
.month-cell.outside { background: color-mix(in srgb, var(--rp-overlay) 30%, transparent); }
.month-cell.outside .month-day { color: var(--rp-muted); }
.month-cell.drop-target { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.month-day {
  align-self: flex-start;
  min-width: 24px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.month-day:hover { background: var(--rp-overlay); }
.month-cell.today .month-day { background: var(--accent); color: var(--on-accent); }
.month-cell.anchor:not(.today) .month-day { box-shadow: inset 0 0 0 1px var(--rp-hl-high); }
.chip {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 20px;
  flex-shrink: 0;
  padding: 0 6px;
  overflow: hidden;
  border-radius: 4px;
  font-size: 0.72rem;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  touch-action: pan-y;
}
.chip:hover { background: var(--rp-overlay); }
.chip::before {
  content: "";
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--cal);
}
.chip.all-day { background: color-mix(in srgb, var(--cal) 30%, var(--rp-base)); font-weight: 600; }
.chip.all-day::before { display: none; }
.chip-time { color: var(--rp-subtle); font-variant-numeric: tabular-nums; }
.chip-title { overflow: hidden; text-overflow: ellipsis; }
.chip.past { opacity: 0.6; }
.chip.selected { box-shadow: inset 0 0 0 2px var(--rp-text); }
.chip.dragging { opacity: 0.35; }
.chip.ghost { position: fixed; z-index: 2000; pointer-events: none; background: var(--rp-surface); box-shadow: var(--shadow); }
.chip.ghost.copy::after { content: "+"; margin-left: 4px; font-weight: 800; }
.more-link { padding: 0 6px; color: var(--rp-muted); font-size: 0.7rem; font-weight: 600; text-align: left; }
.more-link:hover { color: var(--rp-text); }

/* ==========================================================================
   Popovers and menus
   ========================================================================== */

.popover {
  position: fixed;
  z-index: 1500;
  max-width: min(340px, calc(100vw - 16px));
  padding: 6px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--rp-surface);
  box-shadow: var(--shadow);
}
.sheet-handle, .sheet-title { display: none; }
.sheet-backdrop { position: fixed; inset: 0; z-index: 1400; background: var(--backdrop); }

.menu { display: flex; flex-direction: column; gap: 1px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--rp-text);
  font-size: 0.84rem;
  text-align: left;
  transition: background-color 0.12s;
}
.menu-item:hover { background: var(--rp-overlay); }
.menu-item.selected { color: var(--accent); font-weight: 600; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.menu-item > .icon { color: var(--rp-subtle); }
.menu-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-hint { color: var(--rp-muted); font-size: 0.74rem; }
.menu-separator { height: 1px; margin: 4px 2px; background: var(--border); }

/* Inline creation of an event on the grid */
.draft-form { display: flex; flex-direction: column; gap: 8px; width: 280px; max-width: 100%; padding: 4px; }
.draft-when { color: var(--rp-subtle); font-size: 0.78rem; }
.draft-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* ==========================================================================
   Modals
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--backdrop);
  opacity: 0;
  transition: opacity 0.18s ease;
}
.modal-overlay.open { opacity: 1; }

.modal {
  display: flex;
  flex-direction: column;
  width: min(440px, 100%);
  max-height: 88dvh;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--rp-surface);
  box-shadow: var(--shadow);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s ease;
}
.modal-overlay.open .modal { transform: none; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 14px 12px 20px; }
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-body { display: flex; flex-direction: column; gap: 14px; min-height: 0; padding: 0 20px 18px; overflow-y: auto; }
.modal-header + .modal-body { padding-top: 2px; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
.modal-footer .spacer { flex: 1; }
.dialog-message { color: var(--rp-subtle); font-size: 0.9rem; }
.modal.help { width: min(720px, 100%); }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 28px; }
.help-grid h3 { margin: 10px 0 4px; }
.help-grid h3:first-child { margin-top: 0; }
.help-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 3px 0; font-size: 0.84rem; }
.help-keys { display: flex; gap: 4px; }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.form-error {
  padding: 8px 12px;
  border: 1px solid var(--danger);
  border-radius: 6px;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: 0.84rem;
}

/* Event editor */
.modal.editor { width: min(520px, 100%); }
.editor-title {
  width: 100%;
  padding: 4px 0;
  border: none;
  background: transparent;
  font-size: 1.25rem;
  font-weight: 700;
  outline: none;
}
.editor-title::placeholder { color: var(--rp-muted); }
.editor-row { display: flex; align-items: center; gap: 8px; }
.editor-row > .icon { width: 20px; color: var(--rp-muted); }
.editor-row .input { flex: 1; }
.editor-row.top { align-items: flex-start; }
.editor-row.top > .icon { margin-top: 9px; }
.editor-times { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 6px 8px; align-items: center; flex: 1; }
.editor-times .dash { color: var(--rp-muted); text-align: center; }
.editor-times.all-day { grid-template-columns: 1fr auto 1fr; }
.editor-calendar { display: flex; align-items: center; gap: 8px; flex: 1; }
.editor-calendar .calendar-dot { width: 12px; height: 12px; }
.editor-readonly { color: var(--rp-muted); font-size: 0.8rem; }
.editor-notes { white-space: pre-wrap; color: var(--rp-subtle); font-size: 0.86rem; }

/* Picker (search) */
.modal.picker { width: min(600px, 100%); align-self: flex-start; margin-top: 10dvh; }
.modal.picker .modal-body { gap: 0; padding: 0; }
.picker-search { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--rp-muted); }
.picker-input { flex: 1; min-width: 0; border: none; background: transparent; color: var(--rp-text); font-size: 1rem; outline: none; }
.picker-list { display: flex; flex-direction: column; gap: 1px; max-height: 55dvh; padding: 6px; overflow-y: auto; }
.picker-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 6px; text-align: left; }
.picker-item .calendar-dot { width: 10px; height: 10px; }
.picker-item.active { background: var(--rp-overlay); box-shadow: inset 3px 0 0 var(--accent); }
.picker-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-meta { flex-shrink: 0; color: var(--rp-muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.picker-empty { padding: 14px 12px; color: var(--rp-muted); font-size: 0.86rem; }

/* Quick add */
.modal.quick-add { width: min(600px, 100%); align-self: flex-start; margin-top: 12dvh; }
.modal.quick-add .modal-body { gap: 10px; padding: 14px 16px; }
.quick-input { width: 100%; border: none; background: transparent; font-size: 1.05rem; outline: none; }
.quick-input::placeholder { color: var(--rp-muted); }
.quick-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.token-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 8px;
  border-radius: 12px;
  background: var(--rp-overlay);
  color: var(--rp-subtle);
  font-size: 0.76rem;
}
.token-chip.date { color: var(--rp-foam); }
.token-chip.recurrence { color: var(--rp-iris); }
.token-chip.location { color: var(--rp-gold); }
.quick-bar select.input { width: auto; height: 26px; margin-left: auto; font-size: 0.78rem; }

/* Connect dialog */
.connect-steps { display: flex; flex-direction: column; gap: 10px; color: var(--rp-subtle); font-size: 0.86rem; }
.connect-steps ol { display: flex; flex-direction: column; gap: 6px; padding-left: 20px; }
.connect-steps strong { color: var(--rp-text); }
.copy-field { display: flex; gap: 6px; }
.copy-field .input { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.8rem; }

/* ==========================================================================
   Status bar, FAB, toast
   ========================================================================== */

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 28px;
  flex-shrink: 0;
  padding: 0 16px;
  border-top: 1px solid var(--border);
  background: var(--rp-surface);
  color: var(--rp-subtle);
  font-size: 0.76rem;
}
.status-left, .status-hints { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.status-hints { overflow: hidden; color: var(--rp-muted); }
.status-hints kbd + kbd { margin-left: 2px; }
.status-mode { padding: 0 6px; border-radius: 3px; background: var(--rp-overlay); color: var(--rp-gold); font-weight: 700; letter-spacing: 0.05em; }
.status-mode.insert { background: var(--rp-love); color: var(--on-accent); }
.status-mode.copy { background: var(--rp-iris); color: var(--on-accent); }
.status-position { font-family: "JetBrains Mono", ui-monospace, monospace; }
.status-help { color: inherit; font-size: inherit; }

.fab { display: none; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 44px;
  z-index: 3000;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 12px 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--rp-surface);
  box-shadow: var(--shadow);
  font-size: 0.86rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.open { opacity: 1; pointer-events: auto; transform: none; }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--rp-foam); }
.toast-message { flex: 1; min-width: 0; }
.toast-action {
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--rp-iris);
  border-radius: 6px;
  color: var(--rp-iris);
  font-size: 0.8rem;
  font-weight: 700;
}
.toast-action:hover { background: var(--rp-iris); color: var(--on-accent); }

/* ==========================================================================
   Phones
   ========================================================================== */

@media (max-width: 768px) {
  /* 16px text keeps iOS Safari from zooming into focused fields. */
  .input, .editor-title, .picker-input, .quick-input { font-size: 16px; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 200;
    width: min(300px, 85vw);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.3, 1, 0.3, 1), box-shadow 0.25s;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 190;
    display: block;
    background: var(--backdrop);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  .calendar-row { min-height: 42px; font-size: 0.92rem; }
  .calendar-row .icon-button { opacity: 1; }

  .main-header { gap: 6px; height: auto; min-height: 52px; padding: max(8px, env(safe-area-inset-top)) 10px 8px; }
  .menu-toggle { display: inline-flex; color: var(--rp-text); }
  .view-title { font-size: 1.05rem; }
  .header-actions { gap: 4px; }
  #today-button { padding: 0 8px; }
  .nav-buttons { display: none; }
  .segmented button { padding: 0 7px; }

  .grid { --gutter: 40px; --hour: 52px; }
  .day-head { flex-direction: column; align-items: center; gap: 0; }
  .event-location { display: none; }
  .month-cell .chip-time { display: none; }

  .statusbar { display: none; }
  .fab {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom));
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    box-shadow: var(--shadow);
  }
  .fab .icon svg { width: 24px; height: 24px; stroke-width: 2.5; }
  .fab:active { transform: scale(0.94); }
  body.has-modal .fab, body.sidebar-open .fab { display: none; }
  .toast { right: 16px; left: 16px; bottom: calc(88px + env(safe-area-inset-bottom)); max-width: none; }

  /* Popovers become bottom sheets. */
  .popover.sheet {
    inset: auto 0 0 0;
    width: 100%;
    max-width: none;
    max-height: 85dvh;
    padding: 8px 14px calc(16px + env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
    animation: sheet-up 0.25s cubic-bezier(0.3, 1, 0.3, 1);
  }
  .sheet .sheet-handle {
    display: block;
    width: 36px;
    height: 4px;
    margin: 0 auto 10px;
    border-radius: 2px;
    background: var(--rp-muted);
    opacity: 0.6;
  }
  .sheet .sheet-title { display: block; padding: 0 4px 10px; font-size: 1rem; font-weight: 700; }
  .sheet .menu-item { min-height: 46px; font-size: 0.95rem; }
  .sheet .draft-form { width: 100%; }

  .modal-overlay { padding: 0; }
  .modal { width: min(440px, calc(100% - 24px)); }
  .modal.picker, .modal.quick-add { width: calc(100% - 24px); margin-top: max(12px, env(safe-area-inset-top)); }
  .modal-overlay:has(.editor) { align-items: flex-end; }
  .modal.editor {
    width: 100%;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    animation: sheet-up 0.25s cubic-bezier(0.3, 1, 0.3, 1);
  }
  .modal.editor .modal-footer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .editor-times { grid-template-columns: 1fr auto; }
  .editor-times .dash { display: none; }
  .help-grid { grid-template-columns: 1fr; }
}

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
