:root {
    --bg: #0b111a;
    --bg-soft: #111b2a;
    --panel: #131f31;
    --panel-strong: #172740;
    --border: #2a3b55;
    --text: #e7edf7;
    --text-soft: #9baac2;
    --text-faint: #7486a1;
    --accent: #3986ff;
    --accent-hover: #2c6fd4;
    --success: #2db477;
    --warning: #e3b341;
    --danger: #d86161;
    --info: #5b9eff;
    --radius: 14px;
    --shadow: 0 20px 40px rgba(3, 7, 13, 0.45);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: "Manrope", "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(1100px 600px at 12% -8%, rgba(57, 134, 255, 0.18), transparent 62%),
        radial-gradient(900px 500px at 88% 4%, rgba(57, 134, 255, 0.1), transparent 65%),
        linear-gradient(170deg, var(--bg), #070c14 72%);
}

a {
    color: inherit;
}

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

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 28px 20px;
    border-right: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(13, 21, 33, 0.95), rgba(10, 16, 25, 0.9));
    backdrop-filter: blur(8px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 800;
    color: #ffffff;
    background: linear-gradient(145deg, #3d8bff, #2f65c2);
    box-shadow: 0 10px 25px rgba(18, 52, 106, 0.45);
}

.brand-kicker {
    margin: 0 0 4px;
    font-size: 10px;
    letter-spacing: 0.13em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.brand-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.25;
}

.sidebar-nav {
    display: grid;
    gap: 8px;
}

.nav-item {
    border: 1px solid transparent;
    border-radius: 10px;
    text-decoration: none;
    padding: 10px 12px;
    color: var(--text-soft);
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.nav-item:hover {
    color: var(--text);
    border-color: rgba(83, 118, 172, 0.4);
    background: rgba(31, 47, 73, 0.45);
}

.nav-item.active {
    color: #ffffff;
    border-color: rgba(84, 140, 229, 0.9);
    background: linear-gradient(140deg, rgba(57, 134, 255, 0.36), rgba(47, 101, 194, 0.25));
}

.sidebar-footer {
    margin-top: auto;
}

.main-content {
    padding: 24px;
    animation: fade-up 0.24s ease;
}

.page-header,
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.page-title {
    margin: 0;
    font-size: 28px;
    line-height: 1.2;
    letter-spacing: 0.01em;
}

.page-subtitle {
    margin: 8px 0 0;
    max-width: 860px;
    color: var(--text-faint);
    line-height: 1.45;
}

.header-actions,
.head-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

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

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

.panel,
.card {
    background: linear-gradient(165deg, rgba(22, 34, 54, 0.88), rgba(15, 24, 38, 0.95));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}

.stat-card {
    background: linear-gradient(165deg, rgba(21, 33, 52, 0.9), rgba(14, 23, 36, 0.96));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    min-height: 128px;
}

.stat-label {
    margin: 0;
    font-size: 11px;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.stat-value {
    margin: 8px 0 0;
    font-size: 34px;
    line-height: 1.1;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.stat-meta {
    margin: 10px 0 0;
    color: var(--text-soft);
    font-size: 13px;
    line-break: anywhere;
}

.panel-head,
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.panel-head h3,
.card-head h3,
.section-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

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

.text-link,
.link-muted {
    color: var(--text-soft);
    font-size: 13px;
    text-decoration: none;
}

.text-link:hover,
.link-muted:hover {
    color: var(--text);
}

.entity-list,
.site-list {
    display: grid;
    gap: 10px;
}

.entity-row,
.site-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid #24344c;
    border-radius: 10px;
    padding: 10px 12px;
    background: rgba(12, 20, 32, 0.7);
}

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

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    min-width: 800px;
    border-collapse: collapse;
}

.table th,
.table td {
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid rgba(64, 89, 125, 0.45);
    padding: 11px 10px;
    font-size: 14px;
    line-height: 1.35;
}

.table th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-faint);
    font-weight: 700;
}

.form-grid {
    display: grid;
    gap: 12px;
}

.toolbar {
    display: grid;
    grid-template-columns: minmax(240px, 2fr) minmax(180px, 1fr) minmax(180px, 1fr) auto;
    gap: 12px;
    margin-bottom: 14px;
    align-items: end;
}

.toolbar-field {
    margin: 0;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

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

.field {
    display: grid;
    gap: 7px;
}

.field > span,
.field-label {
    color: var(--text-soft);
    font-size: 13px;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    background: rgba(10, 16, 26, 0.78);
    border: 1px solid #344766;
    color: var(--text);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

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

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: #4c8ef3;
    box-shadow: 0 0 0 3px rgba(59, 122, 215, 0.25);
}

.field-check {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--text-soft);
    font-size: 14px;
}

.field-check input {
    width: 16px;
    height: 16px;
}

.field-block {
    display: grid;
    gap: 8px;
}

.checks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 8px;
}

.checks-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid #2f435f;
    border-radius: 10px;
    padding: 8px 10px;
    background: rgba(11, 18, 29, 0.75);
    color: var(--text-soft);
    font-size: 14px;
}

.checks-grid input {
    width: 15px;
    height: 15px;
}

.checks-scroll {
    max-height: 220px;
    overflow-y: auto;
    padding-right: 4px;
}

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

.btn {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 9px 13px;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    transition: filter 0.18s ease, transform 0.18s ease;
}

.btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.06);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(140deg, var(--accent), var(--accent-hover));
    color: #ffffff;
}

.btn-secondary {
    background: rgba(43, 61, 87, 0.78);
    border-color: #46628c;
    color: var(--text);
}

.btn-ghost {
    background: rgba(11, 18, 29, 0.66);
    border-color: #30435f;
    color: var(--text-soft);
}

.btn-danger {
    background: linear-gradient(140deg, #cd5b5b, #a74848);
    color: #ffffff;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
}

.badge-success {
    color: #0f2c1f;
    background: var(--success);
}

.badge-warning {
    color: #362604;
    background: var(--warning);
}

.badge-danger {
    color: #fff4f4;
    background: var(--danger);
}

.badge-info {
    color: #08203d;
    background: var(--info);
}

.badge-muted {
    color: #d2dbeb;
    background: rgba(75, 96, 125, 0.62);
}

.alert {
    border-radius: 10px;
    border: 1px solid transparent;
    padding: 11px 14px;
    font-size: 14px;
    margin-bottom: 14px;
}

.alert-success {
    background: rgba(45, 180, 119, 0.17);
    border-color: rgba(45, 180, 119, 0.45);
    color: #b8f0d6;
}

.alert-error {
    background: rgba(216, 97, 97, 0.16);
    border-color: rgba(216, 97, 97, 0.4);
    color: #ffd2d2;
}

.alert-info {
    background: rgba(91, 158, 255, 0.16);
    border-color: rgba(91, 158, 255, 0.4);
    color: #d9e9ff;
}

.hint {
    color: var(--text-faint);
    font-size: 12px;
    line-height: 1.4;
}

.empty {
    margin: 2px 0;
    color: var(--text-faint);
}

.mono {
    margin: 2px 0 0;
    font-family: "JetBrains Mono", Menlo, Consolas, monospace;
    color: var(--text-soft);
    font-size: 12px;
    line-break: anywhere;
}

.password-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.password-wrap input {
    padding-right: 44px;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 14px;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-soft);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 0;
    cursor: pointer;
    z-index: 2;
}

.password-toggle:hover {
    color: #c8d8f0;
    background: transparent;
}

.eye-icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

#customAuthFields {
    display: none;
}

#customAuthFields.show {
    display: grid;
}

@keyframes fade-up {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1280px) {
    .stats-grid,
    .grid-stats {
        grid-template-columns: 1fr;
    }

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

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

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

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

    .sidebar {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        gap: 14px;
    }

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

    .main-content {
        padding: 16px;
    }
}

@media (max-width: 740px) {
    .page-header,
    .page-head {
        flex-direction: column;
    }

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

    .sidebar-nav {
        grid-template-columns: 1fr;
    }

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