:root {
    --bg: #0b0d11;
    --bg-elev: #10141a;
    --fg: #e8ecef;
    --muted: #8b949e;
    --accent: #ffb347;
    --accent-strong: #ff9f1a;
    --border: #1f242b;
    --danger: #ff8b8b;
    --ok: #7ee3a3;
    --warn: #f0ad4e;
}

* { box-sizing: border-box; }

/* ===== Skip link (a11y) ===== */
.skip-link {
    position: absolute;
    top: -100%;
    left: 8px;
    z-index: 999;
    padding: 8px 14px;
    background: var(--accent);
    color: #1a0f00;
    font-weight: 600;
    border-radius: 0 0 6px 6px;
    text-decoration: none;
    font-size: 13px;
}
.skip-link:focus { top: 0; }

/* The native [hidden] attribute must always win over component display rules
   (e.g. .btn uses inline-flex which would otherwise override). */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Header ===== */
.platform-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elev);
    position: sticky;
    top: 0;
    z-index: 10;
}

.platform-header .brand { color: var(--fg); text-decoration: none; }
.platform-header .brand:hover { text-decoration: none; opacity: 0.85; }

.platform-header nav {
    display: flex;
    gap: 18px;
    flex: 1;
    justify-content: center;
}

.platform-header nav a {
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    padding: 4px 0;
    border-bottom: 2px solid transparent;
    transition: color 0.1s, border-color 0.1s;
}
.platform-header nav a:hover { color: var(--fg); }
.platform-header nav a.active { color: var(--fg); border-bottom-color: var(--accent); }

/* ===== Admin pill ===== */
.admin-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 12px;
    color: var(--muted);
}
.admin-pill strong { color: var(--fg); font-weight: 500; }
.admin-pill .role {
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--border);
    text-transform: lowercase;
    font-size: 11px;
}
.admin-pill .role-super_admin { background: var(--accent); color: #1a0f00; }
.admin-pill .role-owner       { background: #2b3340; color: var(--fg); }
.admin-pill .role-operator    { background: #1f242b; color: var(--muted); }
.admin-pill .role-support     { background: #1f242b; color: var(--muted); }
.admin-pill .role-admin       { background: var(--accent); color: #1a0f00; }
.admin-pill .role-employee    { background: #2b3340; color: var(--fg); }
.admin-pill .role-contractor  { background: #1f242b; color: var(--muted); }

/* ===== Platform admins page ===== */
.role { padding: 2px 6px; border-radius: 4px; background: var(--border); font-size: 11px; text-transform: lowercase; }
.role-admin       { background: var(--accent); color: #1a0f00; }
.role-employee    { background: #2b3340; color: var(--fg); }
.role-contractor  { background: #1f242b; color: var(--muted); }

.status-active   { color: #4ade80; }
.status-disabled { color: var(--muted); }
.status-pending  { color: #fbbf24; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.perms-modal-body { display: flex; flex-direction: column; gap: 16px; }
.perms-groups { display: flex; flex-direction: column; gap: 12px; }

.perm-group {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    margin: 0;
}
.perm-group legend { padding: 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.perm-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--bg-elev);
    gap: 10px;
}
.perm-row:last-child { border-bottom: none; }
.perm-row-main { display: flex; align-items: center; gap: 8px; cursor: pointer; flex: 1; }
.perm-key { font-size: 11px; color: var(--muted); }

.tag { font-size: 10px; padding: 1px 6px; border-radius: 3px; background: var(--border); color: var(--muted); }
.tag-danger { background: rgba(255,139,139,0.15); color: var(--danger); border: 1px solid rgba(255,139,139,0.3); }
.tag.small { font-size: 10px; }

.perm-source-preset         { background: var(--bg-elev); color: var(--muted); }
.perm-source-override-grant { background: rgba(74,222,128,0.15); color: #4ade80; }
.perm-source-override-revoke{ background: rgba(248,113,113,0.15); color: #f87171; }
.perm-source-none           { background: transparent; color: var(--muted); }

.form-stack { display: flex; flex-direction: column; gap: 6px; }
.form-stack label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.form-stack .small { font-size: 11px; }
.admin-pill .logout-btn {
    background: transparent;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    padding: 0 0 0 8px;
    border-left: 1px solid var(--border);
}
.admin-pill .logout-btn:hover { color: var(--accent); }

/* ===== Layout ===== */
main {
    padding: 32px 24px;
    max-width: 1200px;
    margin: 0 auto;
}

h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 8px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }

p.muted, .muted { color: var(--muted); }

code {
    background: var(--bg-elev);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent);
    font-size: 13px;
}

/* ===== KPI cards ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-top: 24px;
}
.kpi {
    padding: 20px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.kpi .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi .value { font-size: 28px; font-weight: 600; margin-top: 4px; }
.kpi .sub   { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ===== Status row ===== */
.status-row { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); margin-top: 24px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }

/* ===== Coming soon panel (stubs) ===== */
.coming-soon {
    margin-top: 32px;
    padding: 40px 24px;
    text-align: center;
    background: var(--bg-elev);
    border: 1px dashed var(--border);
    border-radius: 8px;
}
.coming-soon .badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 4px;
    background: var(--accent);
    color: #1a0f00;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}
.coming-soon h2 {
    color: var(--fg);
    text-transform: none;
    margin: 0 0 8px;
    font-size: 20px;
    letter-spacing: 0;
    font-weight: 600;
}
.coming-soon p {
    color: var(--muted);
    margin: 4px auto;
    max-width: 540px;
}
.coming-soon .features {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 20px;
}
.coming-soon .features span {
    padding: 4px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    color: var(--muted);
}

/* ===== Tables ===== */
table.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}
.data-table th, .data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.data-table th {
    color: var(--muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
    font-weight: 500;
    background: var(--bg-elev);
}
.data-table tbody tr:hover { background: var(--bg-elev); }

/* ===== Badges / chips ===== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 500;
}
.badge-active   { background: #0d2b1a; color: var(--ok);     border: 1px solid #1e6b3f; }
.badge-trial    { background: #1a2030; color: #7eb3ff;       border: 1px solid #2e4470; }
.badge-canceled { background: #2b0d11; color: var(--danger); border: 1px solid #6b1e24; }
.badge-warn     { background: #2b1f0d; color: var(--warn);   border: 1px solid #6b4f1e; }
.badge-muted    { background: var(--bg-elev); color: var(--muted); border: 1px solid var(--border); }

/* ===== Empty / error / loading states ===== */
.empty-state, .error-state, .loading-state {
    margin-top: 24px;
    padding: 24px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-align: center;
    color: var(--muted);
}
.error-state { border-color: #6b1e24; color: var(--danger); }

/* ===== 404 ===== */
.notfound {
    text-align: center;
    padding: 80px 24px;
}
.notfound h1 { font-size: 96px; margin: 0; color: var(--accent); }
.notfound p { color: var(--muted); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-elev);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.1s, border-color 0.1s;
    line-height: 1.2;
}
.btn:hover { background: #1a2030; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #1a0f00; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost   { background: transparent; }
.btn-danger  { background: #6b1e24; color: #fff; border-color: #6b1e24; }
.btn-danger:hover { background: #8a2730; border-color: #8a2730; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ===== Page header ===== */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.page-header h1 { margin-bottom: 0; }
.page-header p { margin: 4px 0 0; }

.breadcrumb { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--fg); text-decoration: none; }

/* ===== Filter bar ===== */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0;
}
.filter-bar input,
.filter-bar select {
    padding: 8px 12px;
    background: var(--bg-elev);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
}
.filter-bar input { flex: 1 1 240px; min-width: 200px; }
.filter-bar input:focus,
.filter-bar select:focus { outline: none; border-color: var(--accent); }
.filter-bar select { min-width: 160px; }

.row-count { font-size: 12px; margin: 0 0 8px; }
.row-sub   { font-size: 11px; color: var(--muted); margin-top: 2px; }
.right     { text-align: right; }

/* ===== Forms ===== */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}
.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.field label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.field input[type=text],
.field input[type=email],
.field input[type=search],
.field select,
.field textarea {
    padding: 10px 12px;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}
.field input:focus,
.field select:focus,
.field textarea:focus { outline: none; border-color: var(--accent); }
.field-hint { font-size: 12px; color: var(--muted); margin: 0; }
.field-hint.ok  { color: var(--ok); }
.field-hint.err { color: var(--danger); }

/* ===== Wizard ===== */
.wizard { margin-top: 24px; }
.wizard-steps {
    display: flex;
    list-style: none;
    padding: 0;
    margin: 0 0 32px;
    gap: 8px;
    counter-reset: step;
}
.wizard-steps li {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--muted);
}
.wizard-steps li span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--border);
    color: var(--fg);
    font-size: 12px;
    font-weight: 600;
}
.wizard-steps li.active { color: var(--fg); border-color: var(--accent); }
.wizard-steps li.active span { background: var(--accent); color: #1a0f00; }
.wizard-steps li.done span { background: var(--ok); color: #002b14; }

.wizard-step h2 {
    color: var(--fg);
    text-transform: none;
    font-size: 18px;
    letter-spacing: 0;
    margin-top: 0;
}

.wizard-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* ===== Modules grid (wizard) ===== */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}
.module-card {
    display: flex;
    flex-direction: column;
    padding: 14px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    text-decoration: none;
    color: inherit;
}
.module-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 16px rgba(255, 179, 71, 0.12);
    text-decoration: none;
}
.module-card.selected {
    border-color: var(--accent);
    background: rgba(255, 179, 71, 0.06);
}
.module-card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.module-card-head input[type=checkbox] { margin: 0; }
.module-card-head strong { flex: 1; font-weight: 500; }
.module-price { font-size: 11px; color: var(--muted); }
.module-desc { font-size: 12px; color: var(--muted); margin: 0; }

/* ===== Module catalog (Phase 3) ===== */
.module-category {
    margin-bottom: 36px;
}
.module-category-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 0 12px 12px;
    margin-bottom: 14px;
    border-left: 3px solid var(--cat-color, var(--accent));
}
.module-category-title-wrap { flex: 1; }
.module-category-title {
    margin: 0;
    color: var(--fg);
    text-transform: none;
    letter-spacing: 0;
    font-size: 16px;
    font-weight: 600;
}
.module-category-desc {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--muted);
}
.module-category-count {
    font-size: 11px;
    color: var(--muted);
    background: var(--bg-elev);
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
}
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
}
.module-card .module-card-icon {
    font-size: 18px;
    line-height: 1;
}
.module-card-title-wrap { flex: 1; min-width: 0; }
.module-card-name {
    font-weight: 500;
    color: var(--fg);
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.module-card-key {
    font-size: 11px;
    color: var(--muted);
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 3px;
}
.module-card-desc {
    font-size: 12px;
    color: var(--muted);
    margin: 8px 0 10px;
    line-height: 1.45;
}
.module-card-meta {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 11px;
    color: var(--muted);
    padding: 6px 0;
    border-top: 1px solid var(--bg);
}
.module-card-price { color: var(--accent); font-weight: 500; }
.module-card-verticals,
.module-card-requires {
    font-size: 11px;
    color: var(--muted);
    margin-top: 6px;
}
.module-card-subs {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
}
.module-card-subs-label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.module-card-sub {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 12px;
    padding: 2px 0;
}
.module-card-sub-icon { color: var(--muted); }
.module-card-sub-name { color: var(--fg); }
.module-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    font-size: 11px;
    color: var(--muted);
}
.module-card-activations.active { color: var(--ok); }

/* Tier tags */
.tag-tier-free       { background: #2b3340; color: var(--muted); }
.tag-tier-starter    { background: rgba(122,199,122,0.15); color: #a8e6a8; }
.tag-tier-pro        { background: rgba(255,179,71,0.18); color: var(--accent); }
.tag-tier-enterprise { background: rgba(168,139,250,0.18); color: #c4b5fd; }

.chip-requires {
    display: inline-block;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    margin-right: 4px;
}

/* Module detail modal */
.module-detail .module-detail-head {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.module-detail-list {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 6px 16px;
    font-size: 13px;
    margin: 16px 0;
}
.module-detail-list dt { color: var(--muted); }
.module-detail-list dd { margin: 0; color: var(--fg); }
.section-subtitle {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin: 16px 0 8px;
    font-weight: 500;
}
.perm-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.perm-pill {
    font-size: 11px;
    padding: 2px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--accent);
}
.schema-key {
    font-size: 12px;
    background: var(--bg);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--accent);
}
.sub-list { margin: 0; padding-left: 20px; font-size: 13px; }
.sub-list li { margin-bottom: 8px; }
.empty-state { padding: 32px; text-align: center; }

/* ===== Recap (wizard step 3) ===== */
.recap { margin-top: 16px; padding: 16px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px; }
.recap h3 { margin-top: 0; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.recap-list {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px 16px;
    margin: 0;
}
.recap-list dt { color: var(--muted); font-size: 12px; }
.recap-list dd { margin: 0; font-size: 13px; }

/* ===== Cards (detail page) ===== */
.card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-top: 16px;
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.card-head h2 {
    margin: 0;
    color: var(--fg);
    text-transform: none;
    font-size: 16px;
    letter-spacing: 0;
    font-weight: 600;
}

.kv-list {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px 16px;
    margin: 0;
    font-size: 13px;
}
.kv-list dt { color: var(--muted); }
.kv-list dd { margin: 0; }

.plan-row {
    display: flex;
    gap: 32px;
    margin-bottom: 16px;
}
.plan-row .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.plan-row .value { font-size: 18px; font-weight: 500; margin-top: 4px; }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: grid;
    place-items: center;
    z-index: 100;
    padding: 24px;
    animation: modal-fade-in 0.15s ease;
}
.modal-card {
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - 48px);
    overflow: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-title { margin: 0; font-size: 16px; font-weight: 600; color: var(--fg); }
.modal-close {
    background: transparent;
    border: 0;
    color: var(--muted);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.modal-close:hover { color: var(--fg); }
.modal-body { padding: 20px; }
.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
body.modal-open { overflow: hidden; }
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ===== Toast ===== */
.toast-root {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
    pointer-events: none;
}
.toast {
    padding: 10px 14px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: 6px;
    color: var(--fg);
    font-size: 13px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    transition: opacity 0.2s, transform 0.2s;
}
.toast-ok   { border-left-color: var(--ok); }
.toast-err  { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--accent); }
.toast-fade { opacity: 0; transform: translateX(8px); }

/* ===== Detail rows: highlight on/off ===== */
.data-table tr.on td:first-child strong { color: var(--fg); }
.data-table tr.off td:first-child strong { color: var(--muted); }
.data-table tr.off td:first-child .row-sub { opacity: 0.7; }

/* ===== Bot detail layout ===== */
.bot-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}
@media (max-width: 900px) {
    .bot-grid { grid-template-columns: 1fr; }
}
.bot-grid .card { margin-top: 0; }
.bot-grid .card.full { grid-column: 1 / -1; }

textarea {
    padding: 10px 12px;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
}
textarea:focus { outline: none; border-color: var(--accent); }

.code-block {
    background: var(--bg);
    color: var(--accent);
    padding: 12px;
    border-radius: 6px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    overflow: auto;
    margin: 8px 0 12px;
    white-space: pre;
    border: 1px solid var(--border);
}

/* ===== Chat box (bot test) ===== */
.chat-box {
    display: flex;
    flex-direction: column;
    height: 380px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.chat-msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.4;
}
.chat-msg .chat-role {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin-bottom: 2px;
}
.chat-user {
    background: var(--accent);
    color: #1a0f00;
    align-self: flex-end;
}
.chat-user .chat-role { color: rgba(26,15,0,0.6); }
.chat-assistant {
    background: var(--bg-elev);
    color: var(--fg);
    align-self: flex-start;
    border: 1px solid var(--border);
}
.chat-form {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--border);
    background: var(--bg-elev);
}
.chat-form input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
}
.chat-form input:focus { outline: none; border-color: var(--accent); }

/* Chat metadata under bot reply (model · latency · cost) */
.chat-msg .chat-meta {
    font-size: 10px;
    color: var(--muted);
    margin-top: 4px;
    font-style: italic;
}

/* Optgroup styling for model selects */
.field select optgroup {
    background: var(--bg-elev);
    color: var(--accent);
    font-weight: 600;
    font-style: normal;
}
.field select option {
    background: var(--bg);
    color: var(--fg);
}

/* ===== Module catalog — missing rules ===== */

/* module-card-footer must stay pinned at bottom of flex card */
.module-card-footer { margin-top: auto; }

/* module-card-activations base state (active variant already defined above) */
.module-card-activations { color: var(--muted); }

/* module-card-perms / module-card-version — explicit selectors for clarity */
.module-card-perms  { /* inherits .module-card-meta color */ }
.module-card-version { /* inherits .module-card-meta color */ }

/* module-grid responsive: 3 col desktop → 1 col mobile */
@media (max-width: 768px) {
    .module-grid {
        grid-template-columns: 1fr;
    }
}
@media (min-width: 769px) and (max-width: 1024px) {
    .module-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

/* module-detail modal — larger width + scroll */
.modal-card:has(.module-detail) {
    max-width: 680px;
}

/* chip base (chip-requires is already defined; chip ensures display) */
.chip {
    display: inline-block;
}

/* kpi-grid responsive */
@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* filter-bar responsive — stack on mobile */
@media (max-width: 480px) {
    .filter-bar {
        flex-direction: column;
    }
    .filter-bar input,
    .filter-bar select {
        width: 100%;
        min-width: 0;
    }
}

/* QCM wizard — repeater (personas, etc.) */
.repeater {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}
.repeater-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.repeater-item {
    border: 1px solid var(--border, #2a2a2a);
    border-radius: 8px;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.repeater-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 0.5rem;
    border-bottom: 1px dashed var(--border, #2a2a2a);
}
.repeater-item-header strong {
    color: var(--accent, #ffb347);
}
.repeater-item .field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.repeater-item .field label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--muted, #aaa);
}
.repeater-item .remove-btn {
    background: transparent;
    color: var(--danger, #ef4444);
    border: 1px solid var(--danger, #ef4444);
    padding: 0.25rem 0.625rem;
    border-radius: 4px;
    font-size: 0.8125rem;
    cursor: pointer;
}
.repeater-item .remove-btn:hover {
    background: var(--danger, #ef4444);
    color: white;
}
.repeater .btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}
.range-value {
    display: inline-block;
    margin-left: 0.5rem;
    color: var(--accent, #ffb347);
    font-weight: 600;
}
.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--muted, #aaa);
    margin-bottom: 0.25rem;
}
.q-hint {
    display: block;
    font-size: 0.8125rem;
    color: var(--muted, #aaa);
    margin-bottom: 0.25rem;
}

/* QCM group label : same look as <label> but rendered as <span> for a11y compliance
   (a <label> without for or nested input is flagged "not associated" by DevTools). */
.qcm-group-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: inherit;
}
.qcm-group-label.required::after {
    content: "";
}

/* AI generator panel (personas) */
.ai-generator-panel {
    border: 1px dashed var(--accent, #ffb347);
    border-radius: 8px;
    padding: 0.875rem 1rem;
    background: rgba(255, 179, 71, 0.06);
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}
.ai-generator-title {
    font-size: 0.9375rem;
}
.ai-generator-title strong {
    color: var(--accent, #ffb347);
}
.ai-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}
.ai-count-label {
    font-size: 0.875rem;
    color: var(--muted, #aaa);
}
.ai-count-select {
    width: auto !important;
    min-width: 80px;
    padding: 0.375rem 0.5rem;
}
.ai-replace-label {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: var(--muted, #aaa);
    cursor: pointer;
}
.btn-ai-generate {
    margin-left: auto;
}
.btn-ai-generate:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.ai-status {
    font-size: 0.8125rem;
    min-height: 1.25em;
}
.ai-status.success {
    color: var(--success, #10b981);
}
.ai-status.error {
    color: var(--danger, #ef4444);
}
@media (max-width: 480px) {
    .ai-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .btn-ai-generate {
        margin-left: 0;
        width: 100%;
    }
}

/* ===== Tenant shell white-label ===== */

/* Logo image dans la barre tenant */
.brand-logo {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    object-fit: contain;
    flex-shrink: 0;
}

/* Monogramme initiales (fallback sans logo) */
.brand-monogram {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    background: var(--accent);
    color: #1a0f00;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: -0.5px;
}

/* Brand tenant : flex row avec gap */
.brand--tenant {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Header tenant : légère teinte accent au border-bottom */
.platform-header--tenant {
    border-bottom-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

/* Nav responsive — masquer les items overflow sur mobile */
@media (max-width: 768px) {
    .platform-header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 14px;
    }
    .platform-header nav {
        overflow-x: auto;
        gap: 12px;
        justify-content: flex-start;
        scrollbar-width: none;
        flex: 1 1 100%;
        order: 3;
    }
    .platform-header nav::-webkit-scrollbar { display: none; }
    .admin-pill { order: 2; }
}
