:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #eef3fb;
    --card: #ffffff;
    --card2: #eef3fb;
    --input: #ffffff;
    --text: #172033;
    --muted: #6b7280;
    --line: #dbe3ef;
    --border: #dbe3ef;
    --brand: #2563eb;
    --brand-2: #0f766e;
    --danger: #dc2626;
    --warning: #d97706;
    --success: #16a34a;
    --shadow: 0 22px 55px rgba(15, 23, 42, .10);
    --radius: 22px;
}

html[data-theme="dark"] {
    --bg: #09111f;
    --surface: #111827;
    --surface-2: #172033;
    --card: #111827;
    --card2: #172033;
    --input: #0f172a;
    --text: #f9fafb;
    --muted: #a6b0c3;
    --line: #263348;
    --border: #263348;
    --brand: #60a5fa;
    --brand-2: #2dd4bf;
    --shadow: 0 22px 55px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, .18), transparent 28rem),
        radial-gradient(circle at bottom right, rgba(15, 118, 110, .14), transparent 28rem),
        var(--bg);
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 285px 1fr;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 18px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    border-right: 1px solid var(--line);
    backdrop-filter: blur(18px);
    overflow-y: auto;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px 10px 24px;
}
.brand img {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    object-fit: cover;
    border: 1px solid var(--line);
    background: var(--surface-2);
}
.brand strong { display: block; font-size: 15px; line-height: 1.2; }
.brand span { color: var(--muted); font-size: 12px; }

.nav-list { display: grid; gap: 8px; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px 13px;
    border-radius: 15px;
    color: var(--muted);
    transition: .18s ease;
}
.nav-link:hover, .nav-link.active {
    color: var(--text);
    background: linear-gradient(135deg, rgba(37, 99, 235, .14), rgba(15, 118, 110, .10));
}
.nav-icon {
    width: 32px;
    height: 32px;
    border-radius: 12px;
    display: inline-grid;
    place-items: center;
    background: var(--surface-2);
    color: var(--brand);
    font-size: 15px;
    flex: 0 0 auto;
}

.main-panel {
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 76px;
    padding: 16px 26px;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    backdrop-filter: blur(18px);
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
}
.topbar-title h1 { margin: 0; font-size: clamp(22px, 2.5vw, 31px); letter-spacing: -.03em; }
.topbar-title p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-chip {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
}
.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    color: white;
    display: inline-grid;
    place-items: center;
    font-weight: 800;
}
.content { padding: 26px; width: min(1500px, 100%); }
.footer { padding: 18px 26px 30px; color: var(--muted); font-size: 13px; }

.card {
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card.pad { padding: 22px; }
.card-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}
.card-header h2 { margin: 0; font-size: 18px; }
.card-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: linear-gradient(135deg, color-mix(in srgb, var(--surface) 86%, transparent), color-mix(in srgb, var(--surface-2) 80%, transparent));
}
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; margin-top: 8px; font-size: 30px; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}
.searchbox {
    min-width: min(360px, 100%);
    position: relative;
}
.searchbox input { padding-left: 40px; }
.searchbox:before {
    content: '⌕';
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}

.btn {
    border: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 14px;
    padding: 10px 14px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: .18s ease;
    white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.02); }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: white; }
.btn.danger { background: rgba(220, 38, 38, .12); color: var(--danger); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 7px 10px; border-radius: 11px; font-size: 13px; }
.btn.icon-only { width: 42px; padding-inline: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 800; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 800;
    background: var(--surface-2);
    color: var(--muted);
}
.badge.Active { background: rgba(22, 163, 74, .13); color: var(--success); }
.badge.Inactive { background: rgba(107, 114, 128, .15); color: var(--muted); }
.badge.Suspended { background: rgba(220, 38, 38, .13); color: var(--danger); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
label { color: var(--muted); font-size: 13px; font-weight: 700; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 11px 13px;
    background: var(--surface);
    color: var(--text);
    outline: none;
}
textarea { min-height: 105px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    border-color: color-mix(in srgb, var(--brand) 70%, var(--line));
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 14%, transparent);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: none;
    background: rgba(2, 6, 23, .62);
    padding: 24px;
    overflow-y: auto;
}
.modal-backdrop.open { display: grid; place-items: start center; }
.modal {
    width: min(780px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 26px;
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-block: 24px;
}
.modal.large { width: min(980px, 100%); }
.modal-header, .modal-footer {
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}
.modal-footer { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
.modal-body { padding: 20px; }
.modal h3 { margin: 0; }

.tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tab-button {
    border: 0;
    padding: 12px 14px;
    color: var(--muted);
    background: transparent;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 800;
}
.tab-button.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.access-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.check-card {
    border: 1px solid var(--line);
    background: var(--surface-2);
    border-radius: 15px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.check-card input { width: auto; }


.profile-photo-xl {
    width: 132px;
    height: 132px;
    border-radius: 38px;
    object-fit: cover;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    background: var(--surface-2);
}
.profile-photo-xl.initials {
    display: inline-grid;
    place-items: center;
    font-size: 48px;
    font-weight: 900;
    color: white;
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
}
.profile-facts {
    display: grid;
    gap: 10px;
}
.profile-facts div {
    padding: 12px;
    border-radius: 16px;
    background: var(--surface-2);
    border: 1px solid var(--line);
}
.profile-facts span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 5px;
}
.profile-facts strong {
    display: block;
    overflow-wrap: anywhere;
    font-size: 14px;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.login-card {
    width: min(1060px, 100%);
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    overflow: hidden;
}
.login-hero {
    padding: 42px;
    background: linear-gradient(135deg, rgba(37, 99, 235, .18), rgba(15, 118, 110, .16));
}
.login-hero img { width: 76px; height: 76px; object-fit: cover; border-radius: 22px; border: 1px solid var(--line); }
.login-hero h1 { font-size: clamp(34px, 4vw, 54px); letter-spacing: -.05em; margin: 28px 0 12px; }
.login-form { padding: 42px; }

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 90;
    display: grid;
    gap: 10px;
}
.toast-item {
    min-width: min(360px, calc(100vw - 36px));
    padding: 13px 15px;
    border-radius: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}
.toast-item.success { border-color: rgba(22, 163, 74, .35); }
.toast-item.error { border-color: rgba(220, 38, 38, .35); }

.mobile-menu { display: none; }

@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
    .content > .grid[style] { grid-template-columns: 1fr !important; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 60;
        width: 290px;
        transform: translateX(-105%);
        transition: .22s ease;
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .mobile-menu { display: inline-flex; }
    .content, .topbar { padding-inline: 18px; }
    .grid-2, .grid-3, .form-grid, .login-card { grid-template-columns: 1fr; }
    .login-hero { display: none; }
    .user-chip span { display: none; }
}

@media (max-width: 620px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .topbar-actions { width: 100%; justify-content: space-between; }
    .toolbar { align-items: stretch; }
    .toolbar > * { width: 100%; }
    .access-grid { grid-template-columns: 1fr; }
    th, td { padding: 12px; }
}


/* =========================================================
   Production UI compatibility layer
   Keeps legacy module styles aligned with the shared theme.
========================================================= */
html[data-theme="dark"] body,
html[data-bs-theme="dark"] body {
    color-scheme: dark;
}

html[data-theme="dark"] .content,
html[data-theme="dark"] .main-panel,
html[data-theme="dark"] main {
    color: var(--text);
}

html[data-theme="dark"] .card,
html[data-theme="dark"] .stat,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .toast-item,
html[data-theme="dark"] .user-chip,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .check-card {
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    border-color: var(--line);
    color: var(--text);
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
    background: var(--input);
    color: var(--text);
    border-color: var(--line);
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
    color: var(--muted);
    opacity: .78;
}

html[data-theme="dark"] table,
html[data-theme="dark"] tbody,
html[data-theme="dark"] td {
    color: var(--text);
    border-color: var(--line);
}

html[data-theme="dark"] th {
    color: var(--muted);
    border-color: var(--line);
}

html[data-theme="dark"] tbody tr:hover {
    background: rgba(96, 165, 250, .08);
}

.nav-group { display: grid; gap: 4px; }
.nav-parent { width: 100%; border: 0; cursor: pointer; text-align: left; font: inherit; }
.nav-parent-title { flex: 1; }
.nav-caret { margin-left: auto; font-size: 12px; transition: transform .18s ease; }
.nav-group.open .nav-caret { transform: rotate(180deg); }
.nav-children { display: none; padding-left: 42px; padding-right: 8px; padding-bottom: 6px; }
.nav-group.open .nav-children { display: grid; gap: 4px; }
.nav-child-link {
    display: flex;
    align-items: center;
    min-height: 34px;
    padding: 8px 10px;
    border-radius: 12px;
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 800;
    transition: .18s ease;
}
.nav-child-link:hover,
.nav-child-link.active {
    color: var(--text);
    background: color-mix(in srgb, var(--brand) 14%, transparent);
}
.nav-section-label {
    margin: 14px 6px 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .12em;
    text-transform: uppercase;
}
.nav-section-label:first-child { margin-top: 4px; }

html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .topbar {
    background: color-mix(in srgb, var(--bg) 84%, transparent);
    border-color: var(--line);
}

html[data-theme="dark"] .nav-link:hover,
html[data-theme="dark"] .nav-link.active,
html[data-theme="dark"] .nav-parent:hover,
html[data-theme="dark"] .nav-parent.active,
html[data-theme="dark"] .nav-child-link:hover,
html[data-theme="dark"] .nav-child-link.active {
    background: rgba(96, 165, 250, .12);
    color: var(--text);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
    }
}

@media print {
    .sidebar, .topbar, .footer, .toast, .mobile-menu, [data-theme-toggle], [data-sidebar-toggle] { display: none !important; }
    .app-shell { display: block !important; }
    .content { width: 100% !important; padding: 0 !important; }
    body { background: #fff !important; color: #111827 !important; }
}

/* =========================================================
   Global performance + dark-mode compatibility fixes
   Added to normalize older module-level CSS that used hard-coded
   white cards/backgrounds and light-only form/table styles.
========================================================= */
:root {
    --soft: var(--surface-2);
    --overlay: rgba(2, 6, 23, .62);
}
html[data-theme="dark"] {
    --soft: var(--surface-2);
    --overlay: rgba(0, 0, 0, .72);
    color-scheme: dark;
}
html[data-theme="dark"] body {
    background:
        radial-gradient(circle at top left, rgba(96, 165, 250, .13), transparent 28rem),
        radial-gradient(circle at bottom right, rgba(45, 212, 191, .10), transparent 28rem),
        var(--bg);
}
html[data-theme="dark"] .content,
html[data-theme="dark"] .main-panel,
html[data-theme="dark"] main,
html[data-theme="dark"] section,
html[data-theme="dark"] .toolbar,
html[data-theme="dark"] .modal-body,
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
    color: var(--text);
}
html[data-theme="dark"] .card,
html[data-theme="dark"] .sd-card,
html[data-theme="dark"] .sd-modal-card,
html[data-theme="dark"] .sd-info,
html[data-theme="dark"] .sd-table,
html[data-theme="dark"] .sd-empty,
html[data-theme="dark"] .profile-doc-card,
html[data-theme="dark"] .pay-card,
html[data-theme="dark"] .release-card,
html[data-theme="dark"] .cw-card,
html[data-theme="dark"] .pd-card,
html[data-theme="dark"] .bm-card,
html[data-theme="dark"] .nwa-navbar-message-dropdown,
html[data-theme="dark"] .nwa-navbar-message-item,
html[data-theme="dark"] .nwa-chat-panel,
html[data-theme="dark"] .nwa-chat-item,
html[data-theme="dark"] .nwa-msg-bubble,
html[data-theme="dark"] .nwa-chat-compose,
html[data-theme="dark"] .nwa-group-members {
    background: color-mix(in srgb, var(--surface) 96%, transparent) !important;
    color: var(--text) !important;
    border-color: var(--line) !important;
}
html[data-theme="dark"] .sd-form-section,
html[data-theme="dark"] .sd-tabs,
html[data-theme="dark"] .sd-chip,
html[data-theme="dark"] .nwa-navbar-message-head,
html[data-theme="dark"] .nwa-navbar-message-foot,
html[data-theme="dark"] .nwa-chat-tabs,
html[data-theme="dark"] .nwa-chat-messages,
html[data-theme="dark"] .nwa-group-box,
html[data-theme="dark"] .nwa-reply-preview,
html[data-theme="dark"] .profile-facts div,
html[data-theme="dark"] .stat,
html[data-theme="dark"] .check-card {
    background: var(--surface-2) !important;
    color: var(--text) !important;
    border-color: var(--line) !important;
}
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .sd-input,
html[data-theme="dark"] .sd-select,
html[data-theme="dark"] .nwa-chat-search input,
html[data-theme="dark"] .nwa-compose-row textarea,
html[data-theme="dark"] .nwa-group-box input {
    background: var(--input) !important;
    color: var(--text) !important;
    border-color: var(--line) !important;
}
html[data-theme="dark"] input[type="file"]::file-selector-button {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
}
html[data-theme="dark"] table,
html[data-theme="dark"] th,
html[data-theme="dark"] td,
html[data-theme="dark"] .sd-table th,
html[data-theme="dark"] .sd-table td {
    color: var(--text) !important;
    border-color: var(--line) !important;
}
html[data-theme="dark"] th,
html[data-theme="dark"] .sd-table th {
    background: var(--surface-2) !important;
    color: var(--muted) !important;
}
html[data-theme="dark"] tbody tr:hover,
html[data-theme="dark"] .sd-suggest-item:hover,
html[data-theme="dark"] .nwa-navbar-message-item:hover,
html[data-theme="dark"] .nwa-chat-item:hover {
    background: rgba(96, 165, 250, .11) !important;
}
html[data-theme="dark"] .muted,
html[data-theme="dark"] .sd-muted,
html[data-theme="dark"] label,
html[data-theme="dark"] small,
html[data-theme="dark"] .nwa-navbar-message-preview,
html[data-theme="dark"] .nwa-chat-meta small,
html[data-theme="dark"] .nwa-msg small {
    color: var(--muted) !important;
}
html[data-theme="dark"] .btn.ghost,
html[data-theme="dark"] .sd-btn.secondary,
html[data-theme="dark"] .nwa-file-btn,
html[data-theme="dark"] .nwa-chat-tabs button {
    background: var(--surface-2) !important;
    color: var(--text) !important;
    border-color: var(--line) !important;
}
html[data-theme="dark"] .nwa-chat-tabs button.active,
html[data-theme="dark"] .sd-tab.active,
html[data-theme="dark"] .tab-button.active {
    background: color-mix(in srgb, var(--brand) 18%, var(--surface)) !important;
    color: var(--brand) !important;
    border-color: color-mix(in srgb, var(--brand) 44%, var(--line)) !important;
}
html[data-theme="dark"] .nwa-msg.mine .nwa-msg-bubble,
html[data-theme="dark"] .btn.primary,
html[data-theme="dark"] .sd-btn:not(.secondary) {
    background: linear-gradient(135deg, var(--brand), var(--brand-2)) !important;
    color: #fff !important;
    border-color: transparent !important;
}
html[data-theme="dark"] .modal-backdrop,
html[data-theme="dark"] .sd-modal {
    background: var(--overlay) !important;
}
html[data-theme="dark"] .toast-item.success,
html[data-theme="dark"] .sd-toast.success {
    background: color-mix(in srgb, var(--success) 16%, var(--surface)) !important;
    color: #bbf7d0 !important;
}
html[data-theme="dark"] .toast-item.error,
html[data-theme="dark"] .sd-toast.error {
    background: color-mix(in srgb, var(--danger) 16%, var(--surface)) !important;
    color: #fecaca !important;
}
@supports not (color: color-mix(in srgb, white, black)) {
    .sidebar, .topbar, .card { background: var(--surface); }
    html[data-theme="dark"] .sidebar, html[data-theme="dark"] .topbar, html[data-theme="dark"] .card { background: var(--surface); }
}
