:root {
    color-scheme: dark;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #a8b4c6;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --success-hover: #16a34a;
    --border: #475569;
    --focus: #93c5fd;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 280px;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
    line-height: 1.5;
}

button,
input {
    font: inherit;
}

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

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

.container {
    width: min(1200px, 100%);
    margin: 0 auto;
    padding-inline: 20px;
}

.page-content {
    padding-block: 32px 48px;
}

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

.page-header p,
.field-hint,
.auth-switch {
    color: var(--text-secondary);
}

.field-hint {
    margin: 8px 0 0;
    font-size: 0.875rem;
}

.section-title {
    margin-top: 32px;
}

.section-card {
    margin-top: 32px;
}

.card,
.stat-card {
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-secondary);
}

.card {
    padding: 32px;
}

.stat-card h2 {
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: 24px;
}

.stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
}

.btn {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: 0;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    transition: background-color 0.15s, opacity 0.15s;
}

.btn-primary {
    background: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-card);
}

.btn-secondary:hover {
    background: #3f5067;
}

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

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-success {
    background: var(--success);
}

.btn-success:hover {
    background: var(--success-hover);
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    min-width: 44px;
    padding-inline: 12px;
    font-size: 1.25rem;
}

.button-row,
.modal-actions,
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.button-row {
    margin-top: 16px;
}

.connect-button {
    margin-top: 32px;
    padding-block: 14px;
    font-size: 1.1rem;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="number"] {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: 0;
    background: var(--bg-primary);
    color: var(--text-primary);
}

input:focus-visible,
.btn:focus-visible,
.nav-link:focus-visible,
a:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.auth-page {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

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

.auth-header {
    margin-bottom: 28px;
    text-align: center;
}

.auth-header p {
    color: var(--text-secondary);
}

.auth-switch {
    margin: 20px 0 0;
    text-align: center;
}

.captcha-box {
    display: grid;
    grid-template-columns: auto auto auto auto minmax(70px, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    font-size: 1.1rem;
    font-weight: 700;
}

.captcha-box input {
    min-width: 0;
}

.alert {
    display: none;
    margin-bottom: 20px;
    padding: 12px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
}

.alert-visible {
    display: block;
}

.alert-error {
    border-color: var(--danger);
    background: rgb(239 68 68 / 12%);
    color: #fecaca;
}

.alert-success {
    border-color: var(--success);
    background: rgb(34 197 94 / 12%);
    color: #bbf7d0;
}

.navbar {
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.navbar-content {
    display: flex;
    width: min(1200px, 100%);
    min-height: 64px;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin: 0 auto;
    padding: 10px 20px;
}

.navbar-brand {
    color: var(--text-primary);
    font-size: 1.2rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.navbar-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    align-items: center;
    justify-content: flex-end;
}

.nav-link {
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    text-decoration: none;
}

.nav-link:hover,
.nav-link.active {
    color: var(--text-primary);
}

.nav-link.active {
    color: var(--focus);
}

.nav-button {
    padding: 0;
}

.qr-container {
    text-align: center;
}

.qr-frame {
    display: grid;
    width: min(332px, 100%);
    min-height: 200px;
    place-items: center;
    margin: 20px auto;
    padding: 16px;
    border-radius: 12px;
    background: #fff;
    color: #111827;
}

.qr-frame img {
    width: min(300px, 100%);
    height: auto;
}

.subscription-url {
    display: block;
    max-width: 100%;
    margin-top: 12px;
    padding: 12px;
    overflow-wrap: anywhere;
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-secondary);
}

.profile-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
    gap: 16px;
    margin: 0;
}

.profile-list div {
    padding: 12px;
    border-radius: 8px;
    background: var(--bg-primary);
}

.profile-list dt {
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
}

.profile-list dd {
    margin: 4px 0 0;
    font-weight: 600;
}

.invite-list {
    display: grid;
    gap: 10px;
    margin-top: 20px;
}

.invite-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    border-radius: 8px;
    background: var(--bg-primary);
}

.invite-item-info {
    min-width: 0;
}

.invite-code-value {
    overflow-wrap: anywhere;
    font-family: "Cascadia Mono", Consolas, monospace;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.invite-meta {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.invite-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.section-toolbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
}

.section-toolbar > div {
    flex: 1;
}

.table-container {
    margin-top: 20px;
    overflow-x: auto;
}

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

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

th {
    color: var(--text-secondary);
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.table-actions {
    display: flex;
    min-width: 250px;
    flex-wrap: wrap;
    gap: 8px;
}

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-admin {
    background: rgb(59 130 246 / 20%);
    color: #bfdbfe;
}

.badge-banned {
    background: rgb(239 68 68 / 20%);
    color: #fecaca;
}

.badge-active {
    background: rgb(34 197 94 / 20%);
    color: #bbf7d0;
}

.pagination {
    justify-content: center;
    margin-top: 20px;
}

.modal-overlay {
    position: fixed;
    z-index: 1000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgb(0 0 0 / 75%);
}

.modal-content {
    width: min(500px, 100%);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-secondary);
}

.modal-actions .btn {
    flex: 1;
}

.hidden {
    display: none !important;
}

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

.empty-state {
    margin: 0;
    padding: 18px;
    color: var(--text-secondary);
    text-align: center;
}

@media (max-width: 720px) {
    .navbar-content,
    .section-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .navbar-content {
        padding-block: 14px;
    }

    .navbar-nav {
        justify-content: flex-start;
    }

    .card,
    .stat-card {
        padding: 20px;
    }

    .invite-item {
        align-items: stretch;
        flex-direction: column;
    }

    .invite-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 420px) {
    .container {
        padding-inline: 14px;
    }

    .auth-page {
        padding: 14px;
    }

    .card,
    .stat-card,
    .modal-content {
        padding: 18px;
    }

    .captcha-box {
        grid-template-columns: auto auto auto auto 1fr;
    }

    .captcha-box .btn-icon {
        grid-column: 1 / -1;
        width: 100%;
    }

    .button-row .btn,
    .invite-actions .btn {
        flex: 1 1 100%;
    }
}
