:root {
    --bg: #f3f5fa;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #172033;
    --muted: #64708a;
    --line: #dfe5ef;
    --brand: #2457d6;
    --brand-strong: #1b44a8;
    --brand-soft: #e8efff;
    --success: #0f7b4f;
    --success-soft: #e7f7ef;
    --warning: #8a5a00;
    --warning-soft: #fff5dc;
    --danger: #b42318;
    --danger-soft: #feeceb;
    --info: #1c5fa8;
    --info-soft: #e8f2ff;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 16px 40px rgba(23, 32, 51, 0.08);
    --sidebar-width: 264px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--brand);
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    font-size: clamp(1.7rem, 3vw, 2.15rem);
    letter-spacing: -0.035em;
    line-height: 1.15;
    margin-bottom: 10px;
}

h2 {
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.sr-only {
    border: 0;
    clip: rect(0, 0, 0, 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    white-space: nowrap;
    width: 1px;
}

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

.eyebrow {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    margin: 0 0 6px;
    text-transform: uppercase;
}

.page-subtitle {
    color: var(--muted);
    margin: 0;
    max-width: 64ch;
}

.button {
    align-items: center;
    background: var(--brand);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: #ffffff;
    cursor: pointer;
    display: inline-flex;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 650;
    gap: 8px;
    justify-content: center;
    min-height: 42px;
    padding: 10px 18px;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.button:hover {
    background: var(--brand-strong);
}

.button--secondary {
    background: var(--surface);
    border-color: var(--line);
    color: var(--text);
}

.button--secondary:hover {
    background: var(--surface-soft);
}

.button--ghost {
    background: transparent;
    border-color: var(--line);
    color: var(--text);
}

.button--ghost:hover {
    background: var(--surface-soft);
}

.button--danger {
    background: var(--danger);
}

.button--danger:hover {
    background: #921b12;
}

.button--small {
    min-height: 34px;
    padding: 6px 12px;
    font-size: 0.82rem;
}

.button--full {
    width: 100%;
}

.button:focus-visible,
input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(36, 87, 214, 0.35);
    outline-offset: 2px;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-top: 22px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.field label {
    font-size: 0.86rem;
    font-weight: 650;
}

.field input,
.field select,
.field textarea {
    appearance: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    min-height: 44px;
    padding: 10px 13px;
    width: 100%;
}

.field select {
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 19px, calc(100% - 13px) 19px;
    background-repeat: no-repeat;
    background-size: 5px 5px, 5px 5px;
    padding-right: 36px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--brand);
    outline: none;
    box-shadow: 0 0 0 3px rgba(36, 87, 214, 0.12);
}

.field input[aria-invalid="true"] {
    border-color: var(--danger);
}

.field input:disabled {
    background: var(--surface-soft);
    color: var(--muted);
}

.field-hint {
    color: var(--muted);
    font-size: 0.78rem;
    margin: 0;
}

.field-error {
    color: var(--danger);
    font-size: 0.8rem;
    margin: 0;
}

.field-grid {
    display: grid;
    gap: 18px;
    grid-template-columns: 1fr 1fr;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding-top: 4px;
}

.form-intro {
    color: var(--muted);
    margin-bottom: 0;
}

.alert {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin: 16px 0;
    padding: 12px 14px;
}

.alert p {
    margin: 0 0 6px;
}

.alert p:last-child {
    margin-bottom: 0;
}

.alert--success {
    background: var(--success-soft);
    border-color: #bfe8d4;
    color: var(--success);
}

.alert--error {
    background: var(--danger-soft);
    border-color: #f6c9c5;
    color: var(--danger);
}

.alert--warning {
    background: var(--warning-soft);
    border-color: #f2dfae;
    color: var(--warning);
}

.alert--info {
    background: var(--info-soft);
    border-color: #c7ddf6;
    color: var(--info);
}

.alert-link {
    word-break: break-all;
}

.auth-body {
    align-items: center;
    background:
        radial-gradient(circle at 15% 15%, rgba(93, 145, 255, 0.35), transparent 28rem),
        radial-gradient(circle at 85% 85%, rgba(20, 184, 166, 0.18), transparent 24rem),
        linear-gradient(135deg, #0d1730 0%, #17336a 58%, #2457d6 100%);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 32px;
}

.auth-shell {
    width: min(440px, 100%);
}

.auth-brand {
    color: #ffffff;
    margin-bottom: 18px;
    text-align: center;
}

.auth-brand a {
    color: #ffffff;
    font-size: 1.25rem;
    font-weight: 750;
    letter-spacing: -0.03em;
    text-decoration: none;
}

.auth-brand span {
    color: #a9c4ff;
}

.auth-brand p {
    color: #b9c8e8;
    font-size: 0.84rem;
    margin: 4px 0 0;
}

.auth-card {
    background: var(--surface);
    border-radius: 18px;
    box-shadow: 0 26px 70px rgba(3, 12, 36, 0.35);
    padding: 32px;
}

.auth-card h1 {
    font-size: 1.8rem;
}

.auth-card .form {
    margin-top: 22px;
}

.auth-links {
    color: var(--muted);
    display: flex;
    flex-direction: column;
    font-size: 0.83rem;
    gap: 8px;
    margin-top: 20px;
    text-align: center;
}

.auth-footer {
    color: #a9b8d8;
    font-size: 0.76rem;
    margin: 18px 0 0;
    text-align: center;
}

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: #101a33;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    gap: 26px;
    height: 100vh;
    overflow-y: auto;
    padding: 26px 16px 20px;
    position: sticky;
    top: 0;
}

.sidebar-brand {
    padding: 0 10px;
}

.sidebar-brand a {
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 750;
    letter-spacing: -0.03em;
    text-decoration: none;
}

.sidebar-brand span {
    color: #8fb2ff;
}

.sidebar-brand p {
    color: #8e9cb8;
    font-size: 0.78rem;
    margin: 5px 0 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-link {
    align-items: center;
    border-radius: 9px;
    color: #b9c5db;
    display: flex;
    font-size: 0.9rem;
    font-weight: 600;
    gap: 11px;
    padding: 10px 12px;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.nav-link.is-active {
    background: rgba(143, 178, 255, 0.14);
    color: #ffffff;
}

.nav-mark {
    background: #52627f;
    border-radius: 50%;
    height: 7px;
    width: 7px;
}

.nav-link.is-active .nav-mark {
    background: #8fb2ff;
    box-shadow: 0 0 0 4px rgba(143, 178, 255, 0.15);
}

.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    font-size: 0.72rem;
    gap: 6px;
    margin-top: auto;
    padding: 16px 10px 0;
}

.sidebar-footer a {
    color: #b9c5db;
}

.sidebar-footer span {
    color: #6f7f9d;
}

.app-main {
    min-width: 0;
}

.topbar {
    align-items: center;
    backdrop-filter: blur(10px);
    background: rgba(243, 245, 250, 0.88);
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 18px;
    justify-content: space-between;
    padding: 14px 32px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-title {
    min-width: 0;
}

.topbar-title h1 {
    font-size: 1.2rem;
    margin: 0;
}

.topbar-title .eyebrow {
    margin-bottom: 2px;
}

.topbar-user {
    align-items: center;
    display: flex;
    gap: 11px;
    min-width: 0;
}

.user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
}

.user-meta strong {
    font-size: 0.84rem;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-meta span {
    color: var(--muted);
    font-size: 0.72rem;
}

.avatar {
    align-items: center;
    background: var(--brand-soft);
    border-radius: 50%;
    color: var(--brand-strong);
    display: inline-flex;
    flex: 0 0 auto;
    font-size: 0.85rem;
    font-weight: 750;
    height: 38px;
    justify-content: center;
    width: 38px;
}

.avatar--small {
    font-size: 0.72rem;
    height: 32px;
    width: 32px;
}

.avatar--large {
    font-size: 1.1rem;
    height: 56px;
    width: 56px;
}

.menu-button {
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    display: none;
    flex-direction: column;
    gap: 4px;
    height: 38px;
    justify-content: center;
    padding: 0 10px;
    width: 42px;
}

.menu-button span {
    background: var(--text);
    border-radius: 2px;
    display: block;
    height: 2px;
    width: 18px;
}

.sidebar-backdrop {
    display: none;
}

.app-content {
    margin: 0 auto;
    max-width: 1240px;
    padding: 32px;
}

.page-header {
    margin-bottom: 24px;
}

.page-header--row {
    align-items: flex-start;
    display: flex;
    gap: 20px;
    justify-content: space-between;
}

.page-header h1 {
    margin-bottom: 6px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.card + .card {
    margin-top: 22px;
}

.card--narrow {
    max-width: 680px;
}

.card-header {
    margin-bottom: 18px;
}

.card-header p {
    color: var(--muted);
    font-size: 0.86rem;
    margin: 0;
}

.card-header--row {
    align-items: flex-start;
    display: flex;
    gap: 18px;
    justify-content: space-between;
}

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

.stat-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 10px 26px rgba(23, 32, 51, 0.05);
    padding: 20px;
}

.stat-label {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 650;
    margin: 0 0 8px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 750;
    letter-spacing: -0.04em;
    line-height: 1;
    margin: 0 0 8px;
}

.stat-note {
    color: var(--muted);
    font-size: 0.74rem;
    margin: 0;
}

.two-column {
    display: grid;
    gap: 22px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.profile-summary {
    align-items: center;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    display: flex;
    gap: 14px;
    margin-bottom: 18px;
    padding: 14px;
}

.profile-summary div {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

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

.data-table {
    border-collapse: collapse;
    font-size: 0.88rem;
    min-width: 640px;
    width: 100%;
}

.data-table th {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 10px 12px;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}

.data-table td {
    border-top: 1px solid var(--line);
    padding: 13px 12px;
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: var(--surface-soft);
}

.user-cell {
    align-items: center;
    display: flex;
    gap: 11px;
}

.user-cell span:last-child {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-cell strong {
    font-size: 0.88rem;
    font-weight: 650;
}

.user-cell small {
    color: var(--muted);
    font-size: 0.76rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cell-actions {
    text-align: right;
    white-space: nowrap;
}

.inline-form {
    display: inline;
    margin-left: 10px;
}

.text-link {
    background: none;
    border: 0;
    color: var(--brand);
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    padding: 0;
    text-decoration: none;
}

.text-link:hover {
    text-decoration: underline;
}

.text-link--danger {
    color: var(--danger);
}

.badge {
    border-radius: 999px;
    display: inline-block;
    font-size: 0.71rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    padding: 3px 9px;
    white-space: nowrap;
}

.badge--owner,
.badge--superadmin {
    background: var(--brand-soft);
    color: var(--brand-strong);
}

.badge--admin {
    background: #eef0ff;
    color: #4b3fbf;
}

.badge--viewer {
    background: #eef3f8;
    color: #49617a;
}

.badge--status-active {
    background: var(--success-soft);
    color: var(--success);
}

.badge--status-inactive {
    background: #f0f1f4;
    color: #697386;
}

.search-form {
    display: flex;
    gap: 8px;
}

.search-form input {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
    min-height: 40px;
    min-width: 220px;
    padding: 8px 12px;
}

.search-form input:focus {
    border-color: var(--brand);
    outline: none;
    box-shadow: 0 0 0 3px rgba(36, 87, 214, 0.12);
}

.pagination {
    align-items: center;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 14px;
    justify-content: space-between;
    margin-top: 18px;
    padding-top: 16px;
}

.page-link {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 7px 12px;
    text-decoration: none;
}

.page-link:hover {
    background: var(--surface-soft);
}

.page-link.is-disabled {
    color: #a9b1c2;
}

.page-status {
    color: var(--muted);
    font-size: 0.78rem;
    text-align: center;
}

.empty-state {
    align-items: center;
    display: flex;
    flex-direction: column;
    padding: 34px 20px;
    text-align: center;
}

.empty-state h2 {
    margin: 14px 0 8px;
}

.empty-state p {
    color: var(--muted);
    margin: 0 0 18px;
    max-width: 54ch;
}

.empty-mark {
    background: var(--brand-soft);
    border-radius: 50%;
    height: 52px;
    position: relative;
    width: 52px;
}

.empty-mark::after {
    background: var(--brand);
    border-radius: 50%;
    content: "";
    height: 16px;
    left: 18px;
    position: absolute;
    top: 18px;
    width: 16px;
}

.empty-steps {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 10px;
    max-width: 860px;
    width: 100%;
}

.empty-steps div {
    align-items: flex-start;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    display: flex;
    gap: 10px;
    padding: 13px;
    text-align: left;
}

.empty-steps span {
    align-items: center;
    background: var(--brand-soft);
    border-radius: 50%;
    color: var(--brand-strong);
    display: inline-flex;
    flex: 0 0 auto;
    font-size: 0.72rem;
    font-weight: 750;
    height: 24px;
    justify-content: center;
    width: 24px;
}

.empty-steps p {
    color: var(--muted);
    font-size: 0.78rem;
    margin: 0;
}

.toast-stack {
    bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: fixed;
    right: 24px;
    width: min(390px, calc(100% - 48px));
    z-index: 80;
}

.toast {
    align-items: flex-start;
    animation: toast-in 0.2s ease-out;
    background: #111a2e;
    border-left: 4px solid var(--brand);
    border-radius: 10px;
    box-shadow: 0 14px 34px rgba(3, 12, 36, 0.24);
    color: #ffffff;
    display: flex;
    gap: 10px;
    padding: 13px 14px;
}

.toast p {
    flex: 1;
    font-size: 0.84rem;
    margin: 0;
}

.toast-dot {
    background: #8fb2ff;
    border-radius: 50%;
    flex: 0 0 auto;
    height: 8px;
    margin-top: 5px;
    width: 8px;
}

.toast--success {
    border-left-color: #35c98a;
}

.toast--success .toast-dot {
    background: #35c98a;
}

.toast--error {
    border-left-color: #ff7b72;
}

.toast--error .toast-dot {
    background: #ff7b72;
}

.toast--warning {
    border-left-color: #f2c94c;
}

.toast--warning .toast-dot {
    background: #f2c94c;
}

.toast--info {
    border-left-color: #8fb2ff;
}

.toast-close {
    background: transparent;
    border: 0;
    color: #9fb0cc;
    cursor: pointer;
    font-size: 1.15rem;
    line-height: 1;
    padding: 0;
}

.toast.is-leaving {
    animation: toast-out 0.18s ease-in forwards;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-out {
    to {
        opacity: 0;
        transform: translateY(8px);
    }
}

.error-page {
    align-items: center;
    background:
        radial-gradient(circle at top left, rgba(36, 87, 214, 0.08), transparent 34rem),
        var(--bg);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.error-shell {
    width: min(560px, 100%);
}

.brand {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 16px;
}

.brand span {
    color: var(--brand);
}

.error-status {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    margin: 0 0 8px;
}

.error-message {
    color: var(--muted);
    line-height: 1.65;
    margin: 0 0 24px;
}

.debug {
    border-top: 1px solid var(--line);
    color: var(--muted);
    margin-top: 24px;
    padding-top: 16px;
}

.debug summary {
    cursor: pointer;
    font-weight: 600;
}

.debug pre {
    background: #0f172a;
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 0.78rem;
    margin: 12px 0 0;
    max-height: 280px;
    overflow: auto;
    padding: 16px;
    white-space: pre-wrap;
    word-break: break-word;
}

@media (max-width: 1080px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        box-shadow: 18px 0 50px rgba(3, 12, 36, 0.28);
        height: 100vh;
        left: 0;
        max-width: 300px;
        position: fixed;
        top: 0;
        transform: translateX(-105%);
        transition: transform 0.2s ease;
        width: 86vw;
        z-index: 70;
    }

    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        background: rgba(9, 17, 34, 0.48);
        display: block;
        inset: 0;
        opacity: 0;
        pointer-events: none;
        position: fixed;
        transition: opacity 0.2s ease;
        z-index: 60;
    }

    .sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .menu-button {
        display: flex;
    }

    .topbar {
        padding: 14px 24px;
    }

    .app-content {
        padding: 24px;
    }

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

@media (max-width: 760px) {
    .topbar-title .eyebrow {
        display: none;
    }

    .user-meta {
        display: none;
    }

    .page-header--row,
    .card-header--row {
        flex-direction: column;
    }

    .page-header--row .button,
    .card-header--row .search-form {
        align-self: stretch;
    }

    .search-form input {
        flex: 1;
        min-width: 0;
    }

    .two-column,
    .field-grid,
    .empty-steps {
        grid-template-columns: 1fr;
    }

    .auth-body {
        padding: 20px;
    }
}

@media (max-width: 520px) {
    .app-content {
        padding: 18px 16px 28px;
    }

    .topbar {
        padding: 12px 16px;
    }

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

    .auth-card {
        padding: 24px;
    }

    .card {
        padding: 18px;
    }

    .page-header h1 {
        font-size: 1.55rem;
    }
}
