/* v3 Phase B UI: calendar (B.6). Colours come from the theme variables; motion only on transform / opacity. */

/* ---------- calendar ---------- */
.cal { --cal-hour: 48px; --cal-gutter: 52px; display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-2) 0 var(--sp-4); }
.cal-bar { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.cal-nav { display: inline-flex; align-items: center; gap: 2px; }
.cal-range { margin: 0 var(--sp-2); font-size: var(--fs-lg); font-weight: 500; font-variant-numeric: tabular-nums; }
.cal-bar .seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-pill); overflow: hidden; }
.cal-bar .seg button { border: 0; background: transparent; color: var(--text-2); padding: 4px 12px; font: inherit; font-size: var(--fs-sm); cursor: pointer; }
.cal-bar .seg button.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.cal-notes:empty { display: none; }
.cal-note { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-2); padding: 4px 8px; border-radius: var(--r-sm); background: var(--surface-2); }
.cal-note.err { color: var(--danger); }
.cal-body { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: var(--sp-3); align-items: start; }
.cal-main { min-width: 0; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.cal-head, .cal-allday { display: grid; grid-template-columns: var(--cal-gutter) repeat(var(--cal-days, 7), minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.cal[data-view="week"] .cal-head, .cal[data-view="week"] .cal-allday, .cal[data-view="week"] .cal-grid { min-width: 620px; }
.cal-dayh { display: flex; flex-direction: column; align-items: center; gap: 0; padding: 6px 0; border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--text-2); font: inherit; cursor: pointer; }
.cal-dayh b { font-size: var(--fs-lg); font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }
.cal-dayh .wd { font-size: var(--fs-xs); }
.cal-dayh.today b { color: var(--accent-text); background: var(--accent); border-radius: var(--r-pill); min-width: 28px; }
.cal-gutter-label { font-size: var(--fs-xs); color: var(--muted); padding: 6px 4px; text-align: right; }
.cal-adcell { border-left: 1px solid var(--line); min-height: 30px; padding: 3px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-adcell.cal-drop-on { background: var(--accent-soft); }
.cal-chip { display: flex; align-items: center; gap: 4px; font-size: var(--fs-xs); line-height: 1.35; padding: 2px 6px; border-radius: var(--r-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cal-chip span { overflow: hidden; text-overflow: ellipsis; }
.cal-chip.cal-event { background: color-mix(in srgb, var(--ev) 18%, var(--surface)); color: var(--text); border-left: 3px solid var(--ev); }
.cal-chip.cal-task { background: var(--accent-soft); color: var(--accent-ink); cursor: grab; touch-action: pan-y; }
.cal-chip.cal-task.due { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--text); }
.cal-scroll { height: min(64vh, 640px); overflow: auto; overscroll-behavior: contain; position: relative; }
.cal-grid { position: relative; display: grid; grid-template-columns: var(--cal-gutter) minmax(0, 1fr); }
.cal-gutter { position: relative; }
.cal-hour { position: absolute; right: 6px; transform: translateY(-50%); font-size: var(--fs-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-cols { position: relative; display: grid; grid-template-columns: repeat(var(--cal-days, 7), minmax(0, 1fr));
  background-image: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px var(--cal-hour)); }
.cal-col { position: relative; border-left: 1px solid var(--line); min-width: 0; }
.cal-col.today { background: color-mix(in srgb, var(--accent) 4%, transparent); }
.cal-block { position: absolute; left: calc(var(--col) / var(--cols) * 100% + 2px); width: calc(100% / var(--cols) - 4px); box-sizing: border-box;
  border-radius: var(--r-sm); padding: 2px 6px; font-size: var(--fs-xs); line-height: 1.3; overflow: hidden; display: flex; flex-direction: column; gap: 0; transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.cal-block b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-time { color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cal-block.cal-event { background: color-mix(in srgb, var(--ev) 20%, var(--surface)); border-left: 3px solid var(--ev); color: var(--text); }
.cal-block.cal-task { background: var(--accent); color: var(--accent-text); cursor: grab; box-shadow: var(--e-1); touch-action: pan-y; }
.cal-block.cal-task .cal-time { color: inherit; opacity: .85; }
.cal-block.cal-task.due { background: color-mix(in srgb, var(--warn) 30%, var(--surface)); color: var(--text); border-left: 3px solid var(--warn); }
.cal-block.cal-task.sel, .cal-chip.cal-task.sel, .cal-tray-item.sel { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.cal-block.cal-task.flagged::after, .cal-tray-item.flagged::after { content: ''; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--flag); }
.cal-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 7px; cursor: ns-resize; }
.cal-dragging { opacity: .45; }
.cal-is-dragging, .cal-is-dragging * { cursor: grabbing !important; user-select: none; }
.cal-ghost { position: fixed; left: 0; top: 0; z-index: 1000; pointer-events: none; padding: 4px 10px; border-radius: var(--r-pill); background: var(--accent); color: var(--accent-text);
  font-size: var(--fs-sm); box-shadow: var(--e-3); max-width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-preview { position: absolute; left: 2px; right: 2px; top: 0; border: 2px dashed var(--accent); border-radius: var(--r-sm); background: var(--accent-soft); pointer-events: none; }
.cal-preview::before { content: attr(data-time); position: absolute; top: 2px; left: 6px; font-size: var(--fs-xs); color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.cal-now { position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--danger); pointer-events: none; z-index: 2; }
.cal-now::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.cal-tray { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); padding: var(--sp-3); position: sticky; top: 0; max-height: 72vh; overflow: auto; }
.cal-tray-h { display: flex; align-items: center; justify-content: space-between; }
.cal-tray-h .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-tray-list { display: flex; flex-direction: column; gap: 4px; }
.cal-tray-item { position: relative; display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: var(--r-sm); background: var(--surface-2); cursor: grab; font-size: var(--fs-sm); touch-action: pan-y; }
.cal-tray-item .tt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-tray-item .grip { color: var(--muted); display: inline-flex; }
.cal-tray-item .due-chip { font-size: var(--fs-xs); color: var(--warn); font-variant-numeric: tabular-nums; }
.cal-settings .cal-add { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; margin-top: var(--sp-2); }
.cal-settings .cal-add input[type=url] { flex: 2 1 260px; }
.cal-settings .cal-add input[type=text] { flex: 1 1 120px; }
.cal-sub-name { display: inline-flex; gap: var(--sp-2); align-items: center; min-width: 0; }
.cal-sub-url { word-break: break-all; }
.cal-feed .bar { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; margin-top: var(--sp-2); }
.cal-feed-url { flex: 1 1 320px; font-family: var(--font-mono); font-size: var(--fs-xs); }
.warn-text { color: var(--warn); }
@media (max-width: 900px) {
  .cal-body { grid-template-columns: minmax(0, 1fr); }
  .cal-tray { position: static; max-height: none; }
  .cal-main { overflow-x: auto; }
}

/* ---------- Today / This Evening + planning ritual (B.7) ---------- */
.plan-banner { display: flex; align-items: center; gap: var(--sp-2); margin: 0 var(--sp-4) var(--sp-2); padding: 8px 12px; border-radius: var(--r-md);
  background: color-mix(in srgb, var(--warn) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 30%, var(--line)); font-size: var(--fs-sm); }
.plan-banner.hidden { display: none; }
.plan-banner .ico { color: var(--warn); display: inline-flex; }
.plan h4 { display: flex; align-items: center; gap: 4px; margin: var(--sp-4) 0 var(--sp-1); }
.plan h4:first-child { margin-top: 0; }
.plan-row { display: flex; align-items: center; gap: var(--sp-2); padding: 7px 0; border-bottom: 1px solid var(--line); }
.plan-row .ico { color: var(--muted); display: inline-flex; }
.plan-tt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.plan-tt > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-seg { display: inline-flex; gap: 2px; flex-shrink: 0; }
.plan-seg .btn.on { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--accent); }
.plan-count { margin-right: auto; }
.m-today { color: var(--warn); }
.m-today.evening { color: var(--accent-ink); }
.today-carried { font-style: italic; }

/* ---------- templates (B.8) ---------- */
.tpl h4 { margin: var(--sp-3) 0 var(--sp-2); }
.tpl h4:first-child { margin-top: 0; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--sp-2); }
.tpl-card { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); transition: transform var(--dur-fast) var(--ease); }
.tpl-card:hover { transform: translateY(-1px); }
.tpl-pick { flex: 1; display: flex; align-items: center; gap: var(--sp-2); padding: 10px 12px; border: 0; background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer; min-width: 0; }
.tpl-pick .ico { color: var(--accent-ink); display: inline-flex; }
.tpl-name { display: flex; flex-direction: column; min-width: 0; }
.tpl-name b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-tools { display: inline-flex; padding-right: 6px; }
.tpl-head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.tpl-preview { border: 1px solid var(--line); border-radius: var(--r-md); padding: 6px 10px; max-height: 260px; overflow: auto; background: var(--surface-2); }
.tpl-line { display: flex; align-items: center; gap: 6px; padding: 3px 0 3px calc(var(--depth, 0) * 18px); font-size: var(--fs-sm); color: var(--text-2); }
.tpl-line .tt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.tpl-actions { justify-content: flex-end; margin-top: var(--sp-3); display: flex; }
.tpl .set-row > span:first-child { flex: 0 0 auto; min-width: 7em; }

/* ---- B.9 quick capture ---- */
.cap-form { display: flex; flex-direction: column; gap: var(--sp-2); min-width: min(420px, 80vw); }
.cap-form .cap-title { font-size: var(--fs-md); }
.cap-form .cap-note { resize: vertical; font-family: inherit; }
.cap-settings .bar { flex-wrap: wrap; margin-bottom: var(--sp-2); }
.cap-bookmarklet { cursor: grab; border-style: dashed; }
.cap-steps { margin: var(--sp-1) 0 var(--sp-2); padding-left: 1.4em; display: grid; gap: var(--sp-1); }
.cap-steps code, .cap-settings code { font-family: var(--font-mono); font-size: var(--fs-xs); background: var(--chip-bg); padding: 0 4px; border-radius: var(--r-xs); }
.cap-done { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: var(--sp-2); color: var(--ok); text-align: center; }
.cap-done p { color: var(--text); }
.cap-settings h4 { display: flex; align-items: center; gap: var(--sp-1); margin: var(--sp-4) 0 var(--sp-1); }
.cap-settings .bar { display: flex; gap: var(--sp-2); align-items: center; }
.cap-settings .bar > input { flex: 1 1 260px; width: auto; min-width: 0; }

/* ---- B.10 Quick Entry live highlighting: overlay behind a transparent input ---- */
.qe-field { position: relative; background: var(--surface-2); border-radius: var(--r-md); }
.qe-field:focus-within { background: var(--surface); }
.qe-field .qe-input { position: relative; background: transparent; z-index: 1; }
.qe-hl { position: absolute; inset: 0; display: flex; align-items: center; padding: 0 15px; overflow: hidden; pointer-events: none;
  font-size: var(--fs-lg); white-space: pre; color: transparent; }
.qe-hl-inner { display: inline-block; white-space: pre; }
.qe-tok { color: transparent; border-radius: 3px; background: color-mix(in srgb, var(--accent) 20%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent); }
.qe-tok[data-k=repeat] { background: color-mix(in srgb, var(--ok) 22%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--ok) 35%, transparent); }
.qe-tok[data-k=tag], .qe-tok[data-k=project] { background: color-mix(in srgb, var(--soon) 22%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--soon) 35%, transparent); }
.qe-tok[data-k=priority], .qe-tok[data-k=flag] { background: color-mix(in srgb, var(--flag) 22%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--flag) 35%, transparent); }
.qe-tok[data-k=estimate] { background: color-mix(in srgb, var(--muted) 22%, transparent); box-shadow: none; }
.qe-repeat { color: var(--ok); }

/* ---- B.11 notes (Markdown edit / preview), link chips, attachments ---- */
.note-field { gap: var(--sp-2); }
.note-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.note-mode button { display: inline-flex; align-items: center; gap: 4px; }
.note-text { min-height: 120px; font-family: var(--font); line-height: 1.5; }
.note-help { line-height: 1.45; }
.md-preview { min-height: 48px; padding: var(--sp-2) var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); font-size: var(--fs-base); line-height: 1.55; overflow-wrap: anywhere; cursor: text; }
.md-preview:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.md-preview > :first-child { margin-top: 0; }
.md-preview > :last-child { margin-bottom: 0; }
.md-preview p, .md-preview ul, .md-preview ol, .md-preview blockquote, .md-preview pre { margin: 0 0 var(--sp-2); }
.md-preview .md-h { margin: var(--sp-3) 0 var(--sp-1); font-weight: 600; line-height: 1.3; }
.md-preview h3 { font-size: var(--fs-lg); } .md-preview h4 { font-size: var(--fs-md); } .md-preview h5, .md-preview h6 { font-size: var(--fs-base); }
.md-preview ul, .md-preview ol { padding-left: 1.4em; }
.md-preview li.md-task { list-style: none; margin-left: -1.3em; }
.md-preview li.md-task.done { color: var(--muted); text-decoration: line-through; }
.md-preview li.md-task input { margin: 0 6px 0 0; vertical-align: -2px; accent-color: var(--accent); cursor: pointer; transition: transform var(--dur-fast) var(--ease); }
.md-preview li.md-task input:active { transform: scale(0.9); }
.md-preview a { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }
.md-preview code { font-family: var(--font-mono); font-size: 0.92em; padding: 1px 4px; border-radius: var(--r-xs); background: var(--surface-2); }
.md-preview pre { padding: var(--sp-2); border-radius: var(--r-sm); background: var(--surface-2); overflow-x: auto; }
.md-preview pre code { padding: 0; background: none; }
.md-preview blockquote { padding-left: var(--sp-3); border-left: 3px solid var(--line-strong); color: var(--text-2); }
.md-preview hr { border: 0; border-top: 1px solid var(--line); margin: var(--sp-3) 0; }
.link-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.link-chip { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 3px 9px; border-radius: var(--r-pill); background: var(--chip-bg); color: var(--text); font-size: var(--fs-sm); text-decoration: none; transition: transform var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease); }
.link-chip:hover { transform: translateY(-1px); }
.link-chip:active { transform: scale(0.97); }
.link-chip .link-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.link-chip .link-host { color: var(--muted); font-size: var(--fs-xs); }
.att-gallery { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-2); border: 1px dashed var(--line); border-radius: var(--r-md); position: relative; }
.att-gallery::after { content: ''; position: absolute; inset: 0; border-radius: inherit; background: var(--accent-soft); opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease); }
.att-gallery.drag-over::after { opacity: 1; }
.att-gallery.off { border-style: solid; }
.att-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.att-title { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-2); }
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--sp-2); }
.att-grid:empty { display: none; }
.att-tile { position: relative; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); overflow: hidden; transition: transform var(--dur-fast) var(--ease); }
.att-tile:hover { transform: translateY(-1px); }
.att-open { display: flex; align-items: center; justify-content: center; height: 72px; background: var(--surface-2); color: var(--muted); }
.att-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-meta { display: flex; flex-direction: column; padding: 4px 6px; min-width: 0; }
.att-name { font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: var(--fs-xs); }
.att-actions { position: absolute; top: 4px; right: 4px; display: flex; gap: 2px; opacity: 0; transition: opacity var(--dur-fast) var(--ease); }
.att-tile:hover .att-actions, .att-tile:focus-within .att-actions { opacity: 1; }
.att-actions .icon-btn { background: var(--surface); box-shadow: var(--e-1); }
.att-tile.uploading { align-items: center; justify-content: center; gap: 6px; min-height: 100px; padding: var(--sp-2); }
@media (hover: none) { .att-actions { opacity: 1; } }
.att-tile .spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent); border-right-color: transparent; animation: spin 700ms linear infinite; }
html[data-motion="off"] .att-tile .spinner { animation: none; }
