:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2d3a4f;
  --text: #e8edf5;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --error: #ef4444;
  --pending: #64748b;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: linear-gradient(160deg, #0b1020 0%, #121a2b 50%, #0f1419 100%);
  color: var(--text);
  min-height: 100vh;
}

.layout { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }

.sidebar {
  background: rgba(26, 35, 50, 0.95);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px; }
.brand-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: grid; place-items: center; font-size: 20px; font-weight: 700;
}
.brand h1 { margin: 0; font-size: 18px; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.dept-nav { display: flex; flex-direction: column; gap: 6px; flex: 1; overflow: auto; }
.dept-btn {
  text-align: left; border: 1px solid transparent; background: transparent;
  color: var(--text); padding: 10px 12px; border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.dept-btn:hover { background: var(--surface-2); }
.dept-btn.active { background: var(--surface-2); border-color: var(--border); }
.dept-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.sidebar-actions { display: flex; flex-direction: column; gap: 8px; }

.content { padding: 28px 32px 48px; overflow: auto; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; }
.topbar h2 { margin: 0 0 4px; font-size: 28px; }
.muted { color: var(--muted); margin: 0; }
.topbar-actions { display: flex; gap: 12px; align-items: center; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-tab {
  text-align: left;
  cursor: pointer;
  width: 100%;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.stat-tab:hover {
  background: var(--surface-2);
  border-color: #4b5c74;
}
.stat-tab.active {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.12);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35);
}
.stat-tab .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-tab .value { font-size: 28px; font-weight: 700; margin-top: 8px; }
.empty-row { text-align: center; padding: 32px 16px !important; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.panel-head h3 { margin: 0; }
.panel-head input {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 8px 12px; min-width: 220px;
}

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:hover td { background: rgba(255,255,255,0.02); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge.ok { background: rgba(34,197,94,0.15); color: #4ade80; }
.badge.error { background: rgba(239,68,68,0.15); color: #f87171; }
.badge.manual_check { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge.needs_attention { background: rgba(249,115,22,0.15); color: #fb923c; }
.badge.pending { background: rgba(100,116,139,0.2); color: #cbd5e1; }
.badge.mode-api { background: rgba(59,130,246,0.15); color: #93c5fd; }
.badge.mode-on_request { background: rgba(167,139,250,0.15); color: #c4b5fd; }
.badge.mode-scheduled { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge.due_soon { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge.overdue { background: rgba(239,68,68,0.15); color: #f87171; }
.badge.on_request { background: rgba(167,139,250,0.15); color: #c4b5fd; }
.badge.scheduled { background: rgba(100,116,139,0.2); color: #cbd5e1; }
.badge.archived { background: rgba(148,163,184,0.2); color: #94a3b8; }

.upcoming-list { padding: 8px 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.upcoming-item {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  padding: 12px 16px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border);
}
.upcoming-item.due_soon { border-color: rgba(245,158,11,0.4); }
.upcoming-item.overdue { border-color: rgba(239,68,68,0.4); }
.muted.small { font-size: 11px; margin-top: 4px; }
.comment-col { max-width: 320px; min-width: 180px; }
.comment-cell {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
}
.hint { font-size: 12px; color: var(--muted); margin: -6px 0 10px; }

.dept-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px; border-radius: 6px; font-size: 12px;
  background: rgba(255,255,255,0.05);
}

.btn {
  border: none; border-radius: 10px; padding: 10px 14px;
  cursor: pointer; font-weight: 600; font-size: 14px;
}
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 6px 10px; font-size: 12px; }

.toggle { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }

.page-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}
.page-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.page-tab:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.page-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--error);
  color: white;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.alert-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.1);
}
.alert-banner-body { display: flex; gap: 12px; align-items: flex-start; }
.alert-banner strong { display: block; margin-bottom: 2px; }
.alert-banner p { margin: 0; font-size: 13px; }
.alert-icon {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(239, 68, 68, 0.2);
  color: #f87171; font-weight: 800; flex-shrink: 0;
}

.spending-chart {
  padding: 16px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.spending-row {
  display: grid;
  grid-template-columns: 88px 1fr 72px;
  gap: 12px;
  align-items: center;
  font-size: 12px;
}
.spending-row-label { color: var(--muted); font-weight: 600; }
.spending-bars {
  display: flex;
  height: 22px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.spending-segment { height: 100%; min-width: 2px; transition: width 0.2s; }
.spending-row-total { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.spending-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  padding: 8px 20px 18px;
  border-top: 1px solid var(--border);
}
.spending-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.spending-legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.spending-empty { padding: 24px 20px; color: var(--muted); font-size: 13px; }
.spending-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spending-custom-range { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spending-date-label { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.spending-date-label input[type="date"] {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 4px 8px; font-size: 13px;
}
.issues-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.btn.danger { color: #f87171; border-color: rgba(239, 68, 68, 0.45); }
.btn.danger:hover { background: rgba(239, 68, 68, 0.12); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.dialog-actions-spacer { flex: 1; }

.filter-tabs {
  display: flex; gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}
.filter-tab {
  border: none; background: transparent; color: var(--muted);
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
  font-size: 12px; font-weight: 600;
}
.filter-tab.active { background: var(--surface); color: var(--text); }
.issues-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.issue-stat {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.issue-stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.issue-stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.issues-list { padding: 12px 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.issue-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  overflow: hidden;
}
.issue-card.critical { border-left: 4px solid var(--error); }
.issue-card.warning { border-left: 4px solid var(--warn); }
.issue-card-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
}
.issue-card-head:hover { background: rgba(255,255,255,0.02); }
.issue-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.issue-title strong { font-size: 15px; }
.issue-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.issue-message { font-size: 13px; margin-top: 8px; line-height: 1.45; }
.issue-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; }
.issue-card-body {
  border-top: 1px solid var(--border);
  padding: 12px 16px 16px;
  background: rgba(0,0,0,0.12);
}
.issue-history { display: flex; flex-direction: column; gap: 8px; }
.issue-history-item {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
}
.issue-history-item time { color: var(--muted); display: block; margin-bottom: 4px; }
.severity-pill {
  display: inline-flex; align-items: center;
  padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
}
.severity-pill.critical { background: rgba(239,68,68,0.15); color: #f87171; }
.severity-pill.warning { background: rgba(245,158,11,0.15); color: #fbbf24; }
tr.row-highlight td { background: rgba(59, 130, 246, 0.12) !important; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 0;
  box-shadow: var(--shadow); width: min(480px, 92vw);
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog form { padding: 24px; display: flex; flex-direction: column; gap: 12px; }
dialog h3 { margin: 0 0 8px; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
dialog input, dialog select, dialog textarea {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 10px 12px; font-size: 14px;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-brand { margin-bottom: 24px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-form input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}
.login-submit { width: 100%; margin-top: 8px; }
.error { color: var(--error); font-size: 13px; margin: 0; }
.user-pill {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}
.dept-nav-label {
  padding: 10px 12px;
  font-size: 14px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.app-loading { padding: 12px 24px; }
.app-load-error {
  margin: 12px 24px 0;
  padding: 12px 16px;
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--error);
  color: #fecaca;
}
