:root {
  --primary: #4F46E5;
  --primary-light: #EEF2FF;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-500: #6B7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --sidebar-w: 220px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--gray-50); color: var(--gray-900); min-height: 100vh; }

/* ===== Layout ===== */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: white; border-right: 1px solid var(--gray-200); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; transition: transform 0.3s; }
.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar-brand { padding: 20px; border-bottom: 1px solid var(--gray-200); }
.brand-logo { font-size: 20px; font-weight: 800; color: var(--primary); }
.brand-sub { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.nav-section { padding: 8px 20px 4px; font-size: 11px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.5px; }
.nav-item { display: flex; align-items: center; gap: 8px; padding: 9px 20px; font-size: 14px; color: var(--gray-700); text-decoration: none; transition: all 0.15s; border-left: 3px solid transparent; }
.nav-item:hover { background: var(--gray-50); color: var(--gray-900); }
.nav-item.active { background: var(--primary-light); color: var(--primary); border-left-color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 12px; width: 16px; text-align: center; }

/* ===== Topbar ===== */
.topbar { background: white; border-bottom: 1px solid var(--gray-200); padding: 12px 24px; display: flex; align-items: center; gap: 16px; position: sticky; top: 0; z-index: 40; }
.topbar-menu { display: none; background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px 8px; color: var(--gray-700); }
.topbar-health { display: flex; gap: 6px; align-items: center; flex: 1; }
.health-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.health-dot.ok { background: var(--success); }
.health-dot.err { background: var(--danger); }
.health-dot.pending { background: var(--warning); animation: pulse 1.5s infinite; }
.health-dot.off { background: var(--gray-300); }
@keyframes pulse { 50% { opacity: 0.4; } }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.refresh-time { font-size: 12px; color: var(--gray-500); }

/* ===== Content ===== */
.content { flex: 1; max-width: 1200px; width: 100%; margin: 0 auto; padding: 24px; }

/* ===== Buttons ===== */
.btn { padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 14px; font-weight: 500; transition: all 0.15s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #4338CA; }
.btn-outline { background: white; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover { background: var(--gray-50); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #DC2626; }
.btn-success { background: var(--success); color: white; }
.btn-sm { padding: 4px 12px; font-size: 13px; }

/* ===== Login ===== */
.login-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 200; }
.login-card { background: white; border-radius: 16px; padding: 40px; width: 400px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.15); }
.login-card h2 { margin-bottom: 8px; color: var(--primary); }
.login-card p { color: var(--gray-500); font-size: 14px; margin-bottom: 24px; }
.login-card input { width: 100%; padding: 12px 16px; border: 1px solid var(--gray-300); border-radius: 8px; font-size: 15px; margin-bottom: 12px; outline: none; }
.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.login-error { color: var(--danger); font-size: 13px; margin-bottom: 12px; display: none; }

/* ===== Stats Grid ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: white; border-radius: 12px; padding: 20px; border: 1px solid var(--gray-200); }
.stat-card .label { font-size: 13px; color: var(--gray-500); margin-bottom: 4px; }
.stat-card .value { font-size: 28px; font-weight: 700; color: var(--gray-900); }
.stat-card .sub { font-size: 12px; color: var(--gray-500); margin-top: 4px; }
.stat-card.highlight { border-left: 3px solid var(--primary); }
.stat-card.success .value { color: var(--success); }
.stat-card.warning .value { color: var(--warning); }
.stat-card.danger .value { color: var(--danger); }

/* ===== Cards ===== */
.card { background: white; border-radius: 12px; border: 1px solid var(--gray-200); overflow: hidden; margin-bottom: 24px; }
.card-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--gray-200); flex-wrap: wrap; gap: 8px; }
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }

/* ===== Table ===== */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 12px 16px; font-size: 12px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
td { padding: 12px 16px; font-size: 14px; border-bottom: 1px solid var(--gray-100); }
tr:hover td { background: var(--gray-50); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.badge-success { background: #D1FAE5; color: #065F46; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-info { background: #DBEAFE; color: #1E40AF; }
.badge-danger { background: #FEE2E2; color: #991B1B; }

/* ===== Funnel ===== */
.funnel-steps { display: flex; flex-direction: column; gap: 10px; }
.funnel-step { display: flex; align-items: center; gap: 16px; }
.funnel-step .step-label { width: 100px; font-size: 14px; font-weight: 500; text-align: right; flex-shrink: 0; }
.funnel-step .step-bar-wrap { flex: 1; height: 32px; background: var(--gray-100); border-radius: 8px; overflow: hidden; }
.funnel-step .step-bar { height: 100%; border-radius: 8px; display: flex; align-items: center; padding: 0 12px; color: white; font-weight: 600; font-size: 13px; transition: width 0.6s ease; min-width: 50px; }
.funnel-step .step-rate { width: 70px; font-size: 13px; color: var(--gray-500); text-align: right; flex-shrink: 0; }

/* ===== Trend Chart ===== */
.trend-chart { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding-top: 20px; }
.trend-bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.trend-bar { width: 100%; max-width: 36px; border-radius: 4px 4px 0 0; transition: height 0.4s ease; min-height: 2px; }
.trend-bar.pv { background: var(--primary); }
.trend-bar.uv { background: var(--success); }
.trend-label { font-size: 11px; color: var(--gray-500); }
.trend-val { font-size: 11px; color: var(--gray-700); font-weight: 600; }

/* ===== Pagination ===== */
.pagination { display: flex; justify-content: center; gap: 8px; padding: 16px; }
.pagination .btn { min-width: 36px; text-align: center; }
.pagination .btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination .btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Filter Bar ===== */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-bar select, .filter-bar input[type="text"], .filter-bar input[type="date"] { padding: 6px 12px; border: 1px solid var(--gray-300); border-radius: 6px; font-size: 13px; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 250; display: flex; align-items: flex-start; justify-content: center; padding: 40px 20px; overflow-y: auto; }
.modal { background: white; border-radius: 16px; width: 100%; max-width: 900px; max-height: 85vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--gray-200); position: sticky; top: 0; background: white; z-index: 10; border-radius: 16px 16px 0 0; }
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-close { width: 36px; height: 36px; border-radius: 8px; border: none; background: var(--gray-100); cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; color: var(--gray-500); }
.modal-close:hover { background: var(--gray-200); }
.modal-body { padding: 24px; }
.modal-section { margin-bottom: 24px; }
.modal-section h3 { font-size: 15px; font-weight: 600; margin-bottom: 12px; color: var(--gray-700); border-bottom: 1px solid var(--gray-100); padding-bottom: 8px; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.info-item { font-size: 14px; }
.info-item .info-label { color: var(--gray-500); font-size: 12px; }
.info-item .info-value { font-weight: 500; margin-top: 2px; }

/* ===== Confirm ===== */
.confirm-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 300; display: flex; align-items: center; justify-content: center; }
.confirm-card { background: white; border-radius: 16px; padding: 24px; width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.confirm-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.confirm-card p { font-size: 14px; color: var(--gray-700); margin-bottom: 8px; }
.confirm-card textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: 8px; font-size: 14px; margin-bottom: 16px; resize: vertical; min-height: 60px; outline: none; }
.confirm-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ===== Loading / Toast / Empty ===== */
.loading { display: flex; justify-content: center; padding: 40px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--gray-200); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; top: 20px; right: 20px; padding: 12px 20px; border-radius: 8px; font-size: 14px; z-index: 300; animation: slideIn 0.3s ease; }
.toast-error { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.toast-success { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.empty { text-align: center; padding: 60px 20px; color: var(--gray-500); }

/* ===== Health Status Cards (Overview) ===== */
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.health-card { background: white; border-radius: 10px; padding: 16px; border: 1px solid var(--gray-200); }
.health-card .hc-name { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.health-card .hc-status { font-size: 12px; display: flex; align-items: center; gap: 6px; }
.health-card .hc-status .health-dot { width: 8px; height: 8px; }
.health-card .hc-detail { font-size: 12px; color: var(--gray-500); margin-top: 6px; }

/* ===== Scores ===== */
.scores-grid { display: flex; gap: 6px; }
.score-item { font-size: 12px; padding: 1px 6px; border-radius: 4px; background: var(--primary-light); color: var(--primary); font-weight: 600; }
.user-link { color: var(--primary); cursor: pointer; text-decoration: none; font-weight: 600; }
.user-link:hover { text-decoration: underline; }

/* ===== Pricing Edit ===== */
.price-table input { width: 80px; padding: 4px 8px; border: 1px solid var(--gray-300); border-radius: 4px; font-size: 14px; text-align: right; }
.price-table .btn-sm { margin-left: 8px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar-menu { display: block; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .health-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  table { font-size: 13px; }
  th, td { padding: 8px 12px; }
  .modal { margin: 10px; max-height: 90vh; }
  .login-card { width: 90%; padding: 24px; }
}

/* Sidebar backdrop for mobile */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 45; }
.sidebar-backdrop.show { display: block; }
