* { box-sizing: border-box; }
html { overflow-x: hidden; max-width: 100%; }

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface2: #f0f1f5;
  --sidebar-bg: #ffffff;
  --topbar-bg: #ffffff;
  --border: #e2e4ea;
  --text: #1a1d29;
  --text2: #6b7280;
  --text3: #9ca3af;
  --accent: #22d3ee;
  --accent-dark: #0e9ab0;
  --menu-hover: #f4f5f7;
  --menu-active-bg: #eff9fb;
  --card-bg: #ffffff;
  --table-bg: #ffffff;
  --table-th: #f4f5f7;
  --table-th-color: #6b7280;
  --table-hover: #f9fafb;
  --input-bg: #ffffff;
  --input-disabled: #f4f5f7;
  --input-disabled-text: #6b7280;
  --form-label: #374151;
  --mobile-toggle-color: #1a1d29;
  --online-color: #1aa86b;
  --offline-color: #e0473f;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #14161f;
  --surface2: #1a1d29;
  --sidebar-bg: #14161f;
  --topbar-bg: #14161f;
  --border: #525870;
  --text: #e2e4ea;
  --text2: #8b8f9c;
  --text3: #525870;
  --accent: #22d3ee;
  --accent-dark: #1bb8d1;
  --menu-hover: #1a1d29;
  --menu-active-bg: #1a1d29;
  --card-bg: #181b27;
  --table-bg: #181b27;
  --table-th: #14161f;
  --table-th-color: #8b8f9c;
  --table-hover: #1f2330;
  --input-bg: #0f1117;
  --input-disabled: #14161f;
  --input-disabled-text: #b8bac4;
  --form-label: #e2e4ea;
  --mobile-toggle-color: #e2e4ea;
  --online-color: #1aa86b;
  --offline-color: #e0473f;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  transition: background 0.2s, color 0.2s;
  overflow-x: hidden;
}

/* SIDEBAR */
.sidebar {
  width: 240px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  border-right: 0.5px solid var(--border);
  flex-shrink: 0;
  transition: background 0.2s;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 18px 20px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-brand .logo-mark {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #042c53; font-weight: 700; font-size: 13px;
}
.sidebar-brand h6 { color: var(--accent); font-weight: 600; margin: 0; font-size: 14px; }
.sidebar-brand small { color: var(--text3); font-size: 10px; display: block; }
.sidebar-menu { padding: 12px 0; flex: 1; }
.menu-section {
  padding: 8px 20px 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: var(--text2);
  text-decoration: none;
  font-size: 13.5px;
  border-left: 3px solid transparent;
  transition: all 0.15s;
}
.menu-item:hover { background: var(--menu-hover); color: var(--text); }
.menu-item.active { background: var(--menu-active-bg); color: var(--accent); border-left-color: var(--accent); }
.menu-item i { font-size: 17px; width: 20px; text-align: center; }

/* TOPBAR */
.main-content { background: var(--bg); min-height: 100vh; transition: background 0.2s; flex: 1; width: 100%; max-width: 100%; overflow-x: hidden; }
.topbar {
  background: var(--topbar-bg);
  border-bottom: 0.5px solid var(--border);
  color: var(--text);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.2s;
  position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar h5 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }

/* THEME TOGGLE */
.theme-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2); color: var(--text2);
  font-size: 12px; cursor: pointer; transition: all 0.15s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* CARDS */
.card-panel {
  background: var(--card-bg);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  transition: background 0.2s;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.stat-card {
  background: var(--card-bg);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex; align-items: center; gap: 14px;
}
.stat-card .stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.stat-card .stat-val { font-size: 22px; font-weight: 700; color: var(--text); }
.stat-card .stat-label { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* STATUS BADGE */
.badge-online { background: #d1fae5; color: #065f46; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-offline { background: #fee2e2; color: #991b1b; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-unknown { background: #f3f4f6; color: #6b7280; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }

[data-theme="dark"] .badge-online { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-offline { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .badge-unknown { background: #1f2937; color: #9ca3af; }

/* TABLES */
.table-custom { width: 100%; border-collapse: collapse; }
.table-custom th {
  background: var(--table-th); color: var(--table-th-color);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left;
}
.table-custom td { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text); }
.table-custom tbody tr:hover td { background: var(--table-hover); }

/* FORMS */
.form-control, .form-select {
  background: var(--input-bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 8px 12px;
  font-size: 14px; width: 100%; transition: all 0.15s;
}
.form-control:focus, .form-select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34,211,238,0.15);
}
.form-control:disabled { background: var(--input-disabled); color: var(--input-disabled-text); }
.form-label { color: var(--form-label); font-size: 13px; font-weight: 500; margin-bottom: 5px; display: block; }

/* BUTTONS */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; border: none; transition: all 0.15s; text-decoration: none; }
.btn-primary { background: var(--accent); color: #042c53; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: #e0473f; color: #fff; }
.btn-danger:hover { background: #c4322b; }
.btn-warning { background: #e8a13f; color: #fff; }
.btn-warning:hover { background: #c4802b; }
.btn-success { background: #1aa86b; color: #fff; }
.btn-success:hover { background: #0d8a56; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text2); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* SIGNAL METER */
.signal-bar { display: flex; align-items: flex-end; gap: 2px; height: 20px; }
.signal-bar span { width: 5px; border-radius: 2px; background: var(--border); }
.signal-bar span.active { background: var(--accent); }
.signal-bar span:nth-child(1) { height: 25%; }
.signal-bar span:nth-child(2) { height: 50%; }
.signal-bar span:nth-child(3) { height: 75%; }
.signal-bar span:nth-child(4) { height: 100%; }

/* MODAL */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 1000;
  align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: var(--card-bg); border: 0.5px solid var(--border);
  border-radius: 14px; padding: 24px; width: 100%; max-width: 460px;
  margin: 16px;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h6 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
.modal-close { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 20px; }

/* ALERT */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
[data-theme="dark"] .alert-success { background: #064e3b; color: #6ee7b7; border-color: #065f46; }
[data-theme="dark"] .alert-danger { background: #7f1d1d; color: #fca5a5; border-color: #991b1b; }
[data-theme="dark"] .alert-warning { background: #78350f; color: #fde68a; border-color: #92400e; }

/* LOGIN PAGE */
.login-wrap {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--card-bg); border: 0.5px solid var(--border);
  border-radius: 16px; padding: 36px; width: 100%; max-width: 380px;
}
.login-logo {
  text-align: center; margin-bottom: 24px;
}
.login-logo .logo-mark {
  width: 52px; height: 52px; background: var(--accent);
  border-radius: 14px; display: inline-flex;
  align-items: center; justify-content: center;
  color: #042c53; font-weight: 700; font-size: 20px;
  margin-bottom: 10px;
}

/* MOBILE */
.mobile-toggle {
  display: none; background: transparent; border: none;
  color: var(--mobile-toggle-color); font-size: 22px; cursor: pointer;
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 1040;
}
.sidebar-overlay.show { display: block; }

@media (max-width: 768px) {
  .mobile-toggle { display: block; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh;
    z-index: 1050; transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.show { transform: translateX(0); }
  .p-4 { padding: 12px !important; }
}

.page-content { padding: 24px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2,1fr); } .grid-3 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 600px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } .hide-mobile { display: none; } .table-custom { font-size: 12px; } }

.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 18px; } .mb-4 { margin-bottom: 24px; }
.mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; }
.d-flex { display: flex; width: 100%; max-width: 100%; overflow-x: hidden; } .align-center { align-items: center; } .justify-between { justify-content: space-between; }
.text-muted { color: var(--text2); } .text-sm { font-size: 12px; } .fw-600 { font-weight: 600; }
.w-100 { width: 100%; }
.grid-2, .grid-3, .grid-4 { min-width: 0; }
.grid-2 > *, .grid-3 > *, .grid-4 > * { min-width: 0; }
.dash-grid { display: grid; grid-template-columns: 1fr 340px; gap: 16px; min-width: 0; }
.dash-grid > * { min-width: 0; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
