:root {
  --bg: #0b1220;
  --panel: #111c2e;
  --panel-2: #16233a;
  --border: #22334d;
  --text: #e8eef8;
  --muted: #8fa3bd;
  --accent: #22d3a6;
  --accent-2: #17b890;
  --danger: #ff6b7d;
  --warn: #ffc857;
  --info: #6aa9ff;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 100% -10%, rgba(34, 211, 166, 0.12), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(106, 169, 255, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

.hidden { display: none !important; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 18px; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  background: #0c1626;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 166, 0.15); }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #1a8cff);
  color: #04121a;
  font-size: 20px;
  font-weight: 800;
}
.brand h1 { font-size: 18px; }
.brand p { font-size: 12px; color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: rgba(13, 22, 38, 0.85);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: rgba(34, 211, 166, 0.12); color: var(--accent); font-weight: 600; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.admin-info { font-size: 12px; color: var(--muted); line-height: 1.5; }
.admin-info strong { display: block; color: var(--text); font-size: 13px; }

.main { flex: 1; min-width: 0; padding: 26px 28px 48px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.topbar h2 { font-size: 24px; }
.topbar p { color: var(--muted); font-size: 13px; margin-top: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(34, 211, 166, 0.18);
  animation: pulse 2s infinite;
}
@keyframes pulse { 50% { opacity: 0.45; } }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 13px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06140f; font-weight: 700; }
.btn.primary:hover { background: var(--accent-2); color: #06140f; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; padding: 11px; }
.btn.sm { padding: 5px 9px; font-size: 11.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Cards / stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: linear-gradient(160deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-card .label { color: var(--muted); font-size: 12px; }
.stat-card .value { font-size: 27px; font-weight: 700; margin: 6px 0 2px; letter-spacing: -0.02em; }
.stat-card .value.accent { color: var(--accent); }
.stat-card .value.warn { color: var(--warn); }
.stat-card .value.danger { color: var(--danger); }
.stat-card .note { font-size: 11.5px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.panel-head h3 { font-size: 14.5px; }
.panel-head p { font-size: 12px; color: var(--muted); }

.bars { display: flex; align-items: flex-end; gap: 12px; height: 170px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.bar-stack { width: 100%; max-width: 34px; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; }
.bar { background: linear-gradient(180deg, var(--accent), #139b78); border-radius: 6px 6px 3px 3px; min-height: 2px; transition: height 0.4s; }
.bar.sensor { background: linear-gradient(180deg, var(--info), #3d74c9); border-radius: 3px; }
.bar-col .bar-label { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.legend { display: flex; gap: 14px; font-size: 11.5px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; background: var(--accent); }
.legend .sensor::before { background: var(--info); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 12.8px; }
th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid rgba(34, 51, 77, 0.55); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: rgba(34, 211, 166, 0.03); }
td .sub { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.pill.green { color: var(--accent); border-color: rgba(34, 211, 166, 0.4); background: rgba(34, 211, 166, 0.1); }
.pill.red { color: var(--danger); border-color: rgba(255, 107, 125, 0.4); background: rgba(255, 107, 125, 0.1); }
.pill.yellow { color: var(--warn); border-color: rgba(255, 200, 87, 0.4); background: rgba(255, 200, 87, 0.09); }
.pill.blue { color: var(--info); border-color: rgba(106, 169, 255, 0.4); background: rgba(106, 169, 255, 0.1); }
.pill.gray { color: #9fb0c6; }

.trust { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.trust-track { flex: 1; height: 6px; background: #0a1524; border-radius: 999px; overflow: hidden; min-width: 48px; }
.trust-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--danger), var(--warn), var(--accent)); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar input { max-width: 260px; }
.toolbar select { max-width: 170px; }

.empty { padding: 34px 10px; text-align: center; color: var(--muted); font-size: 13px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0e2a22; border: 1px solid rgba(34, 211, 166, 0.5);
  color: var(--accent); padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 13px; z-index: 50; max-width: 90vw;
}
.toast.err { background: #2a1119; border-color: rgba(255, 107, 125, 0.5); color: var(--danger); }

.badge-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--danger);
  display: inline-block; margin-left: auto;
}

.user-cell { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  background: rgba(106, 169, 255, 0.15); color: var(--info);
  font-weight: 700; font-size: 12px; text-transform: uppercase; flex-shrink: 0;
}

.page-title-actions { display: flex; gap: 8px; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { font-size: 12px; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--muted); cursor: pointer; }
.chip.active { color: var(--accent); border-color: var(--accent); background: rgba(34, 211, 166, 0.1); }

@media (max-width: 820px) {
  .sidebar { width: 74px; padding: 18px 10px; }
  .sidebar .brand div:not(.brand-mark), .sidebar .nav-item { font-size: 0; }
  .sidebar .nav-item { justify-content: center; padding: 12px; }
  .sidebar .nav-item span { font-size: 18px; }
  .admin-info, .sidebar-footer .btn { display: none; }
  .main { padding: 18px 14px 40px; }
}
