:root {
  --primary: #2563EB;
  --primary-dark: #1D4ED8;
  --primary-light: #DBEAFE;
  --secondary: #F59E0B;
  --success: #10B981;
  --success-light: #D1FAE5;
  --danger: #EF4444;
  --danger-light: #FEE2E2;
  --warning: #F59E0B;
  --warning-light: #FEF3C7;
  --info: #06B6D4;
  --info-light: #CFFAFE;

  --bg: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-sidebar: #1E293B;
  --bg-sidebar-active: #334155;
  --text: #1E293B;
  --text-secondary: #64748B;
  --text-light: #94A3B8;
  --border: #E2E8F0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  --transition: all 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-width: 240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-secondary { color: var(--text-secondary); }
.text-light { color: var(--text-light); }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }

h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }
h4 { font-size: 1rem; font-weight: 600; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.55rem 1.1rem; border-radius: var(--radius); font-size: 0.875rem; font-weight: 500; border: 1px solid transparent; cursor: pointer; transition: var(--transition); font-family: var(--font); white-space: nowrap; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: white; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); border-color: var(--text-light); }
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.4rem; color: var(--text); }
.form-input, .form-select, .form-textarea { width: 100%; padding: 0.55rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.875rem; font-family: var(--font); background: white; transition: var(--transition); }
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.form-textarea { resize: vertical; min-height: 80px; }

/* Cards */
.card { background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 1.25rem; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.card-header h3 { margin: 0; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th, .table td { padding: 0.625rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { background: #F1F5F9; font-weight: 600; color: var(--text); font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table tbody tr:hover { background: #F8FAFC; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .total-row td { font-weight: 700; background: #F8FAFC; border-top: 2px solid var(--text); }
.table-compact th, .table-compact td { padding: 0.4rem 0.6rem; font-size: 0.8125rem; }

.trend-up { color: var(--success); font-weight: 600; }
.trend-down { color: var(--danger); font-weight: 600; }
.trend-flat { color: var(--text-secondary); }

.today-col { background: #DBEAFE; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 0.2rem 0.6rem; border-radius: var(--radius-full); font-size: 0.75rem; font-weight: 500; }
.badge-success { background: var(--success-light); color: #065F46; }
.badge-danger { background: var(--danger-light); color: #991B1B; }
.badge-warning { background: var(--warning-light); color: #92400E; }
.badge-info { background: var(--info-light); color: #155E75; }
.badge-neutral { background: var(--border); color: var(--text-secondary); }

/* App shell */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-width); background: var(--bg-sidebar); color: white; padding: 1.25rem 0; position: fixed; left: 0; top: 0; bottom: 0; overflow-y: auto; }
.sidebar-brand { padding: 0 1.25rem 1.25rem; border-bottom: 1px solid #334155; margin-bottom: 1rem; }
.sidebar-brand h2 { color: white; font-size: 1.1rem; font-weight: 700; }
.sidebar-brand .subtitle { color: #94A3B8; font-size: 0.75rem; margin-top: 0.15rem; }
.sidebar-nav { list-style: none; }
.sidebar-nav li a { display: flex; align-items: center; gap: 0.6rem; padding: 0.65rem 1.25rem; color: #CBD5E1; font-size: 0.875rem; transition: var(--transition); border-left: 3px solid transparent; }
.sidebar-nav li a:hover { background: var(--bg-sidebar-active); color: white; text-decoration: none; }
.sidebar-nav li a.active { background: var(--bg-sidebar-active); color: white; border-left-color: var(--primary); font-weight: 500; }
.sidebar-nav li a .icon { font-size: 1rem; width: 1.2rem; text-align: center; }
.sidebar-nav li a .badge-count { margin-left: auto; background: var(--danger); color: white; font-size: 0.7rem; padding: 0.1rem 0.45rem; border-radius: var(--radius-full); }

.main { flex: 1; margin-left: var(--sidebar-width); padding: 1.5rem 2rem; }
.main-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }
.main-header h1 { font-size: 1.5rem; }
.main-header .meta { color: var(--text-secondary); font-size: 0.875rem; }

/* KPI grid */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { background: var(--bg-card); border-radius: var(--radius-lg); padding: 1rem 1.25rem; box-shadow: var(--shadow); border-left: 4px solid var(--primary); }
.kpi-card.success { border-left-color: var(--success); }
.kpi-card.danger { border-left-color: var(--danger); }
.kpi-card.warning { border-left-color: var(--warning); }
.kpi-card.info { border-left-color: var(--info); }
.kpi-label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; }
.kpi-value { font-size: 1.5rem; font-weight: 700; color: var(--text); margin-top: 0.25rem; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 0.75rem; color: var(--text-light); margin-top: 0.15rem; }

/* Status pill */
.status-pill { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.3rem 0.75rem; border-radius: var(--radius-full); font-size: 0.75rem; font-weight: 500; background: var(--bg); border: 1px solid var(--border); }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.status-pill.online .dot { background: var(--success); box-shadow: 0 0 0 3px var(--success-light); }
.status-pill.offline .dot { background: var(--text-light); }
.status-pill.error .dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-light); }

/* Toast */
.toast-container { position: fixed; top: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { background: white; padding: 0.75rem 1rem; border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: 0.875rem; min-width: 240px; display: flex; align-items: center; gap: 0.6rem; animation: slideIn 0.25s ease; border-left: 3px solid var(--info); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { to { transform: translateX(120%); opacity: 0; } }

/* Loading */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { background: linear-gradient(90deg, var(--border) 0%, #F1F5F9 50%, var(--border) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: var(--radius); height: 1rem; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Alerts list */
.alert-row { display: flex; gap: 0.75rem; padding: 0.85rem 1rem; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 0.5rem; background: white; align-items: flex-start; }
.alert-row.critical { border-left: 4px solid var(--danger); }
.alert-row.warning { border-left: 4px solid var(--warning); }
.alert-row.info { border-left: 4px solid var(--info); }
.alert-row.acked { opacity: 0.55; }
.alert-row .body { flex: 1; }
.alert-row .title { font-weight: 600; font-size: 0.9rem; }
.alert-row .message { color: var(--text-secondary); font-size: 0.85rem; margin-top: 0.15rem; white-space: pre-line; }
.alert-row .meta { color: var(--text-light); font-size: 0.75rem; margin-top: 0.3rem; }

/* Charts */
.chart-container { position: relative; height: 320px; }
.chart-tall { height: 480px; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 100%; height: auto; position: relative; }
  .main { margin-left: 0; padding: 1rem; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
