:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #242836;
    --border: #2e3347;
    --text: #e4e6f0;
    --text-muted: #8b8fa3;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --success: #22c55e;
    --warning: #f59e0b;
    --block-color: #ef4444;
    --bypass-color: #22c55e;
    --redirect-color: #3b82f6;
    --radius: 8px;
    --radius-lg: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Layout ── */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.header h1 {
    font-size: 1.4rem;
    font-weight: 600;
}

.header .subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 2px;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
select {
    width: 100%;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s;
}

input:focus, select:focus {
    border-color: var(--primary);
}

/* ── Login ── */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 1.5rem;
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 28px;
}

/* ── Cards / Panels ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* ── Table ── */
.table-wrap { overflow-x: auto; }

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

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-assigned { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-unassigned { background: rgba(139,143,163,0.15); color: var(--text-muted); }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 10px 20px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab:hover { color: var(--text); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 100%;
    max-width: 440px;
}

.modal h3 {
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* ── Accordion (Client) ── */
.accordion-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 8px;
    overflow: hidden;
}

.accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}

.accordion-header:hover { background: var(--surface-2); }

.accordion-header .arrow {
    transition: transform 0.2s;
    color: var(--text-muted);
}

.accordion-item.open .accordion-header .arrow { transform: rotate(90deg); }

.accordion-body {
    display: none;
    padding: 0 18px 14px;
}

.accordion-item.open .accordion-body { display: block; }

.accordion-header .count {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-left: 8px;
}

/* ── Service Row ── */
.service-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 8px;
}

.service-row:last-child { border-bottom: none; }

.service-name {
    font-weight: 500;
    font-size: 0.9rem;
    min-width: 140px;
}

.service-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.action-btn {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
}

.action-btn:hover { border-color: var(--text-muted); }
.action-btn.active-block { background: var(--block-color); color: #fff; border-color: var(--block-color); }
.action-btn.active-bypass { background: var(--bypass-color); color: #fff; border-color: var(--bypass-color); }
.action-btn.active-redirect { background: var(--redirect-color); color: #fff; border-color: var(--redirect-color); }

.proxy-select {
    margin-top: 6px;
    width: 100%;
}

/* ── Endpoint Info ── */
.endpoint-info {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

.endpoint-info .info-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.endpoint-info .info-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.endpoint-info .info-value {
    font-weight: 500;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    animation: slideIn 0.2s ease;
    min-width: 250px;
}

.toast-success { background: rgba(34,197,94,0.15); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }
.toast-error { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Loading ── */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.loading-text {
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 20px 0;
    text-align: center;
}

/* ── Responsive ── */
@media (max-width: 640px) {
    .container { padding: 16px 12px; }
    .login-card { padding: 24px; margin: 0 12px; }
    .service-row { flex-direction: column; align-items: flex-start; }
    .endpoint-info { flex-direction: column; gap: 12px; }
}
