:root {
  --navy: #0b2a5b;
  --navy-light: #123a78;
  --gold: #f5a623;
  --gold-dark: #d6890a;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #64748b;
  --border: #e2e7ee;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --gray: #64748b;
  --gray-bg: #e8ebf0;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --radius: 10px;
}

body.dark {
  --bg: #0f1621;
  --card: #18212f;
  --text: #e6ebf2;
  --muted: #92a0b5;
  --border: #2a3545;
  --gray-bg: #22303f;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--navy-light); }
body.dark a { color: #7fb1ff; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  background: var(--navy);
  color: #fff;
  flex-shrink: 0;
  padding: 0 0 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar .brand .logo {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--gold);
  color: var(--navy);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px;
}
.sidebar .brand .name { font-weight: 700; font-size: 15px; line-height: 1.25; }
.sidebar .brand .name small { display: block; font-weight: 400; color: rgba(255,255,255,0.65); font-size: 11px; }

.sidebar nav { margin-top: 10px; display: flex; flex-direction: column; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  color: rgba(255,255,255,0.82);
  text-decoration: none;
  padding: 12px 18px;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar nav a .ico { width: 18px; text-align: center; }
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active {
  background: rgba(245,166,35,0.14);
  border-left-color: var(--gold);
  color: #fff;
  font-weight: 600;
}

.main { flex: 1; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .actions { display: flex; align-items: center; gap: 14px; }

.content { padding: 22px 24px 60px; max-width: 1280px; }

.menu-toggle { display: none; background: transparent; border: none; color: var(--text); font-size: 20px; cursor: pointer; }

.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -240px; z-index: 50; transition: left .2s ease; box-shadow: 4px 0 18px rgba(0,0,0,0.25); }
  .sidebar.open { left: 0; }
  .menu-toggle { display: inline-block; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }

  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 40;
  }
  .sidebar-backdrop.show { display: block; }
}

.register-link {
  background: rgba(245,166,35,0.12);
  color: #fff !important;
  font-weight: 700 !important;
  margin: 10px 14px 4px;
  border-radius: 8px;
  border-left: none !important;
}
.register-link:hover { background: var(--gold) !important; color: var(--navy) !important; }

/* ---------- Generic ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 18px;
}
.card h2 { margin-top: 0; font-size: 16px; }
.hint { color: var(--muted); font-size: 13px; }

.row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.row label { width: 110px; color: var(--muted); font-size: 13px; }

input[type="text"], input[type="password"], input[type="search"], select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: 7px;
  font-size: 14px;
}
input[type="text"]:focus, select:focus { outline: 2px solid var(--gold); outline-offset: -1px; }

button {
  background: var(--navy);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
button:hover { background: var(--navy-light); }
button.primary { background: var(--gold); color: #1b2430; font-weight: 700; }
button.primary:hover { background: var(--gold-dark); }
button.danger { background: var(--red); color: white; }
button.danger:hover { background: #b91c1c; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.link-btn, a.link-btn {
  background: transparent;
  color: var(--navy-light);
  text-decoration: underline;
  padding: 0;
  font-size: 14px;
  border: none;
}
body.dark button.link-btn, body.dark a.link-btn { color: #7fb1ff; }

.header-actions { display: flex; align-items: center; gap: 16px; }

table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.02em; }
td.comment-cell { white-space: normal; }
.table-wrap { overflow-x: auto; }

.status-badge { padding: 3px 10px; border-radius: 12px; font-size: 11.5px; font-weight: 700; display: inline-block; }
.status-online { background: var(--green-bg); color: var(--green); }
.status-offline { background: var(--gray-bg); color: var(--gray); }
.status-stale { background: #fef3c7; color: #b45309; }
.status-never { background: var(--red-bg); color: var(--red); }

.error { background: var(--red-bg); color: var(--red); padding: 10px 14px; border-radius: 7px; margin: 14px 0; }
.success { color: var(--green); margin-top: 8px; }
#formMsg.error { padding: 8px 10px; }

/* ---------- Stat cards ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 10px;
  margin-top: 4px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.stat-card .icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}
.stat-card .num { font-size: 17px; font-weight: 800; line-height: 1; }
.stat-card .label { color: var(--muted); font-size: 11px; margin-top: 2px; }
.icon-total { background: #e6edfb; color: var(--navy); }
.icon-online { background: var(--green-bg); color: var(--green); }
.icon-offline { background: var(--gray-bg); color: var(--gray); }
.icon-stale { background: #fef3c7; color: #b45309; }

/* ---------- Filters toolbar ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.toolbar input[type="search"] { min-width: 230px; flex: 1; }
.toolbar .spacer { flex: 1; }

.bulk-bar {
  display: none;
  align-items: center;
  gap: 10px;
  background: #fff7e6;
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 13.5px;
}
body.dark .bulk-bar { background: #2a2310; }
.bulk-bar.show { display: flex; }
.bulk-bar .count { font-weight: 700; }

.pagination { display: flex; gap: 6px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.pagination button { padding: 6px 11px; font-size: 13px; }
.pagination span { color: var(--muted); font-size: 13px; }

.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 18px; }
.chart-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.chart-box h2 { font-size: 14px; margin: 0 0 10px; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--navy) 0%, #0d3a7d 60%, var(--navy) 100%);
}
.login-box {
  width: 100%;
  max-width: 380px;
  margin: 20px;
  background: var(--card);
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-box .logo {
  width: 52px; height: 52px; border-radius: 12px;
  background: var(--gold); color: var(--navy);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; margin-bottom: 14px;
}
.login-box h1 { margin-bottom: 4px; font-size: 20px; color: var(--navy); }
.subtitle { color: var(--muted); font-size: 13px; margin-top: 0; }
.login-box form { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.login-box label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.login-box input { width: 100%; }
.login-box button { margin-top: 20px; width: 100%; padding: 11px; }

/* ---------- Checkbox column ---------- */
td.chk-col, th.chk-col { width: 32px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--navy); }
