:root {
  --hour-h: 56px;              /* single source of truth — app.js reads this */
  --gutter-w: 60px;
  --tray-w: 300px;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --text: #16181d;
  --text-dim: #6b7280;
  --border: #e3e5ea;
  --line: #e8eaee;
  --line-soft: #f1f2f5;
  --accent: #4f46e5;
  --accent-soft: #ecebff;
  --accent-text: #ffffff;
  --high: #dc2626;
  --normal: #d97706;
  --low: #9ca3af;
  --now: #dc2626;
  --shadow: 0 1px 2px rgba(16, 18, 27, .06), 0 4px 16px rgba(16, 18, 27, .05);
  --shadow-lift: 0 8px 28px rgba(16, 18, 27, .18);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f14; --surface: #191b22; --surface-2: #22242d; --text: #e9eaee;
    --text-dim: #9096a3; --border: #2b2e39; --line: #262932; --line-soft: #1f222a;
    --accent: #7c74ff; --accent-soft: #262450; --low: #6b7280;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 20px rgba(0,0,0,.3);
    --shadow-lift: 0 10px 34px rgba(0,0,0,.55);
  }
}
:root[data-theme="light"] {
  --bg: #f6f7f9; --surface: #fff; --surface-2: #f0f1f4; --text: #16181d;
  --text-dim: #6b7280; --border: #e3e5ea; --line: #e8eaee; --line-soft: #f1f2f5;
  --accent: #4f46e5; --accent-soft: #ecebff; --low: #9ca3af;
  --shadow: 0 1px 2px rgba(16,18,27,.06), 0 4px 16px rgba(16,18,27,.05);
  --shadow-lift: 0 8px 28px rgba(16,18,27,.18);
}
:root[data-theme="dark"] {
  --bg: #0e0f14; --surface: #191b22; --surface-2: #22242d; --text: #e9eaee;
  --text-dim: #9096a3; --border: #2b2e39; --line: #262932; --line-soft: #1f222a;
  --accent: #7c74ff; --accent-soft: #262450; --low: #6b7280;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 20px rgba(0,0,0,.3);
  --shadow-lift: 0 10px 34px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* while dragging, kill text selection everywhere */
body.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }

/* ------------------------------- top bar -------------------------------- */
.topbar {
  flex: none;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand h1 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; margin: 0; }
.logo { width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

.daynav { display: flex; align-items: center; gap: 6px; }
.day-label { font-size: 15px; font-weight: 600; margin: 0 0 0 8px; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ------------------------------- buttons -------------------------------- */
.btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 7px 13px; border-radius: 9px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 550; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn.icon { padding: 7px; line-height: 0; }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn .plus { width: 14px; height: 14px; stroke-width: 2.4; }
.btn[hidden] { display: none; }

/* ----------------------------- view switch ------------------------------ */
.viewswitch {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
}
.seg {
  font: inherit; font-size: 13px; border: none; background: transparent; color: var(--text-dim);
  padding: 4px 12px; border-radius: 7px; cursor: pointer; transition: background .15s, color .15s;
}
.seg:hover { color: var(--text); }
.seg:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg.is-active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* -------------------------------- layout -------------------------------- */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: var(--tray-w) 1fr;
}

/* --------------------------------- tray --------------------------------- */
.tray {
  border-right: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0; overflow-y: auto;
  padding: 14px; gap: 10px;
}
.tray.is-drop-target { background: var(--accent-soft); }

.tray-head { display: flex; align-items: center; gap: 8px; }
.tray-head h2 {
  font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim); margin: 0; margin-right: auto;
  display: flex; align-items: center; gap: 7px;
}
.count {
  font-size: 11px; font-variant-numeric: tabular-nums; background: var(--surface-2);
  color: var(--text-dim); border-radius: 20px; padding: 1px 7px; letter-spacing: 0;
}

/* compose */
.compose {
  display: grid; gap: 8px; padding: 11px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.compose[hidden] { display: none; }
.title-input, .notes-input {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; resize: none;
}
.title-input { font-size: 14.5px; font-weight: 550; }
.notes-input { font-size: 13.5px; min-height: 34px; }
.title-input:focus, .notes-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.compose-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field { display: grid; gap: 3px; font-size: 11px; color: var(--text-dim); }
.field select {
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 6px 7px; width: 100%;
}
.field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.compose-actions { display: flex; justify-content: flex-end; gap: 6px; }

.check-row {
  display: flex; align-items: start; gap: 8px; font-size: 12.5px;
  color: var(--text-dim); cursor: pointer; line-height: 1.35;
}
.check-row input { flex: none; margin: 2px 0 0; accent-color: var(--accent); width: 15px; height: 15px; }

/* tray sections */
.tray-section { display: grid; gap: 7px; }
.section-label {
  font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim); margin: 4px 0 0; display: flex; align-items: center; gap: 7px;
}
.tray-section[hidden] { display: none; }

/* tray cards */
.tray-list { display: grid; gap: 7px; align-content: start; }
.tray-empty { font-size: 13px; color: var(--text-dim); text-align: center; padding: 18px 8px; margin: 0; }

.card {
  display: flex; align-items: start; gap: 9px; padding: 9px 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--prio, var(--low));
  border-radius: var(--radius); box-shadow: var(--shadow);
  cursor: grab; touch-action: none;
}
.card:focus-visible, .event:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.prio-high, .event.prio-high { --prio: var(--high); }
.card.prio-normal, .event.prio-normal { --prio: var(--normal); }
.card.prio-low, .event.prio-low { --prio: var(--low); }
.card.is-source, .event.is-source { opacity: .35; }

.card-body { flex: 1; min-width: 0; }
.card-title { font-size: 14px; font-weight: 500; word-wrap: break-word; }
.card-notes { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; white-space: pre-wrap; word-wrap: break-word; }
.card-meta {
  font-size: 11.5px; color: var(--text-dim); margin-top: 3px;
  display: flex; align-items: center; gap: 5px;
}
.card-meta .repeat { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* templates read as a stack of cards rather than a single one */
.card.is-regular { position: relative; }
.card.is-regular::after {
  content: ""; position: absolute; inset: 5px -4px -4px 5px; z-index: -1;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}

.done-list .card { opacity: .6; }
.done-list .card-title { text-decoration: line-through; color: var(--text-dim); }
.tray-foot { margin-top: auto; padding-top: 10px; display: grid; gap: 8px; }
.done-list[hidden] { display: none; }

/* check + delete */
.check {
  flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--border); background: transparent; cursor: pointer;
  display: grid; place-items: center; padding: 0; transition: border-color .15s, background .15s;
}
.check:hover { border-color: var(--accent); }
.check svg { width: 11px; height: 11px; fill: none; stroke: var(--accent-text); stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.is-done .check { background: var(--accent); border-color: var(--accent); }
.is-done .check svg { opacity: 1; }

.del {
  flex: none; background: transparent; border: none; color: var(--text-dim);
  cursor: pointer; padding: 3px; border-radius: 6px; line-height: 0;
  opacity: 0; transition: opacity .15s, color .15s;
}
.card:hover .del, .event:hover .del, .del:focus-visible { opacity: 1; }
.del:hover { color: var(--high); background: var(--surface-2); }
.del svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
@media (hover: none) { .del { opacity: .6; } }

/* ------------------------------- calendar ------------------------------- */
.calendar { min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.cal-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.cal-inner { position: relative; }

/* week column headers — sit above the scroller, aligned to the lanes */
.week-head {
  flex: none; display: grid; grid-template-columns: repeat(7, 1fr);
  margin-left: var(--gutter-w); border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.week-head[hidden] { display: none; }
.daycol-head {
  font: inherit; background: transparent; border: none; cursor: pointer;
  display: grid; justify-items: center; gap: 1px; padding: 6px 2px;
  color: var(--text-dim); border-left: 1px solid var(--line);
  transition: background .15s;
}
.daycol-head:first-child { border-left: none; }
.daycol-head:hover { background: var(--surface-2); }
.daycol-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.daycol-head .dow { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.daycol-head .dom {
  font-size: 16px; font-weight: 550; color: var(--text); line-height: 1.1;
  width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%;
  font-variant-numeric: tabular-nums;
}
.daycol-head.is-today .dom { background: var(--accent); color: var(--accent-text); }
.daycol-head.is-today .dow { color: var(--accent); }
.daycol-head.is-selected:not(.is-today) .dom { box-shadow: inset 0 0 0 1.5px var(--accent); }

.gutter {
  position: absolute; top: 0; left: 0; width: var(--gutter-w); height: 100%;
  border-right: 1px solid var(--border);
}
.hour-label {
  position: absolute; right: 8px; font-size: 11px; color: var(--text-dim);
  transform: translateY(-50%); font-variant-numeric: tabular-nums; white-space: nowrap;
}

.lanes {
  position: absolute; top: 0; left: var(--gutter-w); right: 0; height: 100%;
  background-image:
    repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px var(--hour-h));
}
.lanes::before {                       /* dashed half-hour marks */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 calc(var(--hour-h) / 2),
    var(--line-soft) calc(var(--hour-h) / 2) calc(var(--hour-h) / 2 + 1px),
    transparent calc(var(--hour-h) / 2 + 1px) var(--hour-h));
}
.lanes.is-drop-target { background-color: color-mix(in srgb, var(--accent) 5%, transparent); }

/* week view: the same hour rules, plus a divider between day columns */
.lanes.is-week {
  background-image:
    repeating-linear-gradient(to right, var(--line) 0 1px, transparent 1px calc(100% / var(--cols, 7))),
    repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px var(--hour-h));
}
.today-col {
  position: absolute; top: 0; bottom: 0; z-index: 0; pointer-events: none;
  background: color-mix(in srgb, var(--accent) 4%, transparent);
}
.today-col[hidden] { display: none; }

/* now indicator */
.now-line { position: absolute; left: 0; right: 0; height: 1px; background: var(--now); z-index: 4; pointer-events: none; }
.now-line[hidden] { display: none; }
.now-dot { position: absolute; left: -4px; top: -3.5px; width: 8px; height: 8px; border-radius: 50%; background: var(--now); }

/* drop preview */
.drop-preview {
  position: absolute; left: 4px; right: 8px; z-index: 3; pointer-events: none;
  border: 2px dashed var(--accent); border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.drop-preview[hidden] { display: none; }
.drop-time {
  position: absolute; top: 2px; left: 6px; font-size: 11px; font-weight: 600;
  color: var(--accent); font-variant-numeric: tabular-nums;
}

/* event blocks */
.event {
  position: absolute; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--prio, var(--low));
  border-radius: 8px; box-shadow: var(--shadow);
  padding: 3px 7px 3px 8px; cursor: grab; touch-action: none;
  display: flex; align-items: start; gap: 6px;
  min-height: 16px;
}
.event .event-body { flex: 1; min-width: 0; }
.event-title {
  font-size: 12.5px; font-weight: 550; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.event-time { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; line-height: 1.3; }
.event.is-done .event-title { text-decoration: line-through; color: var(--text-dim); }
.event.is-done { opacity: .65; }
.event .check { width: 15px; height: 15px; margin-top: 1px; }
.event .check svg { width: 9px; height: 9px; }
.event.is-short { padding-top: 1px; align-items: center; }
.event.is-short .event-time { display: none; }

/* too thin for anything but the title */
.event.is-narrow { padding: 2px 3px 2px 5px; }
.event.is-narrow .check, .event.is-narrow .del, .event.is-narrow .event-time { display: none; }
.event.is-narrow .event-title { font-size: 11.5px; }

.resize-handle {
  position: absolute; left: 0; right: 0; bottom: 0; height: 8px;
  cursor: ns-resize; touch-action: none;
}
/* On a 15-minute block the handle would swallow most of the body and every
   attempt to move it would resize instead, so keep it a thin strip. */
.event.is-short .resize-handle { height: 4px; }
.resize-handle::after {
  content: ""; position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%);
  width: 22px; height: 2px; border-radius: 2px; background: var(--border); opacity: 0;
  transition: opacity .15s;
}
.event:hover .resize-handle::after { opacity: 1; }

/* floating drag ghost */
.drag-ghost {
  position: fixed; z-index: 999; pointer-events: none; margin: 0;
  box-shadow: var(--shadow-lift); opacity: .95; cursor: grabbing;
  transform: rotate(1deg);
}

/* -------------------------------- footer -------------------------------- */
.footer {
  flex: none; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 16px; font-size: 12.5px; color: var(--text-dim);
  border-top: 1px solid var(--border); background: var(--surface);
}
.hint { opacity: .8; }
.spacer { flex: 1; }

/* -------------------------------- editor -------------------------------- */
.editor {
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text);
  width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow-lift);
}
.editor::backdrop { background: rgba(8, 9, 12, .45); backdrop-filter: blur(2px); }
.editor-form { display: grid; gap: 12px; padding: 18px; }
.editor-form h2 { font-size: 15px; font-weight: 650; margin: 0; }

.field-block { display: grid; gap: 4px; font-size: 11px; color: var(--text-dim); }
.field-block > span { text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.editor .title-input, .editor .notes-input { background: var(--surface-2); }
.compose-row.three { grid-template-columns: repeat(3, 1fr); }

.editor-when {
  margin: 0; font-size: 12.5px; color: var(--text-dim);
  padding: 8px 10px; background: var(--surface-2); border-radius: 8px;
}
.editor-when[hidden] { display: none; }

.editor-actions { display: flex; align-items: center; gap: 6px; }
.btn.danger { color: var(--high); border-color: transparent; background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--high) 12%, transparent); }

/* pencil affordance on tray cards */
.edit {
  flex: none; background: transparent; border: none; color: var(--text-dim);
  cursor: pointer; padding: 3px; border-radius: 6px; line-height: 0;
  opacity: 0; transition: opacity .15s, color .15s;
}
.card:hover .edit, .edit:focus-visible { opacity: 1; }
.edit:hover { color: var(--accent); background: var(--surface-2); }
.edit svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: none) { .edit { opacity: .6; } }

/* -------------------------------- toast --------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 56px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px;
  border-radius: 9px; font-size: 14px; box-shadow: var(--shadow-lift); z-index: 1000;
}
.toast[hidden] { display: none; }

/* ------------------------------ responsive ------------------------------ */
/* A week column is ~1/7th as wide, so the block's time no longer fits. */
@media (max-width: 1000px) {
  .lanes.is-week .event-time { display: none; }
  .lanes.is-week .event { padding-left: 5px; padding-right: 4px; }
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; }
  .tray { border-right: none; border-bottom: 1px solid var(--border); max-height: 45vh; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-actions { margin-left: 0; }
  .hint { display: none; }
  .lanes.is-week .event .check, .lanes.is-week .event .del { display: none; }
  .daycol-head .dom { font-size: 14px; width: 22px; height: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .drag-ghost { transform: none; }
}
