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

:root {
  --bg: #030712;
  --bg2: #111827;
  --bg3: #1f2937;
  --border: #374151;
  --text: #f9fafb;
  --text2: #9ca3af;
  --accent: #6366f1;
  --accent2: #4f46e5;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --blue: #3b82f6;
  --radius: 12px;
  --sidebar-w: 240px;
  --topbar-h: 60px;
}

html.light {
  --bg: #f1f5f9;
  --bg2: #ffffff;
  --bg3: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text2: #64748b;
}

html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

#app, #status-app { min-height: 100vh; min-height: 100dvh; }

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 0 0;
  position: fixed;
  top: 0; left: 0;
  height: 100vh; height: 100dvh;
  overflow-y: auto;
  z-index: 300;
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  will-change: transform;
}
.sidebar-brand {
  padding: 4px 20px 20px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
.sidebar-brand .brand-icon { font-size: 26px; line-height: 1; }
.sidebar-nav { flex: 1; padding: 0 8px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 9px;
  color: var(--text2);
  cursor: pointer;
  transition: background 0.13s, color 0.13s;
  text-decoration: none !important;
  margin-bottom: 2px;
  font-size: 14px;
  font-weight: 500;
  min-height: 44px;
  border: none;
  width: 100%;
  background: none;
  text-align: left;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { color: var(--accent); background: rgba(99,102,241,0.12); }
.nav-icon { font-size: 17px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text2);
  margin-top: auto;
}
.sidebar-footer-links { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 8px; }
.sidebar-footer-links a { color: var(--text2); font-size: 12px; }
.sidebar-version { font-size: 11px; color: var(--text2); opacity: 0.6; }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 299;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

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

/* Topbar */
.topbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

/* Hamburger */
.hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 8px;
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text2);
  font-size: 18px;
  flex-shrink: 0;
  transition: background 0.13s;
}
.hamburger:hover { background: var(--bg3); color: var(--text); }

/* Page */
.page-content { padding: 20px; flex: 1; }
.page-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.page-subtitle { color: var(--text2); font-size: 14px; }

/* ── Cards ── */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card-sm { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 9px 16px;
  border-radius: 8px; font-size: 14px; font-weight: 500;
  cursor: pointer; border: none;
  transition: background 0.13s, transform 0.1s, opacity 0.13s;
  white-space: nowrap; min-height: 38px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent2); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg3); color: var(--text); }
.btn-success { background: var(--green); color: white; }
.btn-success:hover:not(:disabled) { background: #16a34a; }
.btn-sm { padding: 5px 10px; font-size: 12px; min-height: 30px; }
.btn-icon { padding: 9px; min-width: 38px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--text2); }
.form-control {
  width: 100%; padding: 10px 12px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  font-size: 14px; transition: border-color 0.15s;
  -webkit-appearance: none;
  min-height: 42px;
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.form-control option { background: var(--bg3); }
textarea.form-control { min-height: unset; resize: vertical; }
.form-select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%239ca3af' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 32px;
}
.form-hint { font-size: 12px; color: var(--text2); margin-top: 4px; }
.form-row { display: grid; gap: 12px; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-up { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-down { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-pending { background: rgba(234,179,8,0.15); color: var(--yellow); }
.badge-paused { background: rgba(107,114,128,0.15); color: var(--text2); }

/* ── Monitor Card ── */
.monitor-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  display: flex; align-items: center; gap: 12px;
  border-left-width: 3px;
  -webkit-tap-highlight-color: transparent;
}
.monitor-card:hover { border-color: var(--accent); box-shadow: 0 4px 20px rgba(0,0,0,0.25); }
.monitor-card:active { transform: scale(0.99); }
.monitor-card.status-up { border-left-color: var(--green); }
.monitor-card.status-down { border-left-color: var(--red); }
.monitor-card.status-pending { border-left-color: var(--yellow); }
.monitor-card.status-paused { border-left-color: var(--text2); }

.monitor-dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.dot-up { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse-green 2s infinite; }
.dot-down { background: var(--red); box-shadow: 0 0 6px var(--red); animation: pulse-red 1s infinite; }
.dot-pending { background: var(--yellow); animation: pulse-green 2s infinite; }
.dot-paused { background: var(--text2); }
@keyframes pulse-green { 0%,100%{opacity:1;box-shadow:0 0 5px currentColor} 50%{opacity:0.65;box-shadow:0 0 10px currentColor} }
@keyframes pulse-red { 0%,100%{opacity:1} 50%{opacity:0.4} }

.monitor-info { flex: 1; min-width: 0; }
.monitor-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.monitor-meta { font-size: 11px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.monitor-hb { flex: 1; display: flex; align-items: center; gap: 1.5px; padding: 0 6px; min-width: 0; max-width: 180px; height: 32px; }
.hb-block { flex: 1; border-radius: 2px; min-width: 3px; max-width: 10px; height: 100%; }
.hb-up { background: var(--green); opacity: 0.85; }
.hb-down { background: var(--red); }
.hb-pending { background: var(--yellow); opacity: 0.7; }
.hb-empty { background: var(--border); opacity: 0.5; }

.monitor-uptime { text-align: right; flex-shrink: 0; }
.monitor-uptime-pct { font-size: 13px; font-weight: 600; }
.monitor-ping-val { font-size: 11px; color: var(--text2); }
.monitor-actions { display: flex; flex-direction: column; gap: 3px; margin-left: 4px; }

/* ── Stats grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 4px; }

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 400;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%; max-width: 640px;
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
  overflow-y: auto;
  animation: modalIn 0.18s ease;
}
@keyframes modalIn { from { opacity:0; transform: scale(0.96) translateY(8px); } to { opacity:1; transform:none; } }
.modal-header { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--bg2); z-index: 1; }
.modal-title { font-size: 17px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--bg2); }
.modal-close { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 20px; line-height: 1; padding: 4px 8px; border-radius: 6px; min-height: 36px; min-width: 36px; }
.modal-close:hover { color: var(--text); background: var(--bg3); }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 10px 14px; cursor: pointer; color: var(--text2); font-size: 13px; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all 0.15s; white-space: nowrap; min-height: 42px; display: flex; align-items: center; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }

/* ── Chart ── */
.chart-wrap { position: relative; height: 200px; }

/* ── Alerts ── */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert-danger { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.25); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.25); color: #86efac; }
.alert-warning { background: rgba(234,179,8,0.1); border: 1px solid rgba(234,179,8,0.25); color: #fde047; }
.alert-info { background: rgba(99,102,241,0.1); border: 1px solid rgba(99,102,241,0.25); color: #a5b4fc; }

/* ── Toggle ── */
.toggle { position: relative; width: 44px; height: 24px; cursor: pointer; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 24px; transition: 0.2s; }
.toggle-slider:before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider:before { transform: translateX(20px); }

/* ── Table ── */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.table th { color: var(--text2); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; background: var(--bg3); white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(255,255,255,0.02); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }

/* ── Spinner ── */
.loading { display: flex; align-items: center; justify-content: center; height: 200px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toasts ── */
.toast-container { position: fixed; bottom: 20px; right: 16px; z-index: 999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
  min-width: 220px; max-width: min(340px, calc(100vw - 32px));
  display: flex; align-items: flex-start; gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  animation: toastIn 0.22s ease;
  pointer-events: auto;
}
.toast-success { border-left: 3px solid var(--green); }
.toast-error { border-left: 3px solid var(--red); }
.toast-info { border-left: 3px solid var(--accent); }
@keyframes toastIn { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Page transitions ── */
.page-enter-active, .page-leave-active { transition: opacity 0.18s, transform 0.18s; }
.page-enter-from { opacity: 0; transform: translateY(6px); }
.page-leave-to { opacity: 0; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ── Utilities ── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--text2); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.grid { display: grid; }
.rounded { border-radius: 8px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-full { width: 100%; }

/* ════════════════════════════════════
   RESPONSIVE — Tablet (≤ 1024px)
   ════════════════════════════════════ */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .monitor-hb { max-width: 120px; }
}

/* ════════════════════════════════════
   RESPONSIVE — Mobile (≤ 768px)
   ════════════════════════════════════ */
@media (max-width: 768px) {
  :root { --topbar-h: 56px; }

  /* Sidebar slides off-screen by default */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
    width: min(280px, 82vw);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }
  .sidebar-overlay { display: block; }

  /* Main takes full width */
  .main-content { margin-left: 0; }

  /* Hamburger visible */
  .hamburger { display: inline-flex; }

  /* Page padding */
  .page-content { padding: 14px 12px; }

  /* Page title smaller */
  .page-title { font-size: 19px; }

  /* Stats 2-col */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 22px; }

  /* Monitor card — stack heartbeat under main row */
  .monitor-card { flex-wrap: wrap; gap: 8px; padding: 12px 12px 10px; }
  .monitor-hb { max-width: 100%; flex: 0 0 100%; order: 10; padding: 0; margin-top: 2px; height: 24px; }
  .monitor-actions { flex-direction: row; margin-left: 0; gap: 2px; }

  /* Forms single column */
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }

  /* Modals full-screen on mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 94vh; max-height: 94dvh;
    animation: modalSlideUp 0.22s cubic-bezier(0.34,1.1,0.64,1);
  }
  @keyframes modalSlideUp { from { transform: translateY(100%); } to { transform: none; } }

  /* Tabs scrollable */
  .tab { padding: 10px 12px; font-size: 13px; }

  /* Toast bottom-left on mobile */
  .toast-container { bottom: 16px; right: 12px; left: 12px; }
  .toast { min-width: unset; max-width: 100%; }

  /* Table cards layout for small screens */
  .table-mobile-cards thead { display: none; }
  .table-mobile-cards tr { display: block; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 12px; }
  .table-mobile-cards td { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
  .table-mobile-cards td:last-child { border-bottom: none; padding-top: 8px; }
  .table-mobile-cards td::before { content: attr(data-label); color: var(--text2); font-size: 12px; font-weight: 600; flex-shrink: 0; margin-right: 8px; }

  /* Topbar */
  .topbar { padding: 0 12px; }
  .topbar-title { font-size: 14px; }
  .topbar-right .badge { display: none; }

  /* Card padding */
  .card { padding: 14px; }

  /* Chart smaller */
  .chart-wrap { height: 160px; }
}

/* ════════════════════════════════════
   RESPONSIVE — Small mobile (≤ 380px)
   ════════════════════════════════════ */
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px 8px; }
  .stat-value { font-size: 20px; }
  .monitor-name { font-size: 13px; }
  .page-content { padding: 10px 8px; }
}

/* ════════════════════════════════════
   LIGHT MODE overrides
   ════════════════════════════════════ */
html.light .sidebar { box-shadow: 1px 0 0 var(--border); }
html.light .monitor-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); }
html.light .toast { box-shadow: 0 8px 24px rgba(0,0,0,0.12); }
html.light .modal { box-shadow: 0 20px 60px rgba(0,0,0,0.15); }
