/* ============================================================================
 * Kairos Superadmin — shared UX component foundation (SA-UX-A1)
 *
 * Dependency-free presentation primitives. Styled entirely through the existing
 * Superadmin design tokens (--panel/--text/--primary/--line/--muted/--good/
 * --warn/--danger and the --kairos-* accents from superadmin-kairos-skin.css),
 * so components inherit the dark-purple identity by construction. Light-mode
 * fallbacks are supplied for pages viewed before the skin repaints the tokens.
 *
 * Load ORDER: after the page's inline scaffold, BEFORE superadmin-kairos-skin.css
 * so the skin remains the identity authority. These .sa-* classes are new and are
 * never remapped by the skin — only the token vars they consume are.
 * ==========================================================================*/

:root {
  --sa-good-fg: var(--kairos-good, #1f9d7a);
  --sa-warn-fg: var(--kairos-warn, #a9761a);
  --sa-danger-fg: var(--kairos-danger, #c0392b);
  --sa-info-fg: var(--kairos-purple-soft, #5c39c0);
  --sa-radius: 12px;
  --sa-touch: 44px;
}

/* --- Visually-hidden (accessible labels / captions) ----------------------- */
.sa-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* === 1. STATUS BADGE ======================================================= */
/* Meaning is NEVER color-only: every badge carries a text label and a leading
 * shape (● dot) so it is legible in monochrome and to color-blind users. */
.sa-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; line-height: 1.4;
  border: 1px solid var(--line, #e7e9f2);
  background: var(--accent, rgba(167,139,250,.14));
  color: var(--text, #1f2430);
  white-space: nowrap;
}
.sa-badge::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: currentColor; flex: 0 0 auto;
}
.sa-badge--neutral { color: var(--muted, #69707d); }
.sa-badge--info    { color: var(--sa-info-fg); background: var(--accent, rgba(167,139,250,.14)); }
.sa-badge--success { color: var(--sa-good-fg); background: var(--good, #dff5e8); }
.sa-badge--warning { color: var(--sa-warn-fg); background: var(--warn, #fff4d6); }
.sa-badge--danger  { color: var(--sa-danger-fg); background: var(--danger, #ffe2e2); }
.sa-badge--unavailable { color: var(--muted, #69707d); background: transparent; border-style: dashed; }
.sa-badge--unknown { color: var(--muted, #69707d); }
.sa-badge--unknown::before { border-radius: 2px; } /* square dot = "unknown", not just grey */

/* === 2. STATE PANEL ======================================================== */
.sa-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center;
  padding: 32px 20px; border-radius: var(--sa-radius);
  border: 1px dashed var(--line, #e7e9f2);
  background: var(--panel, #fff);
  color: var(--muted, #69707d);
}
.sa-state[hidden] { display: none !important; }
.sa-state__icon { font-size: 26px; line-height: 1; }
.sa-state__title { font-size: 15px; font-weight: 800; color: var(--text, #1f2430); margin: 0; }
.sa-state__msg { font-size: 13px; margin: 0; max-width: 52ch; }
.sa-state__action { margin-top: 6px; }
.sa-state--error  { border-style: solid; border-color: var(--sa-danger-fg); }
.sa-state--error  .sa-state__icon { color: var(--sa-danger-fg); }
.sa-state--blocked { border-style: solid; border-color: var(--sa-warn-fg); }
.sa-state--partial { border-style: solid; border-color: var(--sa-warn-fg); }
.sa-state--unavailable .sa-state__icon { color: var(--muted, #69707d); }

/* === 3. SKELETON =========================================================== */
.sa-skel {
  display: block; border-radius: 6px;
  background: linear-gradient(90deg,
    var(--line, #e7e9f2) 25%,
    var(--accent, rgba(167,139,250,.14)) 37%,
    var(--line, #e7e9f2) 63%);
  background-size: 400% 100%;
  animation: sa-skel-shimmer 1.4s ease infinite;
}
.sa-skel--text { height: 12px; margin: 6px 0; }
.sa-skel--line { height: 14px; }
.sa-skel--pill { height: 20px; width: 72px; border-radius: 999px; }
.sa-skel-row { display: flex; gap: 14px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line, #e7e9f2); }
.sa-skel-row > .sa-skel { flex: 1; }
.sa-skel-card { padding: 16px; border: 1px solid var(--line, #e7e9f2); border-radius: var(--sa-radius); }
@keyframes sa-skel-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) {
  .sa-skel { animation: none; background: var(--line, #e7e9f2); }
}

/* === 4. TOOLBAR / FILTER GROUP ============================================= */
.sa-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 12px; border-radius: var(--sa-radius);
  background: var(--panel, #fff); border: 1px solid var(--line, #e7e9f2);
}
.sa-toolbar__search { flex: 1 1 220px; min-width: 160px; }
.sa-toolbar__filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.sa-toolbar input, .sa-toolbar select {
  min-height: var(--sa-touch);
  padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line, #e7e9f2);
  background: var(--panel, #fff); color: var(--text, #1f2430);
  font: inherit;
}
.sa-toolbar__meta { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.sa-toolbar__count { font-size: 12px; font-weight: 700; color: var(--muted, #69707d); }
.sa-btn-reset {
  min-height: var(--sa-touch); min-width: var(--sa-touch);
  padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line, #e7e9f2);
  background: transparent; color: var(--text, #1f2430); font: inherit; font-weight: 700;
}
.sa-btn-reset:hover { background: var(--accent, rgba(167,139,250,.14)); }
@media (max-width: 700px) {
  .sa-toolbar { flex-direction: column; align-items: stretch; }
  .sa-toolbar__filters { display: grid; grid-template-columns: 1fr 1fr; }
  .sa-toolbar__meta { margin-left: 0; justify-content: space-between; }
  .sa-toolbar select, .sa-toolbar input { width: 100%; }
}
@media (max-width: 420px) {
  .sa-toolbar__filters { grid-template-columns: 1fr; }
}

/* === 5. DATA TABLE FOUNDATION ============================================= */
.sa-table-wrap {
  border: 1px solid var(--line, #e7e9f2);
  border-radius: var(--sa-radius);
  background: var(--panel, #fff);
  overflow: hidden;
}
.sa-table-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line, #e7e9f2);
}
.sa-table-head__title { font-size: 14px; font-weight: 800; color: var(--text, #1f2430); }
/* Horizontal scroll is CONTAINED here — never the page body. */
.sa-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.sa-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sa-table caption { text-align: left; }
.sa-table th, .sa-table td { padding: 10px 12px; text-align: left; vertical-align: top; }
.sa-table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel, #fff); color: var(--muted, #69707d);
  font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
  border-bottom: 1px solid var(--line, #e7e9f2); white-space: nowrap;
}
.sa-table tbody tr { border-bottom: 1px solid var(--line, #e7e9f2); }
.sa-table tbody tr:last-child { border-bottom: 0; }
.sa-table-row-action {
  min-height: 36px; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line, #e7e9f2); background: transparent;
  color: var(--text, #1f2430); font: inherit; font-weight: 700; text-decoration: none;
  display: inline-flex; align-items: center;
}
.sa-table-row-action:hover { background: var(--accent, rgba(167,139,250,.14)); }

/* === 6. DRAWER / DIALOG PRIMITIVE ========================================= */
.sa-drawer-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(7, 5, 17, .55);
  opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s ease;
}
.sa-drawer-backdrop.is-open { opacity: 1; visibility: visible; }
.sa-drawer {
  position: fixed; top: 0; right: 0; z-index: 1001;
  height: 100vh; width: min(480px, 100vw);
  display: flex; flex-direction: column;
  background: var(--panel, #fff); color: var(--text, #1f2430);
  border-left: 1px solid var(--line, #e7e9f2);
  box-shadow: var(--kairos-shadow, -18px 0 48px rgba(0,0,0,.25));
  transform: translateX(100%); transition: transform .24s var(--kairos-ease-loop, ease);
  outline: none;
}
.sa-drawer.is-open { transform: translateX(0); }
.sa-drawer__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 18px 20px; border-bottom: 1px solid var(--line, #e7e9f2);
}
.sa-drawer__title { margin: 0; font-size: 18px; font-weight: 800; }
.sa-drawer__close {
  min-width: var(--sa-touch); min-height: var(--sa-touch);
  border: 0; background: transparent; color: var(--muted, #69707d);
  font-size: 20px; cursor: pointer; border-radius: 10px;
}
.sa-drawer__close:hover { background: var(--accent, rgba(167,139,250,.14)); color: var(--text, #1f2430); }
.sa-drawer__body { padding: 20px; overflow-y: auto; flex: 1; }
body.sa-scroll-lock { overflow: hidden !important; }
@media (max-width: 640px) {
  /* Mobile: full-screen sheet from the bottom-safe full height. */
  .sa-drawer { width: 100vw; border-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .sa-drawer, .sa-drawer-backdrop { transition: none; }
}

/* === 7. FORM-FIELD PRIMITIVES ============================================= */
.sa-field { display: block; margin-bottom: 16px; }
.sa-field__label { display: block; font-size: 13px; font-weight: 700; color: var(--text, #1f2430); margin-bottom: 6px; }
.sa-field__hint { font-size: 11px; font-weight: 600; color: var(--muted, #69707d); }
.sa-field__help { display: block; font-size: 12px; color: var(--muted, #69707d); margin-top: 6px; }
.sa-field__error { display: block; font-size: 12px; font-weight: 700; color: var(--sa-danger-fg); margin-top: 6px; }
.sa-field__control {
  width: 100%; min-height: var(--sa-touch);
  padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--line, #e7e9f2);
  background: var(--panel, #fff); color: var(--text, #1f2430); font: inherit;
}
.sa-field__control:disabled, .sa-field__control[readonly] {
  background: var(--accent, rgba(167,139,250,.14)); cursor: not-allowed; opacity: .8;
}
.sa-field--invalid .sa-field__control { border-color: var(--sa-danger-fg); }

/* === Shared focus-visible + touch contract ================================ */
.sa-badge, .sa-btn-reset, .sa-table-row-action, .sa-drawer__close,
.sa-toolbar input, .sa-toolbar select, .sa-field__control,
[data-sa-drawer-open] {
  outline-offset: 2px;
}
.sa-btn-reset:focus-visible, .sa-table-row-action:focus-visible,
.sa-drawer__close:focus-visible, .sa-toolbar input:focus-visible,
.sa-toolbar select:focus-visible, .sa-field__control:focus-visible,
[data-sa-drawer-open]:focus-visible {
  outline: 2px solid var(--primary, #4b2aad);
  outline-offset: 2px;
}
