:root {
  --bg: #0b1020;
  --bg-soft: #141b33;
  --panel: #10172b;
  --text: #e7ecff;
  --muted: #97a4cb;
  --accent: #6ee7ff;
  --good: #22c55e;
  --bad: #ef4444;
  --border: #253052;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at 20% -20%, #1c2c5c, var(--bg) 45%);
  color: var(--text);
}
a { color: #8fd8ff; text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(11, 16, 32, 0.86);
  backdrop-filter: blur(7px);
  z-index: 10;
}
h1 { margin: 0 0 6px 0; font-size: 22px; }
h2 { margin: 0 0 12px 0; font-size: 17px; }
.muted { color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.topbar-burger { display: none; }
.btn {
  background: #1f2a48;
  color: #dbe6ff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }
.btn-primary, .btn-accent { background: linear-gradient(135deg, #2a6ff6, #20c5e8); color: white; border: none; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; padding: 16px 20px; }
.card, .panel, .login-card {
  background: linear-gradient(180deg, rgba(23, 34, 64, 0.9), rgba(16, 23, 43, 0.95));
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.2);
}
.card { padding: 14px; }
.card-title { color: var(--muted); font-size: 13px; }
.card-value { font-size: 24px; font-weight: 700; margin-top: 8px; }
.card-value.small { font-size: 16px; word-break: break-all; }
.panel { margin: 0 20px 16px 20px; padding: 14px; }
.panel-header { display: flex; gap: 12px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; align-items: center; }
.searchable-select {
  position: relative;
  width: 280px;
}
.searchable-select input[type="text"] {
  width: 100%;
  padding: 9px 12px;
  background: #0d1427 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2397a4cb' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E") no-repeat right 12px center;
}
.searchable-select .dropdown-options {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: #10172b;
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 100;
  display: none;
  box-shadow: 0 10px 24px rgba(0,0,0,0.4);
}
.searchable-select.active .dropdown-options {
  display: block;
}
.searchable-select .option {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid rgba(255,255,255,0.03);
  transition: background 0.1s;
}
.searchable-select .option:last-child {
  border-bottom: none;
}
.searchable-select .option:hover, .searchable-select .option.focused {
  background: rgba(42,111,246,0.15);
  color: #8fd8ff;
}
.searchable-select .option.selected {
  background: rgba(110, 231, 255, 0.1);
  color: var(--accent);
  font-weight: 600;
}
.searchable-select .option.hidden {
  display: none;
}
input, select, textarea {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #0d1427;
  color: var(--text);
}
textarea { width: 100%; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border-bottom: 1px solid var(--border); text-align: left; padding: 10px 8px; vertical-align: top; }
th { color: #b8c5ed; font-weight: 600; }
.badge { 
  display: inline-block; 
  min-width: 44px; 
  text-align: center; 
  padding: 3px 8px; 
  border-radius: 999px; 
  font-size: 11px; 
  font-weight: 700; 
  user-select: none;
}
.badge-good { background: rgba(34,197,94,0.15); color: #75f7a3; border: 1px solid rgba(34,197,94,0.4); }
.badge-bad { background: rgba(239,68,68,0.14); color: #ff8d8d; border: 1px solid rgba(239,68,68,0.45); }
.truncate { max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Status badge tooltips --- */
.status-badge-with-error {
  cursor: help;
  display: inline-flex;
  align-items: center;
  position: relative;
}

.status-badge-with-error:hover::after {
  content: attr(data-error);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #0b1020;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 400;
  color: #e7ecff;
  white-space: normal;
  max-width: 320px;
  min-width: 160px;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
  line-height: 1.4;
  text-align: left;
}

.status-badge-with-error:hover::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(239, 68, 68, 0.4);
  z-index: 1001;
}

.status-error-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: #ff4d4d;
  color: white;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 900;
  margin-left: 6px;
  line-height: 1;
}

/* --- Row action buttons --- */
.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg);
}

.btn-action .material-symbols-outlined {
  font-size: 18px;
}

.btn-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-action-edit {
  color: #8fd8ff;
  border-color: rgba(42, 111, 246, 0.3);
}

.btn-action-edit:hover {
  background: rgba(42, 111, 246, 0.2);
  border-color: rgba(42, 111, 246, 0.6);
}

.btn-action-delete {
  color: #ff8d8d;
  border-color: rgba(239, 68, 68, 0.3);
  background: transparent;
}

.btn-action-delete:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.6);
}

.alerts { margin: 14px 20px; }
.alert { border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; border: 1px solid; }
.alert-success { background: rgba(34,197,94,0.12); border-color: rgba(34,197,94,0.4); }
.alert-error { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.4); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.login-card { width: min(460px, 100%); padding: 20px; }
.login-form, .admin-form { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.field-help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.config-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.config-grid > div { background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.config-grid strong { font-size: 18px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.settings-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: rgba(255,255,255,0.02); display: flex; flex-direction: column; gap: 8px; }
.status-table td { max-width: 380px; }
.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin: 16px 20px 16px 20px;
}
.chart-card {
  background: linear-gradient(180deg, rgba(23,34,64,0.9), rgba(16,23,43,0.95));
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.2);
  padding: 16px;
}
.chart-card h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}
.chart-container {
  position: relative;
  height: 280px;
}
@media (max-width: 600px) {
  .topbar[data-has-mobile-menu] {
    padding: 14px;
    align-items: flex-start;
    flex-wrap: wrap;
    position: relative;
  }
  .topbar[data-has-mobile-menu] > :first-child {
    min-width: 0;
    max-width: calc(100% - 56px);
  }
  .topbar[data-has-mobile-menu] > .topbar-burger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    min-width: 42px;
    padding: 8px 10px;
  }
  .topbar[data-has-mobile-menu] > .topbar-actions[data-mobile-menu] {
    display: none !important;
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(16, 23, 43, 0.97);
    flex-direction: column;
    align-items: stretch;
  }
  .topbar[data-has-mobile-menu].menu-open > .topbar-actions[data-mobile-menu] {
    display: flex !important;
  }
  .topbar[data-has-mobile-menu] > .topbar-actions[data-mobile-menu] form,
  .topbar[data-has-mobile-menu] > .topbar-actions[data-mobile-menu] .btn {
    width: 100%;
  }
  .cards { padding: 12px 14px; }
  .panel { margin: 0 14px 12px 14px; }
}

/* --- Config form enhancements --- */
.config-fields-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.config-field {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.config-field label {
  font-size: 12px;
  font-weight: 600;
  color: #b8c5ed;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.config-field input,
.config-field select {
  width: 100%;
}

/* --- ApexCharts overrides --- */
.apexcharts-tooltip {
  background: rgba(11, 16, 32, 0.95) !important;
  border: 1px solid #253052 !important;
  border-radius: 8px !important;
}
.apexcharts-tooltip-title {
  background: rgba(20, 27, 51, 0.95) !important;
  color: #e7ecff !important;
  border-bottom: 1px solid #253052 !important;
}
.apexcharts-tooltip-text-y-label {
  color: #97a4cb !important;
}
.apexcharts-tooltip-text-y-value {
  color: #e7ecff !important;
}
.apexcharts-xaxistooltip,
.apexcharts-yaxistooltip {
  background: rgba(20, 27, 51, 0.95) !important;
  border: 1px solid #253052 !important;
  color: #97a4cb !important;
}
.apexcharts-xaxistooltip:after,
.apexcharts-xaxistooltip:before {
  border-bottom-color: rgba(20, 27, 51, 0.95) !important;
}
.apexcharts-legend-text {
  color: #97a4cb !important;
}
.apexcharts-toolbar {
  filter: brightness(0.8);
}
.apexcharts-menu {
  background: rgba(20, 27, 51, 0.95) !important;
  border: 1px solid #253052 !important;
  border-radius: 8px !important;
}
.apexcharts-menu-item {
  color: #97a4cb !important;
}
.apexcharts-menu-item:hover {
  background: rgba(37, 48, 82, 0.5) !important;
}

/* Apex chart container */
.apex-chart {
  min-height: 280px;
}
