/* ===== Reset & Variables ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #6e7681;
  --primary: #1f6feb;
  --primary-glow: rgba(31,111,235,.25);
  --success: #3fb950;
  --success-bg: rgba(63,185,80,.12);
  --warning: #d29922;
  --warning-bg: rgba(210,153,34,.12);
  --danger: #f85149;
  --danger-bg: rgba(248,81,73,.12);
  --info: #58a6ff;
  --info-bg: rgba(88,166,255,.1);
  --purple: #bc8cff;
  --purple-bg: rgba(188,140,255,.1);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --transition: all .2s ease;
  --sidebar-w: 240px;
}
html { scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; overflow-x: hidden; }
a { color: var(--info); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--text); }
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== Layout ===== */
.layout { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 100;
  transition: var(--transition);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.logo-mark {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), #58a6ff);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.sidebar-section { padding: 12px 8px 4px; font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: .8px; }
.sidebar-nav { list-style: none; padding: 0 8px; flex: 1; overflow-y: auto; }
.sidebar-nav li { margin-bottom: 2px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text2);
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
}
.nav-link:hover { background: var(--bg3); color: var(--text); }
.nav-link.active { background: rgba(31,111,235,.15); color: var(--info); }
.nav-link.active::before { content: ''; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; background: var(--primary); border-radius: 0 2px 2px 0; }
.nav-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: white; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: var(--text3); }

/* ===== Main ===== */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

/* ===== Topbar ===== */
.topbar {
  height: 56px;
  background: var(--bg2);
  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: 15px; font-weight: 600; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-time { font-family: var(--mono); font-size: 12px; color: var(--text2); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 6px var(--success); animation: pulse-dot 2s infinite; }
@keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg3); color: var(--text2);
  transition: var(--transition);
}
.btn:hover { background: var(--border); color: var(--text); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: #1a5fd0; color: white; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(248,81,73,.3); }

/* ===== Page Content ===== */
.page { padding: 24px; display: none; }
.page.active { display: block; }
.page-header { margin-bottom: 24px; }
.page-title { font-size: 20px; font-weight: 700; color: var(--text); }
.page-sub { font-size: 13px; color: var(--text2); margin-top: 4px; }

/* ===== Stats Grid ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}
.stat-card:hover { border-color: var(--primary); }
.stat-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 60px; height: 60px;
  background: radial-gradient(circle at top right, var(--glow, var(--primary-glow)), transparent 70%);
}
.stat-card.success { --glow: rgba(63,185,80,.2); }
.stat-card.warning { --glow: rgba(210,153,34,.2); }
.stat-card.danger  { --glow: rgba(248,81,73,.2); }
.stat-card.purple  { --glow: rgba(188,140,255,.2); }
.stat-icon { font-size: 22px; margin-bottom: 12px; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--text); font-family: var(--mono); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 6px; font-weight: 500; }
.stat-trend { font-size: 12px; margin-top: 8px; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ===== Cards ===== */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.card-body { padding: 20px; }
.card-actions { display: flex; gap: 8px; }

/* ===== Grid Layouts ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-7-3 { display: grid; grid-template-columns: 7fr 3fr; gap: 20px; }
.grid-6-4 { display: grid; grid-template-columns: 6fr 4fr; gap: 20px; }

/* ===== Server Cards ===== */
.servers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.server-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: var(--transition);
  cursor: pointer;
  position: relative;
}
.server-card:hover { border-color: var(--primary); box-shadow: 0 0 0 1px rgba(31,111,235,.3); }
.server-card.warning { border-color: rgba(210,153,34,.4); }
.server-card.offline { border-color: rgba(248,81,73,.4); opacity: .8; }
.server-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.server-info { display: flex; align-items: center; gap: 10px; }
.server-type-icon {
  width: 36px; height: 36px;
  background: var(--bg3);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.server-name { font-size: 14px; font-weight: 600; color: var(--text); }
.server-host { font-size: 11px; color: var(--text3); font-family: var(--mono); }
.server-location { font-size: 11px; color: var(--text2); margin-top: 2px; }

.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.status-online  { background: var(--success-bg); color: var(--success); }
.status-warning { background: var(--warning-bg); color: var(--warning); }
.status-offline { background: var(--danger-bg); color: var(--danger); }
.status-maintenance { background: var(--info-bg); color: var(--info); }
.status-dot-sm { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ===== Metric Bars ===== */
.metrics-row { display: flex; flex-direction: column; gap: 10px; }
.metric-item { display: flex; flex-direction: column; gap: 4px; }
.metric-header { display: flex; justify-content: space-between; font-size: 12px; }
.metric-label { color: var(--text2); }
.metric-val { font-family: var(--mono); font-weight: 600; }
.metric-val.ok { color: var(--success); }
.metric-val.warn { color: var(--warning); }
.metric-val.crit { color: var(--danger); }
.progress-bar { height: 5px; background: var(--bg3); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; transition: width .5s ease; }
.fill-ok   { background: var(--success); }
.fill-warn { background: var(--warning); }
.fill-crit { background: var(--danger); }

.server-footer { display: flex; gap: 16px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.server-stat { display: flex; flex-direction: column; }
.server-stat-val { font-size: 13px; font-weight: 600; color: var(--text); font-family: var(--mono); }
.server-stat-label { font-size: 11px; color: var(--text3); }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; padding: 10px 16px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--text3);
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
}
.tbl td { padding: 13px 16px; font-size: 13px; color: var(--text2); border-bottom: 1px solid rgba(48,54,61,.5); }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: rgba(48,54,61,.3); color: var(--text); }
.tbl .mono { font-family: var(--mono); font-size: 12px; }
.tbl .strong { font-weight: 600; color: var(--text); }

/* ===== Alerts ===== */
.alert-item {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 14px 16px;
  border-left: 3px solid;
  background: var(--bg3);
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 8px;
  transition: var(--transition);
}
.alert-item:hover { background: rgba(48,54,61,.5); }
.alert-item.critical { border-color: var(--danger); }
.alert-item.warning  { border-color: var(--warning); }
.alert-item.info     { border-color: var(--info); }
.alert-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-content { flex: 1; min-width: 0; }
.alert-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.alert-msg { font-size: 12px; color: var(--text2); line-height: 1.5; }
.alert-meta { display: flex; gap: 12px; margin-top: 6px; font-size: 11px; color: var(--text3); }
.alert-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ===== Service Status ===== */
.services-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.service-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
}
.service-status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.service-status-dot.running { background: var(--success); box-shadow: 0 0 6px var(--success); }
.service-status-dot.stopped { background: var(--danger); }
.service-status-dot.warning { background: var(--warning); animation: pulse-dot 1s infinite; }
.service-status-dot.unknown { background: var(--text3); }
.service-name { font-size: 13px; font-weight: 600; color: var(--text); }
.service-sub  { font-size: 11px; color: var(--text3); margin-top: 2px; }
.service-metrics { margin-left: auto; text-align: right; }
.service-cpu { font-size: 11px; font-family: var(--mono); color: var(--text2); }
.service-mem { font-size: 11px; color: var(--text3); }

/* ===== Chart Container ===== */
.chart-wrap { position: relative; height: 220px; }
.chart-wrap.tall { height: 280px; }
.chart-wrap.sm { height: 160px; }

/* ===== Uptime Blocks ===== */
.uptime-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.uptime-label { font-size: 12px; color: var(--text2); width: 120px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uptime-blocks { display: flex; gap: 2px; flex: 1; }
.uptime-block {
  flex: 1;
  height: 20px;
  border-radius: 2px;
  background: var(--success);
  opacity: .85;
  transition: opacity .2s;
}
.uptime-block:hover { opacity: 1; }
.uptime-block.down { background: var(--danger); }
.uptime-block.warn { background: var(--warning); }
.uptime-pct { font-size: 12px; font-family: var(--mono); font-weight: 600; color: var(--success); width: 48px; text-align: right; flex-shrink: 0; }
.uptime-pct.warn { color: var(--warning); }
.uptime-pct.bad  { color: var(--danger); }

/* ===== Badge ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-info    { background: var(--info-bg); color: var(--info); }
.badge-purple  { background: var(--purple-bg); color: var(--purple); }
.badge-gray    { background: rgba(110,118,129,.15); color: var(--text3); }

/* ===== Login ===== */
.login-page {
  min-height: 100vh;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  box-shadow: var(--shadow);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-title { font-size: 20px; font-weight: 700; color: var(--text); text-align: center; margin-bottom: 6px; }
.login-sub { font-size: 13px; color: var(--text2); text-align: center; margin-bottom: 28px; }
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text2); margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  transition: var(--transition);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.error-text { font-size: 12px; color: var(--danger); margin-top: 4px; }
.login-error { background: var(--danger-bg); border: 1px solid rgba(248,81,73,.3); border-radius: var(--radius); padding: 10px 14px; font-size: 13px; color: var(--danger); margin-bottom: 16px; }

/* ===== Empty State ===== */
.empty-state { padding: 48px; text-align: center; }
.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: .4; }
.empty-text { font-size: 13px; color: var(--text3); }

/* ===== Toast ===== */
.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  border-left: 3px solid var(--success);
  animation: slide-in .25s ease;
  min-width: 260px;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn  { border-left-color: var(--warning); }
@keyframes slide-in { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Spinner ===== */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
  color: var(--text3);
  gap: 10px;
  font-size: 13px;
}
.spinner-dark {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ===== Mini sparkline ===== */
.sparkline-wrap { height: 32px; }

/* ===== Refresh indicator ===== */
.refresh-bar {
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  overflow: hidden;
  margin-bottom: 20px;
}
.refresh-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 1px;
  transition: width .5s linear;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) { .grid-2,.grid-3,.grid-7-3,.grid-6-4 { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .servers-grid { grid-template-columns: 1fr; }
}
