/* Newli Agenda release 2: app-specific glue on top of Kirby's theme.css (loaded after it).
   Logo swap specificity, links, the rich-text editor, its menus and link popover, the tag option editor, theme switch. */

/* ---- logo: both images are rendered; app.css's `.newli-logo img { display: block }` outranks theme.css's swap ---- */
.brand-logo-wrap { display: inline-flex; align-items: center; }
.newli-logo img.logo-dark, .brand-logo-wrap img.logo-dark { display: none; }
[data-theme="dark"] .newli-logo img.logo-light, [data-theme="dark"] .brand-logo-wrap img.logo-light { display: none; }
[data-theme="dark"] .newli-logo img.logo-dark, [data-theme="dark"] .brand-logo-wrap img.logo-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) .newli-logo img.logo-light,
  :root:not([data-theme="light"]):not([data-theme="dark"]) .brand-logo-wrap img.logo-light { display: none; }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .newli-logo img.logo-dark,
  :root:not([data-theme="light"]):not([data-theme="dark"]) .brand-logo-wrap img.logo-dark { display: block; }
}

/* ---- theme switch (Account sheet) ---- */
.theme-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.theme-label { font-weight: 500; }
.seg { display: flex; gap: 6px; }
.seg .pill { min-height: var(--tap); min-width: 64px; }

/* ---- links: blue, underline on hover/focus only (app.css had a magenta underline color; spec §4 says no magenta) ---- */
.rt a, .desc a, .c-body a { text-decoration-color: currentColor; }

/* ---- rich text view ---- */
.desc.rt { white-space: normal; }
.rt pre { white-space: pre; }
.c-body { white-space: pre-wrap; }

/* ---- rich text editor ---- */
.rt-field { border: 1px solid var(--input-border); border-radius: 12px; background: var(--input-bg); }
.rt-field:focus-within { border-color: var(--text-3); }
.rt-field .rt-toolbar { border-radius: 12px 12px 0 0; }
.rt-edit { position: relative; min-height: 120px; padding: 12px 14px 14px; outline: none; cursor: text; }
.rt-edit.is-empty::before { content: attr(data-placeholder); position: absolute; left: 14px; top: 12px; color: var(--text-3); pointer-events: none; }
.rt-edit:focus-visible { box-shadow: none; }
.rt-toolbar .tb-btn[hidden], .rt-toolbar .tb-sep[hidden] { display: none !important; }
.rt-toolbar .tb-style svg { width: 14px; height: 14px; }
.rt-toolbar .tb-style-name { min-width: 64px; text-align: left; }
.rt-menu { position: absolute; z-index: 8; min-width: 200px; padding: 6px; background: var(--panel); color: var(--text); border-radius: 10px; box-shadow: var(--shadow-pop); display: grid; gap: 2px; }
.rt-menu button { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 36px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text); font: 500 14px var(--font-body); text-align: left; cursor: pointer; }
.rt-menu button:hover, .rt-menu button:focus-visible { background: var(--tb-hover); }
.rt-menu button[aria-checked="true"] { color: var(--tb-active-ink); background: var(--tb-active-bg); }
.rt-menu button[data-cmd="h1"] span:first-child { font-size: 18px; font-weight: 600; }
.rt-menu button[data-cmd="h2"] span:first-child { font-size: 16px; font-weight: 600; }
.rt-menu button[data-cmd="h3"] span:first-child { font-weight: 600; }
.rt-key { color: var(--text-3); font-size: 12px; font-weight: 400; }
.rt-linkbar { position: absolute; z-index: 7; display: flex; align-items: center; gap: 10px; max-width: 320px; padding: 6px 10px; background: var(--panel); border-radius: 8px; box-shadow: var(--shadow-pop); font-size: 13px; }
.rt-linkbar[hidden] { display: none; }
.rt-linkbar-url { color: var(--link); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.rt-field .link-pop { position: absolute; z-index: 9; }
.link-pop-actions { justify-content: flex-end; gap: 8px; }
.link-pop .btn:disabled { opacity: .45; cursor: default; }
@media (max-width: 899px) {
  /* phone: the editor's own field keeps room for the fixed 48px toolbar above the keyboard */
  .rt-field:focus-within .rt-edit { scroll-margin-bottom: 72px; }
  .rt-field .link-pop { position: fixed; left: 0; right: 0; bottom: var(--kb-inset, 0px); z-index: 46; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .rt-menu { position: fixed !important; left: 8px !important; right: 8px; top: auto !important; bottom: calc(var(--kb-inset, 0px) + 56px); z-index: 46; }
  .rt-menu button { min-height: var(--tap); }
  .rt-toolbar .tb-more { display: none !important; }
}
@media (pointer: coarse) and (min-width: 900px) {
  .rt-menu button { min-height: var(--tap); }
}

/* ---- confirm with a destructive action ---- */
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: var(--primary-ink); font-weight: 600; }

/* ---- tag columns in settings: preview + Edit options ---- */
.tagcol-name { font-weight: 500; min-height: var(--tap); display: flex; align-items: center; }

/* ---- tag option editor: 520px modal (desktop) / bottom sheet (phone) ---- */
@media (min-width: 700px) { .sheet.opt-editor { max-width: 520px; } }
.oe-head { flex: 1; min-width: 0; }
.oe-crumb { font-size: 12px; color: var(--text-2); }
.oe-head h2 { margin: 0; }
.oe-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; margin-bottom: 10px; background: var(--error-bg); border-left: 3px solid var(--error-border); border-radius: 8px; color: var(--text); font-size: 14px; }
.oe-empty { margin: 4px 0 10px; }
.oe-list { list-style: none; margin: 0 0 8px; padding: 0; }
.oe-row { border-bottom: 1px solid var(--hairline); }
.oe-row.ro { padding: 8px 0; }
.oe-main { display: flex; align-items: center; gap: 6px; min-height: 48px; }
.oe-grip { width: 32px; height: 32px; flex: none; display: inline-flex; align-items: center; justify-content: center; color: var(--text-3); cursor: grab; touch-action: none; border-radius: 6px; }
.oe-grip svg { width: 16px; height: 16px; }
.oe-dragging { background: var(--hover); box-shadow: var(--shadow-pop); position: relative; z-index: 2; }
.oe-dragging .oe-grip { cursor: grabbing; }
.oe-dot.swatch { width: 28px; height: 28px; position: relative; }
.oe-dot.swatch::before { content: ''; position: absolute; inset: -8px; } /* 44px hit area */
.oe-name { flex: 1; min-width: 0; height: 36px; padding: 0 8px; font: 500 15px var(--font-body); color: var(--text); background: transparent; border: 1px solid transparent; border-radius: 8px; }
.oe-name:hover { border-color: var(--hairline); }
.oe-name:focus { outline: none; border-color: var(--text); background: var(--input-bg); }
.oe-name.invalid { border-color: var(--danger); }
.oe-uses { flex: none; min-width: 56px; text-align: right; font-size: 13px; color: var(--text-2); display: inline-flex; justify-content: flex-end; }
.oe-move, .oe-del { width: 32px; height: 32px; min-width: 32px; min-height: 32px; flex: none; position: relative; }
.oe-move::before, .oe-del::before { content: ''; position: absolute; inset: -6px -2px; }
.oe-move:disabled { opacity: .35; cursor: default; }
.oe-move svg, .oe-del svg { width: 18px; height: 18px; }
.oe-del { color: var(--text-2); }
.oe-del:hover { color: var(--danger); }
.oe-err { color: var(--danger); font-size: 12px; padding: 0 0 8px 72px; }
.oe-add-err { padding-left: 40px; }
.oe-swatches { display: grid; grid-template-columns: repeat(6, 32px); gap: 12px; padding: 6px 0 14px 72px; }
.oe-swatches .swatch { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; }
.oe-swatches .swatch svg { width: 16px; height: 16px; stroke-width: 2.4; }
.oe-swatches .swatch::before { content: ''; position: absolute; inset: -6px; }
.oe-add-row { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.oe-add-plus { width: 32px; display: inline-flex; justify-content: center; color: var(--text-3); }
.oe-add-plus svg { width: 18px; height: 18px; }
.oe-add { flex: 1; min-width: 0; }
.oe-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--hairline); }
.only-desk-inline { display: none; }
@media (min-width: 900px) { .only-desk-inline { display: inline; } }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--hairline-strong); border-top-color: var(--text-2); animation: oe-spin .8s linear infinite; display: inline-block; }
@keyframes oe-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
@media (max-width: 899px) {
  .oe-main { min-height: 56px; gap: 4px; }
  .oe-grip { width: 44px; height: 44px; }
  .oe-dot.swatch { width: 32px; height: 32px; margin: 0 6px; }
  .oe-uses { display: none; }
  .oe-move { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
  .oe-name { height: 44px; font-size: 16px; }
  .oe-add { font-size: 16px; }
  .oe-row.selected { background: var(--selected); }
  .oe-err { padding-left: 92px; }
  .oe-swatches { grid-template-columns: repeat(6, 44px); gap: 8px; padding-left: 8px; justify-content: start; }
  .oe-swatches .swatch { width: 44px; height: 44px; }
  .oe-swatches .swatch::before { inset: 0; }
}
@media (pointer: coarse) and (min-width: 900px) {
  .oe-grip, .oe-move, .oe-del { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
  .oe-swatches .swatch::before { inset: -6px; }
}

/* the toolbar must never widen the panel: grid items default to min-width:auto (content width) */
.detail-body > *, .dblock, .rt-field, .rt-edit { min-width: 0; }
@media (min-width: 900px) { .rt-toolbar { overflow: hidden; } }
/* phones and touch screens: 16px in the editor so iOS doesn't zoom on focus (same rule as every input) */
@media (max-width: 899px), (pointer: coarse) { .rt-edit { font-size: 16px; line-height: 24px; } }

/* app.css paints the filter pills on ::before with fixed #fff/#111; follow the theme tokens instead (dark mode) */
.pill { background: transparent; color: var(--text); }
.pill::before { background: var(--surface); border-color: var(--hairline-strong); }
.pill[aria-pressed="true"] { background: transparent; color: var(--primary-ink); }
.pill[aria-pressed="true"]::before { background: var(--primary); border-color: var(--primary); }
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }

/* ---- inline title edit + open-details chevron (Release 2, John 19 Nov) ---- */
.task .title[role="button"] { cursor: text; border-radius: 4px; }
.task .title[role="button"]:hover { box-shadow: inset 0 -1px 0 var(--hairline-strong); }
.task .title-input { flex: 1 1 auto; min-width: 0; width: 100%; margin: 0; padding: 0 4px; margin-left: -4px; border: 0; border-radius: 4px;
  background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--link, #1A5FD0); outline: none; white-space: nowrap; display: block; -webkit-appearance: none; appearance: none; }
.task.editing-title { cursor: default; }
.task .title.save-failed { box-shadow: inset 0 -2px 0 var(--danger, #C62828); color: var(--danger, #C62828); }
.open-detail { width: 28px; height: 28px; min-width: 28px; margin: -4px -4px -4px auto; color: var(--text-2); opacity: 0; transition: opacity .12s; border-radius: 6px; position: relative; }
.open-detail svg { width: 16px; height: 16px; }
.task:hover .open-detail, .task:focus-within .open-detail, .task.selected .open-detail, .open-detail:focus-visible { opacity: 1; }
.task.editing-title .open-detail { opacity: 0; pointer-events: none; }
/* touch: always visible, 44px hit area without growing the row */
@media (hover: none), (pointer: coarse) {
  .open-detail { opacity: 1; }
  .open-detail::before { content: ''; position: absolute; inset: -8px; }
  .task .title-input { font-size: max(16px, 1em); }
}
.task .body > .title-line { min-width: 0; }

/* ---- Kirby R2 review (14:17) ---- */
/* 1. neutral Status/Priority pills and initials follow the theme (app.css hard-codes light ones on .chip.t-*) */
.chip.t-grey, .chip.t-red, .chip.t-orange, .chip.t-yellow, .chip.t-green, .chip.t-blue, .chip.t-purple, .chip.t-pink { background: var(--pill-bg); color: var(--pill-text); border-color: var(--pill-border); }
.chip.initials { background: var(--initials-bg); color: var(--initials-ink); border-color: var(--initials-bg); }
[data-theme="dark"] { --pill-bg: #1F1F22; --pill-border: #2A2A2D; --pill-text: #D4D4D8; --initials-bg: #2A2A2D; --initials-ink: #F2F2F0; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]):not([data-theme="dark"]) { --pill-bg: #1F1F22; --pill-border: #2A2A2D; --pill-text: #D4D4D8; --initials-bg: #2A2A2D; --initials-ink: #F2F2F0; } }
/* 2. phone: while the description is being edited only the toolbar sits above the keyboard; the toolbar fades at the right edge */
.rt-fade { display: none; }
@media (max-width: 899px) {
  .detail:has(.rt-field:focus-within) .composer, body:has(.rt-field:focus-within) [data-test=composer] { display: none !important; }
  .rt-field:focus-within .rt-fade.on { display: block; position: fixed; right: 0; bottom: var(--kb-inset, 0px); width: 48px; height: 48px; z-index: 41; pointer-events: none;
    background: linear-gradient(to right, transparent, var(--panel) 80%); }
}
/* 3. the option editor replaces Project settings on screen (one dialog, one X), with a Back control */
.scrim.covered { visibility: hidden; }
.oe-back { display: inline-flex; align-items: center; gap: 2px; margin: -6px 0 -2px -8px; padding: 4px 8px 4px 2px; min-height: 32px; border: 0; background: transparent; color: var(--text-2); font: 500 12px var(--font-body); border-radius: 6px; cursor: pointer; }
.oe-back svg { width: 16px; height: 16px; }
.oe-back:hover { color: var(--text); background: var(--hover); }
@media (pointer: coarse), (max-width: 899px) { .oe-back { min-height: var(--tap); margin-top: -12px; margin-bottom: -8px; } }
/* 4. usage count: same row on desktop, under the name on phone */
.oe-namebox { display: contents; }
@media (max-width: 899px) {
  .oe-namebox { display: flex; flex-direction: column; flex: 1; min-width: 0; }
  .oe-namebox .oe-name { flex: none; width: 100%; }
  .oe-namebox .oe-uses { display: block; min-width: 0; text-align: left; font-size: 12px; line-height: 16px; padding: 0 9px 6px; margin-top: -6px; }
}

/* ---- John 19 Nov 14:43: subtle, aligned focus ----
   Text fields never get the outer magenta ring (it spread 4px outside the field, over the '+' and to the row edge).
   Bordered fields (.input, option names, description editor): only their own 1px border changes color (no ring/shadow/outline). Borderless list fields (Add task, inline
   title): a thin underline flush with the input. Buttons keep a visible keyboard ring, now 2px and flush (no gap). */
:root, [data-theme="dark"] { --focus: 0 0 0 2px var(--focus-ring); --field-focus: var(--text-3); --underline-focus: var(--text-3); /* Kirby: underline is text-3 gray (or --hairline-strong), never magenta */ }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]):not([data-theme="dark"]) { --focus: 0 0 0 2px var(--focus-ring); --field-focus: var(--text-3); --underline-focus: var(--text-3); } }
/* :where() keeps this reset at (0,1,0): it beats the global :focus-visible ring but every field rule below beats it */
:where(input:not([type=checkbox]):not([type=radio]):not([type=range]), textarea, select, [contenteditable]):is(:focus, :focus-visible) { outline: none; box-shadow: none; }
.input:focus, .input:focus-visible, select.input:focus-visible,
.composer textarea.input:focus, .composer textarea.input:focus-visible { border-color: var(--field-focus); box-shadow: none; } /* theme.css `.composer textarea.input` (0,2,1) would otherwise outrank .input:focus */
/* borderless detail-pane selects have no border to recolor: they keep one 1px inset line */
.dval select.input:focus-visible { box-shadow: inset 0 0 0 1px var(--field-focus); }
.quick-add :is(input, textarea):focus, .quick-add :is(input, textarea):focus-visible { box-shadow: inset 0 -1px 0 var(--underline-focus); border-radius: 0; }
.task .title-input, .task .title-input:focus { box-shadow: inset 0 -1px 0 var(--underline-focus); border-radius: 0; background: transparent; padding: 0; margin-left: 0; }
.oe-name:focus, .oe-name:focus-visible { border-color: var(--field-focus); box-shadow: none; }
.rt-field:focus-within { border-color: var(--field-focus); box-shadow: none; }
.due-pick:focus-within { box-shadow: inset 0 0 0 1px var(--field-focus); }
.sheet-head .head-title:focus, input.sub-title:focus, textarea.sub-title:focus { box-shadow: inset 0 -1px 0 var(--underline-focus); }
.detail-title.editing:focus { box-shadow: inset 0 -1px 0 var(--underline-focus); }
/* optimistic rows: saving = a touch lighter; failed = marked, with Retry, text kept */
.task.pending .title { opacity: .72; }
.task.not-saved .title { color: var(--danger); }
.not-saved-note { flex: none; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--danger); }
.not-saved-note .text-btn { font-size: 12px; min-height: 28px; padding: 0 6px; color: var(--danger); text-decoration: underline; background: transparent; border: 0; cursor: pointer; }
@media (pointer: coarse) { .not-saved-note .text-btn { min-height: var(--tap); } }
