:root {
    --bg: #050508;
    --bg-elevated: #0a0b10;
    --surface: rgba(16, 18, 26, 0.72);
    --surface-solid: #10121a;
    --panel-border: rgba(0, 240, 255, 0.12);
    --panel-border-strong: rgba(0, 240, 255, 0.22);
    --primary: #00f0ff;
    --primary-dim: #00a8b5;
    --secondary: #7b2dff;
    --danger: #ff2a6d;
    --success: #05ffa1;
    --warning: #ffcc00;
    --text: #e8f4ff;
    --text-muted: #8a94a6;
    --text-dim: #5c6475;
    --shadow-glow: 0 0 24px rgba(0, 240, 255, 0.10);
    --shadow-card: 0 12px 40px rgba(0, 0, 0, 0.45);
    --radius: 14px;
    --radius-sm: 10px;
    --header-height: 64px;
    --sidebar-width: 250px;
}

* {
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    margin: 0;
    min-height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background:
        radial-gradient(circle at 20% 10%, rgba(0, 240, 255, 0.06), transparent 35%),
        radial-gradient(circle at 80% 90%, rgba(123, 45, 255, 0.07), transparent 40%),
        linear-gradient(180deg, var(--bg) 0%, #07070c 100%);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(0, 240, 255, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 240, 255, 0.035) 1px, transparent 1px);
    background-size: 36px 36px;
    mask-image: radial-gradient(circle at center, black 30%, transparent 85%);
    z-index: -1;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.15s;
}

a:hover {
    color: #7df9ff;
}

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

.auth-main {
    width: 100%;
    max-width: 420px;
}

.auth-card {
    background: var(--surface);
    backdrop-filter: blur(18px);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 40px;
    box-shadow: var(--shadow-glow), var(--shadow-card);
    position: relative;
    overflow: hidden;
}

.auth-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary), var(--secondary), transparent);
}

.auth-card h1 {
    margin: 0 0 8px;
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.auth-card p {
    color: var(--text-muted);
    margin-bottom: 28px;
}

/* Layout */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(10, 11, 16, 0.82);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    z-index: 100;
}

.header-brand {
    font-size: 22px;
    font-weight: 900;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.user-role {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--primary-dim);
    font-weight: 700;
    letter-spacing: 0.5px;
    border: 1px solid var(--panel-border);
    padding: 3px 8px;
    border-radius: 6px;
}

.user-name {
    font-weight: 600;
    color: var(--text);
}

.logout-form {
    margin: 0;
}

.app {
    display: flex;
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    backdrop-filter: blur(14px);
    border-right: 1px solid var(--panel-border);
    padding: 20px 0;
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    overflow-y: auto;
    z-index: 90;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 12px;
}

.nav-link {
    padding: 12px 16px;
    color: var(--text-muted);
    font-weight: 600;
    border-radius: var(--radius-sm);
    border-left: 3px solid transparent;
    transition: all 0.18s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-link:hover {
    background: rgba(0, 240, 255, 0.08);
    color: var(--text);
}

.nav-link.active {
    background: rgba(0, 240, 255, 0.10);
    color: var(--primary);
    border-left-color: var(--primary);
    box-shadow: inset 0 0 18px rgba(0, 240, 255, 0.06);
}

.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 28px;
}

.container {
    max-width: 1440px;
    margin: 0 auto;
}

h2 {
    margin: 0 0 22px;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.3px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.18s ease;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    border: 1px solid var(--panel-border);
}

.btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--panel-border-strong);
    transform: translateY(-1px);
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary-dim), var(--primary));
    color: #000;
    border: none;
    box-shadow: 0 0 18px rgba(0, 240, 255, 0.25);
}

.btn-primary:hover {
    box-shadow: 0 0 28px rgba(0, 240, 255, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #c91a4a, var(--danger));
    color: #fff;
    border: none;
    box-shadow: 0 0 18px rgba(255, 42, 109, 0.2);
}

.btn-danger:hover {
    box-shadow: 0 0 28px rgba(255, 42, 109, 0.35);
}

.btn-secondary {
    background: rgba(123, 45, 255, 0.12);
    color: #c7b3ff;
    border: 1px solid rgba(123, 45, 255, 0.3);
}

.btn-secondary:hover {
    background: rgba(123, 45, 255, 0.2);
}

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

.btn-block {
    width: 100%;
}

/* Forms */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 7px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: rgba(0, 0, 0, 0.25);
    color: var(--text);
    transition: all 0.18s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 240, 255, 0.12);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
}

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

/* Tables */
.table-responsive {
    overflow-x: auto;
    background: var(--surface);
    backdrop-filter: blur(12px);
    border-radius: var(--radius);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-card);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th,
.data-table td {
    padding: 14px 18px;
    text-align: left;
    border-bottom: 1px solid var(--panel-border);
}

.data-table th {
    background: rgba(0, 0, 0, 0.25);
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.6px;
}

.data-table tbody tr {
    transition: background 0.15s;
}

.data-table tbody tr:hover {
    background: rgba(0, 240, 255, 0.04);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Toolbar */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    gap: 12px;
    flex-wrap: wrap;
}

.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.filters input,
.filters select {
    padding: 9px 12px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: rgba(0, 0, 0, 0.25);
    color: var(--text);
}

.bulk-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
    flex-wrap: wrap;
}

#selected-count {
    font-weight: 700;
    color: var(--primary);
}

/* Status badges */
.status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid transparent;
}

.status-active { background: rgba(5, 255, 161, 0.12); color: var(--success); border-color: rgba(5, 255, 161, 0.25); }
.status-passive { background: rgba(138, 148, 166, 0.12); color: var(--text-muted); border-color: rgba(138, 148, 166, 0.25); }
.status-backup { background: rgba(255, 204, 0, 0.12); color: var(--warning); border-color: rgba(255, 204, 0, 0.25); }
.status-suspended { background: rgba(255, 42, 109, 0.12); color: var(--danger); border-color: rgba(255, 42, 109, 0.25); }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 18px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--surface);
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 22px;
    text-align: center;
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    opacity: 0.6;
}

.stat-value {
    display: block;
    font-size: 32px;
    font-weight: 900;
    color: var(--text);
    margin-bottom: 4px;
}

.stat-label {
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.6px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 18px;
}

.pagination button {
    padding: 7px 14px;
    border: 1px solid var(--panel-border);
    background: var(--surface);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 700;
    transition: all 0.15s;
}

.pagination button:hover {
    border-color: var(--panel-border-strong);
    color: var(--text);
}

.pagination button.active {
    background: linear-gradient(135deg, var(--primary-dim), var(--primary));
    color: #000;
    border-color: transparent;
    box-shadow: 0 0 16px rgba(0, 240, 255, 0.25);
}

.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    backdrop-filter: blur(20px);
    border: 1px solid var(--panel-border-strong);
    border-radius: var(--radius);
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-glow), var(--shadow-card);
    position: relative;
}

.modal-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid var(--panel-border);
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 800;
}

.modal-close {
    background: none;
    border: none;
    font-size: 26px;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    transition: color 0.15s;
}

.modal-close:hover {
    color: var(--danger);
}

.modal form {
    padding: 22px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 10px;
}

.modal textarea {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
    font-family: 'JetBrains Mono', monospace;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text);
    resize: vertical;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 26px;
    right: 26px;
    padding: 14px 22px;
    border-radius: var(--radius-sm);
    color: #000;
    font-weight: 700;
    z-index: 300;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    animation: slideIn 0.25s ease;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.toast-success { background: var(--success); box-shadow: 0 0 24px rgba(5, 255, 161, 0.3); }
.toast-error { background: var(--danger); color: #fff; box-shadow: 0 0 24px rgba(255, 42, 109, 0.35); }
.toast-info { background: var(--primary); box-shadow: 0 0 24px rgba(0, 240, 255, 0.3); }

@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Import */
.import-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 28px;
}

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

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-muted);
    padding: 30px;
    font-weight: 600;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--panel-border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-inline {
    color: var(--danger);
    padding: 20px;
    text-align: center;
    font-weight: 600;
}

#ajax-loading {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 400;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(5, 5, 8, 0.65);
    backdrop-filter: blur(4px);
    color: var(--primary);
    font-weight: 700;
    font-size: 14px;
}

#ajax-loading.active {
    display: flex;
}

#ajax-loading .spinner {
    width: 26px;
    height: 26px;
    border-width: 3px;
}

/* Error pages */
.error-page {
    text-align: center;
    padding: 80px 20px;
}

.error-page h1 {
    font-size: 90px;
    margin: 0 0 10px;
    background: linear-gradient(90deg, var(--primary), var(--danger));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.error-page p {
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* Responsive */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main {
        margin-left: 0;
    }
    .import-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .header {
        padding: 0 16px;
    }
    .main {
        padding: 18px;
    }
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .filters {
        width: 100%;
    }
    .filters input,
    .filters select {
        flex: 1;
    }
}
