/* App shell: top bar + grouped side menu (a drawer below 1100px), toasts, menus, in-page section nav,
 * and the touch / readability rules every page shares. Builds on the tokens in app.css. */

:root {
  --sidebar-w: 232px;
  --topbar-h: 56px;
  --ease-out: cubic-bezier(.2, .7, .2, 1);
}

/* ---------------------------------------------------------------- top bar */
.has-shell .topbar { height: var(--topbar-h); gap: var(--space-3); padding: 0 var(--space-4); }
.has-shell .brand .suffix { padding-left: var(--space-2); }
.nav-toggle { display: none; color: var(--nav-text); min-width: 40px; }

.topbar-search {
  position: relative; display: flex; align-items: center; flex: 1; max-width: 520px; margin-left: var(--space-3);
}
.topbar-search .icon { position: absolute; left: 12px; color: var(--nav-text); pointer-events: none; }
.topbar-search input {
  width: 100%; min-height: 38px; padding: 0 44px 0 36px;
  background: #2a2a28; color: #f2f0eb; border: 1px solid #3d3c38; border-radius: var(--radius-pill);
  font-size: 0.9rem;
}
.topbar-search input::placeholder { color: #9d998f; }
.topbar-search input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgb(204 162 81 / 0.25); }
.kbd {
  position: absolute; right: 10px; font: 500 11px/1 var(--mono); color: #9d998f;
  border: 1px solid #4a4944; border-radius: 4px; padding: 3px 6px;
}
.topbar-right { margin-left: auto; }

/* dropdown menus (details/summary: works without JS; JS closes them on outside click / Esc) */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 40; min-width: 200px;
  display: grid; padding: var(--space-1);
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  animation: pop-in 160ms var(--ease-out);
}
.menu-pop-right { left: auto; right: 0; }
.menu-pop a, .menu-pop button {
  display: flex; align-items: center; gap: var(--space-2); width: 100%;
  min-height: 40px; padding: 0 var(--space-3); border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text); font: inherit; font-size: 0.92rem; text-align: left; cursor: pointer;
}
.menu-pop a:hover, .menu-pop button:hover, .menu-pop a:focus-visible, .menu-pop button:focus-visible {
  background: var(--surface-2); text-decoration: none; outline: none;
}
.menu-pop form { margin: 0; }
.menu-head { padding: var(--space-2) var(--space-3) var(--space-3); border-bottom: 1px solid var(--border); margin-bottom: var(--space-1);
  font-weight: 600; display: grid; gap: 2px; }
.menu-head small { color: var(--text-muted); font-weight: 400; }
.user-chip { gap: var(--space-2); padding: 3px var(--space-3) 3px 3px; }
.avatar {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--gold); color: var(--ink); font-weight: 700; font-size: 0.85rem;
}
.icon-xs { width: 14px; height: 14px; }
.show-sm { display: none !important; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- side menu */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: calc(100dvh - var(--topbar-h)); }
.sidebar {
  position: sticky; top: var(--topbar-h); align-self: start;
  height: calc(100dvh - var(--topbar-h)); overflow-y: auto; overscroll-behavior: contain;
  padding: var(--space-3) var(--space-2) var(--space-6);
  background: var(--ink); border-right: 1px solid #000;
  scrollbar-width: thin; scrollbar-color: #3d3c38 transparent;
}
.nav-group { display: grid; gap: 2px; padding-bottom: var(--space-3); }
.nav-group + .nav-group { border-top: 1px solid #2c2b28; padding-top: var(--space-3); }
.nav-heading {
  margin: 0 0 var(--space-1); padding: 0 var(--space-3);
  color: #8f8b81; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase;
}
.sidebar a {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 40px; padding: 0 var(--space-3); border-radius: var(--radius-sm);
  color: var(--nav-text); font-size: 0.92rem; font-weight: 500;
}
.sidebar a .icon { flex: none; opacity: 0.85; }
.sidebar a:hover { background: #2a2a28; color: #fff; text-decoration: none; }
.sidebar a:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.sidebar a[aria-current="page"] { background: #2e2c26; color: var(--nav-active); box-shadow: inset 3px 0 0 var(--gold); }
.sidebar .nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .nav-count { margin-left: auto; }

.has-shell main { max-width: 1480px; width: 100%; margin: 0; padding: var(--space-5) var(--space-5) var(--space-6); }
.has-shell main:focus { outline: none; }
.scrim { display: none; }

/* below 1100px: the menu becomes a drawer */
@media (max-width: 1099px) {
  .nav-toggle { display: inline-flex; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; height: 100dvh; width: min(84vw, 300px);
    padding-top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
    transform: translateX(-102%); transition: transform 220ms var(--ease-out); box-shadow: var(--shadow-2);
  }
  .nav-open .sidebar { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgb(0 0 0 / 0.45); }
  .scrim[hidden] { display: none; }
  .has-shell main { padding: var(--space-4) var(--space-4) var(--space-6); }
}
@media (max-width: 720px) {
  .has-shell .topbar { gap: var(--space-2); padding: 0 var(--space-2); }
  .brand .suffix, .hide-sm, .kbd { display: none !important; }
  .show-sm { display: flex !important; }
  .topbar-search { margin-left: 0; min-width: 0; }
  .topbar-search input { padding-right: var(--space-3); }
  .user-chip { padding: 3px; border: 0; }
  .user-chip .icon-xs { display: none; }
}
@media (max-width: 420px) { .brand img { height: 18px; } }

/* ---------------------------------------------------------------- toasts */
.toast {
  position: fixed; z-index: 60; right: var(--space-4); bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: flex-start; gap: var(--space-3); max-width: min(460px, calc(100vw - 32px));
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--gold);
  border-radius: var(--radius); box-shadow: var(--shadow-2);
  animation: toast-in 220ms var(--ease-out);
}
.toast > div { flex: 1; padding-top: 2px; }
.toast.is-leaving { animation: toast-out 160ms ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------------------------------------------------------------- page heads */
.page-head h1 { text-wrap: balance; }
.page-head .intro.is-clamped { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.intro-toggle { background: none; border: 0; padding: 0; color: var(--link); font: inherit; font-size: 0.88rem; cursor: pointer; }
.intro-toggle:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- "on this page" */
.section-nav {
  position: sticky; top: calc(var(--topbar-h) + 6px); z-index: 20;
  display: flex; gap: var(--space-1); overflow-x: auto; scrollbar-width: none;
  margin: 0 0 var(--space-4); padding: var(--space-1);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: var(--radius-pill); box-shadow: var(--shadow-1);
}
.section-nav::-webkit-scrollbar { display: none; }
.section-nav a {
  flex: none; display: inline-flex; align-items: center; min-height: 34px; padding: 0 var(--space-3);
  border-radius: var(--radius-pill); color: var(--text-muted); font-size: 0.86rem; white-space: nowrap;
}
.section-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.section-nav a.is-current { background: var(--ink); color: var(--nav-active); }
[id] { scroll-margin-top: calc(var(--topbar-h) + 64px); }

/* ---------------------------------------------------------------- shared readability */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (min-width: 1100px) {
  .table-wrap > table > thead th { position: sticky; top: 0; z-index: 1; }
}
tbody tr:hover > td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.is-busy { position: relative; pointer-events: none; opacity: 0.75; }
.is-busy::after {
  content: ""; width: 14px; height: 14px; margin-left: var(--space-2); border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* stats: two per row on phones instead of one tall card each */
@media (max-width: 720px) {
  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: var(--space-2); }
  .grid.stats .stat .value { font-size: 1.6rem; }
  .grid.stats .stat .label { font-size: 0.68rem; }
  .page-head { margin-bottom: var(--space-4); }
  .page-head .btn-row { width: 100%; }
}

/* touch screens: every control at least 44px tall */
@media (pointer: coarse) {
  .btn, .btn-sm, input:not([type="checkbox"]):not([type="radio"]), select, .sidebar a, .menu-pop a, .menu-pop button,
  .section-nav a, .chip-link { min-height: 44px; }
  .check { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .menu-pop, .toast, .toast.is-leaving { transition: none !important; animation: none !important; }
  .is-busy::after { animation: none; }
}

/* ---------------------------------------------------------------- terminals (collapsed list) */
.terminal-summary > summary { cursor: pointer; min-height: 36px; display: flex; align-items: center; gap: var(--space-2); font-size: 0.88rem; }
.terminal-summary[open] > summary { margin-bottom: var(--space-2); }

.has-shell .topbar { flex-wrap: nowrap; }

/* ---------------------------------------------------------------- My day */
.eyebrow { margin: 0 0 var(--space-1); color: var(--text-muted); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; }
.day-head { align-items: flex-end; }
.pulse {
  display: grid; grid-template-columns: repeat(3, auto); grid-template-rows: auto auto auto; column-gap: var(--space-5);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius); background: var(--ink); color: #f2f0eb;
  border: 1px solid #000; box-shadow: inset 0 -2px 0 var(--gold);
}
.pulse:hover { text-decoration: none; filter: brightness(1.08); }
.pulse-k { grid-column: 1 / -1; color: var(--nav-text); font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 2px; }
.pulse-v { grid-row: 2; font-family: var(--display); font-size: 1.6rem; line-height: 1.1; color: var(--nav-active); }
.pulse-l { grid-row: 3; color: var(--nav-text); font-size: 0.75rem; }
.day-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.day-side { display: grid; gap: var(--space-4); }
@media (max-width: 980px) { .day-grid { grid-template-columns: minmax(0, 1fr); } .pulse { width: 100%; } }
.task-list { list-style: none; margin: 0; padding: var(--space-1); display: grid; gap: 2px; }
.task a {
  display: flex; align-items: center; gap: var(--space-3); min-height: 52px; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm); color: var(--text); border-left: 3px solid transparent;
}
.task-list.compact .task a { min-height: 44px; }
.task a:hover { background: var(--surface-2); text-decoration: none; }
.task a:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.task-crit a { border-left-color: var(--danger); }
.task-warn a { border-left-color: var(--warn); }
.task-icon { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); color: var(--text-muted); }
.task-crit .task-icon { background: var(--danger-bg); color: var(--danger-text); }
.task-warn .task-icon { background: var(--warn-bg); color: var(--warn-text); }
.task-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.task-text b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-text span { color: var(--text-muted); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.task-meta { flex: none; color: var(--text-faint); font-size: 0.8rem; white-space: nowrap; }
@media (max-width: 560px) { .task-meta { display: none; } }
.day-empty { display: grid; justify-items: center; gap: var(--space-2); color: var(--ok-text); }
.day-empty p { color: var(--text-muted); }
.quick-links { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-5); }
.search-results { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }

.handover-done > summary { cursor: pointer; display: flex; align-items: center; gap: var(--space-2); color: var(--text-muted); list-style: none; }
.handover-done > summary::-webkit-details-marker { display: none; }
.handover-done > summary:hover { color: var(--text); }
.handover-done[open] > summary { border-bottom: 1px solid var(--border); }

.has-shell .brand, .has-shell .topbar-search, .has-shell .topbar-right, .has-shell .nav-toggle { order: 0; }
.search-icon { display: none; color: var(--nav-text); }
.page-search { display: flex; gap: var(--space-2); margin: var(--space-3) 0 var(--space-2); max-width: 640px; }
.page-search input { flex: 1; min-width: 0; }
@media (max-width: 720px) {
  .topbar-search { display: none; }
  .search-icon { display: inline-flex; }
  .topbar-right { gap: var(--space-1); }
}

/* Wide content (tables, long ids) scrolls or wraps inside its card instead of widening the page. */
.card, .card > *, .card-body, details, .grid > *, .handover-body > *, .day-grid > *, .handover-side > * { min-width: 0; }
.terminal-list .mono-sm, .mono-sm { overflow-wrap: anywhere; }
main [class*="cols"] > *, main [class*="grid"] > *, main [class*="layout"] > *, main [class*="side"] > * { min-width: 0; }

/* ---------------------------------------------------------------- find operations */
.find-form { display: grid; gap: var(--space-3); }
.find-form textarea { width: 100%; min-height: 120px; font-family: var(--mono); font-size: 0.9rem; resize: vertical; }
.find-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.find-actions p { margin: 0; flex: 1; min-width: 240px; }
.find-summary { margin: var(--space-4) 0 var(--space-2); color: var(--text-muted); }
.find-value { font-family: var(--mono); font-size: 0.9rem; text-transform: none; letter-spacing: 0; }
.ops-filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; }
.ops-filters .field { min-width: 140px; }
.ops-filters .field.narrow { min-width: 90px; max-width: 120px; }
.ops-filters .field.wide { flex: 1; min-width: 200px; }
.ops-table td { vertical-align: top; }
.op-status { display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill); font-size: 0.78rem; font-weight: 600;
  text-transform: capitalize; background: var(--surface-3); color: var(--text-muted); }
.op-status.op-approved { background: var(--ok-bg); color: var(--ok-text); }
.op-status.op-declined { background: var(--danger-bg); color: var(--danger-text); }
.op-status.op-pending { background: var(--warn-bg); color: var(--warn-text); }
.op-status-lg { font-size: 0.95rem; padding: 6px 14px; }
.op-reason { max-width: 32ch; }
.op-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: var(--space-4); align-items: start; }
.op-dl { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: var(--space-2) var(--space-4); margin: 0; }
.op-dl dt { color: var(--text-muted); font-size: 0.85rem; }
.op-dl dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 520px) { .op-dl { grid-template-columns: 1fr; } .op-dl dt { margin-top: var(--space-2); } }

/* ---------------------------------------------------------------- agreements */
.review-verdict { display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-4); border-radius: var(--radius-pill); font-size: 0.95rem; }
.review-verdict.is-diff { background: var(--warn-bg); color: var(--warn-text); }
.review-verdict.is-clean { background: var(--ok-bg); color: var(--ok-text); }
.review-prod { border-top: 1px solid var(--border); padding: var(--space-3) var(--space-4); }
.review-prod.is-diff { box-shadow: inset 3px 0 0 var(--warn); }
.review-prod-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.review-count { margin-left: auto; }
.review-table tr.is-diff td { background: color-mix(in srgb, var(--warn-bg) 60%, transparent); }
.review-note { margin: 0 0 var(--space-2); }
.review-missing li { padding: var(--space-1) 0; }
.sr-ok { color: var(--ok-text); }
.drop-form { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: stretch; }
.drop-zone {
  flex: 1; min-width: 260px; display: grid; justify-items: center; gap: var(--space-1); padding: var(--space-5);
  border: 2px dashed var(--border-strong); border-radius: var(--radius); cursor: pointer; text-align: center; color: var(--text-muted);
}
.drop-zone:hover, .drop-zone.is-over { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 8%, transparent); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-zone:focus-within { outline: 2px solid var(--gold); outline-offset: 2px; }
.doc-reading { display: block; margin-top: 2px; }

.review-fields > summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.review-fields[open] > summary { margin-bottom: var(--space-1); }

/* KYB */
.kyb-findings { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.kyb-f { padding: 8px 10px; border-radius: 8px; border-left: 3px solid var(--border); background: color-mix(in srgb, var(--text-muted) 6%, transparent); line-height: 1.45; }
.kyb-f-high { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, transparent); }
.kyb-f-medium { border-left-color: var(--warn, #d99a00); background: color-mix(in srgb, var(--warn, #d99a00) 8%, transparent); }
.kyb-src { margin-left: 6px; font-size: 0.75rem; white-space: nowrap; }
.kyb-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: var(--space-3); }
.kyb-box { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.kyb-box h4 { margin: 0 0 4px; font-size: 0.85rem; }
.kyb-box p { margin: 2px 0; overflow-wrap: anywhere; }
.kyb-reasons { margin: 4px 0 0 18px; }
.kyb-notes { white-space: pre-wrap; font-size: 0.85rem; max-height: 420px; overflow: auto; padding: 8px; border: 1px solid var(--border); border-radius: 8px; margin: 6px 0; }
.kyb .table-wrap td { overflow-wrap: break-word; }
.kyb .table-wrap td:nth-child(2) { min-width: 120px; }
.kyb-skip { display: inline-block; margin-top: 4px; }
.kyb-skip > summary { list-style: none; cursor: pointer; white-space: nowrap; padding-inline: 6px; }
.kyb-skip > summary::-webkit-details-marker { display: none; }
.kyb-skip-form { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.kyb-skip-form input[type="text"] { min-width: 0; flex: 1 1 180px; }
.kyb-form p { margin: 4px 0; overflow-wrap: anywhere; }

/* the week's settlements */
.week-table td.num, .week-table th.num, .ov-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.week-table .mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem; }
.week-row.is-carried > tr:first-child { opacity: 0.65; }
.week-detail > td { padding-top: 0 !important; border-top: 0 !important; }
.week-detail summary { cursor: pointer; min-height: 28px; display: inline-flex; align-items: center; }
.week-flags { margin: 6px 0 0 18px; }

/* feedback */
.feedback-form textarea { width: 100%; }
.feedback-form .seg { display: flex; gap: 16px; border: 0; padding: 0; margin: 0 0 12px; }
.feedback-h { font-size: 1rem; margin: 0; }
.feedback-text { white-space: pre-wrap; margin: 0 0 6px; overflow-wrap: anywhere; }
.feedback-reply { margin: 8px 0 0; padding: 8px 10px; border-left: 3px solid var(--border-strong); background: var(--surface-2); border-radius: 6px; }
.feedback-answer { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.feedback-answer input[type="text"] { flex: 1 1 220px; min-width: 0; }

/* the smallest phones (320 px): tighter top bar */
@media (max-width: 359px) {
  .topbar { gap: 4px; padding-inline: 8px; }
  .topbar-right { gap: 2px; }
  .topbar .btn-sm { padding-inline: 6px; }
  .topbar .brand img { width: 112px; height: auto; }
  .topbar .brand .suffix { display: none; }
}
.runs-table input[type="text"] { min-width: 120px; }
.runs-table input[type="number"] { width: 64px; }
.runs-new td { background: color-mix(in srgb, var(--text-muted) 5%, transparent); }
.run-list { margin: 0 0 10px 18px; }
.new-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--gold, #c9a24a); vertical-align: middle; }
.avatar { position: relative; }
.new-dot-avatar { position: absolute; top: -2px; right: -2px; box-shadow: 0 0 0 2px var(--surface, #1b1b1b); }
.whats-new li { margin: 6px 0; line-height: 1.5; }
.runs-table select { min-width: 120px; }
.runs-table td:nth-child(3) select { min-width: 220px; }
.runs-table input[type="date"] { min-width: 140px; }
#plan .card-body, #plan details.disclose, .runs-form { min-width: 0; max-width: 100%; }
.runs-form .table-wrap { overflow-x: auto; max-width: 100%; }
