:root {
    --primary: #6d5ef7;
    --primary-dark: #5646eb;
    --primary-accent: #3b82f6;
    --primary-soft: rgba(109, 94, 247, 0.12);
    --bg: #edf2ff;
    --bg-deep: #e8ecff;
    --card: rgba(255, 255, 255, 0.88);
    --card-strong: #ffffff;
    --text: #101828;
    --muted: #667085;
    --border: rgba(148, 163, 184, 0.24);
    --danger: #dc2626;
    --success: #16a34a;
    --radius: 20px;
    --shadow-soft: 0 22px 54px rgba(15, 23, 42, 0.08);
    --shadow-card: 0 14px 32px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    color: var(--text);
    background:
            radial-gradient(circle at 0 0, rgba(109, 94, 247, 0.18), transparent 22%),
            radial-gradient(circle at 100% 0, rgba(59, 130, 246, 0.18), transparent 24%),
            linear-gradient(180deg, #f7f8ff 0%, var(--bg) 48%, var(--bg-deep) 100%);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button, input, select, textarea {
    font: inherit;
}

button {
    height: 40px;
    padding: 0 18px;
    border: 0;
    border-radius: 12px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-accent));
    box-shadow: 0 10px 26px rgba(109, 94, 247, 0.22);
    cursor: pointer;
    transition: transform .16s ease, filter .16s ease, box-shadow .16s ease;
}

button:hover {
    transform: translateY(-1px);
    filter: brightness(1.03);
}

button.secondary {
    color: #475467;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.22);
}

button.secondary:hover {
    box-shadow: inset 0 0 0 1px rgba(109, 94, 247, 0.18), 0 8px 18px rgba(15, 23, 42, 0.06);
}

.hidden { display: none !important; }

.button-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.login-page {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 16px;
    background:
            radial-gradient(circle at 18% 18%, rgba(139, 92, 246, 0.34), transparent 18%),
            radial-gradient(circle at 84% 14%, rgba(59, 130, 246, 0.26), transparent 22%),
            linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px),
            linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px),
            linear-gradient(135deg, #161a36, #202b60 52%, #22418f);
    background-size: auto, auto, 34px 34px, 34px 34px, auto;
}

.login-page.login-pending .login-panel {
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
}

.login-panel {
    width: min(430px, calc(100vw - 32px));
    min-height: 336px;
    padding: 28px;
    display: flex;
    flex-direction: column;
    transition: opacity .12s ease, transform .12s ease;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.34);
    border-radius: 24px;
    box-shadow: 0 30px 80px rgba(15, 23, 42, 0.24);
    backdrop-filter: blur(16px);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.login-brand-mark,
.brand-mark {
    overflow: hidden;
}

.login-brand-mark {
    width: 48px;
    height: 48px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.92);
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.24);
}

.login-brand-mark img,
.brand-mark img {
    display: block;
    width: 100%;
    height: 100%;
}

.login-brand-copy {
    min-width: 0;
}

.login-brand-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.1;
}

.login-brand-subtitle {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.login-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 38px;
    margin-bottom: 22px;
}

.login-panel h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.1;
}

.login-divider {
    height: 1px;
    margin: 18px 0;
    background: var(--border);
}

.form-heading {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.forgot-password-form button.secondary {
    justify-self: start;
}

.login-link-row {
    margin-top: 14px;
    text-align: right;
}

.text-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
}

.text-link:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.lang-toggle {
    min-width: 68px;
    padding: 0 12px;
}

.form-stack, .form-grid {
    display: grid;
    gap: 14px;
}

.form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

label span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 13px;
}

input, select, textarea {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 12px;
    padding: 11px 13px;
    background: rgba(255, 255, 255, 0.96);
    color: var(--text);
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.03);
}

textarea {
    min-height: 92px;
    resize: vertical;
}

.readonly-input {
    background: rgba(248, 250, 252, 0.92);
    color: #64748b;
    cursor: not-allowed;
}

.form-hint {
    margin: -4px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
}

.error-text {
    min-height: 20px;
    color: var(--danger);
}

.success-text {
    color: var(--success);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    gap: 18px;
    max-width: 1500px;
    margin: 0 auto;
    padding: 20px;
}

.sidebar {
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid rgba(255, 255, 255, 0.56);
    border-radius: 24px;
    padding: 18px 14px;
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(18px);
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 2px 8px 22px;
}

.brand-mark {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    color: #fff;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--primary-accent));
    box-shadow: 0 12px 24px rgba(109, 94, 247, 0.24);
    padding: 0;
}

.brand-copy {
    min-width: 0;
}

.brand {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
}

.brand-subtitle {
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.nav-group-title {
    margin: 18px 10px 8px;
    color: #98a2b3;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 0;
    padding: 12px 14px;
    border-radius: 14px;
    color: var(--muted);
    text-decoration: none;
    transition: background .16s ease, color .16s ease, transform .16s ease;
}

.sidebar a::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.38);
    flex: none;
}

.sidebar a:hover {
    background: rgba(255, 255, 255, 0.78);
    color: var(--text);
    transform: translateX(2px);
}

.sidebar a.active {
    color: #4338ca;
    background: linear-gradient(90deg, rgba(237, 233, 254, 0.92), rgba(224, 231, 255, 0.92));
    box-shadow: inset 0 0 0 1px rgba(109, 94, 247, 0.1);
}

.sidebar a.active::before {
    background: linear-gradient(135deg, var(--primary), var(--primary-accent));
    box-shadow: 0 0 0 4px rgba(109, 94, 247, 0.14);
}

.content {
    min-width: 0;
    padding: 0 0 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid rgba(255, 255, 255, 0.56);
    border-radius: 24px;
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(18px);
}

.topbar-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex: 1;
    min-width: 0;
}

.topbar h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.1;
}

.topbar p {
    margin: 6px 0 0;
    color: var(--muted);
}

.topbar-search {
    min-width: 280px;
    max-width: 420px;
    padding: 11px 16px;
    border-radius: 14px;
    color: var(--muted);
    background: rgba(248, 250, 252, 0.94);
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.18);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.card {
    padding: 20px;
    margin-bottom: 16px;
    background: var(--card);
    border: 1px solid rgba(255, 255, 255, 0.56);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    backdrop-filter: blur(12px);
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.hero-card {
    margin-bottom: 18px;
    padding: 24px;
    border-radius: 28px;
    background:
            radial-gradient(circle at top left, rgba(255,255,255,0.18), transparent 22%),
            linear-gradient(135deg, #7c3aed 0%, #6d5ef7 44%, #3b82f6 100%);
    color: #fff;
    box-shadow: 0 24px 60px rgba(76, 81, 191, 0.22);
}

.hero-copy {
    margin-bottom: 18px;
}

.hero-eyebrow {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    opacity: .84;
}

.hero-card h2 {
    margin: 10px 0 8px;
    font-size: 38px;
    line-height: 1.05;
}

.hero-card p {
    margin: 0;
    color: rgba(255,255,255,0.84);
    font-size: 15px;
}

.hero-stats {
    margin-top: 16px;
}

.dashboard-panels {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.dashboard-panel {
    margin-bottom: 0;
    padding: 18px;
}

.dashboard-panel-header {
    margin-bottom: 12px;
}

.stat-group-title {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.dashboard-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-stats-balance {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card {
    margin: 0;
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: none;
    backdrop-filter: blur(14px);
}

.stat-card-light {
    background: rgba(248, 250, 252, 0.9);
    border-color: rgba(148, 163, 184, 0.16);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.stat-label {
    color: rgba(255,255,255,0.74);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .02em;
}

.stat-number {
    margin-top: 8px;
    color: inherit;
    font-size: 28px;
    font-weight: 700;
    line-height: 1.15;
    word-break: break-word;
}

.stat-card-light .stat-label {
    color: var(--muted);
}

.stat-number-dark {
    color: var(--text);
}

.section-card {
    padding: 18px 20px;
}

.section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.section-subtitle {
    margin-top: 6px;
    color: var(--muted);
    font-size: 13px;
}

.dashboard-note-card {
    display: none;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: end;
    margin-bottom: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: transparent;
}

table.audit-log-table {
    table-layout: fixed;
}

table.audit-log-table th:nth-child(4),
table.audit-log-table td:nth-child(4),
table.audit-log-table th:nth-child(5),
table.audit-log-table td:nth-child(5) {
    width: 140px;
    max-width: 140px;
    white-space: normal;
    word-break: break-word;
}

table.audit-log-table th:nth-child(1),
table.audit-log-table td:nth-child(1) {
    width: 160px;
}

table.audit-log-table th:nth-child(2),
table.audit-log-table td:nth-child(2) {
    width: 150px;
}

table.audit-log-table th:nth-child(6),
table.audit-log-table td:nth-child(6) {
    width: 120px;
}

table.audit-log-table th:nth-child(7),
table.audit-log-table td:nth-child(7) {
    width: 220px;
}

.table-card {
    max-height: calc(100vh - 220px);
    overflow: auto;
}

th, td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    position: sticky;
    top: 0;
    z-index: 4;
    background: rgba(248, 250, 252, 0.9);
    color: var(--muted);
    font-weight: 600;
    box-shadow: inset 0 -1px 0 var(--border);
}

tr:hover td {
    background: rgba(237, 233, 254, 0.35);
}

.pager {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 12px;
}

.code-block {
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
    padding: 14px;
    background: rgba(248, 250, 252, 0.92);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.totp-status-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin-bottom: 14px;
    color: var(--muted);
    font-size: 14px;
}

.totp-guide {
    margin-bottom: 16px;
    padding: 14px 16px;
    background: rgba(248, 250, 252, 0.92);
    border: 1px solid var(--border);
    border-radius: 16px;
}

.totp-guide-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.totp-guide-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.totp-guide-status,
.totp-guide-tip {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.7;
}

.totp-guide-status {
    margin-bottom: 10px;
}

.totp-guide-list {
    margin: 0 0 10px 18px;
    padding: 0;
    color: var(--text);
    font-size: 13px;
    line-height: 1.8;
}

.totp-state-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    background: #e2e8f0;
    color: #475569;
    font-size: 12px;
    font-weight: 600;
}

.totp-state-badge.enabled {
    background: #ddd6fe;
    color: #5b21b6;
}

.totp-qr-wrap {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.totp-qr-image {
    width: 180px;
    height: 180px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #fff;
}

.totp-qr-fallback {
    color: var(--muted);
    font-size: 13px;
}

.totp-prepared-panel {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.totp-qr-tip {
    margin: 10px 0 14px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.7;
}

.totp-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.totp-actions button.danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
}

@media (max-width: 780px) {
    .app-shell {
        grid-template-columns: 1fr;
        padding: 12px;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 5;
    }

    .sidebar nav {
        display: flex;
        overflow-x: auto;
        gap: 6px;
    }

    .sidebar a {
        white-space: nowrap;
    }

    .nav-group-title {
        display: none;
    }

    .content {
        padding: 0 0 18px;
    }

    .stats, .form-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-panels {
        grid-template-columns: 1fr;
    }

    .dashboard-stats,
    .dashboard-stats-balance {
        grid-template-columns: 1fr;
    }

    .topbar,
    .topbar-main {
        align-items: flex-start;
        gap: 12px;
        flex-direction: column;
    }

    .topbar-search {
        min-width: 0;
        width: 100%;
        max-width: none;
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .hero-card h2 {
        font-size: 30px;
    }

    table {
        min-width: 760px;
    }

    .card.table-card {
        overflow-x: auto;
    }
}
