/* S9 styles (s9-settings) -- consumes pomio.css tokens only; no new global tokens here. */

/* ---- A1 sticky settings navigation ------------------------------------------
   Desktop (> 820px): vertical list, sticky just below the 56px topbar. It gets
   its own max-height + scroll so every item (14 for an admin) stays reachable
   on short viewports; the section column is unaffected (no layout shift).
   <= 820px: the horizontal chip row sticks directly under the sticky topbar
   (z 60) and stays below the bottom-nav (z 80) and drawers/modals (100+). */
.settings-nav {
  position: sticky;
  top: calc(var(--header-h) + 16px);
  max-height: calc(100vh - var(--header-h) - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: 2px; /* room for the 2px focus ring inside the scroll box */
}
.settings-nav a { flex: none; }
/* Sticky is bounded by its grid area (the row = the sections column), which
   ends where the tab section's 96px bottom padding starts (crm.css
   `main > section`). Grow the row over that padding (net layout height
   unchanged) so, at the very end of the page, a tall nav is not pushed up
   under the topbar. */
@media (min-width: 821px) {
  .settings-layout { margin-bottom: -96px; }
  .settings-sections { padding-bottom: 96px; }
}
.settings-nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; box-shadow: inset 0 0 0 3px var(--focus-edge, transparent); }

@media (max-width: 820px) {
  .settings-layout { gap: 12px; }
  .settings-nav {
    position: sticky;
    top: var(--header-h);
    z-index: 40;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    /* full-bleed bar over the section padding (main > section: 12px sides) */
    margin: 0 -12px;
    padding: 8px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    scroll-padding-inline: 12px;
  }
  .settings-nav a.active { box-shadow: inset 0 -3px 0 var(--accent); border-color: var(--accent-text); }
  /* a jumped-to section lands below topbar + sticky chip row (8 + 40 + 8 + 1px) */
  .st-anchor, .settings-section { scroll-margin-top: calc(var(--header-h) + 57px + 12px); }
}

@media (prefers-reduced-motion: reduce) {
  .settings-nav { scroll-behavior: auto; }
}

/* ---- shared small bits --------------------------------------------------- */
.st9-sub { margin: 0 0 8px; font-size: 15px; }
.st9-notice { margin: 8px 0 12px; padding: 8px 10px; border-radius: var(--radius-control); background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 13px; }
.st9-danger-text { color: var(--danger-text) !important; }
.st9-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.st9-logo-preview { max-height: 40px; margin: 0; display: block; background: #fff; border-radius: 6px; padding: 4px; }
.st9-logo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 12px; }
.st9-logo-row .btn-sm { min-height: var(--tap-primary); }

/* ---- A8 brand colours ---------------------------------------------------- */
.st9-brand-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; align-items: start; }
.st9-color-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.st9-color-row input[type=color] { flex: none; width: 48px; min-width: 48px; height: var(--tap); cursor: pointer; }
.st9-color-row .st9-hex { flex: 1 1 110px; width: auto; min-width: 0; max-width: 150px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .02em; }
.st9-color-row .st9-hex::placeholder { text-transform: none; font-family: var(--font-ui); }
.st9-color-row .btn-sm { min-height: var(--tap); }
.st9-hex[aria-invalid="true"] { border-color: var(--danger-text) !important; }
.st9-brand-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.st9-brand-actions button { min-height: var(--tap); }
#st9-brand-inuse { margin: 10px 0 0; font-variant-numeric: tabular-nums; }

/* Live preview: two mini cards with their OWN palette (a copy of the pomio.css
   Signal/Voltage values), so both themes are visible whatever the app theme
   is. Brand tokens arrive as --pv-accent* inline on the card only
   (settings.js update()); the document is never touched. Semantic colours
   are fixed Pomio values on purpose (brand next to danger/warning/success). */
.st9-preview { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.st9-pv {
  margin: 0; padding: 10px; border-radius: var(--radius-card); border: 1px solid var(--pv-border);
  background: var(--pv-bg); color: var(--pv-text); font-size: 12px; min-width: 0;
  --pv-accent: #C8FF3D; --pv-accent-hover: #D3FF64; --pv-accent-ink: #0F172A; --pv-accent-soft: rgba(200, 255, 61, .22); --pv-accent-text: #4D7C0F; --pv-tenant-accent: #C8FF3D;
}
.st9-pv[data-pv="light"] {
  --pv-bg: #F4F6F8; --pv-surface: #FFFFFF; --pv-text: #0F172A; --pv-muted: #64748B; --pv-border: #E2E8F0; --pv-border-strong: #CBD5E1;
  --pv-danger-text: #B91C1C; --pv-danger-soft: rgba(220, 38, 38, .09);
  --pv-warning-text: #B45309; --pv-warning-soft: rgba(245, 158, 11, .14);
  --pv-success-text: #047857; --pv-success-soft: rgba(16, 185, 129, .12);
}
.st9-pv[data-pv="dark"] {
  --pv-bg: #0A0A0F; --pv-surface: #14141C; --pv-text: #FFFFFF; --pv-muted: #9CA3AF; --pv-border: #2A2A34; --pv-border-strong: #3A3A46;
  --pv-danger-text: #F87171; --pv-danger-soft: rgba(248, 113, 113, .14);
  --pv-warning-text: #FBBF24; --pv-warning-soft: rgba(245, 158, 11, .16);
  --pv-success-text: #34D399; --pv-success-soft: rgba(16, 185, 129, .16);
}
.st9-pv-title { font-weight: 700; font-size: 12px; color: var(--pv-muted); margin: 0 0 8px; }
.st9-pv-nav { display: flex; gap: 4px; padding: 4px; border-radius: 8px; background: var(--pv-surface); border: 1px solid var(--pv-border); margin-bottom: 8px; }
.st9-pv-navitem { flex: 1; min-width: 0; padding: 5px 6px; border-radius: 6px; color: var(--pv-muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st9-pv-navitem.is-active { background: var(--pv-accent-soft); color: var(--pv-text); box-shadow: inset 3px 0 0 var(--pv-accent); }
.st9-pv-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.st9-pv-btn { display: inline-flex; align-items: center; min-height: 26px; padding: 3px 10px; border-radius: 8px; font-weight: 700; background: var(--pv-accent); color: var(--pv-accent-ink); border: 1px solid var(--pv-accent); }
.st9-pv-btn.is-ghost { background: var(--pv-surface); color: var(--pv-text); border-color: var(--pv-border-strong); font-weight: 600; }
.st9-pv-link { color: var(--pv-accent-text); text-decoration: underline; font-weight: 600; }
.st9-pv-badge { padding: 1px 8px; border-radius: 999px; background: var(--pv-accent-soft); color: var(--pv-text); border: 1px solid var(--pv-tenant-accent); font-weight: 600; }
.st9-pv-focus { padding: 2px 8px; border-radius: 6px; background: var(--pv-surface); color: var(--pv-text); border: 1px solid var(--pv-accent-text); box-shadow: 0 0 0 3px var(--pv-accent-soft); }
.st9-pv-sem span { padding: 1px 8px; border-radius: 999px; font-weight: 600; }
.st9-pv-sem-danger { background: var(--pv-danger-soft); color: var(--pv-danger-text); }
.st9-pv-sem-warning { background: var(--pv-warning-soft); color: var(--pv-warning-text); }
.st9-pv-sem-success { background: var(--pv-success-soft); color: var(--pv-success-text); }

@media (max-width: 820px) {
  .st9-brand-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 420px) {
  .st9-preview { grid-template-columns: minmax(0, 1fr); }
  .st9-brand-actions button { width: 100%; }
}

/* ---- confirm dialog (<dialog>, settings.js confirmDialog) --------------- */
.st9-dialog {
  width: min(460px, calc(100vw - 32px)); max-width: calc(100vw - 32px); padding: 20px; border: 1px solid var(--border);
  border-radius: var(--radius-card); background: var(--surface); color: var(--text); box-shadow: var(--shadow-pop);
}
.st9-dialog::backdrop { background: var(--overlay, rgba(15, 23, 42, .5)); }
.st9-dialog h2 { margin: 0 0 8px; font-size: 18px; }
.st9-dialog-text { margin: 0; color: var(--muted); font-size: 14px; }
.st9-dialog .modal-actions button { min-height: var(--tap); }

/* ---- A9 company categories ------------------------------------------------ */
.st9-cat-list { list-style: none; margin: 0 0 12px; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-card); }
.st9-cat-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-top: 1px solid var(--border); min-width: 0; }
.st9-cat-row:first-child { border-top: 0; }
.st9-cat-row.is-archived .st9-cat-name { color: var(--muted); }
.st9-cat-pos { flex: none; width: 26px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.st9-cat-main { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.st9-cat-actions { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.st9-cat-actions .btn-sm, .st9-cat-edit .btn-sm { min-height: var(--tap); }
.st9-icon-btn { min-width: var(--tap); justify-content: center; font-size: 16px; }
.st9-cat-edit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.st9-cat-edit input { flex: 1 1 180px; min-width: 0; }
.st9-cat-edit .ua-field-error { flex-basis: 100%; }
.st9-cat-new { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.st9-cat-new input { flex: 1 1 220px; min-width: 0; }
.st9-cat-new button { min-height: var(--tap); }
.st9-cat-new .ua-field-error { flex-basis: 100%; }
@media (max-width: 560px) {
  .st9-cat-row { flex-wrap: wrap; }
  .st9-cat-main { flex-basis: calc(100% - 36px); }
  .st9-cat-actions { flex-basis: 100%; justify-content: flex-start; padding-left: 36px; }
  .st9-cat-new button { width: 100%; }
}

/* ---- A3 deactivate dialog: ownership impact + decision (usersAccess.js) --- */
.ua-own { margin-top: 12px; }
.ua-own-title { margin: 0 0 6px; font-size: 14px; }
.ua-own-list { margin: 0 0 8px; padding-left: 20px; font-size: 14px; }
.ua-own-list li { margin: 2px 0; }
.ua-own-note { margin: 6px 0; font-size: 13px; color: var(--muted); }
.ua-own-note p { margin: 0; }
.ua-own-autos { margin: 4px 0 0; padding-left: 20px; overflow-wrap: anywhere; }
.ua-own-choice { border: 0; margin: 12px 0 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.ua-own-choice legend { font-weight: 700; font-size: 13px; margin-bottom: 6px; padding: 0; }
.ua-own-opt { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.ua-own-opt select { width: 100%; min-height: var(--tap); padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-control); background: var(--input-bg); color: var(--text); font-size: 14px; }
.ua-own-status { min-height: 1.2em; margin: 10px 0 0; font-variant-numeric: tabular-nums; }
.ua-own-status:empty { display: none; }
.ua-modal .ua-own-choice .ua-role-opt { min-height: var(--tap); }

/* 375px: 44px tap targets for everything these S9 sections add */
@media (max-width: 820px) {
  .st9-color-row input, .st9-color-row .btn-sm, .st9-brand-actions button,
  .st9-cat-actions .btn-sm, .st9-cat-edit .btn-sm, .st9-cat-edit input, .st9-cat-new input, .st9-cat-new button,
  .ua-own-opt select, .ua-modal .ua-own-choice .ua-role-opt,
  #st9-brand input.st9-hex, #st9-cat input { min-height: var(--tap-primary); }
  .st9-color-row input[type=color], .st9-icon-btn { min-width: var(--tap-primary); height: var(--tap-primary); }
}
