:root {
  --bg: #071016;
  --panel: #0b1720;
  --border: #203747;
  --text: #f4f7fb;
  --muted: #9aa8b5;
  --green: #21d19f;
  --cyan: #00d9ff;
  --blue: #3b82f6;
  --amber: #f6a800;
  --violet: #8b5cf6;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(0,217,255,.10), transparent 28%),
    radial-gradient(circle at bottom right, rgba(59,130,246,.10), transparent 28%),
    var(--bg);
}

.dashboard-wrapper {
  height: 100vh;
  padding: 14px 20px;
  overflow: hidden;
}

.top-header {
  height: 76px;
  padding: 0 20px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(16,34,49,.95), rgba(8,18,26,.95));
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand, .header-status-top, .nav-left, .nav-right, .user-info, .system-online {
  display: flex;
  align-items: center;
}

.header-brand { gap: 16px; }
.header-status-top { gap: 12px; }
.nav-left, .nav-right { gap: 10px; }

.logo-box {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cyan);
  font-weight: 900;
}

.logo-box img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 1px;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.clock-box {
  font-family: Consolas, monospace;
  font-size: 22px;
  font-weight: 700;
  color: white;
}

.system-online {
  gap: 8px;
  padding: 9px 14px;
  border-radius: 12px;
  background: rgba(33,209,159,.10);
  border: 1px solid rgba(33,209,159,.25);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 20px var(--green);
}

.top-navbar {
  height: 52px;
  margin-bottom: 10px;
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #0b1720;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-link, .logout-btn {
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
}

.nav-link { color: #c7d0d8; }
.nav-link:hover { background: rgba(255,255,255,.05); color: white; }
.nav-link.active { color: var(--cyan); background: rgba(0,217,255,.12); border: 1px solid rgba(0,217,255,.2); }

.user-info {
  gap: 8px;
  color: white;
  font-size: 14px;
  font-weight: 600;
}

.user-info i { color: var(--cyan); font-size: 18px; }

.role-badge {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0,217,255,.10);
  color: var(--cyan);
  font-size: 11px;
  font-weight: 700;
}

.logout-btn {
  color: #ff8c8c;
  border: 1px solid rgba(255,140,140,.25);
  background: rgba(255,140,140,.05);
}
.logout-btn:hover { background: rgba(255,140,140,.10); color: #ffb3b3; }

.alarm-banner {
  height: 48px;
  margin-bottom: 10px;
  padding: 0 18px;
  border-radius: 14px;
  background: linear-gradient(135deg, #b91c1c, #7f1d1d);
  color: #fff;
  border: 1px solid rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: alarmPulse 1s infinite;
}

.alarm-banner strong { margin-right: 12px; letter-spacing: 1px; }
.btn-mute { border: 1px solid rgba(255,255,255,.4); background: rgba(255,255,255,.12); color: #fff; border-radius: 10px; padding: 7px 14px; font-weight: 700; }

.dashboard-grid {
  height: calc(100vh - 174px);
}

.alarm-banner:not(.d-none) + .dashboard-grid {
  height: calc(100vh - 232px);
}

.dashboard-grid > div { display: flex; }

.monitor-card {
  width: 100%;
  height: 100%;
  min-height: unset;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(16,34,49,.96), rgba(7,16,22,.96));
  position: relative;
  overflow: hidden;
}

.monitor-card::after {
  content: "";
  position: absolute;
  inset: auto -80px -80px auto;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  filter: blur(20px);
  opacity: .16;
  background: currentColor;
}

.monitor-top {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 14px;
}

.monitor-icon {
  width: 54px;
  height: 54px;
  border-radius: 15px;
  border: 1px solid currentColor;
  display: grid;
  place-items: center;
  font-size: 24px;
}

.monitor-top h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.badge-status {
  display: inline-flex;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.badge-status.online { color: var(--green); background: rgba(33,209,159,.12); }

.monitor-value {
  position: relative;
  z-index: 2;
  margin-top: 42px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.monitor-value span {
  font-size: clamp(52px, 4vw, 72px);
  line-height: 1;
  font-weight: 900;
}

.monitor-value small { font-size: 22px; color: var(--muted); font-weight: 800; }

.monitor-footer {
  position: absolute;
  left: 22px;
  right: 22px;
  bottom: 16px;
  z-index: 2;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}
.monitor-footer strong { color: var(--text); }

.accent-cyan { color: var(--cyan); }
.accent-blue { color: var(--blue); }
.accent-amber { color: var(--amber); }
.accent-violet { color: var(--violet); }

.direction-layout {
  position: relative;
  z-index: 2;
  margin-top: 25px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.compass {
  width: 130px;
  height: 130px;
  border: 2px solid #344655;
  border-radius: 50%;
  position: relative;
  background: radial-gradient(circle, transparent 56%, rgba(255,255,255,.04) 57%), repeating-conic-gradient(from 0deg, rgba(255,255,255,.24) 0deg 1deg, transparent 1deg 15deg);
}

.compass span { position: absolute; color: #c5ccd5; font-weight: 900; }
.compass .n { top: 4px; left: 50%; transform: translateX(-50%); }
.compass .e { right: 8px; top: 50%; transform: translateY(-50%); }
.compass .s { bottom: 4px; left: 50%; transform: translateX(-50%); }
.compass .w { left: 8px; top: 50%; transform: translateY(-50%); }
.needle { width: 3px; height: 45px; background: var(--amber); position: absolute; left: 50%; top: 24px; transform: translateX(-50%) rotate(35deg); transform-origin: bottom center; border-radius: 999px; opacity: .35; }
.center-dot { width: 14px; height: 14px; background: #f3f4f6; border-radius: 50%; position: absolute; inset: 0; margin: auto; }
.direction-info span { display: block; font-size: 56px; font-weight: 900; line-height: 1; color: var(--text); }
.direction-info small { display: block; margin-top: 10px; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; }

.alarm-danger { border-color: rgba(255,70,70,.95) !important; box-shadow: 0 0 30px rgba(255,70,70,.35); }
.alarm-danger::before { content: "ALARM"; position: absolute; top: 18px; right: 20px; padding: 6px 10px; border-radius: 999px; background: rgba(255,70,70,.18); color: #ff6b6b; border: 1px solid rgba(255,70,70,.45); font-size: 11px; font-weight: 900; letter-spacing: 2px; z-index: 3; }

.setting-modal { background: #0b1720; color: #fff; border: 1px solid var(--border); }
.setting-modal .form-control { background: #071016; border: 1px solid var(--border); color: #fff; }
.setting-modal label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }

@keyframes alarmPulse { 0%,100% { box-shadow: 0 0 0 rgba(255,70,70,0); } 50% { box-shadow: 0 0 28px rgba(255,70,70,.45); } }

@media (max-width: 992px) {
  body { overflow: auto; }
  .dashboard-wrapper { height: auto; overflow: visible; }
  .top-header, .top-navbar { height: auto; padding: 14px; flex-direction: column; align-items: flex-start; gap: 12px; }
  .dashboard-grid, .alarm-banner:not(.d-none) + .dashboard-grid { height: auto; }
  .monitor-card { min-height: 280px; }
}

.history-wrapper {
  overflow: hidden;
}

.history-panel {
  height: calc(100vh - 160px);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(16,34,49,.96), rgba(7,16,22,.96));
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.history-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
}

.history-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.history-filter .form-select {
  width: 240px;
  background: #071016;
  border: 1px solid var(--border);
  color: #fff;
}

.history-table-wrap {
  max-height: calc(100vh - 245px);
  overflow: auto;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.08);
}

.history-table {
  margin-bottom: 0;
}

.history-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #102231;
  color: #c7d0d8;
  font-size: 13px;
}

.history-status {
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255,70,70,.16);
  color: #ff8c8c;
  border: 1px solid rgba(255,70,70,.35);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
}

@media (max-width: 992px) {
  .history-panel { height: auto; }
  .history-header { flex-direction: column; align-items: flex-start; }
  .history-filter .form-select { width: 100%; }
  .history-table-wrap { max-height: none; }
}

.history-filter-bar {
  display: grid;
  grid-template-columns: 190px 180px 160px 160px auto auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.history-filter-bar .form-select,
.history-filter-bar .form-control {
  background: #071016;
  border: 1px solid var(--border);
  color: #fff;
}

.history-filter-bar .form-control::placeholder {
  color: #728292;
}

.sensor-history-table-wrap {
  max-height: calc(100vh - 315px);
}

@media (max-width: 1200px) {
  .history-filter-bar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .history-filter-bar {
    grid-template-columns: 1fr;
  }
}
