/* Pulse UI improvements (after 0.21.0): global search, pinned and recent pages, dashboard tiles, smarter tables, theme switch, toasts,
   confirmations, empty states, keyboard shortcuts and phone cards. Loaded after pulse.css; uses its tokens. */

/* ---------- 1. Global search (GlobalSearchBox.razor, pulse-ui.js) ---------- */
.gs { position: relative; flex: 1 1 360px; max-width: 520px; }
.gs-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); display: grid; pointer-events: none; }
.gs-input { width: 100%; height: 38px; padding: 0 64px 0 34px; font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 19px; }
.gs-input:focus { outline: none; border-color: var(--focus); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
.gs-kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font: 11px/1 var(--font-sans); color: var(--muted); padding: 3px 6px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--surface); pointer-events: none; }
.gs-input:focus ~ .gs-kbd, .gs-input:not(:placeholder-shown) ~ .gs-kbd { display: none; }
.gs-results { position: absolute; z-index: 70; top: calc(100% + 6px); left: 0; right: 0; max-height: min(70vh, 560px); overflow-y: auto; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(16, 24, 40, .18); }
.gs-group { padding: 8px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.gs-hit { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--ink); text-decoration: none; }
.gs-hit:hover, .gs-hit:focus, .gs-hit.is-active { background: var(--surface-2); outline: none; }
.gs-hit-icon { color: var(--brand-primary); display: grid; }
.gs-hit-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.gs-hit-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-hit-detail { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-hit-status { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--neutral-bg); padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.gs-note { margin: 0; padding: 10px; color: var(--muted); }
@media (max-width: 768px) {
  .gs { order: 3; flex-basis: 100%; max-width: none; }
  .gs-kbd { display: none; }
}
.gs:not(:focus-within) .gs-results { display: none; }

/* ---------- 2. Pinned and recent pages in the sidebar (NavMenu.razor, PinnedPages.cs) ---------- */
.nav-row { display: flex; align-items: center; gap: 2px; }
.nav-row > .nav-item, .nav-row > .nav-quick { flex: 1; min-width: 0; }
/* Pinned and Recent shortcuts look like menu entries (pulse.css .nav-item) but are not nav-item: the menu keeps one nav-item per page. */
.nav-quick { display: flex; gap: 10px; align-items: center; color: #fff; text-decoration: none; padding: 8px 10px; border-radius: var(--radius-sm); opacity: .9; }
.nav-quick:hover { background: rgba(255, 255, 255, .10); opacity: 1; }
.nav-quick.active { background: rgba(255, 255, 255, .18); opacity: 1; font-weight: 600; }
.nav-pin { flex: none; width: 30px; height: 30px; display: grid; place-items: center; padding: 0; font-size: 15px; line-height: 1; color: #fff; background: none;
  border: 0; border-radius: var(--radius-sm); cursor: pointer; opacity: 0; }
.nav-row:hover .nav-pin, .nav-pin:focus-visible, .nav-pin.is-pinned { opacity: .75; }
.nav-pin:hover { opacity: 1; background: rgba(255, 255, 255, .12); }
@media (pointer: coarse) { .nav-pin { opacity: .5; width: 44px; height: 44px; } .nav-quick { min-height: 48px; } }
/* With a mouse the star takes no room of its own: it sits over the end of the link and shows on hover or focus (filled for a pinned page),
   so titles do not wrap in the narrow sidebar; the Pinned list at the top already shows what is pinned. Its backing matches the row behind it
   (the row's hover or current-page tint over the sidebar colour). Touch screens keep the star beside the link: there is no hover to reveal it. */
@media not (pointer: coarse) {
  .nav-row { position: relative; }
  .nav-pin { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; }
  .nav-row:hover > .nav-pin, .nav-pin:focus-visible { background: color-mix(in srgb, var(--brand-primary) 90%, #fff); }
  .nav-row > .active ~ .nav-pin { background: color-mix(in srgb, var(--brand-primary) 82%, #fff); }
  .nav-row > .nav-pin.is-pinned { opacity: 0; }
  .nav-row:hover > .nav-pin, .nav-row > .nav-pin:focus-visible { opacity: .75; }
  .nav-row > .nav-pin:hover { opacity: 1; background: color-mix(in srgb, var(--brand-primary) 78%, #fff); }
}
.nav-section { display: flex; flex-direction: column; gap: 2px; margin: 4px 0 6px; }
.nav-section-head { padding: 10px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: rgba(255, 255, 255, .7); }
.nav-section-all { border-top: 1px solid rgba(255, 255, 255, .15); margin-top: 4px; padding-top: 12px; }

/* ---------- 3. Dashboard tiles on Home (WorkflowBoard ShowTiles) ---------- */
.dash-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin: 4px 0 16px; }
.dash-tile { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "icon value" "label label" "hint hint"; align-items: center; gap: 2px 10px;
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--ink); text-decoration: none; transition: transform .12s ease, box-shadow .12s ease; }
.dash-tile:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(16, 24, 40, .12); }
.dash-tile.is-warn { border-left-color: var(--warn); }
.dash-tile.is-danger { border-left-color: var(--danger); }
.dash-tile-icon { grid-area: icon; color: var(--brand-primary); display: grid; }
.dash-tile-value { grid-area: value; font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.dash-tile.is-warn .dash-tile-value { color: var(--warn); }
.dash-tile.is-danger .dash-tile-value { color: var(--danger); }
.dash-tile-label { grid-area: label; font-weight: 600; }
.dash-tile-hint { grid-area: hint; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-all > summary { cursor: pointer; list-style: none; }
.home-all > summary::-webkit-details-marker { display: none; }
.home-all > summary::before { content: "▸ "; color: var(--muted); }
.home-all[open] > summary::before { content: "▾ "; }
.home-all[open] > summary { margin-bottom: 12px; }
@media (prefers-reduced-motion: reduce) { .dash-tile { transition: none; } .dash-tile:hover { transform: none; } }

/* ---------- 4. Tables (pulse-ui.js): sort, filter, pages, export, saved views, phone cards, empty state ---------- */
tbody[data-tt-hidden], tr[data-tt-out] { display: none; }
/* The toolbar sits in space the table itself keeps above it (!important: a wrapper's own margin, a u-mt-* utility, never shrinks it). */
table[data-tt-bar] { margin-top: 44px !important; }
.tt-layer { position: absolute; top: 0; left: 0; width: 0; height: 0; z-index: 15; }
.tt-bar { position: absolute; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 2px; box-sizing: border-box; overflow: hidden; }
.tt-bar[hidden] { display: none; }
.tt-filter { flex: 0 1 240px; min-width: 120px; height: 32px; padding: 0 10px; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); }
.tt-filter:focus { outline: 2px solid var(--focus); outline-offset: 0; }
.tt-count { font-size: 12px; color: var(--muted); white-space: nowrap; margin-right: auto; }
.tt-pager { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.tt-pager[hidden] { display: none; }
.tt-btn, .tt-views { height: 30px; padding: 0 10px; font: inherit; font-size: 13px; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer; }
.tt-btn:hover, .tt-views:hover { background: var(--surface-2); }
.tt-views { max-width: 150px; }
th[data-tt-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
th[data-tt-sort]:hover { color: var(--brand-primary); }
th[data-tt-sort]::after { content: "↕"; margin-left: 4px; font-size: 11px; opacity: .3; }
th[aria-sort="ascending"]::after { content: "↑"; opacity: 1; }
th[aria-sort="descending"]::after { content: "↓"; opacity: 1; }
th[data-tt-sort]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
/* Empty list (item 9). */
table[data-tt-empty]::after { content: attr(data-tt-empty); display: table-caption; caption-side: bottom; padding: 28px 16px; text-align: center; color: var(--muted);
  border: 1px dashed var(--line); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }
/* Phone (item 14): a table of three columns or more becomes one card per row, each value under its column's name. Long values wrap; what still
   cannot fit scrolls inside the table's own box, as before (the page itself never scrolls sideways). */
@media (max-width: 640px) {
  table[data-tt-cards], table[data-tt-cards] tbody, table[data-tt-cards] tfoot, table[data-tt-cards] tr, table[data-tt-cards] td { display: block; width: 100%; }
  table[data-tt-cards] { min-width: 0; }
  table[data-tt-cards] thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table[data-tt-cards] tbody[data-tt-hidden], table[data-tt-cards] tr[data-tt-out] { display: none; }
  table[data-tt-cards] tr { margin: 0 0 10px; padding: 8px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
  table[data-tt-cards] tfoot tr { background: var(--surface-2); font-weight: 600; }
  table[data-tt-cards] td, table[data-tt-cards] tfoot th { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; padding: 5px 0; border: 0;
    text-align: right; overflow-wrap: anywhere; word-break: break-word; min-width: 0; }
  table[data-tt-cards] td > * { min-width: 0; max-width: 100%; }
  table[data-tt-cards] td::before { content: attr(data-label); flex: none; max-width: 45%; font-weight: 600; color: var(--muted); text-align: left; }
  table[data-tt-cards] td[data-label=""]::before { content: none; }
  table[data-tt-cards] td[colspan] { display: block; text-align: center; }
  .tt-views, .tt-btn[data-tt="csv"] { display: none; }
}
@media print { .tt-layer { display: none; } table[data-tt-bar] { margin-top: 0 !important; } }

/* ---------- 6. Forms (Field.razor) ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--ink); }
.field-required { color: var(--danger); }
.field-hint { display: block; margin: 0; font-size: 12px; font-weight: 400; color: var(--muted); }
.field-error { display: block; margin: 0; font-size: 12px; font-weight: 600; color: var(--danger); }
label.field { cursor: default; font-weight: 400; }
/* An error under its field keeps the alert classes of the banner it replaces, without the banner's look. */
.field-error.alert { display: block; margin: 0; padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; color: var(--danger); font-size: 12px; font-weight: 600; }
/* The control's placeholder repeated the label: the label shows it now, so the box stays clear (the attribute stays for scripts). */
.field.field-ph input::placeholder, .field.field-ph textarea::placeholder { color: transparent; }
/* Fields side by side in a row line up on their boxes, not their labels; a field grows like the control it wraps did. */
.row:has(> .field) { align-items: flex-end; }
.row > .field { flex: 1 1 180px; }
/* A control with its own width (u-max-*, an inline width) keeps it; its field is as wide as the label or the control, whichever is wider. */
.row > .field:has(> [class*="u-max-"], > [class*="u-w-"], > [style*="width"]) { flex: 0 0 auto; }
.row > .field:has(> [class*="u-max-"], > [class*="u-w-"], > [style*="width"]) > .field-label { white-space: nowrap; }
.field > .checkbox { margin-top: 4px; }
/* A field inside a stack keeps the stack's spacing; inside a grid it fills its cell. */
.grid > .field, .form-grid > .field { align-self: start; }
.field.has-error .input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

/* ---------- 7. Theme switch (MainLayout, pulse-ui.js) ---------- */
.theme-toggle { display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; color: var(--ink); background: none; border: 1px solid transparent;
  border-radius: var(--radius-sm); cursor: pointer; }
.theme-toggle:hover { background: var(--surface-2); border-color: var(--line); }
.theme-icon::before { content: "◐"; font-size: 18px; line-height: 1; }
:root[data-theme="light"] .theme-icon::before { content: "☀"; }
:root[data-theme="dark"] .theme-icon::before { content: "☾"; }

/* ---------- 8. Confirmation dialog (pulse-ui.js) ---------- */
dialog.confirm { width: min(440px, 92vw); padding: 20px 22px 16px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
dialog.confirm::backdrop { background: rgba(15, 20, 25, .5); }
.confirm-q { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.confirm-detail { margin: 0 0 18px; color: var(--muted); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- 9. Loading placeholders ---------- */
.skeleton { display: block; min-height: 14px; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%);
  background-size: 400% 100%; animation: skeleton 1.4s ease infinite; }
@keyframes skeleton { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------- 10. Toasts (ErrorAlert with a success tone; pulse-ui.js toast()) ---------- */
.toast-host { position: fixed; z-index: 90; right: 20px; bottom: 20px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.toast { min-width: 220px; max-width: min(420px, 90vw); margin: 0; padding: 12px 16px; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--ok); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(16, 24, 40, .2); pointer-events: auto;
  animation: toast-in .2s ease-out, toast-out .4s ease-in 4s forwards; }
.toast.alert { margin: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); pointer-events: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: toast-out 0s linear 4s forwards; } }
@media (max-width: 640px) { .toast-host { left: 12px; right: 12px; bottom: 12px; align-items: stretch; } }
@media print { .toast-host { display: none; } }

/* ---------- 11. Room board drag-to-move (FrontDesk Rack.razor) ---------- */
.rack [draggable="true"] { cursor: grab; }
.rack-drop { outline: 2px dashed var(--ok); outline-offset: -3px; }
.rack-drop.is-over { outline-style: solid; box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 25%, transparent); }

/* ---------- 13. Keyboard shortcuts sheet ("?", pulse-ui.js) ---------- */
dialog.shortcuts { width: min(520px, 94vw); padding: 18px 20px 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
dialog.shortcuts::backdrop { background: rgba(15, 20, 25, .5); }
dialog.shortcuts h2 { margin: 0 0 10px; }
dialog.shortcuts td:first-child { width: 40%; white-space: nowrap; }
kbd { display: inline-block; padding: 2px 6px; font: 12px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; }

/* Dark theme: links in the brand colour are too dark on a dark page; lighten them (buttons, menu and tiles keep their own colours). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .main a:not(.btn):not(.gs-hit):not(.dash-tile), :root:not([data-theme="light"]) .topbar a:not(.btn) {
    color: color-mix(in srgb, var(--brand-primary) 35%, #ffffff); }
}
:root[data-theme="dark"] .main a:not(.btn):not(.gs-hit):not(.dash-tile), :root[data-theme="dark"] .topbar a:not(.btn) {
  color: color-mix(in srgb, var(--brand-primary) 35%, #ffffff); }

/* Figure tiles in a .kpis strip sit side by side, as in .grid-kpi (nine pages used the class without a layout, so the tiles stacked). */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); gap: 12px; margin: 12px 0; }
.tt-btn[hidden] { display: none; }
