/* Components. Quiet by default; colour only where it carries meaning. */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 0 10px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; color: var(--ink);
  font-size: var(--text-sm); font-weight: 500; line-height: 1; white-space: nowrap;
  text-decoration: none; cursor: pointer;
  transition: background-color var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out), color var(--dur);
}
.btn:hover { background: var(--wash); }
.btn:active { background: var(--wash-strong); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.btn--outline { border-color: var(--rule-strong); background: var(--paper); }
.btn--outline:hover { background: var(--wash); }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.btn--danger { color: var(--danger); }
.btn--danger:hover { background: var(--danger-wash); }
/* The confirming button of a destructive action (confirm dialog). */
.btn--danger-solid { background: var(--danger); color: var(--paper); }
.btn--danger-solid:hover { background: color-mix(in srgb, var(--danger) 86%, var(--ink)); }
.btn--icon { padding: 0; width: 32px; }
.btn--lg { min-height: 40px; padding: 0 16px; font-size: var(--text-md); }
.btn--block { width: 100%; }
/* Label wrapper next to a loading spinner: keep icon and text on one line like any button. */
.btn__label-idle { display: inline-flex; align-items: center; gap: 6px; }
.btn .htmx-indicator { display: none; }
.btn.htmx-request .htmx-indicator { display: inline-flex; }
.btn.htmx-request .btn__label-idle { display: none; }
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn--icon { width: 44px; }
}

/* inline-flex: transforms don't apply to inline spans, so the icon would never turn */
.spin { display: inline-flex; vertical-align: -3px; animation: spin 0.9s linear infinite; }
/* The box must hug the icon or it turns around the wrong centre: in a flex row (a callout)
   it would stretch to the row's height and the icon would swing in a wide circle. */
.spin > .icon, .callout .spin > .icon { display: block; margin: 0; }
.callout > .spin { flex: none; align-self: flex-start; margin-top: 3px; color: var(--ink-muted); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Busy submit buttons: htmx requests (.htmx-request) and plain form posts (.is-busy, set in app.js). */
form.htmx-request [type="submit"]:not(:has(.htmx-indicator)),
form.is-busy [type="submit"]:not(:has(.htmx-indicator)) { pointer-events: none; opacity: 0.75; }
form.htmx-request [type="submit"]:not(:has(.htmx-indicator))::after,
form.is-busy [type="submit"].is-submitter:not(:has(.htmx-indicator))::after {
  content: ""; width: 14px; height: 14px; flex: none; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite;
}
form.is-busy [type="submit"].is-submitter .htmx-indicator { display: inline-flex; }
form.is-busy [type="submit"].is-submitter .btn__label-idle { display: none; }
@media (prefers-reduced-motion: reduce) {
  /* A loading indicator is essential feedback: keep it turning, slowly. */
  .spin, form.htmx-request [type="submit"]::after, form.is-busy [type="submit"].is-submitter::after {
    animation-duration: 1.6s !important; animation-iteration-count: infinite !important;
  }
}

/* ---------- Waiting for a background AI job: steps, elapsed time, what it found so far ---------- */
.job-progress { display: grid; gap: var(--s-3); max-width: 760px; padding: var(--s-4); border: 1px solid var(--rule); border-radius: var(--radius-lg); background: var(--wash); }
.job-progress > *, .job-progress p { margin: 0; }
.job-progress__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s-1) var(--s-3); }
.job-progress__title { font-weight: 600; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); font-size: var(--text-sm); }
.steps__item { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-muted); }
.steps__item[data-state="active"] { color: var(--ink); font-weight: 600; }
.steps__mark { flex: none; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--rule-strong); color: var(--accent); }
.steps__item[data-state="done"] .steps__mark { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.steps__item[data-state="active"] .steps__mark { border-color: transparent; }
.steps__mark .spin { vertical-align: 0; }
.job-found { list-style: none; margin: 0; padding: 0; display: grid; border-top: 1px solid var(--rule); }
.job-found__row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 2px var(--s-3);
  padding: var(--s-2) 0; border-bottom: 1px solid var(--rule);
}
.job-found__row:last-child { border-bottom: 0; padding-bottom: 0; }
.job-found__title { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.job-found__groups { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }

/* Writing grading: a band appears in each criterion as soon as the AI has written it. */
.live-bands { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-2); margin: 0 0 var(--s-2); }
.live-bands__item { display: grid; gap: 2px; align-content: space-between; padding: var(--s-2) var(--s-3); border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper); }
.live-bands__item dt { font-size: var(--text-xs); color: var(--ink-muted); line-height: 1.3; }
.live-bands__item dd { margin: 0; font-size: var(--text-xl); font-weight: 700; line-height: 1.2; }
.live-bands__item[data-pending] dd { color: var(--ink-faint); }
@media (max-width: 640px) { .live-bands { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: var(--s-4); }
.field > label, .field__label { font-size: var(--text-sm); font-weight: 500; }
.field__help { font-size: var(--text-xs); color: var(--ink-muted); }
/* A group of choices (radio / checkbox): a quiet grey panel instead of the browser's groove border.
   The legend is floated so it sits inside the panel rather than breaking the border. */
fieldset.field { min-width: 0; margin: 0 0 var(--s-4); padding: var(--s-3) var(--s-4); border: 1px solid var(--rule); border-radius: var(--radius-lg); background: var(--wash); }
fieldset.field > legend { float: left; width: 100%; padding: 0; margin-bottom: var(--s-2); }
fieldset.field > legend + * { clear: both; }
fieldset.field .field__help { margin: var(--s-2) 0 0; }
.field__error { font-size: var(--text-xs); color: var(--danger); }
.input, .field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea, .select, .textarea {
  width: 100%; min-height: 36px; padding: 6px 10px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--rule-strong); border-radius: var(--radius);
  font-size: var(--text-md); line-height: 1.5;
  transition: border-color var(--dur), box-shadow var(--dur);
}
.field textarea, .textarea { min-height: 120px; resize: vertical; }

/* File inputs: the browser's grey button becomes one of ours. */
input[type="file"] { font-size: var(--text-sm); color: var(--ink-muted); cursor: pointer; }
input[type="file"]::file-selector-button {
  margin-right: var(--s-3); min-height: 30px; padding: 0 12px; cursor: pointer;
  border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--paper);
  color: var(--ink); font: 500 var(--text-sm)/1 var(--font-ui);
  transition: background-color var(--dur) var(--ease-out);
}
input[type="file"]:hover::file-selector-button { background: var(--wash); }
.field input[type="file"] { padding: 4px 6px; }

/* ---------- Dropdown (static/js/dropdown.js) ----------
   Native selects (touch screens, or before the script runs) lose the OS arrow for ours. */
select.select, .field select {
  appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23898479' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
/* The native select stays for forms/htmx/x-model but is hidden once enhanced. */
.dropdown-native { position: absolute !important; width: 1px !important; height: 1px !important; min-height: 0 !important; padding: 0 !important;
  margin: -1px; overflow: hidden; clip-path: inset(50%); border: 0 !important; opacity: 0; pointer-events: none; }
.dropdown__button {
  display: inline-flex; align-items: center; justify-content: space-between; gap: var(--s-2);
  text-align: left; cursor: pointer; background-image: none; padding-right: 10px;
}
.dropdown__button:hover { border-color: color-mix(in srgb, var(--ink) 35%, var(--rule-strong)); }
.dropdown__button[disabled] { opacity: 0.55; cursor: default; }
.dropdown__button.is-open { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.dropdown__button.is-invalid { border-color: var(--danger); }
.dropdown__button.is-placeholder .dropdown__value { color: var(--ink-muted); }
.dropdown__value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown__button > .icon { flex: none; color: var(--ink-muted); transition: transform var(--dur) var(--ease-out); }
.dropdown__button.is-open > .icon { transform: rotate(180deg); color: var(--accent); }
.dropdown__list {
  position: fixed; z-index: 90; max-width: min(320px, calc(100vw - 16px)); max-height: min(300px, 60vh); overflow: auto;
  margin: 0; padding: 4px; list-style: none; overscroll-behavior: contain;
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
  font-size: var(--text-sm); animation: dropdown-in 120ms var(--ease-out);
}
.dropdown__list.is-above { animation-name: dropdown-in-up; }
@keyframes dropdown-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes dropdown-in-up { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .dropdown__list { animation: none; } .dropdown__button > .icon { transition: none; } }
.dropdown__option {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  min-height: 32px; padding: 4px 8px; border-radius: var(--radius); color: var(--ink); cursor: pointer;
}
.dropdown__option.is-active { background: var(--wash-strong); }
.dropdown__option[aria-selected="true"] { font-weight: 600; }
.dropdown__option[aria-selected="true"] .icon { color: var(--accent); flex: none; }
.dropdown__option.is-placeholder { color: var(--ink-muted); }
.dropdown__option[aria-disabled="true"] { color: var(--ink-faint); cursor: default; }
.dropdown__text { min-width: 0; overflow-wrap: anywhere; }
.dropdown__group { padding: 8px 8px 2px; font-size: var(--text-xs); font-weight: 600; color: var(--ink-muted); }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash);
}
.field--invalid input, .field--invalid select, .field--invalid textarea { border-color: var(--danger); }
::placeholder { color: var(--ink-placeholder); opacity: 1; }
.check { display: flex; align-items: flex-start; gap: var(--s-2); font-size: var(--text-sm); }
.check input { width: 16px; height: 16px; margin-top: 3px; accent-color: var(--accent); }
.form-actions { display: flex; gap: var(--s-2); align-items: center; margin-top: var(--s-4); }
@media (pointer: coarse) {
  .input, .field input:not([type="checkbox"]):not([type="radio"]), .field select, .select { min-height: 44px; font-size: 16px; }
}

/* Search field with icon */
.search { position: relative; display: flex; align-items: center; }
.search .icon { position: absolute; left: 10px; color: var(--ink-muted); pointer-events: none; }
.search .input { padding-left: 34px; }

/* ---------- Chips (tags, CEFR) ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 7px; border-radius: var(--radius-sm);
  font-size: var(--text-xs); font-weight: 500; line-height: 1; white-space: nowrap;
  color: var(--tag-gray); background: var(--tag-gray-bg);
}
.chip[data-color="brown"] { color: var(--tag-brown); background: var(--tag-brown-bg); }
.chip[data-color="orange"] { color: var(--tag-orange); background: var(--tag-orange-bg); }
.chip[data-color="yellow"] { color: var(--tag-yellow); background: var(--tag-yellow-bg); }
.chip[data-color="green"] { color: var(--tag-green); background: var(--tag-green-bg); }
.chip[data-color="blue"] { color: var(--tag-blue); background: var(--tag-blue-bg); }
.chip[data-color="purple"] { color: var(--tag-purple); background: var(--tag-purple-bg); }
.chip[data-color="pink"] { color: var(--tag-pink); background: var(--tag-pink-bg); }
.chip[data-color="red"] { color: var(--tag-red); background: var(--tag-red-bg); }
.chip--cefr { font-weight: 650; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.chip--cefr[data-level="A1"] { color: var(--cefr-a1); background: var(--cefr-a1-bg); }
.chip--cefr[data-level="A2"] { color: var(--cefr-a2); background: var(--cefr-a2-bg); }
.chip--cefr[data-level="B1"] { color: var(--cefr-b1); background: var(--cefr-b1-bg); }
.chip--cefr[data-level="B2"] { color: var(--cefr-b2); background: var(--cefr-b2-bg); }
.chip--cefr[data-level="C1"] { color: var(--cefr-c1); background: var(--cefr-c1-bg); }
.chip--cefr[data-level="C2"] { color: var(--cefr-c2); background: var(--cefr-c2-bg); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* Filter chips (toggleable) */
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border: 1px solid var(--rule-strong); border-radius: 999px; background: var(--paper);
  font-size: var(--text-sm); color: var(--ink-muted); cursor: pointer;
}
.filter-chip:hover { background: var(--wash); color: var(--ink); }
.filter-chip[aria-pressed="true"], .filter-chip:has(input:checked) { border-color: var(--accent); color: var(--accent); background: var(--accent-wash); }
.filter-chip input { position: absolute; opacity: 0; pointer-events: none; }

/* ---------- Notion-style page header: cover + icon + title ---------- */
.cover { position: relative; height: 200px; background: var(--wash); overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover__credit { position: absolute; right: var(--s-3); bottom: var(--s-2); font-size: 11px; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); text-decoration: none; }
.cover__actions { position: absolute; right: var(--s-3); top: var(--s-3); display: flex; gap: var(--s-1); opacity: 0; transition: opacity var(--dur); }
.cover:hover .cover__actions, .cover:focus-within .cover__actions { opacity: 1; }
.cover__actions .btn { background: color-mix(in srgb, var(--paper) 88%, transparent); }
@media (max-width: 767px) { .cover { height: 132px; } .cover__actions { opacity: 1; } }

.page-icon {
  width: 72px; height: 72px; margin-top: -40px; margin-bottom: var(--s-3);
  display: grid; place-items: center; position: relative;
  border-radius: var(--radius-lg); background: var(--paper);
  box-shadow: 0 0 0 4px var(--paper);
  font-family: var(--font-read); font-size: 1.25rem; font-weight: 600; font-style: italic;
}
.page-icon--plain { margin-top: 0; }
.page-icon[data-color] { color: var(--tag-gray); background: var(--tag-gray-bg); }
.page-icon[data-color="blue"] { color: var(--tag-blue); background: var(--tag-blue-bg); }
.page-icon[data-color="green"] { color: var(--tag-green); background: var(--tag-green-bg); }
.page-icon[data-color="orange"] { color: var(--tag-orange); background: var(--tag-orange-bg); }
.page-icon[data-color="purple"] { color: var(--tag-purple); background: var(--tag-purple-bg); }
.page-icon[data-color="pink"] { color: var(--tag-pink); background: var(--tag-pink-bg); }
.page-icon[data-color="yellow"] { color: var(--tag-yellow); background: var(--tag-yellow-bg); }
.page-icon[data-color="brown"] { color: var(--tag-brown); background: var(--tag-brown-bg); }
.page-icon[data-color="red"] { color: var(--tag-red); background: var(--tag-red-bg); }

.headword { font-family: var(--font-read); font-size: var(--text-3xl); font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
@media (max-width: 767px) { .headword { font-size: 2rem; } }

/* ---------- Properties table ---------- */
.props { display: grid; grid-template-columns: minmax(120px, 168px) minmax(0, 1fr); margin: var(--s-4) 0 var(--s-5); }
.prop { display: contents; }
.prop__label, .prop__value { min-height: 34px; padding: 5px 8px; border-radius: var(--radius-sm); display: flex; align-items: center; gap: 8px; }
.prop__label { color: var(--ink-muted); font-size: var(--text-sm); }
.prop__value { min-width: 0; flex-wrap: wrap; }
.prop__value--editable { cursor: text; }
.prop__value--editable:hover { background: var(--wash); }
.prop__value .empty { color: var(--ink-placeholder); }
@media (max-width: 540px) {
  .props { grid-template-columns: minmax(0, 1fr); }
  .prop__label { min-height: 0; padding-bottom: 0; padding-top: var(--s-2); font-size: var(--text-xs); }
}

/* ---------- Toggle blocks ---------- */
.toggle { border-radius: var(--radius); }
.toggle > summary {
  list-style: none; display: flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 4px 6px; margin-left: -6px; border-radius: var(--radius);
  cursor: pointer; font-weight: 600;
}
.toggle > summary::-webkit-details-marker { display: none; }
.toggle > summary:hover { background: var(--wash); }
.toggle > summary > .icon:first-child { transition: transform 200ms var(--ease-out); color: var(--ink-muted); }
.toggle[open] > summary > .icon:first-child { transform: rotate(90deg); }
.toggle > summary .toggle__actions { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: opacity var(--dur); }
.toggle > summary:hover .toggle__actions, .toggle > summary:focus-within .toggle__actions, .toggle[open] > summary .toggle__actions { opacity: 1; }
@media (pointer: coarse) { .toggle > summary .toggle__actions { opacity: 1; } }
.toggle__body { padding: var(--s-1) 0 var(--s-3) 26px; }
.toggle[open] > .toggle__body { animation: disclose 240ms var(--ease-out); }
@keyframes disclose { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------- Callout ---------- */
.callout { display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--radius); background: var(--wash); }
.callout .icon { margin-top: 3px; color: var(--ink-muted); }
.callout--warning { background: var(--warning-wash); }
.callout--warning .icon { color: var(--warning); }
.callout--danger { background: var(--danger-wash); }
.callout--danger .icon { color: var(--danger); }
.callout--success { background: var(--success-wash); }
.callout--success .icon { color: var(--success); }
.callout p:last-child { margin-bottom: 0; }

/* ---------- Database view: table ---------- */
.dbbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); padding-bottom: var(--s-2); border-bottom: 1px solid var(--rule); margin-bottom: 0; }
.dbbar .search { flex: 1 1 220px; max-width: 360px; }
.dbbar__right { margin-left: auto; display: flex; gap: 2px; align-items: center; }
.seg { display: inline-flex; padding: 2px; border-radius: var(--radius); background: var(--wash); }
.seg a, .seg button { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 8px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--ink-muted); font-size: var(--text-sm); text-decoration: none; cursor: pointer; }
.seg [aria-current="true"], .seg [aria-pressed="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

/* position: relative keeps absolutely placed children (.sr-only labels) inside the
   scroller; without it they escape the clip and make the whole page scroll sideways. */
.table-wrap { position: relative; overflow-x: auto; margin: 0 calc(-1 * var(--s-2)); container-type: inline-size; }
.dbtable { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.dbtable th {
  text-align: left; font-weight: 500; color: var(--ink-muted); font-size: var(--text-xs);
  padding: 8px; border-bottom: 1px solid var(--rule); white-space: nowrap;
}
.dbtable th a { text-decoration: none; display: inline-flex; gap: 4px; align-items: center; }
.dbtable td { padding: 8px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.dbtable tr:hover td { background: var(--wash); }
.dbtable .col-check { width: 32px; }
.dbtable .col-check input { opacity: 0; accent-color: var(--accent); width: 16px; height: 16px; }
.dbtable tr:hover .col-check input, .dbtable .col-check input:checked, .dbtable .col-check input:focus-visible { opacity: 1; }
@media (pointer: coarse) { .dbtable .col-check input { opacity: 1; } }
.dbtable .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.dbtable .col-actions .cluster { flex-wrap: nowrap; gap: 2px; }

/* A narrow table's headers may wrap ("Lần gần / nhất") rather than push it wider than its box. */
@container (max-width: 640px) { .dbtable th { white-space: normal; } }

/* Narrow tables (phone, or beside the sidebar): settings-style tables become stacked rows */
@container (max-width: 600px) {
  .dbtable--stack thead { display: none; }
  .dbtable--stack tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 8px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
  .dbtable--stack tr:hover td { background: none; }
  .dbtable--stack td { border: 0; padding: 0 8px; min-width: 0; }
  .dbtable--stack td.title-cell, .dbtable--stack td.col-actions, .dbtable--stack td.span-all { grid-column: 1 / -1; }
  .dbtable--stack td.col-actions { text-align: left; width: auto; }
  .dbtable--stack td.col-actions .cluster { justify-content: flex-start; flex-wrap: wrap; }
  .dbtable--stack .chip { white-space: normal; height: auto; min-height: 22px; padding-block: 3px; }
}
.dbtable .title-cell { font-weight: 500; }
.dbtable .title-cell a { text-decoration: none; }
.dbtable .title-cell a:hover { text-decoration: underline; }
.dbtable tr.htmx-swapping td { opacity: 0; transition: opacity 200ms; }

/* Gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(208px, 1fr)); gap: var(--s-3); padding-top: var(--s-3); }
.gcard { display: flex; flex-direction: column; border: 1px solid var(--rule); border-radius: var(--radius-lg); overflow: hidden; text-decoration: none; background: var(--paper); transition: box-shadow var(--dur) var(--ease-out); }
.gcard:hover { box-shadow: var(--shadow-pop); }
.gcard__img { aspect-ratio: 16 / 9; background: var(--wash); }
.gcard__img img { width: 100%; height: 100%; object-fit: cover; }
.gcard__body { padding: var(--s-3); display: grid; gap: 4px; }
.gcard__title { font-family: var(--font-read); font-weight: 600; font-size: var(--text-lg); }

/* Plain list rows (history, notebook) */
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: var(--s-3); min-height: 44px; padding: 6px 8px; margin: 0 -8px; border-radius: var(--radius); }
.row:hover { background: var(--wash); }
.row__main { min-width: 0; flex: 1; }
.row__title { font-weight: 500; text-decoration: none; }
.row__meta { font-size: var(--text-xs); color: var(--ink-muted); }
.row__actions { display: flex; gap: 2px; opacity: 0; }
.row:hover .row__actions, .row:focus-within .row__actions { opacity: 1; }
@media (pointer: coarse) { .row__actions { opacity: 1; } }

/* Bulk action bar */
.bulkbar {
  position: fixed; left: 50%; bottom: var(--s-5); z-index: 45; transform: translateX(-50%);
  display: flex; align-items: center; gap: var(--s-2);
  padding: 6px 6px 6px 14px; border-radius: var(--radius-lg);
  background: var(--paper); border: 1px solid var(--rule-strong); box-shadow: var(--shadow-pop);
  font-size: var(--text-sm);
}
@media (max-width: 767px) { .bulkbar { bottom: calc(var(--tabbar-h) + var(--s-3)); max-width: calc(100vw - 24px); overflow-x: auto; } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: var(--s-5); z-index: 90; transform: translateX(-50%); display: grid; gap: var(--s-2); width: max-content; max-width: calc(100vw - 24px); }
@media (max-width: 767px) { .toasts { bottom: calc(var(--tabbar-h) + var(--s-3)); } }
.toast {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 40px; padding: 6px 6px 6px 14px; border-radius: var(--radius-lg);
  background: var(--toast-bg); color: var(--toast-ink); box-shadow: var(--shadow-pop);
  font-size: var(--text-sm);
}
.toast .btn { color: var(--toast-ink); min-height: 28px; }
.toast .btn:hover { background: color-mix(in srgb, var(--toast-ink) 14%, transparent); }
.toast__undo { font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.toast[data-level="error"] { background: var(--danger); color: #fff; }

/* ---------- Popover menu & sheet ---------- */
.menu { position: relative; }
.menu__panel {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 50; min-width: 200px;
  padding: 4px; border-radius: var(--radius-lg); background: var(--paper);
  border: 1px solid var(--rule); box-shadow: var(--shadow-pop);
}
.menu__item { display: flex; width: 100%; align-items: center; gap: var(--s-2); min-height: 32px; padding: 0 8px; border: 0; border-radius: var(--radius); background: none; text-align: left; text-decoration: none; font-size: var(--text-sm); cursor: pointer; }
.menu__item:hover, .menu__item:focus-visible { background: var(--wash); }
.menu__item--danger { color: var(--danger); }
.menu__sep { height: 1px; margin: 4px; background: var(--rule); }

.sheet-scrim { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0.32); }
.sheet {
  position: fixed; inset: auto 0 0 0; z-index: 75;
  padding: var(--s-2) var(--s-3) calc(var(--s-4) + env(safe-area-inset-bottom));
  background: var(--paper); border-radius: 16px 16px 0 0; box-shadow: var(--shadow-pop);
}
.sheet__grip { width: 36px; height: 4px; border-radius: 4px; background: var(--rule-strong); margin: 4px auto var(--s-3); }
.sheet .nav__item { min-height: 44px; font-size: var(--text-md); }

/* ---------- Dialog (only for protected focus, e.g. picking a cover) ---------- */
dialog.dialog { width: min(640px, calc(100vw - 24px)); max-height: 85dvh; padding: 0; border: 1px solid var(--rule); border-radius: var(--radius-lg); background: var(--paper); color: var(--ink); box-shadow: var(--shadow-pop); }
dialog.dialog::backdrop { background: rgba(0, 0, 0, 0.36); }
.dialog__head { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--rule); }
.dialog__body { padding: var(--s-4); overflow: auto; }

/* Confirm dialog (nhoConfirm in app.js): a question, an optional detail line, Cancel + the action. */
dialog.confirm {
  width: min(440px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--rule); border-radius: var(--radius-lg);
  background: var(--paper); color: var(--ink); box-shadow: var(--shadow-pop);
}
dialog.confirm::backdrop { background: rgba(0, 0, 0, 0.36); }
dialog.confirm[open] { animation: confirm-in 200ms var(--ease-out); }
dialog.confirm[open]::backdrop { animation: confirm-fade 200ms var(--ease-out); }
@keyframes confirm-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
@keyframes confirm-fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { dialog.confirm[open], dialog.confirm[open]::backdrop { animation: none; } }
.confirm__body { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-2) var(--s-3); padding: var(--s-5) var(--s-5) var(--s-4); }
.confirm__icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--danger-wash); color: var(--danger); }
.confirm__icon[hidden] { display: none; }
.confirm__icon[hidden] + .confirm__text { grid-column: 1 / -1; }
.confirm__text { display: grid; gap: var(--s-1); align-content: center; min-height: 36px; }
.confirm__title { margin: 0; font-size: var(--text-md); font-weight: 600; line-height: 1.45; text-wrap: pretty; }
.confirm__message { margin: 0; font-size: var(--text-sm); color: var(--ink-muted); white-space: pre-line; text-wrap: pretty; }
.confirm__actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s-2); margin-top: var(--s-3); }
@media (max-width: 480px) {
  .confirm__actions { flex-direction: column-reverse; }
  .confirm__actions .btn { width: 100%; }
}

/* ---------- Empty state, skeleton ---------- */
.empty-state { padding: var(--s-5) var(--s-4); text-align: left; max-width: 46ch; }
.empty-state h3 { margin-bottom: var(--s-2); }
.empty-state p { color: var(--ink-muted); }
.skeleton { display: inline-block; height: 0.9em; width: 10ch; border-radius: 4px; background: linear-gradient(90deg, var(--wash) 0%, var(--wash-strong) 50%, var(--wash) 100%); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; vertical-align: middle; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---------- Inline edit form ---------- */
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); width: 100%; padding: 2px 0; }
.inline-form .input, .inline-form .textarea { flex: 1 1 240px; }
.inline-form .field { margin: 0; flex: 1 1 240px; }

/* ---------- Divider, kbd, badge ---------- */
.divider { height: 1px; background: var(--rule); margin: var(--s-5) 0; border: 0; }
kbd { font-family: var(--font-ui); font-size: 11px; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--rule-strong); border-bottom-width: 2px; color: var(--ink-muted); }
.badge { display: inline-flex; align-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent-wash); color: var(--accent); font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums; justify-content: center; }
.stack { display: grid; gap: var(--s-3); }
.stack--tight { gap: var(--s-2); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.spread { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.grow { flex: 1; min-width: 0; }
.cluster--end { justify-content: flex-end; }

/* Meter: usage against a limit */
.meter { height: 6px; max-width: 420px; border-radius: 999px; background: var(--wash-strong); overflow: hidden; }
.meter > span { display: block; height: 100%; width: var(--pct, 0%); background: var(--accent); border-radius: inherit; }
.meter > span[data-level="high"] { background: var(--danger); }

/* Code-ish textarea (prompt editor) */
.textarea--code { width: 100%; min-height: 60vh; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: var(--text-sm); line-height: 1.55; tab-size: 2; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.9em; padding: 1px 4px; border-radius: 4px; background: var(--wash); }

/* ---------- Today ---------- */
.today-sentence { font-family: var(--font-read); font-size: var(--text-xl); line-height: 1.55; max-width: 34ch; margin-bottom: var(--s-5); }
.today-sentence a { text-decoration: none; }
.today-sentence a:hover { text-decoration: underline; }
.today-sentence strong { color: var(--accent); font-family: var(--font-ui); font-weight: 650; }

/* ---------- Spacing utilities ---------- */
.mt-2 { margin-top: var(--s-2); } .mt-4 { margin-top: var(--s-4); } .mt-6 { margin-top: var(--s-6); }
.mb-2 { margin-bottom: var(--s-2); } .mb-4 { margin-bottom: var(--s-4); }
.pl-0 { padding-left: 0; }
.narrow-form { max-width: 520px; }

/* ---------- Auth layout ---------- */
.auth { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: var(--s-5) var(--s-4); }
.auth__panel { width: 100%; max-width: 380px; }
.auth__brand { font-family: var(--font-read); font-size: 2.5rem; font-weight: 650; letter-spacing: -0.03em; line-height: 1; margin-bottom: var(--s-2); }
.auth__brand span { color: var(--accent); }
.auth__tagline { color: var(--ink-muted); margin-bottom: var(--s-6); }

/* Row delete buttons stay quiet until the row is hovered (colour only on intent). */
.dbtable .col-actions .btn--danger { color: var(--ink-faint); opacity: 0; }
.dbtable tr:hover .col-actions .btn--danger, .dbtable .col-actions .btn--danger:focus-visible { opacity: 1; }
.dbtable .col-actions .btn--danger:hover { color: var(--danger); }
@media (pointer: coarse) { .dbtable .col-actions .btn--danger { opacity: 1; } }

/* Page meta line under a title (replaces eyebrows above headings) */
.page__meta { margin-top: var(--s-2); color: var(--ink-muted); font-size: var(--text-sm); }
.props--compact { margin: var(--s-2) 0 0; grid-template-columns: minmax(96px, 120px) minmax(0, 1fr); }
.props--compact .prop__label, .props--compact .prop__value { min-height: 28px; padding-block: 2px; }
.btn--primary kbd { color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent-ink) 45%, transparent); background: transparent; }

/* ---------- Today: daily journal page ---------- */
/* Previous/next day: one tight pair that never wraps inside the 48px top bar. */
.day-nav { flex-wrap: nowrap; gap: 2px; }
.journal { max-width: 760px; }
.journal__icon { margin-bottom: var(--s-3); font-style: normal; font-family: var(--font-read); font-size: 1.625rem; }
.journal .props { margin-top: var(--s-4); }
.journal__review { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3) var(--s-5); padding: var(--s-4) var(--s-5); border-radius: var(--radius); background: var(--wash); }
.journal__review .today-sentence { margin: 0; flex: 1 1 260px; }
.journal__review .btn { margin-left: auto; }
.journal__word { font-family: var(--font-read); font-weight: 600; font-size: var(--text-lg); text-decoration: none; }
.journal .toggle > summary .badge { margin-left: var(--s-1); }
@media (max-width: 767px) { .journal__review { padding: var(--s-3) var(--s-4); } .journal__review .btn { margin-left: 0; width: 100%; } }

/* ---------- People: users, roles, sign-up (settings/users) ---------- */
.signup-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-5); margin-bottom: var(--s-4); padding: var(--s-3) var(--s-4);
  border: 1px solid var(--rule); border-radius: var(--radius-lg); background: var(--wash); }
.signup-bar .switch { padding: 0; color: var(--ink); }
.signup-bar__role { display: inline-flex; align-items: center; gap: var(--s-2); }
.users-table__name { font-weight: 600; }
.users-table .title-cell .chip { margin-left: 4px; vertical-align: 1px; }
.users-table tr.is-locked .users-table__name { color: var(--ink-muted); }
.check-list { display: grid; gap: var(--s-2); }
.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: var(--s-4); }
.role-card { display: grid; align-content: start; gap: var(--s-3); padding: var(--s-4); border: 1px solid var(--rule); border-radius: var(--radius-lg); background: var(--paper); }
.role-card form { display: grid; gap: var(--s-3); }
.role-card__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.role-card__name { flex: 1 1 160px; font-weight: 600; font-size: var(--text-md); }
.role-card__members { margin-left: auto; color: var(--ink-muted); }
.role-card__perms { display: grid; gap: var(--s-2); margin: 0; padding: var(--s-3) 0 0; border: 0; border-top: 1px solid var(--rule); }
.role-card__cap { display: grid; gap: 4px; padding-top: var(--s-3); border-top: 1px solid var(--rule); }
.role-card__cap .input { width: 8em; }
.role-card__foot { display: flex; justify-content: flex-end; }

/* ---------- Import files: paste (Ctrl+V), numbered image previews, full-size view ---------- */
.file-paste .field__help .icon { vertical-align: -2px; color: var(--ink-muted); }
.file-grid { list-style: none; margin: var(--s-3) 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--s-3); }
.file-grid__item { position: relative; display: grid; gap: 2px; min-width: 0; }
.file-grid__thumb { position: relative; display: block; height: 120px; padding: 4px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--wash); cursor: zoom-in; }
.file-grid__thumb:hover { border-color: var(--rule-strong); }
.file-grid__thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.file-grid__thumb img { width: 100%; height: 100%; object-fit: contain; }
.file-grid__num { position: absolute; top: 4px; left: 4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: var(--ink); color: var(--paper); font-size: 11px; font-weight: 600; line-height: 20px; text-align: center; }
.file-grid__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-grid__remove { position: absolute; top: 4px; right: 4px; background: var(--paper); box-shadow: 0 0 0 1px var(--rule);
  opacity: 0; transition: opacity var(--dur); }
.file-grid__item:hover .file-grid__remove, .file-grid__remove:focus-visible { opacity: 1; }
@media (hover: none) { .file-grid__remove { opacity: 1; } }
.file-list { list-style: none; margin: var(--s-3) 0 0; padding: 0; display: grid; gap: 4px; }
.file-list__item { display: flex; align-items: center; gap: var(--s-2); }
.file-list__item > .icon { color: var(--ink-muted); }
.file-list__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
dialog.file-preview { width: auto; max-width: 92vw; max-height: 92dvh; }
.file-preview .dialog__head h2 { display: flex; align-items: baseline; gap: 4px; min-width: 0; margin: 0; }
.file-preview .dialog__head h2 .muted { margin-left: var(--s-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.file-preview__body { padding: var(--s-2); background: var(--wash); }
.file-preview__body img { display: block; max-width: 90vw; max-height: 80dvh; margin: 0 auto; object-fit: contain; }
.file-preview__body img { cursor: zoom-in; }
.file-preview__body img.is-zoomed { max-width: none; max-height: none; cursor: zoom-out; }
