:root {
  --bg: #eef1f7;
  --panel: #ffffff;
  --panel-2: #f4f6fb;
  --border: #e3e7f0;
  --text: #131826;
  --text-dim: #6b7385;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --ok: #16a34a;
  --alarm: #dc2626;
  --confirmed: #7f1d1d;
  --warn: #d97706;
  --highlight: #16a34a;
  --shadow-sm: 0 1px 2px rgba(20, 30, 60, 0.06);
  --shadow-md: 0 6px 20px rgba(20, 30, 60, 0.08);
  --shadow-lg: 0 20px 48px rgba(20, 30, 60, 0.16);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  height: 60px;
  position: relative;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  flex-shrink: 0;
  position: relative;
  background: linear-gradient(135deg, #2f6fed, #4f9bff);
  box-shadow: 0 4px 10px rgba(47, 111, 237, 0.35);
}

.brand-icon::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%);
  animation: brand-ping 2.4s infinite;
}

@keyframes brand-ping {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.6); }
  70% { box-shadow: 0 0 0 9px rgba(255, 255, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 7px;
  line-height: 1;
}

.brand-mark {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.01em;
  background: linear-gradient(120deg, #2f6fed, #4f9bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-sep {
  color: #c7cfe0;
  font-size: 14px;
}

.brand-sub {
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 700;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.view-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--bg);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.crumb-link {
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.15s;
}

.crumb-link:hover {
  color: var(--accent);
}

.crumb-current {
  color: var(--text);
  font-weight: 700;
}

.crumb-sep {
  color: #cbd2e1;
}

.global-search {
  position: relative;
  flex: 1;
  max-width: 440px;
  margin: 0 24px;
}

.global-search-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.global-search-input::placeholder {
  color: #9aa1b2;
}

.global-search-input:focus {
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.12);
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: 360px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.search-dropdown.hidden {
  display: none;
}

.search-empty {
  padding: 14px;
  font-size: 13px;
  color: var(--text-dim);
}

.search-result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.search-result:last-child {
  border-bottom: none;
}

.search-result:hover {
  background: var(--panel-2);
}

.search-result-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.search-result-title {
  font-size: 13.5px;
  font-weight: 700;
}

.search-result-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}

.user-name {
  color: var(--text-dim);
  font-weight: 600;
}

.logout-btn {
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.logout-btn:hover {
  border-color: var(--alarm);
  color: var(--alarm);
  background: #fef2f2;
}

/* ---- login ---- */

.login-wrap {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #e0ecff 0%, transparent 45%),
    radial-gradient(circle at 85% 80%, #dcf6ec 0%, transparent 45%),
    linear-gradient(160deg, #f3f6fd 0%, #eef1f7 60%);
}

.login-card {
  width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 30px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  font-size: 24px;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(120deg, #2f6fed, #4f9bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.login-sub {
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 8px;
  font-weight: 600;
}

.field {
  padding: 11px 13px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.field:focus {
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.12);
}

.login-submit {
  margin-top: 4px;
  padding: 11px;
  border-radius: 9px;
  border: none;
  background: linear-gradient(120deg, #2f6fed, #2f8fed);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(47, 111, 237, 0.3);
  transition: transform 0.12s, box-shadow 0.12s;
}

.login-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(47, 111, 237, 0.38);
}

.login-error {
  color: var(--alarm);
  font-size: 12.5px;
  text-align: center;
  min-height: 14px;
  font-weight: 600;
}

.login-hint {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-dim);
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}

/* ---- dashboard / location cards ---- */

.page-pad {
  padding: 30px 32px;
  animation: fade-in-up 0.35s ease;
}

.page-title {
  font-size: 23px;
  font-weight: 800;
  margin: 0 0 22px;
  letter-spacing: -0.01em;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}

.location-card,
.section-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  cursor: pointer;
  position: relative;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.location-card:hover,
.section-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
}

.card-kind {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  background: rgba(47, 111, 237, 0.1);
  padding: 4px 9px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.card-title {
  font-size: 16.5px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.card-sub {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 2px;
  font-weight: 600;
}

.card-stats {
  display: flex;
  gap: 16px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- section view ---- */

.layout {
  display: flex;
  height: 100%;
}

.sidebar {
  width: 324px;
  min-width: 324px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.search {
  margin: 14px;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.search:focus {
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.12);
}

.filter-row {
  display: flex;
  gap: 8px;
  padding: 0 14px 12px;
}

.filter-select {
  flex: 1;
  padding: 8px 8px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12.5px;
  outline: none;
}

.sensor-list {
  overflow-y: auto;
  flex: 1;
  padding: 0 8px 12px;
}

.list-empty {
  padding: 20px 14px;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-dim);
  background: var(--panel);
}

.pager button {
  padding: 6px 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 11.5px;
  cursor: pointer;
  font-weight: 600;
}

.pager button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pager-info {
  text-align: center;
  flex: 1;
}

.zone-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  padding: 12px 8px 6px;
  font-weight: 700;
}

.sensor-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}

.sensor-item:hover {
  background: var(--panel-2);
}

.sensor-item.active {
  background: rgba(47, 111, 237, 0.08);
  border-color: var(--accent);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}

.status-dot.alarm {
  background: var(--alarm);
  box-shadow: 0 0 0 rgba(220, 38, 38, 0.6);
  animation: pulse-dot 1.4s infinite;
}

.status-dot.confirmed {
  background: var(--confirmed);
}

.sensor-item-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sensor-item-title {
  font-size: 13.5px;
  font-weight: 700;
}

.sensor-item-sub {
  font-size: 11.5px;
  color: var(--text-dim);
}

.viewer-wrap {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: linear-gradient(160deg, #eef2f9, #e5ebf4);
}

.viewport {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

.stage img {
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  box-shadow: 0 10px 40px rgba(20, 30, 60, 0.18);
}

.markers {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.marker {
  position: absolute;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  margin-top: -11px;
  border-radius: 50%;
  background: rgba(22, 163, 74, 0.2);
  border: 2px solid var(--ok);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #0b3d1e;
  transition: transform 0.15s;
}

.marker:hover {
  transform: scale(1.25);
}

.marker.alarm {
  background: rgba(220, 38, 38, 0.28);
  border-color: var(--alarm);
  color: #7a0d0d;
  animation: pulse-marker 1.2s infinite;
  z-index: 5;
}

.marker.confirmed {
  background: rgba(127, 29, 29, 0.55);
  border-color: var(--confirmed);
  color: #fff0f0;
  z-index: 5;
}

/* Selection highlight — a bright green halo so the clicked/found sensor
   stands out from the crowd, independent of its ok/alarm/confirmed color. */
.marker.active {
  transform: scale(1.3);
  outline: 4px solid var(--highlight);
  outline-offset: 3px;
  filter: drop-shadow(0 0 8px rgba(22, 163, 74, 0.7));
  z-index: 10;
}

.marker.active:hover {
  transform: scale(1.3);
}

@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.6); }
  70% { box-shadow: 0 0 0 7px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

@keyframes pulse-marker {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.55); }
  70% { box-shadow: 0 0 0 14px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.zoom-controls {
  position: absolute;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}

.zoom-controls button {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s;
}

.zoom-controls button:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--shadow-md);
}

.detail-panel {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 304px;
  max-height: calc(100% - 40px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow-lg);
  z-index: 20;
  animation: fade-in-up 0.25s ease;
}

.detail-panel.hidden {
  display: none;
}

.detail-panel.is-alarm {
  border-color: var(--alarm);
}

.detail-panel.is-confirmed {
  border-color: var(--confirmed);
}

.detail-title {
  font-size: 16.5px;
  font-weight: 800;
  margin-bottom: 4px;
}

.detail-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(22, 163, 74, 0.12);
  color: var(--ok);
  margin-bottom: 12px;
}

.detail-badge.alarm {
  background: rgba(220, 38, 38, 0.12);
  color: var(--alarm);
}

.detail-badge.confirmed {
  background: rgba(127, 29, 29, 0.12);
  color: var(--confirmed);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}

.detail-row span:first-child {
  color: var(--text-dim);
  font-weight: 600;
}

.detail-row span:last-child {
  font-weight: 700;
}

.timer-box {
  margin-top: 14px;
  padding: 14px;
  border-radius: 12px;
  background: #fef2f2;
  text-align: center;
  border: 1px solid #fbdada;
}

.timer-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  font-weight: 700;
}

.timer-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--alarm);
  font-variant-numeric: tabular-nums;
}

.timer-hint {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 4px;
}

.confirmed-box {
  margin-top: 14px;
  padding: 13px;
  border-radius: 12px;
  background: #fdf2f2;
  border: 1px solid #f3d7d7;
}

.confirmed-hint {
  font-size: 12px;
  color: var(--text);
  line-height: 1.45;
  font-weight: 600;
}

.history-box {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.history-box.hidden {
  display: none;
}

.history-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 700;
}

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11.5px;
  padding: 5px 0;
}

.history-time {
  color: var(--text-dim);
  white-space: nowrap;
}

.history-action {
  color: var(--text);
  text-align: right;
  font-weight: 600;
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.detail-actions button {
  flex: 1;
  padding: 9px 6px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

.detail-actions button:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.detail-actions button.primary {
  background: linear-gradient(120deg, #2f6fed, #2f8fed);
  border-color: transparent;
  color: #fff;
}

.detail-actions button.danger {
  border-color: var(--alarm);
  color: var(--alarm);
  background: #fff;
}

.close-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
}

.close-btn:hover {
  color: var(--text);
}
