/* Go-Balancer — Cloudflare Dashboard Style */
:root {
    --bg-page: #f9f9fa;
    --bg-white: #ffffff;
    --border: #e6e6e6;
    --border-light: #f0f0f0;
    --text-primary: #1a1a1a;
    --text-secondary: #6e6e6e;
    --text-muted: #a0a0a0;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-subtle: rgba(37, 99, 235, 0.06);
    --orange: #f48120;
    --orange-subtle: rgba(244, 129, 32, 0.08);
    --success: #1a8f36;
    --success-subtle: rgba(26, 143, 54, 0.07);
    --danger: #d63b3b;
    --danger-subtle: rgba(214, 59, 59, 0.06);
    --warning: #c27b11;
    --warning-subtle: rgba(194, 123, 17, 0.07);
    --radius: 8px;
    --radius-lg: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.04);
    --sidebar-width: 210px;
    --topbar-height: 52px;
    --transition: 0.12s ease;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    font-size: 14px;
}

.hidden { display: none !important; }

/* === LOGIN === */
#login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-page);
}

.login-wrapper { width: 100%; max-width: 360px; padding: 20px; }

.login-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px 28px;
    box-shadow: var(--shadow);
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
    color: var(--orange);
}

.login-logo h1 { font-size: 1.25rem; font-weight: 700; color: var(--text-primary); }
.login-subtitle { color: var(--text-secondary); margin-bottom: 24px; font-size: 0.82rem; }

/* === FORMS === */
.form-group { margin-bottom: 12px; }
.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}

input[type="text"], input[type="password"], input[type="number"], textarea, select {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: var(--font);
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }
textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; margin-top: 12px; }

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-ghost { background: var(--bg-white); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--text-secondary); color: var(--text-primary); }
.btn-outline { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 5px 10px; font-size: 0.75rem; }
.btn-full { width: 100%; }
.btn-icon {
    padding: 4px;
    border-radius: 4px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}
.btn-icon:hover { color: var(--danger); background: var(--danger-subtle); }

.error-message { color: var(--danger); font-size: 0.8rem; margin-bottom: 8px; min-height: 16px; }

/* === DASHBOARD LAYOUT === */
#dashboard { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
}

.sidebar-brand svg { color: var(--orange); }

.sidebar-nav { flex: 1; padding: 8px 6px; display: flex; flex-direction: column; gap: 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-item:hover { background: var(--bg-page); color: var(--text-primary); }
.nav-item.active { background: var(--accent-subtle); color: var(--accent); font-weight: 600; }
.nav-item.active svg { color: var(--accent); }
.nav-item svg { color: var(--text-muted); }

.sidebar-footer { padding: 8px 6px; border-top: 1px solid var(--border); }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: var(--topbar-height);
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar h2 { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }

/* === PAGES === */
.page { display: none; padding: 24px; flex: 1; }
.page.active { display: block; }

/* === STATS === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }

.stat-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.stat-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.backends-icon { background: var(--accent-subtle); color: var(--accent); }
.vhosts-icon { background: var(--success-subtle); color: var(--success); }
.health-icon { background: var(--orange-subtle); color: var(--orange); }
.settings-icon { background: var(--warning-subtle); color: var(--warning); }

.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 1.3rem; font-weight: 700; line-height: 1.2; color: var(--text-primary); }
.stat-label { font-size: 0.7rem; color: var(--text-secondary); font-weight: 500; }

/* === CARDS === */
.card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 12px;
}

.card h3 { font-size: 0.88rem; font-weight: 600; color: var(--text-primary); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }

.overview-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* === TABLE LIST === */
.table-list { display: flex; flex-direction: column; }

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-light);
    transition: background var(--transition);
}

.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--bg-page); }

.list-item-address {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.list-item-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--success);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
}

.list-compact .list-item { padding: 6px 10px; }

/* === ADD ROW === */
.add-row { display: flex; gap: 6px; align-items: center; }
.input-sm { width: 170px; padding: 6px 9px; font-size: 0.8rem; }

/* === VIRTUAL HOSTS === */
.add-vhost-panel {
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
}

.vhost-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    overflow: hidden;
}

.vhost-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-page);
    border-bottom: 1px solid var(--border);
}

.vhost-domain {
    font-weight: 600;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.vhost-domain .badge {
    font-size: 0.63rem;
    padding: 1px 7px;
    background: var(--bg-white);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-weight: 600;
}

.vhost-body { padding: 12px 14px; }
.vhost-backends { margin-bottom: 8px; }
.vhost-add-row { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; align-items: center; }

/* === SETTINGS FORM === */
.settings-form { max-width: 520px; }
.settings-form .btn-primary { margin-top: 6px; }

/* === SCHEME BADGES === */
.scheme-badge {
    font-size: 0.6rem;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.scheme-badge.http { background: var(--accent-subtle); color: var(--accent); }
.scheme-badge.https { background: var(--success-subtle); color: var(--success); }
.skip-badge {
    font-size: 0.6rem;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--warning-subtle);
    color: var(--warning);
    font-weight: 600;
}

/* === CHECKBOX === */
.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}
.checkbox-label input[type="checkbox"] { width: auto; accent-color: var(--accent); }

/* === ADD BACKEND FORM === */
.add-backend-form { margin-bottom: 12px; }
.add-backend-form .add-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* === SECURITY === */
.sec-details {
    margin-bottom: 10px;
    padding: 8px 10px;
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    border-radius: 6px;
}
.sec-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.sec-tag {
    font-size: 0.62rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 3px;
    background: var(--success-subtle);
    color: var(--success);
    white-space: nowrap;
}

/* === TOGGLE === */
.security-toggle-section {
    margin: 12px 0;
    padding: 12px 14px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
}
.toggle-label input[type="checkbox"] { display: none; }
.toggle-switch {
    width: 34px;
    height: 18px;
    background: var(--border);
    border-radius: 9px;
    position: relative;
    transition: background var(--transition);
}
.toggle-switch::after {
    content: '';
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 3px;
    transition: transform var(--transition);
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}
.toggle-label input:checked + .toggle-switch {
    background: var(--accent);
}
.toggle-label input:checked + .toggle-switch::after {
    transform: translateX(16px);
}
.toggle-hint {
    font-size: 0.68rem;
    color: var(--text-muted);
}
.security-options {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
}
.security-options h4 {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin: 12px 0 6px;
}
.security-options h4:first-child { margin-top: 0; }
.check-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin: 6px 0;
}

/* === TOAST === */
#toast-container {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toast {
    padding: 9px 16px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 500;
    animation: slideIn 0.2s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    max-width: 320px;
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }

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

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; }
    .form-row { grid-template-columns: 1fr; }
    .overview-panels { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* === ANALYTICS === */
.analytics-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.analytics-header h3 { font-size: 1rem; font-weight: 700; }
.time-badge {
    font-size: 0.72rem;
    font-weight: 500;
    padding: 4px 10px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text-secondary);
}

.analytics-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.analytics-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 12px; }

.metric-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
}
.metric-card.full-width { margin-bottom: 12px; }

.metric-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.metric-card-title {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
}
.metric-card-count {
    font-size: 0.68rem;
    font-weight: 600;
    background: var(--bg-page);
    border: 1px solid var(--border);
    padding: 1px 7px;
    border-radius: 10px;
    color: var(--text-secondary);
}

.metric-card-body {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 6px;
}
.metric-big-number {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1;
    color: var(--text-primary);
}
.metric-big-number.danger { color: var(--danger); }
.metric-unit {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
}

.metric-card-chart {
    height: 32px;
    margin-top: auto;
}

/* Area Chart */
.area-chart {
    height: 120px;
    display: flex;
    align-items: flex-end;
    gap: 1px;
    padding: 8px 0;
    position: relative;
}
.area-chart .area-bar {
    flex: 1;
    background: linear-gradient(to top, rgba(37,99,235,0.15), rgba(37,99,235,0.4));
    border-radius: 2px 2px 0 0;
    min-width: 1px;
    position: relative;
    transition: background 0.1s;
}
.area-chart .area-bar:hover {
    background: linear-gradient(to top, rgba(37,99,235,0.3), rgba(37,99,235,0.7));
}
.area-chart .area-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
}

/* Sparkline in cards */
.spark-bars {
    display: flex;
    align-items: flex-end;
    gap: 1px;
    height: 100%;
}
.spark-bars .spark-bar {
    flex: 1;
    background: rgba(37,99,235,0.25);
    border-radius: 1px 1px 0 0;
    min-width: 1px;
}

/* Status Codes */
.status-summary {
    display: flex;
    gap: 16px;
    margin-bottom: 10px;
}
.status-summary .status-item {
    display: flex;
    flex-direction: column;
}
.status-summary .status-num {
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.2;
}
.status-summary .status-num.s2 { color: var(--success); }
.status-summary .status-num.s4 { color: var(--warning); }
.status-summary .status-num.s5 { color: var(--danger); }
.status-summary .status-lbl {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 500;
}

.status-bar-wrap { margin-top: 4px; }
.status-bar {
    display: flex;
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    background: var(--border-light);
}
.status-segment { min-width: 2px; }
.status-segment.success { background: var(--success); }
.status-segment.warning { background: var(--warning); }
.status-segment.danger { background: var(--danger); }

/* Error breakdown */
.error-breakdown {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Metric list (domains/backends) */
.metric-list { max-height: 200px; overflow-y: auto; }
.metric-list .metric-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.8rem;
}
.metric-list .metric-row:last-child { border-bottom: none; }
.metric-row-left {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    color: var(--text-primary);
}
.metric-row-left .dot-active {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
}
.metric-row-right {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.72rem;
    color: var(--text-secondary);
}
.metric-row-right .metric-val {
    font-weight: 600;
    color: var(--text-primary);
}
.metric-row-right .metric-err {
    color: var(--danger);
    font-weight: 600;
}

@media (max-width: 768px) {
    .analytics-grid-3 { grid-template-columns: 1fr; }
    .analytics-grid-2 { grid-template-columns: 1fr; }
}

/* File upload inputs */
input[type="file"] {
    width: 100%;
    padding: 7px 10px;
    background: var(--bg-white);
    border: 1px dashed var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: border-color var(--transition);
}
input[type="file"]:hover { border-color: var(--accent); }
input[type="file"]::file-selector-button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    margin-right: 8px;
}

/* Let's Encrypt info */
.le-info {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    background: var(--success-subtle);
    border: 1px solid rgba(26, 143, 54, 0.15);
    border-radius: 6px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
}
.le-info svg { color: var(--success); flex-shrink: 0; margin-top: 1px; }
