: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); }
.badge-tier-free { background: rgba(139,143,163,0.15); color: var(--text-muted); }
.badge-tier-basic { background: rgba(59,130,246,0.15); color: var(--redirect-color); }
.badge-tier-pro { background: rgba(245,158,11,0.15); color: var(--warning); }

/* ── Locked category ── */
.accordion-item.locked { opacity: 0.5; }
.accordion-item.locked .accordion-header { cursor: not-allowed; }
.lock-icon { margin-left: 8px; font-size: 0.85rem; }

/* ── 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-off { background: var(--surface-2); color: var(--text-muted); 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; }
}

/* ── Filter Items ── */
.filter-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.filter-item:last-child { border-bottom: none; }

.filter-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.filter-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.filter-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.filter-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.filter-level {
    padding: 4px 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.8rem;
    outline: none;
}

.filter-level:disabled { opacity: 0.4; }
.filter-item.filter-locked { opacity: 0.4; }

/* ── Toggle Switch ── */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 22px;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: var(--text);
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--success);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

/* ── 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;
}

/* ══════════════════════════════════════════
   Client Dashboard Redesign
   ══════════════════════════════════════════ */

/* ── Dashboard Header ── */
.dash-header { margin-bottom: 20px; }
.dash-header-top {
    display: flex; justify-content: space-between; align-items: center;
    padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.dash-brand { font-size: 1.3rem; font-weight: 700; }
.dash-header-actions { display: flex; align-items: center; gap: 12px; }
.dash-username { color: var(--text-muted); font-size: 0.85rem; }

.stats-bar {
    display: flex; align-items: center; gap: 8px; padding-top: 12px;
    flex-wrap: wrap;
}
.stat-chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 999px; padding: 5px 14px; font-size: 0.8rem; white-space: nowrap;
}
.stat-chip.tier-free { border-color: var(--text-muted); }
.stat-chip.tier-basic { border-color: var(--redirect-color); color: var(--redirect-color); }
.stat-chip.tier-pro { border-color: var(--warning); color: var(--warning); }

.btn-upgrade {
    margin-left: auto; padding: 6px 18px; border: none; border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6); color: #fff;
    font-size: 0.8rem; font-weight: 600; cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}
.btn-upgrade:hover { transform: translateY(-1px); box-shadow: 0 4px 15px rgba(99,102,241,0.4); }

/* ── Upgrade Banner ── */
.upgrade-banner {
    position: relative; display: flex; align-items: center; gap: 16px;
    background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(139,92,246,0.08));
    border: 1px solid rgba(99,102,241,0.25); border-radius: var(--radius-lg);
    padding: 16px 20px; margin-bottom: 16px;
}
.banner-content { flex: 1; }
.banner-title { font-weight: 600; font-size: 0.95rem; margin-bottom: 2px; }
.banner-desc { color: var(--text-muted); font-size: 0.8rem; }
.banner-dismiss {
    position: absolute; top: 8px; right: 12px; background: none; border: none;
    color: var(--text-muted); font-size: 1.2rem; cursor: pointer; line-height: 1;
}

/* ── Section Titles ── */
.section-title {
    font-size: 1.05rem; font-weight: 600; margin: 20px 0 12px;
    display: flex; align-items: center; gap: 8px;
}
.section-sub { font-size: 0.8rem; color: var(--text-muted); font-weight: 400; }

/* ── Filter Grid ── */
.filter-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 10px; margin-bottom: 8px;
}
.filter-card {
    position: relative; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 14px 16px;
    transition: transform 0.15s, border-color 0.15s;
}
.filter-card:hover { transform: translateY(-2px); border-color: rgba(99,102,241,0.3); }
.filter-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.filter-card-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.filter-card-icon { font-size: 1.4rem; flex-shrink: 0; }
.filter-card-info { min-width: 0; }
.filter-card-name { font-weight: 600; font-size: 0.85rem; }
.filter-card-desc { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-card-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; margin-top: 2px; }

/* Locked filter overlay */
.filter-card.locked-overlay { pointer-events: none; }
.filter-card.locked-overlay::after {
    content: 'Upgrade'; position: absolute; inset: 0;
    background: rgba(15,17,23,0.75); backdrop-filter: blur(3px);
    border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 600; color: var(--primary); letter-spacing: 0.5px;
}

/* ── Category Grid ── */
.category-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}
.category-card {
    position: relative; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px 14px; text-align: center;
    cursor: pointer; transition: transform 0.15s, border-color 0.15s;
}
.category-card:hover { transform: translateY(-2px); border-color: rgba(99,102,241,0.3); }
.category-card.active { border-color: var(--primary); background: var(--surface-2); }
.cat-icon { font-size: 2rem; display: block; margin-bottom: 8px; }
.cat-name { font-weight: 600; font-size: 0.85rem; margin-bottom: 4px; }
.cat-count { font-size: 0.72rem; color: var(--text-muted); }

/* Locked category overlay */
.category-card.locked-overlay { pointer-events: none; }
.category-card.locked-overlay::after {
    content: 'Upgrade'; position: absolute; inset: 0;
    background: rgba(15,17,23,0.75); backdrop-filter: blur(3px);
    border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 600; color: var(--primary);
}

/* ── Category Expanded Panel ── */
.category-expanded {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px; margin-top: 12px; margin-bottom: 8px;
}
.cat-exp-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.cat-exp-title { font-weight: 600; font-size: 1rem; }
.cat-exp-close { background: none; border: none; color: var(--text-muted); font-size: 1.3rem; cursor: pointer; }

/* ── Tier Table (Upgrade Modal) ── */
.tier-table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.tier-table th, .tier-table td { text-align: center; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 0.8rem; }
.tier-table th { font-size: 0.85rem; }
.tier-table th.current { color: var(--primary); }
.tier-table td.current { background: rgba(99,102,241,0.08); }
.tier-table .feature-name { text-align: left; color: var(--text-muted); }
.tier-check { color: var(--success); }
.tier-cross { color: var(--text-muted); opacity: 0.4; }
.tier-note { text-align: center; color: var(--text-muted); font-size: 0.8rem; margin-top: 12px; }

/* ── Copy Button ── */
.copy-btn {
    background: none; border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text-muted); font-size: 0.7rem; padding: 2px 8px; cursor: pointer;
    margin-left: 6px; transition: color 0.15s, border-color 0.15s;
}
.copy-btn:hover { color: var(--primary); border-color: var(--primary); }

/* ── 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; }
    .filter-grid { grid-template-columns: 1fr; }
    .category-grid { grid-template-columns: repeat(2, 1fr); }
    .stats-bar { gap: 6px; }
    .upgrade-banner { flex-direction: column; text-align: center; }
    .dash-brand { font-size: 1.1rem; }
}
