/* ============================================================================
   Sutton Studio harness v1 — shared components (SHIPPED asset).

   The styles behind js/dom.js + js/controls.js. Every app links, in order:
     1. design-tokens.css   (pinned tokens)
     2. app-shell.css       (canonical page chrome: header, buttons, inputs, table)
     3. components.css      (this file: pills, dropdowns, pickers, forms,
                             feedback, overlays, live search, segmented control)
     4. the app's own app.css (app-specific components ONLY)

   Consumes design-tokens.css only: no hard-coded colors or spacing. Apps never
   restyle or fork these classes; a change here is a harness release (see
   ../README.md, "Updating the harness").

   Class prefix: ui- for interactive controls. Older modules used wh-; the
   function names (shadSelect, shadDate, ...) are kept so ports are drop-in.
   ============================================================================ */

/* ---- Utilities ------------------------------------------------------------ */
.nowrap { white-space: nowrap; }
.muted { color: var(--color-label); }
.btn:disabled { opacity: .5; cursor: default; filter: none; }
.btn--danger { background: var(--pill-red-bg); color: var(--pill-red-text); }
/* White shadcn button: the DEFAULT button and the title row's main action
   (cp-projects "Create project"). Dark .btn--primary is for confirming a
   dialog (Save, Delete); gray .btn--secondary stays available. */
.btn--white {
  background: var(--color-bg); color: var(--color-text);
  border-color: var(--color-border); box-shadow: var(--shadow-sm);
}
.btn--white:hover { background: var(--color-hover); }
.btn--white .icon { color: var(--color-text); }
.input:focus, .search:focus { outline: none; border-color: var(--color-accent); box-shadow: var(--focus-ring); }

/* ---- Sticky page header (full-page apps; DESIGN.md "Main page header") ------- */
.app-header {
  position: sticky; top: 0; z-index: 50; background: var(--color-list-bg);
  margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-8)) 0; padding: var(--space-4) var(--space-8) 0;
}
.app-header .title-row { margin-bottom: var(--space-2); }
.app-header > .tab-row {   /* the tab hairline bleeds to the page edges, labels stay inset */
  margin: 0 calc(-1 * var(--space-8)); padding: 0 var(--space-8);
}
.app-header { margin-bottom: var(--space-3); }

/* ---- Pills: option-pill look by default (cp-projects detail screen) ----------
   5px rounded rectangle, mid-pastel background, near-black ink. Color still
   carries meaning (pill() maps statuses to palette keys; see dom.js). */
.pill {
  display: inline-flex; align-items: center; vertical-align: middle; gap: 2px;
  border-radius: var(--radius-opt); padding: 1px 6px; font-size: var(--fs-sm);
  line-height: 18px; font-weight: var(--fw-medium); white-space: nowrap;
  background: var(--opt-gray); color: var(--opt-ink);
}
.pill .icon { width: 12px; height: 12px; }
.pill--gray { background: var(--opt-gray); }      .pill--red { background: var(--opt-red); }
.pill--orange { background: var(--opt-orange); }  .pill--amber { background: var(--opt-amber); }
.pill--yellow { background: var(--opt-yellow); }  .pill--lime { background: var(--opt-lime); }
.pill--green { background: var(--opt-green); }    .pill--teal { background: var(--opt-teal); }
.pill--cyan { background: var(--opt-cyan); }      .pill--blue { background: var(--opt-blue); }
.pill--indigo { background: var(--opt-indigo); }  .pill--purple, .pill--violet { background: var(--opt-purple); }
.pill--magenta { background: var(--opt-magenta); } .pill--pink { background: var(--opt-pink); }
.pill--salmon { background: var(--opt-salmon); }  .pill--slate { background: var(--opt-slate); }
.pill-group { display: inline-flex; flex-wrap: wrap; gap: 4px; vertical-align: middle; }

/* ---- Notification pills (dom.js notif / notifOn) ----------------------------------------- */
.notif {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-pill);
  font-size: var(--fs-2xs); font-weight: var(--fw-semibold); line-height: 1; letter-spacing: 0; font-variant-numeric: tabular-nums;
}
.notif--attention { background: var(--notif-attention-bg); color: var(--notif-attention-ink); }
.notif--danger { background: var(--notif-danger-bg); color: var(--notif-danger-ink); }
.notif--accent { background: var(--notif-accent-bg); color: var(--notif-accent-ink); }
.notif--neutral { background: var(--notif-neutral-bg); color: var(--notif-neutral-ink); }
.notif-anchor { position: relative; display: inline-flex; }
.notif-anchor > .notif { position: absolute; top: -4px; right: -6px; height: 16px; min-width: 16px; padding: 0 4px; box-shadow: 0 0 0 2px var(--color-bg); }
.notif-dot { position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 0 2px var(--color-bg); }
.notif-dot.notif--danger { background: var(--notif-danger-bg); }
.notif-dot.notif--accent { background: var(--btn-primary-bg); }
.notif-dot.notif--attention { background: #f59e0b; }
.notif-dot.notif--neutral { background: var(--cream-500); }
.tab .notif, .st-view .notif, .peek-tab .notif { margin-left: 2px; }

/* ---- Label-above-value fields ------------------------------------------------ */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3) var(--space-4); }
.field-grid--3 { grid-template-columns: repeat(3, 1fr); }
.field-label { font-size: var(--fs-sm); color: var(--color-label); margin-bottom: 2px; }
.field-value { font-size: var(--fs-base); color: var(--color-text); }

/* ---- Progress meter ------------------------------------------------------------ */
.meter { height: 6px; border-radius: var(--radius-pill); background: var(--color-surface-alt); overflow: hidden; }
.meter-fill { height: 100%; background: var(--color-accent); border-radius: inherit; transition: width .2s ease; }

/* ---- Segmented control ------------------------------------------------------------ */
.seg { display: inline-flex; padding: 2px; border-radius: var(--radius-input); background: var(--btn-secondary-bg); }
.seg-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 var(--space-3); border: none; background: none;
  border-radius: 6px; cursor: pointer; font: inherit; font-size: var(--fs-base); font-weight: var(--fw-medium); color: var(--color-label);
}
.seg-btn .icon { width: 15px; height: 15px; }
.seg-btn--on { background: var(--color-bg); color: var(--color-text); box-shadow: var(--shadow-sm); }

/* ---- Live search (DESIGN.md golden rule 8) ------------------------------------------ */
.ui-search { position: relative; display: inline-flex; align-items: center; }
.ui-search .search { padding-right: 28px; }
.ui-search-clear {
  position: absolute; right: 4px; width: 22px; height: 22px; display: none; align-items: center; justify-content: center;
  appearance: none; border: none; background: none; cursor: pointer; border-radius: 6px; color: var(--color-label);
}
.ui-search-clear:hover { background: var(--color-hover); color: var(--color-text); }
.ui-search-clear .icon { width: 14px; height: 14px; }
.ui-search--has .ui-search-clear { display: inline-flex; }
/* Hide the browser's own clear button: the styled one above replaces it. */
.ui-search input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ---- Compact toolbar (cp-projects main screen): 28px white controls ------------------
   Everything in a .toolbar (and a smart table's toolbar) is one height: search,
   dropdowns, white buttons and icon buttons. */
.toolbar .search, .st-toolbar .search {
  height: var(--toolbar-control-h); width: var(--toolbar-search-w); font-size: var(--fs-sm); padding-left: var(--space-3);
}
.toolbar .ui-select-trigger, .st-toolbar .ui-select-trigger {
  height: var(--toolbar-control-h); min-width: 120px; max-width: 200px; font-size: var(--fs-sm); font-weight: var(--fw-medium);
}
.toolbar .btn, .st-toolbar .btn { height: var(--toolbar-control-h); font-size: var(--fs-sm); padding: 0 var(--space-3); gap: 6px; }
.toolbar .btn .icon, .st-toolbar .btn .icon { width: 14px; height: 14px; }
.toolbar .icon-ghost, .st-toolbar .icon-ghost { width: var(--toolbar-control-h); height: var(--toolbar-control-h); background: var(--color-bg); }
.toolbar .icon-ghost:hover, .st-toolbar .icon-ghost:hover { background: var(--color-hover); }
.toolbar .icon-ghost .icon, .st-toolbar .icon-ghost .icon { width: 15px; height: 15px; }
/* A dropdown whose value narrows the list wears a dark border (cp-projects). */
.ui-select.is-filtered .ui-select-trigger { border-color: var(--color-text); }
.btn .st-badge, .btn .ui-badge {
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--radius-pill); background: var(--color-accent);
  color: var(--color-on-accent); font-size: var(--fs-2xs); font-weight: var(--fw-semibold);
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---- Table helpers (the table itself ships in app-shell.css) ------------------------- */
/* Every table: a top border on the table AND its header row, and a STICKY header.
   Tables live in a .table-scroll (dataTable / smartTable build it) sized to the
   viewport, so the header sticks while rows scroll. With border-collapse the
   header's borders don't travel with the sticky cells, so they're drawn as
   inset shadows instead (no seam for rows to show through). */
.table-scroll { overflow: auto; position: relative; }
/* In #tab-body the SCROLLER bleeds to the page edges (the table inside fills it),
   so horizontal scrolling and the sticky header both work edge to edge. */
.content #tab-body .table-scroll { margin-left: calc(-1 * var(--space-8)); margin-right: calc(-1 * var(--space-8)); }
.content #tab-body .table-scroll > .table { margin: 0; width: 100%; }
.content #tab-body .table-scroll > .table th:first-child,
.content #tab-body .table-scroll > .table td:first-child { padding-left: var(--space-8); }
.content #tab-body .table-scroll > .table th:last-child,
.content #tab-body .table-scroll > .table td:last-child { padding-right: var(--space-8); }
.table thead th {
  position: sticky; top: 0; z-index: 3; background: var(--color-bg);
  border-top: 0; border-bottom: 0;
  /* One hairline above and one below, in the grid color, so the header never
     reads as a double rule. */
  box-shadow: inset 0 1px 0 var(--color-border-faint), inset 0 -1px 0 var(--color-border-faint);
}
.table th.num { text-align: right; }
.th-sort { cursor: pointer; user-select: none; }
.th-sort:hover { background: var(--color-hover); }
.th-sort .icon { width: 13px; height: 13px; margin-left: 4px; vertical-align: -2px; color: var(--color-label); }
.table-empty td { height: auto; padding: var(--space-6) var(--space-2); text-align: center; color: var(--color-label); }

/* ---- ShadCN-style dropdown / menu / date / time (DESIGN.md golden rule 5) ----------- */
.ui-select { position: relative; display: inline-block; }
.ui-select-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.ui-select-trigger {
  display: inline-flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  width: 100%; height: var(--control-height); border: 1px solid var(--color-border); border-radius: var(--radius-input);
  background: var(--color-bg); color: var(--color-text); font-family: inherit; font-size: var(--fs-base); cursor: pointer;
  padding: 0 var(--space-2) 0 var(--space-3);
}
.ui-select-trigger:hover { background: var(--color-hover); }
.ui-select-trigger:focus-visible { outline: none; border-color: var(--color-accent); box-shadow: var(--focus-ring); }
.ui-select-trigger[aria-expanded="true"] { border-color: var(--color-accent); }
.ui-select-label { flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.ui-select-placeholder { color: var(--color-muted); }
.ui-select-caret, .ui-select-lead { width: 15px; height: 15px; color: var(--color-label); flex: none; }
.ui-menu {
  position: absolute; z-index: 80; top: calc(100% + 4px); left: 0; min-width: 100%; max-height: 320px; overflow-y: auto; padding: 4px;
  background: var(--color-bg); border: 1px solid var(--color-border-faint); border-radius: var(--radius-input); box-shadow: var(--shadow-md);
}
.ui-menu--up { top: auto; bottom: calc(100% + 4px); }
/* Portaled to <body>: 100% would mean the viewport. Selects get an inline
   min-width matching their trigger (popoverOpen matchWidth). */
.ui-menu--portal { position: fixed; z-index: 9999; min-width: 0; }
/* contextMenu(): no iOS callout on a long press; the target stays lit while its menu is open. */
.has-ctx-menu { -webkit-touch-callout: none; }
.ui-menu--actions { min-width: 220px; }
.ui-menu-filter { padding: 2px 2px 6px; border-bottom: 1px solid var(--color-border-faint); margin-bottom: 4px; }
.ui-menu-filter .input { width: 100%; height: 30px; }
.ui-menu-sep { height: 1px; background: var(--color-border-faint); margin: 4px 0; }
.ui-menu-empty { padding: 6px 8px; color: var(--color-muted); font-size: var(--fs-base); }
.ui-menu-item {
  display: flex; align-items: center; gap: var(--space-2); width: 100%; appearance: none; border: none; background: none; cursor: pointer;
  text-align: left; font: inherit; font-size: var(--fs-base); color: var(--color-text); padding: 6px 8px; border-radius: 6px; white-space: nowrap;
}
.ui-menu-item:hover, .ui-menu-item--focus { background: var(--color-surface-alt); }
.ui-menu-item:disabled { opacity: .5; cursor: default; }
/* A hairline of air between rows so adjacent highlights (hover + selected) never touch. */
.ui-menu-item + .ui-menu-item { margin-top: 2px; }
.ui-menu-item--sel { background: var(--cream-100); }
.ui-menu-group {
  font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .04em; color: var(--color-muted); padding: 6px 8px 2px;
}
.ui-menu-hint { margin-left: auto; padding-left: var(--space-3); color: var(--color-muted); font-size: var(--fs-xs); }
.ui-menu { overscroll-behavior: contain; }
.ui-menu .ui-menu-sep { margin: 4px -4px; }      /* separators run full bleed */
.ui-menu .avatar { margin-right: 0; }
.ui-menu-item--sel { font-weight: var(--fw-semibold); }
.ui-menu-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.ui-menu-check { width: 16px; display: inline-flex; flex: none; margin-left: var(--space-3); color: var(--color-text); }
.ui-menu-check .icon { width: 15px; height: 15px; }
.ui-menu-ico { width: 16px; height: 16px; flex: none; color: var(--color-label); }
.ui-menu-item--danger, .ui-menu-item--danger .ui-menu-ico { color: var(--color-danger-text); }
.ui-menu-root { display: inline-flex; width: auto; }
.ui-menu-trigger {
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; appearance: none; border: none;
  background: none; cursor: pointer; border-radius: 6px; color: var(--color-label);
}
.ui-menu-trigger:hover { background: var(--color-hover); color: var(--color-text); }
.ui-menu-trigger .icon { width: 17px; height: 17px; }
.ui-cal { padding: 8px; width: 264px; }
.ui-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.ui-cal-head .icon-ghost { width: 28px; height: 28px; }
.ui-cal-title { font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.ui-cal-dows { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-bottom: 2px; }
.ui-cal-dows span { text-align: center; font-size: var(--fs-2xs); color: var(--color-label); padding: 2px 0; }
.ui-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.ui-cal-day {
  appearance: none; border: 1px solid transparent; background: none; cursor: pointer; font: inherit; font-size: var(--fs-sm);
  aspect-ratio: 1; border-radius: 6px; color: var(--color-text); display: flex; align-items: center; justify-content: center;
}
.ui-cal-day:hover { background: var(--color-hover); }
.ui-cal-day--dim { color: var(--color-muted); }
.ui-cal-day--today { border-color: var(--tone-ring); }
.ui-cal-day--sel, .ui-cal-day--sel:hover { background: var(--tone-sel); color: var(--tone-sel-ink); font-weight: var(--fw-semibold); }
.ui-cal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: 6px; }
.ui-timemenu { max-height: 260px; }

/* ---- Forms ---------------------------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3) var(--space-4); }
.form-grid--1 { grid-template-columns: 1fr; }
.form-grid--3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .form-grid, .form-grid--3, .field-grid, .field-grid--3 { grid-template-columns: 1fr; } }
.form-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.form-field--wide { grid-column: 1 / -1; }
.form-label { font-size: var(--fs-sm); color: var(--color-label); font-weight: var(--fw-medium); }
.form-label .req { color: var(--color-danger-text); }
.form-hint { margin: 0; font-size: var(--fs-sm); color: var(--color-label); }
.form-field .input, .form-field .ui-select { width: 100%; }
/* Numbers: no OS spinners (DESIGN.md form controls). */
.input[type="number"] { -moz-appearance: textfield; }
.input[type="number"]::-webkit-inner-spin-button,
.input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.ui-check {
  display: inline-flex; align-items: center; gap: var(--space-2); appearance: none; border: none; background: none; cursor: pointer;
  font: inherit; font-size: var(--fs-base); color: var(--color-text); text-align: left; padding: 2px 0;
}
.ui-check-box {
  width: 18px; height: 18px; flex: none; border-radius: 5px; border: 1.5px solid var(--color-border); background: var(--color-bg);
  display: inline-flex; align-items: center; justify-content: center; color: var(--color-on-accent);
}
.ui-check-box .icon { width: 13px; height: 13px; stroke-width: 3; }
.ui-check-box--on { background: var(--btn-primary-bg); border-color: var(--btn-primary-bg); }
.ui-switch {
  position: relative; width: 32px; height: 18px; flex: none; border-radius: var(--radius-pill); border: none; cursor: pointer;
  background: var(--color-border); transition: background .15s ease; padding: 0;
}
.ui-switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--color-bg); box-shadow: var(--shadow-sm); transition: transform .15s ease;
}
.ui-switch--on { background: var(--color-accent-bright); }
.ui-switch--on::after { transform: translateX(14px); }
.file-field { display: inline-flex; align-items: center; gap: var(--space-3); }
.file-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-trigger {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; height: var(--control-height); padding: 0 var(--space-3);
  border: 1px solid var(--color-border); border-radius: var(--radius-input); background: var(--color-bg); font-size: var(--fs-base);
}
.file-trigger:hover { background: var(--color-hover); }
.file-trigger .icon { width: 15px; height: 15px; }

/* ---- Banners, empty, loading ------------------------------------------------------------ */
.banner {
  display: block; padding: var(--space-3) var(--space-4); border: 1px solid var(--banner-border); background: var(--banner-bg);
  color: var(--banner-text); border-radius: var(--radius-input); font-size: var(--fs-base); margin-bottom: var(--space-4);
}
.banner a { color: var(--banner-link); }
.banner--danger  { background: var(--pill-red-bg);   border-color: var(--color-danger-border);  color: var(--color-danger-strong); }
.banner--warn    { background: var(--pill-amber-bg); border-color: var(--color-warn-border);    color: var(--color-warn-strong); }
.banner--success { background: var(--pill-green-bg); border-color: var(--color-success-border); color: var(--color-success-strong); }
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: var(--space-8) var(--space-4); color: var(--color-label); }
.empty-icon {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
  background: var(--color-surface-alt); color: var(--color-muted); margin-bottom: var(--space-3);
}
.empty-icon .icon { width: 22px; height: 22px; }
.empty-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--color-text); }
.empty-detail { font-size: var(--fs-sm); margin-top: 4px; max-width: 460px; }
.empty .btn { margin-top: var(--space-4); }
.loading { display: flex; align-items: center; justify-content: center; gap: var(--space-2); color: var(--color-label); padding: var(--space-8) 0; }
.icon--spin { animation: ui-spin .9s linear infinite; }
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* ---- Toasts (Sonner-style): a plain card, a small colored icon, title + muted description --- */
.toasts { position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: 200; display: flex; flex-direction: column; gap: var(--space-2); width: 356px; max-width: calc(100vw - 32px); }
.toast {
  position: relative; display: flex; align-items: flex-start; gap: 10px;
  background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius-card);
  box-shadow: 0 4px 12px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.05);
  padding: 14px 14px 14px 16px; font-size: var(--fs-base); color: var(--color-text);
  animation: toast-in .24s cubic-bezier(.2, .8, .2, 1);
}
.toast-icon { flex: none; display: inline-flex; margin-top: 1px; color: var(--color-text); }
.toast-icon .icon { width: 16px; height: 16px; stroke-width: 2; }
.toast--success .toast-icon { color: var(--color-success-text); }
.toast--error .toast-icon { color: var(--color-danger-text); }
.toast--warn .toast-icon { color: var(--color-warn-text); }
.toast-main { flex: 1; min-width: 0; }
.toast-title { font-weight: var(--fw-semibold); line-height: 1.35; }
.toast-body { line-height: 1.4; }
.toast-title + .toast-body { color: var(--color-label); font-size: var(--fs-sm); margin-top: 2px; }
.toast-action { margin-top: 10px; }
.toast .icon-ghost {
  position: absolute; top: -7px; left: -7px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--color-bg); border: 1px solid var(--color-border); color: var(--color-label);
  opacity: 0; transition: opacity .12s ease;
}
.toast:hover .icon-ghost, .toast .icon-ghost:focus-visible { opacity: 1; }
.toast .icon-ghost .icon { width: 11px; height: 11px; stroke-width: 2.25; }
.toast--leaving { animation: toast-out .18s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* ---- Modal ------------------------------------------------------------------------------ */
.modal-backdrop { position: fixed; inset: 0; z-index: 150; background: var(--color-scrim); display: flex; align-items: center; justify-content: center; padding: var(--space-5); }
.modal { background: var(--color-bg); border-radius: var(--radius-card); box-shadow: var(--shadow-md); width: 520px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column; }
.modal--wide { width: 820px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-faint); }
.modal-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.modal-body { padding: var(--space-4); overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-top: 1px solid var(--color-border-faint); }
.modal-text { margin: 0 0 var(--space-3); color: var(--color-text); }

/* ---- Side panel (peek) ----------------------------------------------------------------
   Opens from the right over the page (no dim), or centered / full page
   (mode: 'center' | 'full'). Anatomy, top to bottom:
     .peek-head    title + actions + close            (full-bleed line below)
     .peek-tabs    optional sub-tabs (Details | Chat)  (full-bleed line below)
     .peek-body    sections, each divided by a FULL-BLEED line (.peek-sec)
     .peek-foot    optional actions                    (full-bleed line above) */
.peek-scrim { position: fixed; inset: 0; z-index: 140; }
.peek-scrim--dim { background: var(--color-scrim-soft); }
.peek {
  position: fixed; top: 0; right: 0; height: 100vh; width: 500px; max-width: 94vw; z-index: 141;
  background: var(--color-bg); border-left: 1px solid var(--color-border); box-shadow: var(--shadow-md);
  display: flex; flex-direction: column; transform: translateX(105%); transition: transform .2s ease;
}
.peek--narrow { width: 400px; }
.peek--wide { width: 720px; }
.peek--xwide { width: 960px; }
.peek--open { transform: none; }
.peek--center {
  top: 50%; left: 50%; right: auto; width: min(880px, 94vw); max-width: none; height: min(88vh, 1000px);
  border: 1px solid var(--color-border); border-radius: 12px; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
  transform: translate(-50%, -48%); opacity: 0; transition: transform .18s ease, opacity .18s ease;
}
.peek--center.peek--open { transform: translate(-50%, -50%); opacity: 1; }
.peek--full { inset: 0; width: 100vw; max-width: none; height: 100vh; border-left: 0; box-shadow: none; transform: none; opacity: 0; transition: opacity .15s ease; }
.peek--full.peek--open { opacity: 1; }
.peek-head {
  flex: none; display: flex; align-items: center; gap: var(--space-2); min-height: 52px;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4); border-bottom: 1px solid var(--color-border);
}
.peek-head > .icon { color: var(--color-label); }
.peek-title { flex: 1; min-width: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peek-head-actions { display: inline-flex; align-items: center; gap: 2px; }
.peek-head-actions .icon-ghost, .peek-head > .icon-ghost { width: 30px; height: 30px; }
.peek-body { flex: 1; overflow-y: auto; padding: 0 var(--space-4) var(--space-4); }
.peek-foot { flex: none; display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-top: 1px solid var(--color-border); }
.peek--center .peek-body { padding: 0 var(--space-6) var(--space-5); }
.peek--full .peek-head { padding-left: var(--space-8); padding-right: var(--space-8); }
.peek--full .peek-body { padding: 0 max(var(--space-8), calc((100% - 900px) / 2)) var(--space-6); }
/* Sub-tabs between the header and the body: the tab row's line runs full bleed. */
.peek-tabs {
  flex: none; display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-4); border-bottom: 1px solid var(--color-border);
}
.peek--center .peek-tabs { padding: 0 var(--space-6); }
.peek--full .peek-tabs { padding: 0 max(var(--space-8), calc((100% - 900px) / 2)); }
.peek-head:has(+ .peek-tabs) { border-bottom: 0; }
.peek-tab {
  appearance: none; background: none; border: none; cursor: pointer; font-family: inherit;
  font-size: var(--fs-base); font-weight: var(--fw-medium); color: var(--tab-inactive-color);
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0; margin-bottom: -1px;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.peek-tab:hover { color: var(--color-text); }
.peek-tab--active { color: var(--color-text); font-weight: var(--fw-semibold); border-bottom-color: var(--color-accent); }
.peek-tab .icon { width: 15px; height: 15px; }
.peek-tab-count {
  font-size: var(--fs-2xs); font-weight: var(--fw-semibold); min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--radius-pill); background: var(--color-surface-alt); color: var(--color-label);
  display: inline-flex; align-items: center; justify-content: center;
}
.peek-tab--active .peek-tab-count { background: var(--banner-bg); color: var(--color-accent); }
/* Sections: each one is divided from the previous by a full-bleed line. */
.peek-sec { padding: var(--space-4) 0; border-top: 1px solid var(--color-border); margin: 0 calc(-1 * var(--space-4)); padding-left: var(--space-4); padding-right: var(--space-4); }
.peek--center .peek-sec { margin: 0 calc(-1 * var(--space-6)); padding-left: var(--space-6); padding-right: var(--space-6); }
.peek--full .peek-sec { margin: 0; padding-left: 0; padding-right: 0; }
.peek-body > .peek-sec:first-child { border-top: 0; }
.peek-sec-head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
.peek-sec-title { flex: 1; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--color-text); }
.peek-sec-head .btn { height: 26px; font-size: var(--fs-sm); padding: 0 var(--space-2); }
/* Full-bleed tables inside a section touch both panel edges. */
.peek-sec > .table, .peek-sec > .table-scroll { margin-left: calc(-1 * var(--space-4)); margin-right: calc(-1 * var(--space-4)); width: calc(100% + 2 * var(--space-4)); }
.peek-sec > .table th:first-child, .peek-sec > .table td:first-child { padding-left: var(--space-4); }
.peek-sec > .table th:last-child, .peek-sec > .table td:last-child { padding-right: var(--space-4); }
/* Label-beside-value rows (properties at the top of a record). */
.field-rows { display: flex; flex-direction: column; gap: var(--space-2); }
.field-rows .field { display: flex; align-items: center; gap: var(--space-3); min-height: var(--control-height); }
.field-rows .field-label { width: 140px; flex: none; margin: 0; }
.field-rows .field-value { flex: 1; min-width: 0; }
.field-rows .field-value > .ui-select, .field-rows .field-value > .input { width: 100%; }
/* Chat tab: the thread scrolls, the composer stays pinned at the bottom. */
.peek-body.peek-body--chat { display: flex; flex-direction: column; overflow: hidden; padding-top: var(--space-3); }

/* ---- Avatars --------------------------------------------------------------------------- */
.avatar {
  flex: none; display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;
  border-radius: 50%; font-size: var(--fs-2xs); font-weight: var(--fw-semibold); color: var(--opt-ink); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 20px; height: 20px; font-size: 9px; }
.avatar--lg { width: 32px; height: 32px; font-size: var(--fs-sm); }
.person { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.person-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Smart table (js/table.js) ------------------------------------------------------------
   Toolbar: saved-view tabs on the left; search, Group, Filter, Columns and the
   Table settings icon on the right. */
.st { position: relative; }
.st-toolbar { display: flex; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-3); flex-wrap: wrap; }
.st-views { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; min-width: 0; }
.st-controls { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.st-view {
  height: var(--toolbar-control-h); padding: 0 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: var(--radius-input); background: transparent;
  font-family: inherit; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--color-label); white-space: nowrap;
}
.st-view:hover { background: var(--color-hover); color: var(--color-text); }
.st-view--active, .st-view--active:hover { background: var(--color-surface-alt); color: var(--color-text); }
.st-view .icon { width: 14px; height: 14px; color: var(--color-label); }
.st-view--active .icon { color: var(--color-text); }
.st-view-emoji { font-size: 14px; line-height: 1; }
.st-view .st-view-shared { width: 12px; height: 12px; color: var(--color-muted); }
.st-view-add { padding: 0; width: var(--toolbar-control-h); justify-content: center; color: var(--color-muted); }
.st-view-add:hover { background: transparent; color: var(--color-text); }
.st-view-more { display: inline-flex; margin-right: -4px; padding: 2px; border-radius: 4px; }
.st-view-more:hover { background: var(--color-border-faint); }
.content #tab-body .table-scroll > .table.st-table { width: max-content; min-width: 100%; }
.table.st-table { width: max-content; min-width: 100%; }
.table.st-table { table-layout: fixed; width: max-content; min-width: 100%; }
.st-table td { height: var(--st-row-h, var(--row-height)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-table th { overflow: visible; white-space: nowrap; user-select: none; }
.st-th { position: relative; cursor: pointer; }
.st-th:hover { background: var(--color-hover); }
.st-th-inner { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; overflow: hidden; }
.st-th-label { overflow: hidden; text-overflow: ellipsis; }
.st-th .icon { width: 13px; height: 13px; color: var(--color-muted); flex: none; }
.st-th--sorted .icon { color: var(--color-accent); }
.st-th--filtered .st-th-label { color: var(--color-accent); }
.st-th.num .st-th-inner { justify-content: flex-end; width: 100%; }
.st-th--dragging { opacity: .4; }
.st-th--drop-before { box-shadow: inset 2px 0 0 var(--color-accent), inset 0 -1px 0 var(--color-border); }
.st-th--drop-after { box-shadow: inset -2px 0 0 var(--color-accent), inset 0 -1px 0 var(--color-border); }
.st-resize { position: absolute; top: 0; right: -4px; width: 10px; height: 100%; cursor: col-resize; z-index: 5; }
.st-resize::after { content: ''; position: absolute; top: 20%; right: 4px; width: 2px; height: 60%; border-radius: 1px; background: transparent; }
.st-th:hover .st-resize::after { background: var(--color-border); }
.st-resize:hover::after { background: var(--color-accent); }
body.st-resizing, body.st-resizing * { cursor: col-resize !important; user-select: none; }
.st-row { cursor: default; }
.st-row--click { cursor: pointer; }
.st-row--click:hover > td { background: var(--color-hover); }
.st-row.is-menu-open > td { background: var(--color-hover); }
.st-cell--current { background: var(--st-current-bg, var(--table-current-bg)); }
.st-th--current { background: var(--st-current-bg, var(--table-current-bg)) !important; }
.st-cell--edit { cursor: pointer; }
.st-cell--edit:hover { box-shadow: inset 0 0 0 1px var(--color-border); }
.st-cell-input { width: 100%; height: calc(var(--st-row-h, var(--row-height)) - 8px); border: 1px solid var(--color-accent); border-radius: 6px; padding: 0 6px; font: inherit; }
.st-group > td {
  cursor: pointer; background: var(--st-group-bg, var(--table-group-bg)); font-weight: var(--fw-semibold); color: var(--color-text);
  height: auto; padding-top: var(--space-2); padding-bottom: var(--space-2); overflow: visible;
}
.st-group:hover > td { filter: brightness(0.98); }
:root[data-theme="dark"] .st--custom-group .st-group > td { background: color-mix(in srgb, var(--st-group-bg) 16%, var(--color-bg)); }
:root[data-theme="dark"] .st--custom-current .st-cell--current,
:root[data-theme="dark"] .st--custom-current .st-th--current { background: color-mix(in srgb, var(--st-current-bg) 12%, var(--color-bg)) !important; }
:root[data-theme="dark"] .st-group:hover > td { filter: brightness(1.15); }
.st-group-inner { position: sticky; left: var(--space-8); display: inline-flex; align-items: center; gap: 6px; }
.st-group-inner .icon { width: 14px; height: 14px; color: var(--color-muted); }
.st-group-count { color: var(--color-muted); font-weight: var(--fw-regular); font-size: var(--fs-sm); }
.st--no-counts .st-group-count { display: none; }
.st-group--l1 > td { font-size: var(--fs-base); }
.st-group--l0 > td { font-size: var(--fs-md); }
.content #tab-body .st-table tr.st-member > td:first-child { padding-left: calc(var(--space-8) + var(--st-indent, 0px)); }
.st-empty > td { height: auto; padding: var(--space-6) var(--space-8); text-align: center; color: var(--color-muted); white-space: normal; }

/* ---- Editors used by table settings + custom columns ------------------------------------- */
.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: var(--space-1) 0 var(--space-4); }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; border: 0; padding: 0; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 0 1px var(--color-border-faint); transition: transform .1s ease;
}
.swatch:hover { transform: scale(1.08); }
.swatch--on { box-shadow: 0 0 0 2px var(--color-bg), 0 0 0 4px var(--color-text); }
.swatch--none { width: auto; height: 28px; border-radius: var(--radius-pill); padding: 0 12px; font: inherit; font-size: var(--fs-sm); color: var(--color-label); background: var(--color-bg); box-shadow: inset 0 0 0 1px var(--color-border); }
.swatch .icon { width: 14px; height: 14px; color: var(--opt-ink); }
.color-field {
  display: inline-flex; align-items: center; gap: var(--space-2); height: var(--control-height); padding: 0 var(--space-3) 0 4px;
  border: 1px solid var(--color-border); border-radius: var(--radius-input); background: var(--color-bg);
}
.color-field:focus-within { border-color: var(--color-accent); box-shadow: var(--focus-ring); }
.color-well { width: 26px; height: 26px; border: 0; padding: 0; border-radius: 6px; background: none; cursor: pointer; overflow: hidden; }
.color-well::-webkit-color-swatch-wrapper { padding: 0; }
.color-well::-webkit-color-swatch { border: 0; border-radius: 6px; }
.color-well::-moz-color-swatch { border: 0; border-radius: 6px; }
.color-hex { border: 0; outline: none; background: none; font: inherit; font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--color-text); width: 84px; text-transform: lowercase; }
.opt-dots { display: grid; grid-template-columns: repeat(8, 24px); gap: 6px; padding: 4px; }
.opt-dot { width: 22px; height: 22px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.12); cursor: pointer; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.opt-dot .icon { width: 13px; height: 13px; color: var(--opt-ink); }
.edit-list { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-2) 0 var(--space-3); }
.edit-row { display: flex; align-items: center; gap: var(--space-2); }
.edit-row > .input { flex: 1; min-width: 0; }
.edit-row .input--px { width: 110px; flex: none; }
.edit-head { display: flex; gap: var(--space-2); font-size: var(--fs-sm); color: var(--color-label); margin-top: var(--space-3); }
.hint { font-size: var(--fs-sm); color: var(--color-label); margin: 0 0 var(--space-3); }
.sort-grip { display: inline-flex; align-items: center; justify-content: center; width: 18px; flex: none; color: var(--color-muted); cursor: grab; }
.sort-grip:hover { color: var(--color-text); }
.sort-grip .icon { width: 15px; height: 15px; }
.sort-row--dragging { opacity: .4; }
.sort-row--above { box-shadow: 0 -2px 0 var(--color-accent); }
.sort-row--below { box-shadow: 0 2px 0 var(--color-accent); }

/* ---- Chat (js/chat.js): thread + rich composer with @mentions ----------------------------- */
.chat { display: flex; flex-direction: column; gap: var(--space-3); flex: 1; min-height: 0; }
.msg-thread { display: flex; flex-direction: column; gap: var(--space-3); flex: 1; min-height: 0; overflow-y: auto; padding-bottom: var(--space-2); }
.msg { display: flex; align-items: flex-start; gap: var(--space-2); }
.msg-avatar { flex: none; margin-top: 2px; display: inline-flex; }
.msg-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.msg-head { display: flex; align-items: baseline; gap: var(--space-2); }
.msg-author { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--color-text); }
.msg-time { font-size: var(--fs-xs); color: var(--color-muted); }
.msg-del { margin-left: auto; width: 22px !important; height: 22px !important; align-self: center; opacity: 0; }
.msg-del .icon { width: 14px; height: 14px; }
.msg:hover .msg-del { opacity: 1; }
.msg-body {
  font-size: var(--fs-sm); line-height: 1.5; color: var(--color-text); white-space: pre-wrap; word-break: break-word;
  background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 10px; padding: var(--space-2) var(--space-3);
}
.msg--me .msg-body { background: var(--color-surface-alt); }
.msg-body--rich { white-space: normal; }
.msg-body--rich > * + * { margin-top: 4px; }
.rc { flex: none; position: relative; border: 1px solid var(--color-border); border-radius: 12px; background: var(--color-bg); padding: var(--space-2); transition: border-color .12s, box-shadow .12s; }
.rc:focus-within { border-color: var(--color-accent); box-shadow: 0 0 0 1px var(--color-accent); }
.rc-toolbar { display: flex; align-items: center; flex-wrap: nowrap; overflow: hidden; }
.rc-tb {
  appearance: none; border: none; background: none; cursor: pointer; color: var(--color-label); display: inline-flex; align-items: center;
  justify-content: center; gap: 5px; height: 28px; min-width: 27px; flex: none; padding: 0 4px; border-radius: 6px; font: inherit; font-size: var(--fs-sm);
}
.rc-tb .icon { width: 16px; height: 16px; }
.rc-tb:hover { background: var(--color-surface-alt); color: var(--color-text); }
.rc-style { color: var(--color-text); font-weight: var(--fw-medium); padding: 0 6px; }
.rc-style .icon:last-child { width: 14px; height: 14px; }
.rc-sep { width: 1px; height: 18px; background: var(--color-border); margin: 0 4px; flex: none; }
.rc-editor {
  position: relative; min-height: 44px; max-height: 220px; overflow-y: auto; outline: none; padding: var(--space-2);
  font-size: var(--fs-sm); line-height: 1.5; color: var(--color-text); word-break: break-word;
}
.rc-editor.is-empty::before { content: attr(data-placeholder); color: var(--color-muted); pointer-events: none; position: absolute; left: var(--space-2); top: var(--space-2); }
.rc-bottom { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.rc-bottom-left, .rc-bottom-right { display: flex; align-items: center; gap: 2px; }
.rc-bottom-right { gap: var(--space-3); }
.rc-notify { font-size: var(--fs-sm); color: var(--color-label); white-space: nowrap; }
.rc-send {
  width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; padding: 0;
  border: 1px solid var(--color-border); background: var(--color-bg); color: var(--color-muted); cursor: default;
}
.rc-send .icon { width: 16px; height: 16px; }
.rc-send.is-ready { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-accent); cursor: pointer; }
.rc-editor p, .rc-editor h2, .rc-editor h3, .rc-editor blockquote, .rc-editor pre, .rc-editor ol, .rc-editor ul,
.msg-body--rich p, .msg-body--rich h2, .msg-body--rich h3, .msg-body--rich blockquote, .msg-body--rich pre, .msg-body--rich ol, .msg-body--rich ul { margin: 0; }
.rc-editor h2, .msg-body--rich h2 { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.rc-editor h3, .msg-body--rich h3 { font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.rc-editor blockquote, .msg-body--rich blockquote { border-left: 3px solid var(--color-border); padding-left: var(--space-2); color: var(--color-label); }
.rc-editor pre, .msg-body--rich pre { background: var(--color-surface-alt); border-radius: 6px; padding: var(--space-2); font-family: ui-monospace, Menlo, monospace; font-size: 12px; white-space: pre-wrap; }
.rc-editor code, .msg-body--rich code { background: var(--color-surface-alt); border-radius: 4px; padding: 0 4px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.rc-editor mark, .msg-body--rich mark { background: var(--pill-yellow-bg); color: inherit; border-radius: 2px; }
.rc-editor ol, .rc-editor ul, .msg-body--rich ol, .msg-body--rich ul { padding-left: 1.4em; }
.rc-editor a, .msg-body--rich a { color: var(--color-accent); text-decoration: underline; }
.rc-pop {
  position: absolute; left: 0; right: 0; z-index: 30; display: flex; flex-direction: column; gap: 2px; padding: var(--space-1);
  background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius-card); box-shadow: var(--shadow-md);
  max-height: 260px; overflow-y: auto; overscroll-behavior: contain; bottom: calc(100% + 4px);
}
.rc-pop--emoji { flex-direction: row; flex-wrap: wrap; width: 264px; right: auto; }
.rc-pop--style, .rc-pop--more { right: auto; min-width: 200px; }
.rc-emoji { border: none; background: none; cursor: pointer; font-size: 18px; width: 32px; height: 32px; border-radius: 6px; }
.rc-emoji:hover { background: var(--color-surface-alt); }
.rc-opt {
  display: flex; align-items: center; gap: var(--space-2); width: 100%; text-align: left; border: none; background: none; cursor: pointer;
  padding: 6px var(--space-2); border-radius: var(--radius-input); font: inherit; font-size: var(--fs-sm); color: var(--color-text);
}
.rc-opt .icon { width: 15px; height: 15px; color: var(--color-label); flex: none; }
.rc-opt.is-active, .rc-opt:hover { background: var(--color-surface-alt); }
.rc-opt-name { font-weight: var(--fw-medium); white-space: nowrap; flex: 1 1 auto; }
.rc-opt-sub { color: var(--color-label); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.rc-check { margin-left: auto; display: inline-flex; }
.mention { color: var(--pill-blue-text); background: var(--pill-blue-bg); border-radius: 4px; padding: 0 3px; font-weight: var(--fw-medium); white-space: nowrap; }
.mention--me { color: var(--pill-yellow-text); background: var(--pill-yellow-bg); }

/* ---- Slim scrollbars (app-wide) -------------------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--color-border) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--color-muted); background-clip: content-box; }
