:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #eaecf2;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-soft: #eef2ff;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --sidebar-bg: #0f172a;
  --sidebar-fg: #cbd5e1;
  --sidebar-active: #1e293b;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  display: grid;
  place-items: center;
  font-size: 18px;
  box-shadow: 0 4px 14px rgba(99,102,241,.35);
}
.brand-title { color: #fff; font-weight: 700; font-size: 15px; line-height: 1.1; }
.brand-sub { font-size: 11px; letter-spacing: .14em; color: #94a3b8; text-transform: uppercase; }

.sidebar-nav { margin-top: 16px; display: flex; flex-direction: column; gap: 4px; }
.sidebar-nav .nav-link {
  color: var(--sidebar-fg);
  padding: 10px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
  font-size: 13.5px;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.sidebar-nav .nav-link i { font-size: 16px; width: 18px; text-align: center; }
.sidebar-nav .nav-link:hover { color: #fff; background: rgba(255,255,255,.04); }
.sidebar-nav .nav-link.active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--primary);
}

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.06); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip .avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg,#22d3ee,#3b82f6); color: white; display: grid; place-items: center; font-weight: 600; }
.user-chip .username { color: #fff; font-weight: 600; font-size: 13px; }
.user-chip .role { font-size: 11px; color: #94a3b8; }

/* ---- Topbar / content ---- */
.content { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 26px 32px 14px;
  gap: 16px;
}
.page-title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.page-sub { color: var(--muted); margin: 4px 0 0; font-size: 13.5px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-body { padding: 6px 32px 40px; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body { padding: 20px; }

/* ---- Stat cards ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 16px; }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; color: white; flex-shrink: 0; }
.stat-icon.indigo { background: linear-gradient(135deg,#6366f1,#8b5cf6); }
.stat-icon.green { background: linear-gradient(135deg,#10b981,#059669); }
.stat-icon.red { background: linear-gradient(135deg,#ef4444,#dc2626); }
.stat-icon.amber { background: linear-gradient(135deg,#f59e0b,#d97706); }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-top: 4px; }

/* ---- Tables ---- */
.table { font-size: 13.5px; margin: 0; }
.table > :not(caption) > * > * { padding: 14px 16px; vertical-align: middle; border-bottom-color: var(--border); }
.table thead th { background: #fafbfd; color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .06em; border-bottom: 1px solid var(--border); }
.table-hover > tbody > tr:hover > * { background: #fbfcff; }

/* ---- Badges ---- */
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; letter-spacing: .02em; }
.status-badge .dot { width: 6px; height: 6px; border-radius: 50%; }
.status-badge.success { background: #ecfdf5; color: #047857; }
.status-badge.success .dot { background: #10b981; }
.status-badge.failed, .status-badge.error { background: #fef2f2; color: #b91c1c; }
.status-badge.failed .dot, .status-badge.error .dot { background: #ef4444; }
.status-badge.running { background: #eff6ff; color: #1d4ed8; }
.status-badge.running .dot { background: #3b82f6; animation: pulse 1.4s infinite; }
.status-badge.unknown { background: #f1f5f9; color: #475569; }
.status-badge.unknown .dot { background: #94a3b8; }
.status-badge.ok { background: #ecfdf5; color: #047857; }
.status-badge.ok .dot { background: #10b981; }
@keyframes pulse { 0%,100% { opacity: 1;} 50% { opacity: .35;} }

/* ---- Buttons ---- */
.btn { font-weight: 500; border-radius: 8px; padding: 8px 14px; font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-soft { background: var(--primary-soft); color: var(--primary-600); border: 1px solid transparent; }
.btn-soft:hover { background: #e0e7ff; color: var(--primary-600); }
.btn-outline-secondary { color: #475569; border-color: var(--border); background: white; }
.btn-outline-secondary:hover { background: #f8fafc; color: #0f172a; border-color: #cbd5e1; }

/* ---- Forms ---- */
.form-label { font-weight: 500; font-size: 13px; color: #374151; margin-bottom: 6px; }
.form-control, .form-select { font-size: 13.5px; border-radius: 8px; border-color: var(--border); padding: 9px 12px; }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.form-text { color: var(--muted); font-size: 12px; }
.form-section { padding: 18px 0; border-top: 1px dashed var(--border); }
.form-section:first-of-type { border-top: none; padding-top: 0; }
.form-section h6 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 14px; }

/* ---- Empty states ---- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state .bi { font-size: 36px; opacity: .4; }

/* ---- Flash messages ---- */
.flash-stack { margin-bottom: 16px; }
.alert { border-radius: 10px; border: 1px solid transparent; font-size: 13.5px; }
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-danger { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

/* ---- Login page ---- */
.auth-shell { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 60%, #ec4899 100%); padding: 24px; }
.auth-card { width: 100%; max-width: 420px; background: white; border-radius: 18px; padding: 40px; box-shadow: var(--shadow-lg); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.auth-brand .brand-icon { width: 44px; height: 44px; font-size: 20px; }
.auth-brand .brand-title { color: var(--text); font-size: 18px; }
.auth-brand .brand-sub { color: var(--muted); }

/* ---- Code/mono ---- */
code, pre { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.kbd { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-family: 'JetBrains Mono', monospace; font-size: 12px; color: #334155; }

/* ---- Misc ---- */
.text-muted { color: var(--muted) !important; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.list-tight { padding-left: 18px; margin: 0; }
.list-tight li { margin-bottom: 4px; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; align-items: center; padding: 12px 16px; }
  .sidebar-brand { border-bottom: none; padding: 0; flex-shrink: 0; }
  .sidebar-nav { flex-direction: row; overflow-x: auto; margin-top: 0; margin-left: 16px; }
  .sidebar-nav .nav-link span { display: none; }
  .sidebar-footer { display: none; }
  .topbar { padding: 18px 20px 10px; }
  .page-body { padding: 6px 20px 30px; }
}
