/* ==========================================
   Users (UI-REST), approved Graphite mockup 03/10/2026. Loaded after graphite.css; page pieces only, scoped
   under .us; colours come from --g-* tokens so Dark and Light follow the released palette.
   ========================================== */

:root, [data-theme="dark"] {
    --us-skin: #18191c;
    --us-r-SuperAdmin: #c3b4dc; --us-r-Admin: #eeb39d; --us-r-Operator: #a9c7d8; --us-r-Viewer: #a4a5ad;
}
[data-theme="light"] {
    --us-skin: #ffffff;
    --us-r-SuperAdmin: #6b559a; --us-r-Admin: #97492f; --us-r-Operator: #2c5f7c; --us-r-Viewer: #5c5b62;
}

/* Toast sits outside .g-app content flow: same icon rule as graphite.css. */
.us .g-modal svg, .us-toast svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.g-main { color: var(--g-text); }
.us .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.us > :not(.g-modal-backdrop):not(.g-modal):not(.sd-panel-scrim):not(.sd-panel):not(.us-toast) { max-width: 1320px; margin-left: auto; margin-right: auto; }
.us-actions .g-btn.bad { color: var(--g-bad); }
.us-dim { color: var(--g-muted); }

/* ---- Head ---- */
.us-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.us-head-main { min-width: 0; }
.us-head h1 { margin: 6px 0 0; font-size: 33px; font-weight: 550; line-height: 1.2; letter-spacing: -1.2px; outline: none; }
.us-sub { margin-top: 7px; font-size: 12.5px; color: var(--g-muted); }
.us-sub b { color: var(--g-text-2); font-weight: 550; }
.us-ro { display: inline-flex; align-items: center; gap: 5px; color: var(--g-text-2); }
.us-ro svg:not([width]) { width: 13px; height: 13px; }
.us-head-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.us-head-actions .g-btn { height: 38px; }
.us-head-actions .g-icon-btn { width: 38px; height: 38px; }
.us-btn-primary { border: 1px solid var(--g-coral-line); background: var(--g-coral-bg); color: var(--g-coral-ink); font-weight: 500; }
.us-btn-primary:hover:not(:disabled) { border-color: var(--g-coral); }
.us-btn-primary:disabled, .g-btn:disabled { opacity: .55; cursor: default; }
.us-btn-danger { border: 1px solid var(--g-bad); background: var(--g-bad-bg); color: var(--g-bad); }
.us-btn-warn { border: 1px solid var(--g-warn); background: var(--g-warn-bg); color: var(--g-warn); }

/* ---- Alerts (refresh failed, write failed) ---- */
.us-alert { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--g-line); background: var(--g-panel); font-size: 12.5px; color: var(--g-text-2); }
.us-alert svg { width: 16px; height: 16px; flex: none; }
.us-alert span { flex: 1; }
.us-alert.warn { border-color: #554331; background: var(--g-warn-bg); } .us-alert.warn svg { color: var(--g-warn); }
.us-alert.bad { border-color: #5a3531; background: var(--g-bad-bg); } .us-alert.bad svg { color: var(--g-bad); }
[data-theme="light"] .us-alert.warn, [data-theme="light"] .us-alert.bad { border-color: currentColor; color: var(--g-text); }
.us-alert .g-btn { height: 30px; }

/* ---- Toolbar ---- */
.us .sd-toolbar { padding-top: 0; }
.us .sd-seg .n { margin-left: 2px; font-variant-numeric: tabular-nums; }
.us .sd-search { flex: 0 1 320px; }
.us-clear { margin-left: auto; padding: 4px 2px; border: 0; background: none; color: var(--g-coral-ink); font-size: 12.5px; cursor: pointer; }
.us-clear:hover { text-decoration: underline; }

/* ---- Table ---- */
.us-table { min-width: 720px; }
.sd-work.has-panel .us-table { min-width: 600px; }
.us-person { display: flex; align-items: center; gap: 11px; min-width: 0; }
.us-avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%; border: 1px solid var(--g-line); background: var(--g-hover); color: var(--g-text-2); font-size: 12px; font-weight: 600; letter-spacing: .3px; }
.us-avatar.off { opacity: .55; }
.us-avatar.lg { width: 44px; height: 44px; font-size: 15px; }
.us-person-text { min-width: 0; }
.us-name { display: block; font-weight: 500; color: var(--g-text); overflow: hidden; text-overflow: ellipsis; }
.us-name.none { color: var(--g-muted); font-weight: 400; font-style: italic; }
.us-email { display: block; font-size: 12px; color: var(--g-muted); overflow: hidden; text-overflow: ellipsis; }
.us-you { margin-left: 6px; padding: 0 5px; border-radius: 4px; border: 1px solid var(--g-coral-line); background: var(--g-coral-bg); color: var(--g-coral-ink); font-size: 10.5px; font-weight: 500; line-height: 16px; vertical-align: 1px; }
.us-role { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--g-text-2); }
.us-role i { width: 7px; height: 7px; border-radius: 2px; background: var(--rc); flex: none; }
.us-role.r-SuperAdmin { --rc: var(--us-r-SuperAdmin); } .us-role.r-Admin { --rc: var(--us-r-Admin); }
.us-role.r-Operator { --rc: var(--us-r-Operator); } .us-role.r-Viewer { --rc: var(--us-r-Viewer); }
.us-when { display: block; }
.us-when small { display: block; font-size: 11.5px; color: var(--g-muted); }
.us-lock { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; font-size: 11px; color: var(--g-muted); }
.us .us-lock svg { width: 12px; height: 12px; }
.us-table tr.off td:not(:first-child) { color: var(--g-muted); }
.us-table .m-cell { display: none; }

/* Skeleton */
.us-skel { margin-top: 2px; }
.us-skel-row { display: flex; align-items: center; gap: 24px; height: 52px; padding: 0 16px; border-bottom: 1px solid var(--g-line-soft); }
.us-skel-row i { display: block; height: 10px; border-radius: 5px; background: var(--g-hover); }
@media (prefers-reduced-motion: no-preference) {
    .us-skel-row i { animation: us-pulse 1.4s ease-in-out infinite; }
    @keyframes us-pulse { 50% { opacity: .45; } }
}

/* ---- Panel ---- */
.us-panel-id { display: flex; align-items: center; gap: 12px; padding-top: 14px; }
.us-panel-id > div { min-width: 0; }
.us-panel-id .us-email { font-size: 12.5px; }
.us-panel .sd-facts dd .us-role { justify-content: flex-end; }
.us-role-note { margin: 4px 0 0; font-size: 12px; line-height: 1.5; color: var(--g-muted); }
.us-actions { display: grid; gap: 6px; margin-top: 4px; }
.us-actions .g-btn { justify-content: flex-start; height: 36px; width: 100%; }
.us-actions .g-btn svg { width: 15px; height: 15px; }
.us-actions .g-btn small { margin-left: auto; font-size: 11px; color: var(--g-muted); }
.us-note { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0 0; padding: 9px 10px; border: 1px solid var(--g-line-soft); border-radius: 8px; font-size: 12px; line-height: 1.5; color: var(--g-text-2); }
.us-note svg { width: 15px; height: 15px; margin-top: 1px; flex: none; color: var(--g-muted); }
.us-note.warn { border-color: #554331; background: var(--g-warn-bg); } .us-note.warn svg { color: var(--g-warn); }
[data-theme="light"] .us-note.warn { border-color: var(--g-warn); }
.us-panel .sd-panel-foot { justify-content: flex-start; }
/* graphite.css draws .sd-facts dividers with a fixed dark colour; follow the theme token in Light (also a Graphite backlog item). */
[data-theme="light"] .us-panel .sd-facts > div { border-bottom-color: var(--g-line-soft); }
[data-theme="light"] .us-panel .sd-facts dt { color: var(--g-muted); }

/* ---- Dialogs ---- */
.us-modal { width: min(520px, calc(100vw - 32px)); }
.us-modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.us-modal-foot .g-btn { height: 36px; }
.us-modal p { margin: 0 0 10px; line-height: 1.55; }
.us-form { display: grid; gap: 12px; }
.us-form label, .us-field { display: grid; gap: 5px; font-size: 12.5px; color: var(--g-text-2); }
.us-input { height: 36px; width: 100%; padding: 0 9px; border: 1px solid var(--g-line); border-radius: 8px; background: var(--us-skin); color: var(--g-text); font-size: 13px; color-scheme: dark; }
[data-theme="light"] .us-input { color-scheme: light; }
.us-input:focus { outline: 2px solid var(--g-coral); outline-offset: 0; border-color: transparent; }
.us-input[aria-invalid="true"] { border-color: var(--g-bad); }
.us-input[readonly] { color: var(--g-muted); }
.us-pass { position: relative; }
.us-pass .us-input { padding-right: 70px; }
.us-pass button { position: absolute; right: 4px; top: 4px; height: 28px; padding: 0 9px; border: 0; border-radius: 6px; background: var(--g-hover); color: var(--g-text-2); font-size: 12px; cursor: pointer; }
.us-err { font-size: 12px; color: var(--g-bad); }
.us-hint { font-size: 11.5px; color: var(--g-muted); }
.us-form-error { display: flex; gap: 8px; align-items: center; margin: 0; padding: 8px 10px; border: 1px solid #5a3531; border-radius: 8px; background: var(--g-bad-bg); color: var(--g-bad); font-size: 12.5px; }
[data-theme="light"] .us-form-error { border-color: var(--g-bad); }
.us-form-error svg { width: 15px; height: 15px; flex: none; }
.us-roles { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; }
.us-roles legend { margin-bottom: 5px; padding: 0; font-size: 12.5px; color: var(--g-text-2); }
.us-roles label { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: start; padding: 9px 11px; border: 1px solid var(--g-line); border-radius: 9px; cursor: pointer; }
.us-roles label:has(input:checked) { border-color: var(--g-coral-line); background: var(--g-coral-bg); }
.us-roles label:has(input:disabled) { opacity: .5; cursor: not-allowed; }
.us-roles input { margin: 3px 0 0; accent-color: var(--g-coral); grid-row: span 2; }
.us-roles b { font-weight: 550; color: var(--g-text); font-size: 13px; }
.us-roles small { font-size: 11.5px; color: var(--g-muted); line-height: 1.45; }
.us-switch { display: flex !important; align-items: center; gap: 10px !important; cursor: pointer; }
.us-switch input { width: 16px; height: 16px; accent-color: var(--g-coral); margin: 0; }
.us-sim-note { display: flex; gap: 8px; align-items: flex-start; margin: 4px 0 0; padding: 8px 10px; border: 1px dashed var(--g-warn); border-radius: 8px; font-size: 11.5px; line-height: 1.5; color: var(--g-warn); }
.us-sim-note svg { width: 15px; height: 15px; margin-top: 1px; flex: none; }
.us-mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 11.5px; }
.us-target { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; padding: 10px 12px; border: 1px solid var(--g-line-soft); border-radius: 9px; }
.us-target > div { min-width: 0; }
.g-btn.busy { pointer-events: none; }
.us-spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; }
@media (prefers-reduced-motion: no-preference) { .us-spin { animation: us-rot .8s linear infinite; } @keyframes us-rot { to { transform: rotate(360deg); } } }

/* ---- Toast ---- */
.us-toast { position: fixed; left: 50%; bottom: 24px; z-index: 95; display: flex; align-items: center; gap: 9px; transform: translateX(-50%); max-width: min(600px, calc(100vw - 32px)); padding: 10px 14px; border: 1px solid var(--g-line); border-radius: 10px; background: var(--g-raised); color: var(--g-text); font-size: 13px; box-shadow: 0 12px 40px #0005; }
.us-toast svg { width: 16px; height: 16px; color: var(--g-ok); flex: none; }
.us-toast.bad svg { color: var(--g-bad); }

/* ---- Responsive ---- */
@media (max-width: 1150px) {
    .us-table .opt-lg { display: none; }
    .us-table, .sd-work.has-panel .us-table { min-width: 560px; }
}
@media (max-width: 720px) {
    .us-head { flex-direction: column; align-items: stretch; gap: 14px; }
    .us-head h1 { font-size: 27px; }
    .us-head-actions { justify-content: flex-end; }
    .us-head-actions .us-btn-primary { flex: 1; justify-content: center; }
    .us .sd-toolbar { gap: 8px; }
    .us .sd-seg { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
    .us .sd-search { flex: 1 1 100%; min-width: 0; }
    .us-clear { margin-left: 0; }
    /* Table → list rows with graphite.css phone rules (m-show/m-title/m-line); every field stays in the panel. */
    .us-table, .sd-work.has-panel .us-table { min-width: 0; }
    .us-table td.m-line { padding-left: 43px; }
    .us-table td.m-line > * + *::before { content: "·"; margin: 0 7px; color: var(--g-muted); }
    .us-table td.m-line .us-role, .us-table td.m-line .sd-status { font-size: 12px; }
    .us-modal { width: calc(100vw - 20px); }
}
[data-theme="light"] .us .sd-panel-head { border-color: var(--g-line); }
