:root {
  --bg: #0b1220;
  --surface: #111c2e;
  --surface-2: #17243a;
  --border: #263852;
  --text: #e7edf7;
  --muted: #91a0b8;
  --primary: #38bdf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select,
input,
textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
}

select,
input,
textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

button {
  cursor: pointer;
}

.topbar {
  min-height: 84px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar h1,
.section-heading h2,
.panel-header h3,
.chat-header h2 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

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

.separator {
  color: var(--border);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.status-loading {
  background: var(--warning);
}

.status-online {
  background: var(--success);
}

.status-offline {
  background: var(--danger);
}

.dashboard-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 84px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  background: #0e1829;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar h2 {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.sidebar label {
  color: var(--muted);
  font-size: 12px;
}

.nav-button {
  padding: 11px 12px;
  text-align: left;
  color: var(--muted);
  background: transparent;
}

.nav-button:hover,
.nav-button.active {
  color: var(--text);
  border-color: var(--primary);
  background: rgba(56, 189, 248, 0.1);
}

.primary-button {
  padding: 11px 14px;
  color: #04111f;
  font-weight: 700;
  background: var(--primary);
  border-color: var(--primary);
}

.primary-button:hover {
  filter: brightness(1.08);
}

.sidebar-footer {
  margin-top: auto;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-footer small {
  display: block;
  margin-top: 6px;
}

.main-content {
  min-width: 0;
  padding: 28px;
}

.dashboard-section {
  margin-bottom: 34px;
}

.section-heading,
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
}

.section-heading h2 {
  font-size: 24px;
}

.panel-header h3 {
  font-size: 17px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card,
.panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-card {
  min-height: 130px;
  padding: 18px;
}

.kpi-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.kpi-card strong {
  display: block;
  margin: 16px 0 7px;
  font-size: 28px;
}

.kpi-card small {
  color: var(--muted);
}

.kpi-card.warning strong {
  color: var(--warning);
}

.kpi-card.success strong {
  color: var(--success);
}

.kpi-card.danger strong {
  color: var(--danger);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.8fr);
  gap: 18px;
}

.panel {
  padding: 20px;
}

.panel-badge {
  padding: 6px 9px;
  border-radius: 999px;
  color: var(--primary);
  background: rgba(56, 189, 248, 0.1);
  font-size: 12px;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-badge {
  display: inline-block;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.status-running {
  color: #86efac;
  background: rgba(34, 197, 94, 0.14);
}

.status-offline {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.14);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.detail-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.detail-item strong {
  display: block;
  margin-top: 5px;
}

.chart-panel {
  min-height: 420px;
}

#trendChart {
  width: 100%;
  min-height: 380px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-row label {
  color: var(--muted);
  font-size: 12px;
}

.control-row select {
  width: 230px;
}

.message,
.muted,
.empty-state {
  color: var(--muted);
}

.empty-state {
  padding: 28px;
  text-align: center;
}

.hidden {
  display: none !important;
}

.chat-toggle {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  padding: 14px 18px;
  color: #04111f;
  font-weight: 700;
  background: var(--primary);
  border-color: var(--primary);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.chat-panel {
  position: fixed;
  top: 0;
  right: -430px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(430px, 100vw);
  height: 100vh;
  padding: 20px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: right 0.25s ease;
}

.chat-panel.open {
  right: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.icon-button {
  width: 32px;
  height: 32px;
  color: var(--text);
  background: transparent;
  border-color: var(--border);
  font-size: 22px;
}

.chat-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 20px 0;
}

.chat-controls label {
  color: var(--muted);
  font-size: 11px;
}

.chat-controls select {
  width: 100%;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.chat-message {
  max-width: 90%;
  margin-bottom: 12px;
  padding: 11px 13px;
  border-radius: 12px;
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 13px;
}

.chat-message.user {
  margin-left: auto;
  background: rgba(56, 189, 248, 0.18);
}

.chat-message.assistant {
  background: var(--surface-2);
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (max-width: 1200px) {
  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 850px) {
  .dashboard-layout {
    display: block;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-footer {
    margin-top: 10px;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .section-heading,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .main-content,
  .topbar {
    padding: 18px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .control-row {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
  }

  .control-row select {
    width: 100%;
  }
}