/* ============ Admin design system - Madar 360 ============
   Calm neutral surfaces + ONE brand accent (orange). 4/8 px spacing scale,
   logical properties throughout (RTL/LTR), light + dark parity.
   Font: Inter (Latin) + IBM Plex Sans Arabic (Arabic), from Google Fonts (allowed by the CSP). */

/* ---------- tokens ---------- */
:root {
    /* brand */
    --brand: #fd9800;
    --brand-hover: #ea8c00;
    --brand-ink: #b25e00;            /* accent used as TEXT on light surfaces (AA) */
    --brand-soft: rgba(253, 152, 0, .12);
    --on-brand: #231500;

    /* neutrals */
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --surface-3: #f2f4f7;
    --border: #e4e7ec;
    --border-strong: #d0d5dd;
    --text: #101828;
    --text-2: #475467;
    --text-3: #667085;

    /* semantic */
    --success: #067647;  --success-soft: #e7f7ee;
    --warning: #b54708;  --warning-soft: #fef3e2;
    --danger: #c9302c;   --danger-soft: #fdecea;
    --info: #175cd3;     --info-soft: #eaf2ff;

    /* radius */
    --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-pill: 999px;

    /* spacing (4/8 scale) */
    --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px;

    /* elevation */
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-md: 0 8px 20px -4px rgba(16, 24, 40, .12), 0 3px 6px -2px rgba(16, 24, 40, .05);
    --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, .22);
    --ring: 0 0 0 3px rgba(253, 152, 0, .28);
    --scrim: rgba(16, 24, 40, .5);

    /* type scale */
    --fs-xs: 12px; --fs-sm: 13px; --fs-md: 14px; --fs-lg: 16px; --fs-xl: 20px; --fs-2xl: 24px;
    --font: 'Inter', 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, system-ui, sans-serif;
    --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;

    /* layout + z-index */
    --sidebar-w: 248px;
    --topbar-h: 64px;
    --control-h: 40px;
    --z-sticky: 20; --z-drawer: 40; --z-modal: 50; --z-top: 60;

    /* legacy aliases (inline styles / other modules) */
    --card: var(--surface);
    --card-edge: var(--border);
    --muted: var(--text-3);
    --accent: var(--brand);
    --accent-dark: var(--brand-ink);
    --accent-soft: var(--brand-soft);
    --radius: var(--r-md);
    --shadow: var(--shadow-xs);
    --btn-text: var(--on-brand);

    color-scheme: light;
}

[data-theme="dark"] {
    --brand: #fd9800;
    --brand-hover: #ffa81f;
    --brand-ink: #ffb340;
    --brand-soft: rgba(253, 152, 0, .16);
    --on-brand: #1a1100;

    --bg: #0b0f17;
    --surface: #131925;
    --surface-2: #171e2c;
    --surface-3: #1d2535;
    --border: #252e3f;
    --border-strong: #35405a;
    --text: #f2f4f7;
    --text-2: #c3cad6;
    --text-3: #98a2b3;

    --success: #4ade80;  --success-soft: rgba(74, 222, 128, .13);
    --warning: #fbbf24;  --warning-soft: rgba(251, 191, 36, .13);
    --danger: #f87171;   --danger-soft: rgba(248, 113, 113, .14);
    --info: #7cb2ff;     --info-soft: rgba(124, 178, 255, .14);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .45);
    --shadow-md: 0 8px 20px -4px rgba(0, 0, 0, .55);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .7);
    --ring: 0 0 0 3px rgba(253, 152, 0, .34);
    --scrim: rgba(3, 6, 12, .66);

    color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { scrollbar-color: var(--border-strong) transparent; -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--fs-md);
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: 1.35; }
button, input, select, textarea { font-family: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
::selection { background: var(--brand-soft); }
.hidden { display: none !important; }
.muted { color: var(--text-3); font-size: var(--fs-sm); }
.err { color: var(--danger); font-size: var(--fs-sm); margin: var(--s-2) 0; }
.icon { display: inline-flex; }
.icon svg { width: 1em; height: 1em; display: block; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- message banners ---------- */
.msg {
    font-size: var(--fs-sm);
    margin-block-start: var(--s-3);
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-2);
}
.msg.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.msg.err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.msg.inj-stale { background: var(--warning-soft); color: var(--warning); border-color: transparent; }

/* ---------- floating lang/theme tools ---------- */
.float-tools { position: fixed; top: var(--s-4); inset-inline-end: var(--s-4); display: flex; gap: var(--s-2); z-index: var(--z-top); }
.tool-btn {
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-2);
    border-radius: var(--r-md);
    min-width: 40px; height: 40px;
    padding: 0 var(--s-3);
    font-size: var(--fs-sm); font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-xs);
    transition: border-color .15s, color .15s, background .15s;
}
.tool-btn:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-2); }
.tool-btn .icon { font-size: 18px; }
.float-tools.inline { position: static; z-index: auto; }
.float-tools.inline .tool-btn { box-shadow: none; background: transparent; border-color: transparent; }
.float-tools.inline .tool-btn:hover { background: var(--surface-3); }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
    min-height: var(--control-h);
    padding: 0 var(--s-4);
    background: var(--brand);
    color: var(--on-brand);
    border: 1px solid transparent;
    border-radius: var(--r-md);
    font-size: var(--fs-md); font-weight: 600; line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: var(--shadow-xs);
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { background: var(--brand-hover); }
.btn:active { transform: translateY(.5px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary { padding: 0 var(--s-5); }
.btn.ghost, .btn.secondary {
    background: var(--surface); color: var(--text); border-color: var(--border-strong);
}
.btn.ghost:hover, .btn.secondary:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn.text { background: transparent; border-color: transparent; color: var(--text-2); box-shadow: none; }
.btn.text:hover { background: var(--surface-3); color: var(--text); }
.btn.small { min-height: 32px; padding: 0 var(--s-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn.large { min-height: 48px; padding: 0 var(--s-5); font-size: var(--fs-lg); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: #b02a26; }
.btn.ghost.danger, .btn.secondary.danger { background: var(--surface); color: var(--danger); border-color: var(--border-strong); }
[data-theme="dark"] .btn.danger { color: #1a0505; }
[data-theme="dark"] .btn.danger:hover { background: #fca5a5; }
.btn:disabled, .btn[aria-disabled="true"] {
    background: var(--surface-3); color: var(--text-3); border-color: var(--border);
    box-shadow: none; cursor: not-allowed; transform: none;
}
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after {
    content: ''; position: absolute; inset-inline-start: 50%; inset-block-start: 50%;
    width: 16px; height: 16px; margin: -8px 0 0 -8px;
    border: 2px solid var(--on-brand); border-inline-end-color: transparent; border-radius: 50%;
    animation: spin .7s linear infinite;
}
.row-actions { display: flex; gap: var(--s-1); flex-wrap: wrap; align-items: center; }
.row-actions .btn.small { min-width: 32px; padding: 0 var(--s-2); font-size: 16px; line-height: 1; }

/* ---------- form controls ---------- */
label { display: block; font-size: var(--fs-sm); font-weight: 600; color: var(--text); margin: var(--s-3) 0 6px; }
input, select, textarea {
    width: 100%;
    min-height: var(--control-h);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text);
    border-radius: var(--r-md);
    padding: 0 var(--s-3);
    font-size: var(--fs-md);
    box-shadow: var(--shadow-xs);
    transition: border-color .15s, box-shadow .15s;
}
textarea { padding: var(--s-2) var(--s-3); line-height: 1.6; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text-3); opacity: .8; }
input:hover, select:hover, textarea:hover { border-color: var(--text-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-3); color: var(--text-3); cursor: not-allowed; }
input[aria-invalid="true"], .invalid { border-color: var(--danger); }
select {
    appearance: none; -webkit-appearance: none;
    padding-inline-end: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2398a2b3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-size: 16px; background-position: right 12px center;
}
[dir="rtl"] select { background-position: left 12px center; }
input[type="checkbox"], input[type="radio"] {
    width: 18px; height: 18px; min-height: 0; padding: 0; accent-color: var(--brand); cursor: pointer; box-shadow: none; flex: 0 0 auto;
}
input[type="color"] { padding: 3px; cursor: pointer; }
input[type="file"] { padding: 6px var(--s-2); line-height: 1.8; }
.help { font-size: var(--fs-xs); color: var(--text-3); margin-block-start: 6px; }
.field-error { font-size: var(--fs-xs); color: var(--danger); margin-block-start: 6px; }
td select, td input:not([type="checkbox"]) { min-height: 32px; width: auto; max-width: 200px; font-size: var(--fs-sm); }
td select { padding-inline-end: 32px; }

/* ---------- login ---------- */
.login-split { min-height: 100vh; display: flex; }
.login-brand {
    flex: 0 0 44%;
    position: relative; overflow: hidden;
    background: #0f1623;
    color: #f2f4f7;
    display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
    padding: var(--s-7);
    gap: var(--s-3);
}
.login-brand::before, .login-brand::after {
    content: ''; position: absolute; border-radius: 50%; border: 1px solid rgba(253, 152, 0, .16); pointer-events: none;
    inset-inline-end: -140px; inset-block-end: -140px; width: 420px; height: 420px;
}
.login-brand::after { inset-inline-end: -60px; inset-block-end: -60px; width: 260px; height: 260px; border-color: rgba(253, 152, 0, .24); }
.login-brand > * { position: relative; }
.login-brand .icon {
    font-size: 28px; color: var(--brand);
    width: 56px; height: 56px; align-items: center; justify-content: center;
    border-radius: var(--r-lg); background: rgba(253, 152, 0, .12); border: 1px solid rgba(253, 152, 0, .28);
    margin-block-end: var(--s-3);
}
.login-brand-name { font-size: 28px; font-weight: 700; letter-spacing: -.01em; }
.login-brand-tagline { font-size: var(--fs-lg); color: #a4adbd; max-width: 340px; line-height: 1.8; margin: 0; }
.login-form-panel { flex: 1; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: var(--s-6) var(--s-4); }
.login-form-panel form {
    width: 100%; max-width: 400px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
    padding: var(--s-6); box-shadow: var(--shadow-md);
    animation: rise .25s ease both;
}
.login-form-panel h1 { margin: 0 0 var(--s-4); font-size: var(--fs-xl); text-align: start; letter-spacing: -.01em; }
.login-form-panel label:first-of-type { margin-block-start: 0; }
.login-form-panel .btn.primary { width: 100%; margin-block-start: var(--s-5); min-height: 44px; }
.login-form-panel .err { background: var(--danger-soft); padding: var(--s-2) var(--s-3); border-radius: var(--r-md); margin-block: var(--s-3) 0; }

@media (max-width: 760px) {
    .login-split { flex-direction: column; }
    .login-brand { flex: 0 0 auto; flex-direction: row; align-items: center; padding: var(--s-4) var(--s-5); gap: var(--s-3); }
    .login-brand::before, .login-brand::after { display: none; }
    .login-brand .icon { font-size: 20px; width: 40px; height: 40px; margin: 0; border-radius: var(--r-md); }
    .login-brand-name { font-size: var(--fs-lg); }
    .login-brand-tagline { display: none; }
    .login-form-panel { align-items: flex-start; padding: var(--s-5) var(--s-4); }
    .login-form-panel form { padding: var(--s-5); box-shadow: var(--shadow-sm); }
    .float-tools:not(.inline) { top: 12px; }
}

/* ---------- shell: sidebar + content ---------- */
.shell { display: flex; min-height: 100vh; align-items: stretch; }
.sidebar {
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-inline-end: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: var(--s-4) var(--s-3);
    gap: 2px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand {
    display: flex; align-items: center; gap: var(--s-3);
    font-size: var(--fs-lg); font-weight: 700; letter-spacing: -.01em;
    padding: var(--s-1) var(--s-2) var(--s-4); margin-block-end: var(--s-2);
    border-bottom: 1px solid var(--border);
}
.sidebar-brand .icon {
    font-size: 20px; color: var(--brand);
    width: 36px; height: 36px; align-items: center; justify-content: center;
    border-radius: var(--r-md); background: var(--brand-soft);
}
.nav-label {
    font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
    color: var(--text-3); padding: var(--s-4) var(--s-3) var(--s-1);
}
[lang="ar"] .nav-label { letter-spacing: 0; text-transform: none; font-size: var(--fs-xs); }
.tab {
    position: relative;
    display: flex; align-items: center; gap: var(--s-3);
    background: none; border: none;
    color: var(--text-2);
    min-height: 40px; padding: 0 var(--s-3);
    cursor: pointer;
    font-size: var(--fs-md); font-weight: 500;
    border-radius: var(--r-md);
    text-align: start; width: 100%;
    transition: background .12s, color .12s;
}
.tab .icon { font-size: 18px; flex: 0 0 auto; color: var(--text-3); transition: color .12s; }
.tab:hover { background: var(--surface-3); color: var(--text); }
.tab:hover .icon { color: var(--text-2); }
.tab.active { background: var(--brand-soft); color: var(--text); font-weight: 600; }
.tab.active .icon { color: var(--brand-ink); }
.tab.active::before {
    content: ''; position: absolute; inset-inline-start: -12px; inset-block: 8px;
    width: 3px; border-radius: 0 3px 3px 0; background: var(--brand);
}
[dir="rtl"] .tab.active::before { border-radius: 3px 0 0 3px; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(8px);
    min-height: var(--topbar-h);
    padding: var(--s-2) var(--s-6);
    display: flex; align-items: center; gap: var(--s-3);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: var(--z-sticky);
}
.topbar h1 { margin: 0; font-size: var(--fs-xl); flex: 1; min-width: 0; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-toggle { display: none; }
.head-right { display: flex; align-items: center; gap: var(--s-2); }
.whoami {
    display: inline-flex; align-items: center; gap: var(--s-2);
    font-size: var(--fs-sm); font-weight: 500; color: var(--text-2);
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--r-pill); padding: 5px var(--s-3) 5px 6px;
    max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
[dir="rtl"] .whoami { padding: 5px 6px 5px var(--s-3); }
.whoami::before {
    content: ''; flex: 0 0 24px; height: 24px; border-radius: 50%;
    background: var(--brand-soft) center / 14px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b25e00' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 21c1-4 4-6 8-6s7 2 8 6'/%3E%3C/svg%3E");
}
.nav-scrim { display: none; }

@media (max-width: 900px) {
    .shell { flex-direction: column; }
    .sidebar {
        position: fixed; inset-block: 0; inset-inline-start: 0; height: 100%;
        width: min(300px, 86vw); z-index: var(--z-drawer);
        transform: translateX(-102%); transition: transform .22s ease;
        box-shadow: var(--shadow-lg);
        padding-block: var(--s-4);
    }
    [dir="rtl"] .sidebar { transform: translateX(102%); }
    .nav-open .sidebar, [dir="rtl"] .nav-open .sidebar { transform: none; }
    .nav-open .nav-scrim { display: block; position: fixed; inset: 0; background: var(--scrim); z-index: calc(var(--z-drawer) - 1); animation: fade .15s ease both; }
    .tab { min-height: 44px; }
    .nav-toggle { display: inline-flex; }
    .topbar { padding-inline: var(--s-4); }
    .topbar h1 { font-size: var(--fs-lg); }
    .whoami { display: none; }
}

/* ---------- page + cards ---------- */
.view { padding: var(--s-5) var(--s-6) var(--s-7); max-width: 1280px; width: 100%; animation: rise .2s ease both; }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--s-5);
    margin-bottom: var(--s-4);
    box-shadow: var(--shadow-xs);
}
.card h2 { margin: 0 0 var(--s-4); font-size: var(--fs-lg); font-weight: 600; letter-spacing: -.005em; }
.card h3 { font-size: var(--fs-md); font-weight: 600; color: var(--text); margin: var(--s-5) 0 var(--s-2); }
.card > h3:first-child, .card > h2:first-child { margin-block-start: 0; }
.card-sub { margin: calc(var(--s-2) * -1) 0 var(--s-4); line-height: 1.8; max-width: 72ch; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); align-items: end; }
.grid > div > label:first-child { margin-block-start: 0; }
.grid-full { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
@media (max-width: 700px) {
    .view { padding: var(--s-4) var(--s-4) var(--s-6); }
    .card { padding: var(--s-4); border-radius: var(--r-md); }
    .grid { grid-template-columns: 1fr; }
}

/* ---------- tables ---------- */
.table-wrap { overflow: auto; max-height: 70vh; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-md); }
th, td { text-align: start; padding: var(--s-3) 14px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
td { white-space: normal; overflow-wrap: anywhere; }
td:has(> input[type="checkbox"]:only-child) { inline-size: 1%; white-space: nowrap; }
.pill, .chip { white-space: nowrap; }
th {
    color: var(--text-3); font-weight: 600; font-size: var(--fs-xs); letter-spacing: .03em; text-transform: uppercase;
    background: var(--surface-2); position: sticky; top: 0; z-index: 1;
}
[lang="ar"] th { letter-spacing: 0; text-transform: none; font-size: var(--fs-sm); }
tbody tr { transition: background .1s; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.inj-selected td, tbody tr.selected td { background: var(--brand-soft); }

/* status pills / badges */
.pill {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: var(--fs-xs); font-weight: 600; line-height: 1;
    padding: 5px 10px; border-radius: var(--r-pill);
    background: var(--surface-3); color: var(--text-2);
    border: 1px solid transparent;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.on { background: var(--success-soft); color: var(--success); }
.pill.off { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warning-soft); color: var(--warning); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: var(--accent-soft); color: var(--accent-dark); }

.chips { display: flex; flex-wrap: wrap; gap: var(--s-1); align-items: center; }
td.chips { display: table-cell; white-space: normal; min-inline-size: 150px; }
.perm-overview td.chips:nth-child(2) { min-inline-size: 300px; }
.perm-overview td.chips:nth-child(3) { min-inline-size: 180px; }
td.chips > * { margin: 2px; vertical-align: middle; }
td.chips > .chip { white-space: normal; max-inline-size: 100%; overflow-wrap: anywhere; vertical-align: top; }
.chip { display: inline-block; font-size: var(--fs-xs); padding: 3px 10px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-2); font-weight: 500; border: 1px solid var(--border); }
.chip-admin { background: var(--brand-soft); color: var(--brand-ink); border-color: transparent; font-weight: 600; }

.id-chip {
    display: inline-flex; align-items: center; gap: var(--s-2);
    direction: ltr; font-family: var(--mono); font-size: var(--fs-xs);
    background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r-sm);
    padding: 3px var(--s-2); color: var(--text-2); max-width: 240px;
}
.id-chip code { overflow: hidden; text-overflow: ellipsis; }
.copy-btn { background: none; border: none; cursor: pointer; font-size: 14px; padding: 2px; line-height: 1; color: var(--text-3); display: inline-flex; align-items: center; border-radius: var(--r-sm); }
.copy-btn:hover { color: var(--text); background: var(--border); }

/* empty state */
.empty {
    display: flex; flex-direction: column; align-items: center; gap: var(--s-3);
    text-align: center; color: var(--text-3); padding: var(--s-6) var(--s-4); font-size: var(--fs-md);
    border: 1px dashed var(--border-strong); border-radius: var(--r-md); background: var(--surface-2);
}
.empty::before {
    content: ''; width: 44px; height: 44px; border-radius: 50%;
    background: var(--surface-3) center / 22px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2398a2b3' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 12h-6l-2 3h-4l-2-3H2'/%3E%3Cpath d='M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z'/%3E%3C/svg%3E");
}

/* skeleton / spinner */
.skeleton { display: block; height: 14px; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--surface-3), var(--border), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--brand); animation: spin .7s linear infinite; display: inline-block; }

/* ---------- modals ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: var(--scrim);
    display: flex; align-items: center; justify-content: center; padding: var(--s-4);
    z-index: var(--z-modal); animation: fade .12s ease both;
    backdrop-filter: blur(2px);
}
.modal {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-lg); padding: var(--s-5);
    width: 440px; max-width: 100%; max-height: 92vh; overflow-y: auto;
    text-align: start; box-shadow: var(--shadow-lg); animation: rise .15s ease both;
}
.modal-icon { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; border-radius: 50%; background: var(--danger-soft); margin-block-end: var(--s-3); }
.modal-icon svg { width: 22px; height: 22px; color: var(--danger); }
.modal h3 { margin: 0 0 var(--s-2); font-size: var(--fs-lg); }
.modal p { margin: 0 0 var(--s-5); line-height: 1.8; }
.modal-actions { display: flex; gap: var(--s-2); justify-content: flex-end; margin-block-start: var(--s-5); flex-wrap: wrap; }
.modal-actions .btn { min-width: 96px; }
.modal-wide { width: 680px; }
.idle-modal { text-align: center; }
.idle-modal h3 { font-size: var(--fs-xl); }
.idle-modal p { font-variant-numeric: tabular-nums; margin-block-end: 0; }
.idle-modal .modal-actions { justify-content: center; }
.idle-modal::before {
    content: ''; display: block; width: 48px; height: 48px; margin: 0 auto var(--s-3); border-radius: 50%;
    background: var(--warning-soft) center / 24px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b54708' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpolyline points='12 7 12 12 15.5 14'/%3E%3C/svg%3E");
}
.modal-backdrop:has(.idle-modal) { z-index: calc(var(--z-top) + 5); }
@media (max-width: 480px) { .modal-actions { flex-direction: column-reverse; } .modal-actions .btn { width: 100%; } }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: var(--s-4); inset-inline-start: var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); z-index: var(--z-top); max-width: calc(100vw - 32px); }
.toast {
    background: var(--surface); border: 1px solid var(--border); border-inline-start: 4px solid var(--success);
    color: var(--text); border-radius: var(--r-md); padding: var(--s-3) var(--s-4);
    font-size: var(--fs-sm); box-shadow: var(--shadow-md); animation: rise .2s ease both;
}
.toast.err { border-inline-start-color: var(--danger); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- clients tab ---------- */
.cl-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; margin-block-end: var(--s-4); }
.cl-head h2 { margin: 0; }
.cl-name { font-weight: 600; }
/* dir=auto keeps mixed-script names bidi-correct; align every line to the page start edge so EN and AR names line up */
:root[dir="ltr"] td [dir="auto"] { text-align: left; }
:root[dir="rtl"] td [dir="auto"] { text-align: right; }
.cl-thumb { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface-2); overflow: hidden; vertical-align: middle; }
.cl-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cl-thumb-empty { border-style: dashed; }
.cl-thumb-lg { width: 72px; height: 72px; flex: 0 0 auto; }
.cl-swatches { display: inline-flex; gap: var(--s-1); }
.cl-swatch { width: 18px; height: 18px; border-radius: 50%; background: var(--sw, transparent); border: 1px solid var(--border-strong); }
.cl-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-5); align-items: start; }
@media (max-width: 900px) { .cl-form-grid { grid-template-columns: 1fr; } }
.cl-col { min-width: 0; }
.cl-field label, .cl-token label { margin-top: var(--s-3); }
.cl-field .muted { margin-top: var(--s-1); }
.cl-check { display: flex; align-items: center; gap: var(--s-2); margin-top: var(--s-3); }
.cl-check input { flex: 0 0 auto; }
.cl-pa { display: grid; grid-template-columns: 1fr 1fr auto; gap: var(--s-3); align-items: end; }
.cl-pa input[type="color"], .cl-token input[type="color"] { padding: 3px; height: var(--control-h); cursor: pointer; }
.cl-token-row { display: grid; grid-template-columns: 56px 1fr; gap: var(--s-2); }
.cl-token-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s-3); }
.cl-adv { margin-top: var(--s-4); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-2) var(--s-4) var(--s-4); background: var(--surface-2); }
.cl-adv summary { cursor: pointer; font-weight: 600; font-size: var(--fs-sm); padding: var(--s-2) 0; }
.cl-adv-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.cl-warnings { margin-top: var(--s-3); font-size: var(--fs-sm); }
.cl-warnings.ok { color: var(--text-3); }
.cl-warnings.warn { background: var(--danger-soft); color: var(--danger); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); }
.cl-warn-title { font-weight: 600; margin-bottom: var(--s-1); }
.cl-prev-wrap { margin-top: var(--s-4); }
.cl-prev-title { font-size: var(--fs-xs); font-weight: 600; margin-bottom: 6px; color: var(--text-3); }
.cl-preview {
    background: var(--tn-primary, #2b3440); color: var(--tn-text, #eef1f4);
    border-radius: var(--tn-radius, 12px); font-family: var(--tn-font, inherit);
    border: 1px solid var(--tn-accent, #7fa3c7); border-inline-start: 4px solid var(--tn-accent, #7fa3c7);
    padding: var(--s-4); display: flex; flex-direction: column; gap: 10px;
}
.cl-prev-heading { font-weight: 700; font-size: var(--fs-lg); color: var(--tn-accent, #7fa3c7); }
.cl-prev-field { background: var(--tn-field, #212830); color: var(--tn-text, #eef1f4); border-radius: var(--tn-radius, 12px); padding: 10px var(--s-3); font-size: var(--fs-md); }
.cl-prev-muted { color: var(--tn-muted, #9aa7b4); font-size: var(--fs-sm); }
.cl-prev-btn { align-self: flex-start; border: 0; cursor: default; font-family: inherit; font-size: var(--fs-md); font-weight: 600; background: var(--tn-accent, #7fa3c7); color: var(--tn-primary, #2b3440); border-radius: var(--tn-radius, 12px); padding: var(--s-2) 18px; }
.cl-logo { margin-top: var(--s-4); }
.cl-logo-row { display: flex; align-items: center; gap: var(--s-4); }
.cl-logo-btns { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.cl-logo-btns .btn { width: auto; }
.cl-actions { display: flex; gap: var(--s-2); margin-top: var(--s-5); flex-wrap: wrap; }

/* ---------- audit log: see the Phase 2 block below ---------- */
.audit-table td { white-space: normal; overflow-wrap: anywhere; }
.audit-table td:nth-child(1), .audit-table td:nth-child(5) { white-space: nowrap; }
.audit-table td:nth-child(2) { min-inline-size: 160px; }
.audit-table td:nth-child(4) { min-inline-size: 200px; }
.audit-more { margin-block-start: var(--s-3); }

/* ---------- Inject tab ---------- */
#inject { counter-reset: injstep; }
#inject > .card:not(:first-child) > h3:first-child { display: flex; align-items: center; gap: var(--s-3); margin-block-end: var(--s-4); font-size: var(--fs-lg); }
#inject > .card:not(:first-child) > h3:first-child::before {
    counter-increment: injstep; content: counter(injstep);
    flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--brand-soft); color: var(--brand-ink); font-size: var(--fs-sm); font-weight: 700;
}
.inj-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }
.inj-head h3 { margin-block: 0; }
.inj-unsupported { font-weight: 600; }
.inj-table tr.inj-selected td { background: var(--brand-soft); }
.inj-st { white-space: nowrap; }
.inj-st-current { background: var(--success-soft); color: var(--success); }
.inj-st-theme_stale, .inj-st-runtime_stale { background: var(--warning-soft); color: var(--warning); }
.inj-st-outside { background: var(--danger-soft); color: var(--danger); }
.inj-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px var(--s-2); margin-block: var(--s-3) 0; }
.inj-label { color: var(--text-3); font-size: var(--fs-sm); }
.inj-value, .inj-path, .inj-detail { direction: ltr; unicode-bidi: isolate; overflow-wrap: anywhere; font-family: var(--mono); font-size: var(--fs-xs); color: var(--text-2); }
.inj-detail { display: block; margin-block-start: 6px; }
.inj-options { display: flex; flex-wrap: wrap; gap: var(--s-4); align-items: flex-start; }
.inj-field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 240px; min-inline-size: 0; }
.inj-field label { font-size: var(--fs-sm); color: var(--text); margin: 0; }
.inj-bg-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin-block-start: var(--s-2); }
.inj-warn { font-weight: 600; }
.inj-client { margin-block-start: var(--s-2); }
.inj-theme-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }
.inj-logo { max-block-size: 40px; max-inline-size: 140px; object-fit: contain; border-radius: var(--r-md); background: var(--surface-2); }
.inj-files td.inj-path { text-align: start; }
.inj-files tr.inj-del td, .inj-list li.inj-del { color: var(--danger); }
.inj-progress { margin-block-start: var(--s-3); display: flex; flex-direction: column; gap: var(--s-2); align-items: flex-start; }
.inj-progress progress { inline-size: 100%; max-inline-size: 480px; height: 8px; accent-color: var(--brand); }
.inj-report h3, .inj-confirm h3 { color: var(--text); }
.inj-list { margin: var(--s-2) 0 var(--s-3); padding-inline-start: 20px; display: flex; flex-direction: column; gap: var(--s-1); }
.inj-error p { margin: 6px 0 0; }

/* flow choice cards */
.inj-flow { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s-3); }
.inj-flow-btn {
    position: relative; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; text-align: start;
    padding: var(--s-4) var(--s-5); padding-inline-end: 52px;
    border: 1px solid var(--border-strong); border-radius: var(--r-lg);
    background: var(--surface); color: var(--text); cursor: pointer; font: inherit;
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.inj-flow-btn::after {
    content: ''; position: absolute; inset-inline-end: var(--s-4); inset-block-start: var(--s-4);
    width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--surface);
}
.inj-flow-btn:hover { border-color: var(--text-3); box-shadow: var(--shadow-sm); }
.inj-flow-btn strong { font-size: var(--fs-lg); font-weight: 600; }
.inj-flow-btn.inj-flow-on { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand); }
.inj-flow-btn.inj-flow-on::after { border-color: var(--brand); background: radial-gradient(circle, var(--brand) 0 4px, var(--surface) 5px); }
.inj-flow-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.inj-flow-btn:disabled { opacity: .6; cursor: not-allowed; }

/* Tours-tab inline form fields (label.field) */
label.field { display: flex; flex-direction: column; gap: 6px; margin: 0; font-weight: 600; }
label.field > span { font-size: var(--fs-sm); }

/* ---------- refinements ---------- */
.id-chip:has(> .btn) { background: none; border: 0; padding: 0; }
.id-chip .btn { font-family: var(--font); }
.id-chip a { display: inline-flex; color: var(--text-2); font-size: 16px; }
.id-chip a:hover { color: var(--brand-ink); }
td .btn.small:not(.primary):not(.danger) { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
td .btn.small:not(.primary):not(.danger):hover { background: var(--surface-3); }
td .btn.small:not(.primary):not(.danger):disabled { background: var(--surface-3); color: var(--text-3); }
input[type="file"]::file-selector-button {
    font: inherit; font-size: var(--fs-sm); font-weight: 600; color: var(--text);
    background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
    padding: 4px var(--s-3); margin-inline-end: var(--s-3); cursor: pointer;
}
input[type="file"] { color: var(--text-3); font-size: var(--fs-sm); }
.inj-value { font-family: var(--font); font-size: var(--fs-sm); color: var(--text); font-weight: 500; }
.inj-path { font-family: var(--mono); }
[data-theme="dark"] .idle-modal::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fbbf24' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpolyline points='12 7 12 12 15.5 14'/%3E%3C/svg%3E");
}
[data-theme="dark"] .whoami::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffb340' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 21c1-4 4-6 8-6s7 2 8 6'/%3E%3C/svg%3E");
}
td.row-actions { display: table-cell; white-space: nowrap; inline-size: 1%; }
td.row-actions .btn + .btn { margin-inline-start: var(--s-1); }
td .btn.small.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; box-shadow: none; }
td .btn.small.danger:hover { background: var(--danger); color: #fff; }
[data-theme="dark"] td .btn.small.danger:hover { color: #1a0505; }
@media (max-width: 760px) { .login-brand { justify-content: flex-start; min-height: 72px; } }

/* ---------- collapsible cards (collapse.js) ---------- */
.card-collapsible { position: relative; }
.card-head { padding-inline-end: 44px; }
.card-head { cursor: pointer; }
.card-toggle {
    position: absolute; inset-block-start: var(--s-3); inset-inline-end: var(--s-3);
    inline-size: 40px; block-size: 40px; padding: 0; border: 0; border-radius: var(--r-md);
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; color: var(--text-3); cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}
.card-toggle:hover { background: var(--surface-2); color: var(--text); }
.card-toggle:focus-visible { outline: none; box-shadow: var(--ring); color: var(--text); }
.card-chevron { transition: transform .24s ease; }
.card-collapsible.is-collapsed .card-chevron { transform: rotate(-90deg); }
:root[dir="rtl"] .card-collapsible.is-collapsed .card-chevron { transform: rotate(90deg); }
/* body: grid rows 1fr -> 0fr animates height without measuring; opacity fades; visibility hides it from AT/focus after the transition */
.card-body {
    display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr; opacity: 1; visibility: visible;
    transition: grid-template-rows .24s ease, opacity .2s ease, visibility 0s linear 0s;
}
.card-body-in { min-block-size: 0; min-inline-size: 0; display: flow-root; }
.card-collapsible.is-animating > .card-body > .card-body-in,
.card-collapsible.is-collapsed > .card-body > .card-body-in { overflow: hidden; }
.card-collapsible.is-collapsed > .card-body {
    grid-template-rows: 0fr; opacity: 0; visibility: hidden;
    transition: grid-template-rows .24s ease, opacity .16s ease, visibility 0s linear .24s;
}
.card-collapsible > .card-head { transition: margin-block-end .24s ease; }
.card-collapsible.is-collapsed > .card-head { margin-block-end: 0; }
.card-collapsible.card-noanim, .card-collapsible.card-noanim * { transition: none !important; }
@media (prefers-reduced-motion: reduce) {
    .card-body, .card-collapsible > .card-head, .card-chevron, .card-collapsible.is-collapsed > .card-body { transition: none; }
}

/* ============ Phase 2: account menu, forms, tables, audit, states ============ */

/* ---------- avatar ---------- */
.avatar {
    display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
    inline-size: 32px; block-size: 32px; border-radius: 50%;
    background: var(--brand-soft); color: var(--brand-ink);
    font-size: var(--fs-xs); font-weight: 700; letter-spacing: .02em; line-height: 1; user-select: none;
}
.avatar-admin { background: var(--brand); color: var(--on-brand); }
.avatar-lg { inline-size: 44px; block-size: 44px; font-size: var(--fs-md); }
.who { display: inline-flex; align-items: center; gap: var(--s-3); min-inline-size: 0; }
.who-name { font-weight: 600; overflow-wrap: anywhere; }

/* ---------- topbar account dropdown ---------- */
.float-tools.inline { display: none; }
.acct { position: relative; }
.acct-btn {
    display: inline-flex; align-items: center; gap: var(--s-2);
    min-block-size: 40px; padding: 3px var(--s-2) 3px 3px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-pill);
    color: var(--text); font: inherit; font-size: var(--fs-sm); font-weight: 500; cursor: pointer;
    transition: border-color .15s, background .15s, box-shadow .15s;
}
[dir="rtl"] .acct-btn { padding: 3px 3px 3px var(--s-2); }
.acct-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.acct-btn[aria-expanded="true"] { border-color: var(--brand); box-shadow: var(--ring); }
.acct-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.acct-name { max-inline-size: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-chev { font-size: 16px; color: var(--text-3); transition: transform .15s; }
.acct-btn[aria-expanded="true"] .acct-chev { transform: rotate(180deg); }
.acct-panel {
    position: absolute; inset-block-start: calc(100% + 8px); inset-inline-end: 0;
    inline-size: 292px; max-inline-size: calc(100vw - 32px);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg); padding: var(--s-2); z-index: var(--z-modal);
    animation: rise .14s ease both;
}
.acct-info { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3); }
.acct-info-text { min-inline-size: 0; display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.acct-info-name { font-weight: 600; font-size: var(--fs-md); overflow-wrap: anywhere; }
.acct-info-email { color: var(--text-3); font-size: var(--fs-xs); overflow-wrap: anywhere; direction: ltr; text-align: start; }
.acct-info .pill { margin-block-start: 4px; }
.acct-sep { block-size: 1px; background: var(--border); margin: var(--s-1) calc(var(--s-2) * -1); }
.acct-item {
    display: flex; align-items: center; gap: var(--s-3); inline-size: 100%;
    min-block-size: 40px; padding: 0 var(--s-3); background: none; border: 0; border-radius: var(--r-md);
    color: var(--text); font: inherit; font-size: var(--fs-md); text-align: start; cursor: pointer;
}
.acct-item .icon { font-size: 18px; color: var(--text-3); }
.acct-item:hover, .acct-item:focus-visible { background: var(--surface-3); outline: none; }
.acct-item:focus-visible { box-shadow: inset 0 0 0 2px var(--brand); }
.acct-item-label { flex: 1; }
.acct-val { color: var(--text-3); font-size: var(--fs-sm); }
.acct-danger, .acct-danger .icon { color: var(--danger); }
@media (max-width: 640px) {
    .acct-name, .acct-chev { display: none; }
    .acct-btn { padding: 3px; }
    .acct-item { min-block-size: 44px; }
}

/* ---------- icon buttons ---------- */
.btn.icon-btn { inline-size: 32px; min-inline-size: 32px; padding: 0; font-size: 16px; }
.row-actions .btn.icon-btn { padding: 0; }
.btn.icon-btn .icon { font-size: 16px; }
@media (pointer: coarse) { .btn.icon-btn { inline-size: 40px; min-inline-size: 40px; min-block-size: 40px; } }
td.row-actions { display: table-cell; }
td.row-actions .btn.icon-btn + .btn.icon-btn { margin-inline-start: var(--s-1); }

/* ---------- forms: sections, grids, switches ---------- */
.acc-form { display: block; }
.fsec { border: 0; padding: 0; margin: 0; min-inline-size: 0; }
.fsec-title { font-size: var(--fs-md); font-weight: 600; margin: 0 0 2px; padding: 0; color: var(--text); }
.fsec-hint { margin: 0 0 var(--s-3); }
.card .fsec > h3.fsec-title { margin: 0 0 2px; }
.acc-set > legend { padding: 0; float: inline-start; inline-size: 100%; margin: 0 0 2px; }
.acc-set > legend + * { clear: both; }
.acc-controls { display: block; margin: 0; }
.acc-top, .acc-controls > .fsec { margin-block-start: var(--s-5); padding-block-start: var(--s-5); border-top: 1px solid var(--border); }
.acc-top { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-6); }
.acc-col { min-inline-size: 0; }
.acc-col > .fsec + .fsec { margin-block-start: var(--s-5); }
.acc-note + .acc-top { margin-block-start: var(--s-3); }
.acc-form > .fsec:first-child { margin-block-end: 0; }
.acc-extra { grid-column: auto; }
.fgrid { display: grid; gap: var(--s-4); }
.fgrid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fld label, .acc-field label { margin-block: 0 6px; }
.fld { min-inline-size: 0; }
.fld + .fld { margin-block-start: var(--s-3); }
.fgrid > .fld + .fld { margin-block-start: 0; }
.acc-switches { display: grid; grid-template-columns: 1fr; gap: var(--s-3); }
.acc-switch {
    position: relative; display: flex; align-items: flex-start; gap: var(--s-3); margin: 0;
    padding: var(--s-3) var(--s-4); border: 1px solid var(--border); border-radius: var(--r-md);
    background: var(--surface); cursor: pointer; font-weight: 500;
    transition: border-color .15s, box-shadow .15s;
}
.acc-switch:hover { border-color: var(--border-strong); }
.acc-switch input { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; margin: 0; opacity: 0; cursor: pointer; min-height: 0; }
.sw-track { flex: 0 0 40px; block-size: 22px; border-radius: var(--r-pill); background: var(--border-strong); position: relative; margin-block-start: 1px; transition: background .15s; }
.sw-track::after { content: ''; position: absolute; inset-block-start: 2px; inset-inline-start: 2px; inline-size: 18px; block-size: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs); transition: inset-inline-start .15s; }
.acc-switch input:checked + .sw-track { background: var(--brand); }
.acc-switch input:checked + .sw-track::after { inset-inline-start: 20px; }
.acc-switch:has(input:focus-visible) { box-shadow: var(--ring); border-color: var(--brand); }
.acc-switch.is-disabled, .acc-switch:has(input:disabled) { opacity: .6; cursor: not-allowed; }
.sw-text, .chk-text { display: flex; flex-direction: column; gap: 2px; min-inline-size: 0; }
.sw-label { color: var(--text); }
.sw-text small, .chk-text small { font-size: var(--fs-xs); line-height: 1.5; font-weight: 400; }
.acc-badges { display: grid; grid-template-columns: 1fr; gap: var(--s-3); }
.acc-field { min-inline-size: 0; max-inline-size: 520px; }
.acc-badges .acc-field { max-inline-size: none; }
.acc-hint { margin: 0; }
.acc-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: var(--s-3); }
.acc-group { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); min-inline-size: 0; }
.acc-group + .acc-group { margin-top: 0; }
.acc-group-head { display: flex; align-items: center; gap: var(--s-2); margin-block-end: var(--s-2); padding-block-end: var(--s-2); border-bottom: 1px solid var(--border); }
.acc-group-title { font-size: var(--fs-sm); font-weight: 600; color: var(--text); margin: 0; flex: 1; min-inline-size: 0; }
.acc-group-count { font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.acc-group-all { min-block-size: 28px; padding: 0 var(--s-2); color: var(--brand-ink); }
.acc-group-list, .acc-client-grid { display: flex; flex-direction: column; gap: 2px; }
.acc-client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 2px var(--s-4); }
.acc-check { display: flex; align-items: flex-start; gap: var(--s-2); margin: 0; padding: 6px 4px; border-radius: var(--r-sm); cursor: pointer; font-weight: 500; }
.acc-check:hover { background: var(--surface-3); }
.acc-check input { margin-block-start: 2px; }
.acc-set:disabled .acc-group, fieldset.acc-set:disabled { opacity: .6; }
.acc-note { margin: 0 0 var(--s-3); }
#createType { margin-block-end: var(--s-5); }
.acc-types { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s-3); }
.acc-type {
    position: relative; display: flex; align-items: flex-start; gap: var(--s-3); margin: 0;
    padding: var(--s-3) var(--s-4); border: 1px solid var(--border); border-radius: var(--r-md);
    background: var(--surface); cursor: pointer; font-weight: 500;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.acc-type:hover { border-color: var(--border-strong); }
.acc-type.is-on { border-color: var(--brand); background: var(--brand-soft); }
.acc-type:has(input:focus-visible) { box-shadow: var(--ring); border-color: var(--brand); }
.acc-type input { margin-block-start: 3px; }
.acc-type-text { display: flex; flex-direction: column; gap: 2px; min-inline-size: 0; }
.acc-type-title { color: var(--text); }
.acc-type-text small { font-size: var(--fs-xs); line-height: 1.5; font-weight: 400; }
.acc-type-current { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-3); margin-block-end: var(--s-3); }
.form-actions {
    display: flex; justify-content: flex-end; gap: var(--s-2);
    position: sticky; inset-block-end: 0; z-index: 2;
    margin-block-start: var(--s-5); padding: var(--s-3) 0 0;
    background: linear-gradient(to top, var(--surface) 75%, transparent); border-top: 1px solid var(--border);
}
.acc-form > .msg { margin-block: var(--s-4) 0; }
.modal-head { margin-block-end: var(--s-4); }
.modal-head h3 { margin: 0 0 2px; }
.modal-head p { margin: 0; }
.acc-modal { inline-size: min(820px, 100%); padding-block-end: 0; }
.acc-modal .modal-actions { position: sticky; inset-block-end: 0; background: var(--surface); margin-block-start: var(--s-4); padding-block: var(--s-3) var(--s-4); border-top: 1px solid var(--border); z-index: 2; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3); }
.inline-form .field { flex: 1 1 220px; min-inline-size: 0; }
.inline-form > .btn { flex: 0 0 auto; }
.lock-form .field { flex: 0 1 280px; }
.input-row { display: flex; align-items: center; gap: var(--s-2); }
.input-row input { flex: 1; }
.modal .msg.err { margin-block-start: var(--s-3); }
.modal .fld { margin-block-end: var(--s-2); }
.bulk-bar { margin-block-end: var(--s-3); padding: var(--s-2) var(--s-3); background: var(--brand-soft); border-radius: var(--r-md); }
.card > .msg { margin-block-start: var(--s-3); }
@media (max-width: 900px) {
    .fgrid-3 { grid-template-columns: 1fr; }
    .acc-top { grid-template-columns: 1fr; gap: 0; }
    .acc-col + .acc-col { margin-block-start: var(--s-5); }
}
@media (max-width: 640px) {
    .acc-groups { grid-template-columns: 1fr; }
    .acc-modal { padding: var(--s-4); padding-block-end: 0; }
    .modal-backdrop:has(.acc-modal) { padding: var(--s-2); }
}

/* ---------- toolbars / card header actions ---------- */
.cl-head .btn, .card-actions .btn { min-block-size: 36px; }
.card-actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }

/* ---------- tables: polish ---------- */
table.nw td { white-space: nowrap; overflow-wrap: normal; }
#toursTable th, #toursTable td { padding-inline: 10px; }
#toursTable td select { max-inline-size: 150px; }
#toursTable .id-chip { max-inline-size: 150px; }
/* Tour link name (host label): inline editor and folder note */
#toursTable .host-cell { display: flex; flex-direction: column; gap: 4px; min-inline-size: 140px; }
#toursTable .host-cell input { inline-size: 100%; min-inline-size: 150px; font-family: var(--mono, ui-monospace, monospace); }
#toursTable .host-cell .host-folder, #toursTable .host-cell .host-info { font-size: var(--fs-xs); white-space: normal; }
#toursTable td:has(> .host-cell) { white-space: normal; }
#toursTable .id-chip code { max-inline-size: 190px; }
#newTourLinkHint { margin-block: 8px 0; }
.host-info.err, #newTourLinkHint.err { color: var(--danger); }
.act-chip { white-space: nowrap; }
.audit-table td:nth-child(2), .audit-table td:nth-child(3) { white-space: nowrap; }
table.nw td .who-name { overflow-wrap: normal; }
td.chips .muted { white-space: nowrap; }
.table-wrap { scrollbar-width: thin; }
.table-wrap table { min-inline-size: 100%; }
select, input { text-overflow: ellipsis; }

/* ---------- empty + loading states ---------- */
.empty > .btn { margin-block-start: var(--s-1); }
.empty-title { font-weight: 600; color: var(--text-2); }
.sk-row td { padding-block: var(--s-4); }
.sk-row td .skeleton { inline-size: 70%; }
.sk-row td:first-child .skeleton { inline-size: 18px; }
.sk-row td:nth-child(2n) .skeleton { inline-size: 55%; }
.sk-row td:nth-child(3n) .skeleton { inline-size: 85%; }
.skeleton-list { display: grid; gap: var(--s-2); }
.skeleton-list .skeleton { block-size: 36px; border-radius: var(--r-md); }

/* ---------- audit log ---------- */
.audit-filters {
    display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: flex-end;
    padding: var(--s-4); margin-block-end: var(--s-4);
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
}
.audit-field { display: flex; flex-direction: column; gap: 6px; min-inline-size: 0; flex: 1 1 220px; }
.audit-field.audit-field-sm { flex: 0 1 260px; }
.audit-filters > .btn { flex: 0 0 auto; }
.audit-time { display: flex; flex-direction: column; gap: 2px; min-inline-size: 0; }
.audit-rel { font-weight: 600; color: var(--text); }
.audit-abs { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
.act-chip { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 600; line-height: 1.3; padding: 4px 10px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-2); white-space: normal; }
.act-chip::before { content: ''; inline-size: 6px; block-size: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.act-auth { background: var(--info-soft); color: var(--info); }
.act-account { background: var(--brand-soft); color: var(--brand-ink); }
.act-client { background: var(--success-soft); color: var(--success); }
.act-tour { background: var(--warning-soft); color: var(--warning); }
.act-bad { background: var(--danger-soft); color: var(--danger); }
.audit-target { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.audit-target .kv-type { font-weight: 600; color: var(--text-2); }
.audit-target code { font-family: var(--mono); font-size: var(--fs-xs); color: var(--text-3); direction: ltr; unicode-bidi: isolate; overflow-wrap: anywhere; }
.audit-ip { font-family: var(--mono); font-size: var(--fs-xs); direction: ltr; unicode-bidi: isolate; color: var(--text-2); }
.kv-list { display: flex; flex-wrap: wrap; gap: 4px; }
.kv { display: inline-flex; gap: 4px; align-items: baseline; max-inline-size: 100%; font-size: var(--fs-xs); background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 2px 8px; }
.kv b { color: var(--text-3); font-weight: 600; white-space: nowrap; }
.kv span { color: var(--text); overflow-wrap: anywhere; direction: ltr; unicode-bidi: isolate; }
.audit-table td.audit-details { white-space: normal; min-inline-size: 260px; max-inline-size: 460px; overflow-wrap: anywhere; direction: inherit; text-align: start; padding-block: var(--s-3); font-family: var(--font); font-size: var(--fs-xs); line-height: 1.5; color: var(--text-2); }

/* ---------- permissions overview ---------- */
.perm-overview td:first-child { min-inline-size: 220px; }
.perm-who { display: flex; align-items: center; gap: var(--s-3); }
.perm-who-text { min-inline-size: 0; }
.perm-who-text .muted { overflow-wrap: anywhere; }

/* ---------- inject polish ---------- */
.inj-head { margin-block-end: var(--s-3); }
.inj-size { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- mobile: tables become stacked cards ---------- */
@media (max-width: 640px) {
    .table-wrap:has(> table:not(.no-stack)) { overflow: visible; max-height: none; border: 0; background: transparent; border-radius: 0; }
    table:not(.no-stack), table:not(.no-stack) tbody { display: block; inline-size: 100%; min-inline-size: 0; }
    table:not(.no-stack) thead { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    table:not(.no-stack) tr { position: relative; display: block; margin-block-end: var(--s-3); padding: var(--s-1) var(--s-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-xs); }
    table:not(.no-stack) tbody tr:last-child td { border-bottom: 1px dashed var(--border); }
    table:not(.no-stack) tbody tr:hover { background: var(--surface); }
    table:not(.no-stack) td, table:not(.no-stack) td.chips, table:not(.no-stack) td.row-actions, table:not(.no-stack) td.audit-details {
        display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: var(--s-1) var(--s-3);
        inline-size: auto; min-inline-size: 0 !important; max-inline-size: none; padding: 10px 0;
        border-bottom: 1px dashed var(--border); white-space: normal !important;
    }
    .act-chip { white-space: normal; }
    table:not(.no-stack) tr > td:last-child, table:not(.no-stack) tbody tr:last-child td:last-child { border-bottom: 0; }
    table:not(.no-stack) td[data-label]::before {
        content: attr(data-label); flex: 0 0 34%; max-inline-size: 34%;
        color: var(--text-3); font-size: var(--fs-xs); font-weight: 600; text-align: start;
    }
    table:not(.no-stack) td[data-label] > * { min-inline-size: 0; }
    table:not(.no-stack) td.row-actions::before { display: none; }
    table:not(.no-stack) td.row-actions { justify-content: flex-start; padding-block: var(--s-3) var(--s-2); }
    table:not(.no-stack) td > .audit-time, table:not(.no-stack) td > .kv-list { flex: 1 1 55%; }
    table:not(.no-stack) td:has(> input[type="checkbox"]:only-child) { position: absolute; inset-block-start: 8px; inset-inline-end: 12px; padding: 0; border: 0; inline-size: auto; }
    table:not(.no-stack) td:has(> input[type="checkbox"]:only-child)::before { display: none; }
    table:not(.no-stack) tr.sk-row td::before { display: none; }
    table:not(.no-stack) td select, table:not(.no-stack) td input:not([type="checkbox"]) { max-inline-size: 100%; flex: 1 1 140px; }
    table:not(.no-stack) .id-chip { max-inline-size: 100%; }
}

/* Read-only reviewer banner (panel:view_all) */
.view-banner {
    margin: 0 0 16px;
    padding: 10px 14px;
    border: 1px solid var(--warning);
    background: var(--warning-soft);
    color: var(--warning);
    border-radius: 10px;
    font-weight: 600;
}
.view-banner.hidden { display: none; }

.cl-view-grid { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 12px; }
.cl-view-grid dt { color: var(--muted, #667085); }
.cl-view-grid dd { margin: 0; }
