@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

:root {
  --bg-base:       #050d1a;
  --bg-surface:    #0a1628;
  --bg-card:       #0f1f3d;
  --bg-card-hover: #132548;
  --bg-input:      #0d1a30;
  --border:        rgba(59, 130, 246, 0.15);
  --border-bright: rgba(59, 130, 246, 0.35);

  --blue-100: #dbeafe;
  --blue-300: #93c5fd;
  --blue-400: #60a5fa;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-900: #1e3a8a;

  --cyan-400:  #22d3ee;
  --cyan-500:  #06b6d4;
  --teal-400:  #2dd4bf;

  --text-primary:   #e2eaf6;
  --text-secondary: #7b9abf;
  --text-muted:     #4a6080;

  --green:  #34d399;
  --yellow: #fbbf24;
  --red:    #f87171;
  --orange: #fb923c;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --shadow-card: 0 4px 24px rgba(0,0,0,0.4), 0 1px 4px rgba(59,130,246,0.08);
  --shadow-glow: 0 0 20px rgba(59,130,246,0.15);
  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--blue-900); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--blue-700); }

/* ── App Shell ─────────────────────────────────────────────────── */
#app { display: flex; min-height: 100vh; }

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-mark {
  display: flex; align-items: center; gap: 10px;
}
.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--blue-600), var(--cyan-500));
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
  box-shadow: 0 0 12px rgba(59,130,246,0.4);
}
.logo-text { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.logo-sub  { font-size: 11px; color: var(--text-secondary); margin-top: 1px; }

.sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13.5px; font-weight: 500;
  transition: all var(--transition);
  border: 1px solid transparent;
  text-decoration: none;
}
.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}
.nav-item.active {
  background: rgba(59,130,246,0.12);
  color: var(--blue-400);
  border-color: rgba(59,130,246,0.25);
}
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-section-title {
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--text-muted); padding: 14px 12px 4px; text-transform: uppercase;
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
}
.status-dot {
  display: inline-block; width: 7px; height: 7px;
  border-radius: 50%; background: var(--green);
  box-shadow: 0 0 6px var(--green);
  margin-right: 6px; animation: pulse 2s infinite;
}
.status-dot.offline { background: var(--red); box-shadow: 0 0 6px var(--red); animation: none; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.5} }

/* ── Main Content ──────────────────────────────────────────────── */
.main {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.alert-bell {
  position: relative; cursor: pointer;
  width: 34px; height: 34px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; transition: all var(--transition);
}
.alert-bell:hover { border-color: var(--border-bright); }
.alert-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--red); color: #fff;
  font-size: 9px; font-weight: 700;
  width: 16px; height: 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  display: none;
}
.alert-badge.show { display: flex; }

.user-chip {
  display: flex; align-items: center; gap: 7px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; padding: 5px 12px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all var(--transition);
}
.user-chip:hover { border-color: var(--border-bright); }

/* ── Page Content ──────────────────────────────────────────────── */
.page { display: none; padding: 24px; flex: 1; }
.page.active { display: block; }

/* ── Section Title ─────────────────────────────────────────────── */
.section-title {
  font-size: 13px; font-weight: 600; letter-spacing: 0.06em;
  color: var(--text-secondary); text-transform: uppercase;
  margin-bottom: 14px; margin-top: 24px;
}
.section-title:first-child { margin-top: 0; }

/* ── Grid ──────────────────────────────────────────────────────── */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
  transition: all var(--transition);
}
.card:hover { border-color: var(--border-bright); box-shadow: var(--shadow-card), var(--shadow-glow); }
.card-title {
  font-size: 11px; font-weight: 600; letter-spacing: 0.07em;
  color: var(--text-secondary); text-transform: uppercase; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between;
}

/* ── Metric Card ───────────────────────────────────────────────── */
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
  transition: all var(--transition);
  position: relative; overflow: hidden;
}
.metric-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--blue-600), var(--cyan-500));
  opacity: 0;
  transition: opacity var(--transition);
}
.metric-card:hover::before { opacity: 1; }
.metric-card:hover { border-color: var(--border-bright); }

.metric-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.07em;
  color: var(--text-secondary); text-transform: uppercase;
}
.metric-value {
  font-family: 'DM Mono', monospace;
  font-size: 26px; font-weight: 500;
  color: var(--text-primary);
  margin: 6px 0 2px;
  line-height: 1;
}
.metric-value.large { font-size: 32px; }
.metric-unit { font-size: 13px; color: var(--text-secondary); }
.metric-icon {
  position: absolute; right: 16px; top: 50%;
  transform: translateY(-50%);
  font-size: 28px; opacity: 0.12;
}
.metric-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.metric-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
  margin-top: 6px;
}
.metric-badge.green { background: rgba(52,211,153,0.12); color: var(--green); }
.metric-badge.red   { background: rgba(248,113,113,0.12); color: var(--red); }
.metric-badge.yellow{ background: rgba(251,191,36,0.12);  color: var(--yellow); }
.metric-badge.blue  { background: rgba(59,130,246,0.12);  color: var(--blue-400); }

/* ── Status indicator ──────────────────────────────────────────── */
.status-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.status-pill.running { background: rgba(52,211,153,0.12); color: var(--green); }
.status-pill.standby { background: rgba(59,130,246,0.12); color: var(--blue-400); }
.status-pill.error   { background: rgba(248,113,113,0.12); color: var(--red); }
.status-pill.off     { background: rgba(74,96,128,0.2);    color: var(--text-muted); }

/* ── Chart Container ───────────────────────────────────────────── */
.chart-container { position: relative; height: 240px; }
.chart-container.tall { height: 320px; }

/* ── Controls Row ──────────────────────────────────────────────── */
.controls-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover { border-color: var(--border-bright); color: var(--text-primary); }
.btn.primary {
  background: var(--blue-600);
  border-color: var(--blue-600);
  color: #fff;
}
.btn.primary:hover { background: var(--blue-700); }
.btn.active {
  background: rgba(59,130,246,0.15);
  border-color: var(--blue-500);
  color: var(--blue-400);
}

/* ── Form Elements ─────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; display: block; text-transform: uppercase; letter-spacing: 0.06em; }
.form-input, .form-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  transition: border-color var(--transition);
  appearance: none;
}
.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237b9abf' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.range-group { display: flex; align-items: center; gap: 12px; }
.form-range {
  flex: 1; height: 4px;
  background: var(--bg-input);
  border-radius: 2px; appearance: none; cursor: pointer;
}
.form-range::-webkit-slider-thumb {
  appearance: none; width: 16px; height: 16px;
  background: var(--blue-500); border-radius: 50%;
  box-shadow: 0 0 6px rgba(59,130,246,0.5);
}
.range-value {
  font-family: 'DM Mono', monospace; font-size: 14px; font-weight: 500;
  color: var(--blue-400); min-width: 52px; text-align: right;
}

/* ── Table ─────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 8px 12px;
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--text-muted); text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 12px;
  font-size: 13px; color: var(--text-secondary);
  border-bottom: 1px solid rgba(59,130,246,0.06);
}
.data-table tr:hover td { background: var(--bg-card-hover); color: var(--text-primary); }
.data-table .val {
  font-family: 'DM Mono', monospace; font-size: 13px;
  color: var(--blue-300); font-weight: 500;
}

/* ── Alert Panel ───────────────────────────────────────────────── */
.alert-panel {
  background: rgba(248,113,113,0.08);
  border: 1px solid rgba(248,113,113,0.25);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px;
}
.alert-panel .alert-icon { font-size: 18px; }
.alert-panel .alert-text { font-size: 13px; color: var(--red); }

/* ── Login Page ────────────────────────────────────────────────── */
#login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: var(--bg-base);
  background-image: radial-gradient(ellipse at 50% 0%, rgba(59,130,246,0.08) 0%, transparent 60%);
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 36px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), var(--shadow-glow);
}
.login-logo {
  display: flex; align-items: center; gap: 12px; margin-bottom: 28px;
}
.login-logo .logo-icon { width: 44px; height: 44px; font-size: 22px; }
.login-title { font-size: 22px; font-weight: 600; }
.login-sub   { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.login-error {
  background: rgba(248,113,113,0.1); border: 1px solid rgba(248,113,113,0.3);
  border-radius: var(--radius-md); padding: 9px 12px;
  font-size: 13px; color: var(--red); margin-bottom: 16px; display: none;
}
.login-error.show { display: block; }
.login-btn {
  width: 100%; padding: 11px;
  background: var(--blue-600); border: none;
  border-radius: var(--radius-md); color: #fff;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background var(--transition);
  margin-top: 8px;
}
.login-btn:hover { background: var(--blue-700); }

/* ── Notification Toast ────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
}
.toast {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 12px 16px;
  font-size: 13px; max-width: 320px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: slideIn 0.3s ease;
  display: flex; align-items: flex-start; gap: 10px;
}
.toast.error { border-color: rgba(248,113,113,0.4); }
.toast.success { border-color: rgba(52,211,153,0.3); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Dropdown ──────────────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-md); min-width: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 200; display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  padding: 9px 14px; font-size: 13px; cursor: pointer;
  color: var(--text-secondary); transition: all var(--transition);
}
.dropdown-item:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.dropdown-item.danger { color: var(--red); }
.dropdown-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Gauge Bar ─────────────────────────────────────────────────── */
.gauge-bar {
  height: 6px; background: var(--bg-input);
  border-radius: 3px; overflow: hidden; margin-top: 8px;
}
.gauge-fill {
  height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--blue-600), var(--cyan-400));
  transition: width 0.5s ease;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px)  {
  .sidebar { transform: translateX(-220px); }
  .main { margin-left: 0; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}
