/* Minimal Custom CSS - MG Backoffice ergänzen */
:root {
  --bg: #eef3fa;
  --accent: #1659d4;
}

.hidden { display: none !important; }
html, body { background: var(--bg); }

.shell { display: grid; grid-template-columns: 72px 1fr; min-height: 100vh; }
.sidebar { background: #fff; border-right: 1px solid var(--mg-color-neutral); display: flex; flex-direction: column; align-items: center; padding: .8rem .4rem; gap: .5rem; }
.logo { width: 40px; height: 40px; border-radius: 50%; background: conic-gradient(from 40deg, #0cc, #56f, #e3f, #0cc); margin-bottom: .4rem; }
.nav-btn { width: 44px; height: 44px; border: 1px solid var(--mg-color-neutral); border-radius: 8px; background: #f8f9fa; cursor: pointer; font-size: 1.2rem; }
.nav-btn.active { border-color: var(--mg-color-brand-primary); background: #e9f0ff; }

.content { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: 74px; background: var(--mg-color-brand-primary); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem; }
.topbar h1 { margin: 0; font-size: 1.35rem; font-weight: 700; }
.topbar .sub { opacity: .85; font-size: .9rem; }
.topbar button { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.3); color: #fff; }

main { display: flex; flex: 1 0 auto; flex-direction: column; padding: 1.25rem; }
.tab { display: none; }
.tab.active { display: block; }
.tab.active#tab-heatmap { display: flex; flex: 1 0 auto; flex-direction: column; min-height: calc(100vh - 74px - 2.5rem); }

.filter-row { display: flex; gap: .7rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filter-row label { display: flex; flex-direction: column; gap: .25rem; font-weight: 500; }
.status { margin-left: auto; color: var(--mg-color-text-default); font-size: .9rem; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi { display: flex; align-items: center; gap: .8rem; min-height: 92px; background: #fff; border: 1px solid var(--mg-color-neutral); border-radius: 8px; padding: 1rem; box-shadow: 0 2px 7px rgba(20, 48, 83, .06); }
.kpi h3 { margin: 0; font-size: .85rem; color: var(--mg-color-text-default); font-weight: 600; }
.kpi .v { margin-top: .4rem; font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.kpi-content { min-width: 0; }
.kpi-content small { display: block; margin-top: .2rem; color: #8795a9; font-size: .68rem; }
.kpi-icon { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 38px; border-radius: 9px; font-size: 1.25rem; font-weight: 800; }
.kpi--rooms .kpi-icon { background: #e4efff; color: #1769d1; }
.kpi--occupancy .kpi-icon { background: #e8e4ff; color: #5b43c5; }
.kpi--sensors .kpi-icon { background: #fff0d5; color: #b87500; }
.kpi--fresh .kpi-icon { background: #e1f4e8; color: #198754; }
.dashboard-page-heading { align-items: center; margin-bottom: .8rem; }
.dashboard-page-heading .section-heading__title { font-size: 1.6rem; }
.dashboard-heading-actions { align-items: center; }
.dashboard-controls { display: flex; align-items: flex-end; gap: .7rem; flex-wrap: wrap; margin-bottom: 1rem; padding: .75rem; background: #fff; border: 1px solid var(--mg-color-neutral); border-radius: 7px; }
.dashboard-control { min-width: 145px; margin: 0; }
.dashboard-control--event { flex: 1 1 260px; }
.dashboard-controls .mg-input { width: 100%; box-sizing: border-box; }
.detections-page-heading { align-items: center; margin-bottom: .8rem; }
.detections-page-heading .section-heading__title { font-size: 1.6rem; }
.detections-filter-panel { display: grid; grid-template-columns: minmax(150px, 1.2fr) minmax(150px, 1.2fr) minmax(170px, 1.4fr) minmax(150px, 1fr) minmax(100px, .7fr) auto auto auto; align-items: end; gap: .65rem; margin-bottom: .9rem; padding: .75rem; background: #fff; border: 1px solid var(--mg-color-neutral); border-radius: 7px; }
.detections-filter-panel > label:not(.detections-inline-check) { min-width: 0; margin: 0; }
.detections-filter-panel .mg-input { width: 100%; min-width: 0; box-sizing: border-box; }
.detections-inline-check { display: flex; align-items: center; gap: .35rem; min-height: 36px; padding: 0 .35rem; white-space: nowrap; }
.detections-filter-panel > button { white-space: nowrap; }
.detections-table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--mg-color-neutral); border-radius: 7px; }
#detectionsTable { min-width: 1080px; margin: 0; }
#detectionsTable tbody tr.detection-block-start td { border-top: 3px solid #b9cdf2; }
.detection-block { display: flex; flex-direction: column; gap: .1rem; white-space: nowrap; }
.detection-block strong { color: var(--mg-color-text-default); font-size: .78rem; }
.detection-block small, .detection-apple small { color: #6f819f; font-size: .68rem; }
.detection-platform { display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.platform-icon { display: inline-grid; place-items: center; width: 23px; height: 23px; border-radius: 6px; font-size: .9rem; font-weight: 700; }
.platform-icon--apple { color: #fff; background: #1f2937; }
.platform-icon--android { color: #fff; background: #3f9f56; }
.platform-icon--other { color: #49617f; background: #e8eef7; }
.detection-apple { display: flex; flex-direction: column; gap: .1rem; max-width: 190px; }
.detection-apple code { color: #49617f; font-size: .68rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detection-class { color: var(--mg-color-text-default); font-size: .78rem; }

.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem; margin: 0 0 1rem; padding: .1rem 0 .8rem; border-bottom: 1px solid var(--mg-color-neutral); }
.section-heading__title { margin: 0; color: var(--mg-color-text-default); font-size: 1.35rem; line-height: 1.2; }
.section-heading__sub { margin: .25rem 0 0; color: #6f819f; font-size: .82rem; }
.section-heading__controls { display: flex; align-items: center; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; }
.room-controls .mg-input { min-width: 145px; }
.room-controls input[type="search"] { min-width: 190px; }
.room-controls .room-control { display: flex; flex-direction: column; gap: .2rem; color: #6f819f; font-size: .68rem; font-weight: 600; line-height: 1; text-align: left; }
.room-controls .room-control .mg-input { margin-top: .1rem; color: var(--mg-color-text-default); font-size: .82rem; font-weight: 400; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.eyebrow { margin-bottom: .35rem; color: #6f819f; font-size: .65rem; font-weight: 700; letter-spacing: .14em; }
.rooms-page-heading { align-items: center; margin-bottom: 1rem; }
.rooms-page-heading .section-heading__title { font-size: 1.55rem; }
.rooms-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.rooms-kpi { display: flex; align-items: center; gap: .75rem; min-height: 78px; padding: .8rem 1rem; background: #fff; border: 1px solid var(--mg-color-neutral); border-radius: 7px; box-shadow: 0 2px 7px rgba(20, 48, 83, .06); }
.rooms-kpi__icon { display: grid; place-items: center; width: 30px; height: 30px; flex: 0 0 30px; border-radius: 6px; font-weight: 800; font-size: 1rem; }
.rooms-kpi__label { color: #6f819f; font-size: .7rem; font-weight: 600; }
.rooms-kpi strong { display: block; margin-top: .1rem; color: var(--mg-color-text-default); font-size: 1.35rem; line-height: 1.1; }
.rooms-kpi small { color: #8795a9; font-size: .65rem; }
.rooms-kpi--connected .rooms-kpi__icon { background: #e3efff; color: #1769d1; }
.rooms-kpi--pending .rooms-kpi__icon { background: #fff1d6; color: #bd7900; }
.rooms-kpi--offline .rooms-kpi__icon { background: #ffe3e7; color: #d53d59; }
.rooms-kpi--rooms .rooms-kpi__icon { background: #e1f4e8; color: #198754; }
.rooms-filter-panel { display: flex; align-items: flex-end; gap: .6rem; flex-wrap: wrap; margin-bottom: .9rem; padding: .75rem; background: #fff; border: 1px solid var(--mg-color-neutral); border-radius: 7px; }
.rooms-filter-panel > label { min-width: 145px; margin: 0; }
.rooms-filter-panel .scanner-search { flex: 1 1 240px; }
.rooms-filter-panel .scanner-inline-check { display: flex; align-items: center; gap: .35rem; min-height: 36px; padding: 0 .35rem; white-space: nowrap; }
.rooms-filter-panel .scanner-inline-check input { margin: 0; }

.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.room { cursor: pointer; min-height: 190px; transition: transform .2s, box-shadow .2s; }
.room:hover { border-color: var(--accent); box-shadow: 0 6px 18px rgba(0,0,0,.12); transform: translateY(-2px); }
.room-card-header { min-width: 0; }
.room-card-header > div { min-width: 0; }
.room .mg-card__title { margin: 0; font-size: 1.1rem; }
.room-measured { flex: 0 0 auto; color: #6f819f; font-size: .72rem; white-space: nowrap; text-align: right; }
.room-card-body { display: flex; flex-direction: column; }
.room .big { font-size: 2rem; color: var(--accent); font-weight: 700; }
.room .meta { color: #6f819f; font-size: .85rem; margin-top: .3rem; }
.room-spark { display: block; width: 100%; height: 40px; margin-top: .8rem; }
.env-row { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.env-top { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .95rem; font-weight: 600; margin: 0 0 .4rem 0; padding-bottom: .4rem; border-bottom: 1px dashed var(--mg-color-neutral); }
.env-values { color: #4d607d; font-size: .78rem; line-height: 1.5; }
.env-timestamp.stale { color: #a86600; }
.aq-badge { padding: .1rem .5rem; border-radius: 4px; font-size: .75rem; font-weight: 700; }
.aq-good { background: #d4edda; color: #155724; }
.aq-moderate { background: #fff3cd; color: #856404; }
.aq-poor { background: #f8d7da; color: #721c24; }

/* Room modal: toolbar, class accordion, chart sections */
.ts-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 150px auto auto auto auto;
  align-items: end;
}
.ts-toolbar > label { min-width: 0; }
.ts-toolbar > label:not(.ts-inline-check) .mg-input { width: 100%; min-width: 0; box-sizing: border-box; }
.ts-toolbar > button { white-space: nowrap; }
.ts-status { margin-left: 0; }
.ts-inline-check { display: flex; flex-direction: row !important; align-items: center; gap: .4rem !important; padding-bottom: .55rem; white-space: nowrap; }
.ts-reload-spinner { display: inline-block; margin-right: .35rem; animation: ts-reload-spin .8s linear infinite; }
@keyframes ts-reload-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.ts-accordion { margin: .25rem 0 1rem 0; border: 1px solid var(--mg-color-neutral); border-radius: 6px; }
.ts-accordion summary { cursor: pointer; padding: .55rem .8rem; font-weight: 600; user-select: none; }
.ts-accordion summary .meta { color: #6f819f; font-weight: 400; font-size: .85rem; }
.ts-accordion[open] summary { border-bottom: 1px solid var(--mg-color-neutral); }
.ts-classes { display: flex; flex-wrap: wrap; gap: .35rem 1rem; padding: .7rem .8rem; }
.ts-classes label { display: flex; align-items: center; gap: .3rem; font-size: .9rem; white-space: nowrap; }
.ts-chart-title { margin: 1rem 0 .4rem 0; font-size: 1rem; }
.ts-env-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

.modal { position: fixed; inset: 0; background: rgba(13,25,43,.4); display: flex; align-items: flex-start; justify-content: center; padding: 2rem; z-index: 100; }
.modal-content { background: #fff; border: 1px solid var(--mg-color-neutral); border-radius: 8px; width: min(1140px, 100%); max-height: 90vh; overflow: auto; padding: 1.5rem; }
.modal-content header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; border-bottom: 1px solid var(--mg-color-neutral); padding-bottom: 1rem; }
.modal-content header h2 { margin: 0; }
.modal-content header button { min-height: 32px; padding: .2rem .5rem; }
#scannerModal .modal-content { width: min(920px, 100%); }
#scannerModal .mg-form { max-width: none; gap: 0; }

.badge { display: inline-block; padding: .2rem .6rem; border-radius: 4px; font-size: .75rem; font-weight: 700; }
.badge-assigned { background: #e7f0ff; color: #1d4fb8; border: 1px solid #c9dcff; }
.badge-unassigned { background: #fff1da; color: #a86600; border: 1px solid #f3d49a; }
.badge-online { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.badge-offline { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.meta-cell { color: #6f819f; font-style: italic; }

.scanner-toolbar .scanner-search { min-width: 230px; flex: 1 1 260px; }
.scanner-toolbar label:not(.scanner-inline-check) .mg-input { width: 100%; box-sizing: border-box; }
.scanner-inline-check { flex-direction: row !important; align-items: center; gap: .4rem !important; padding-bottom: .55rem; white-space: nowrap; }
.room-group-panel { margin: 0 0 .8rem; padding: .75rem; background: #fff; border: 1px solid var(--mg-color-neutral); border-radius: 7px; }
.room-group-panel .mg-h3 { margin: 0 0 .6rem; font-size: 1rem; }
.room-group-controls { display: flex; align-items: flex-end; gap: .6rem; flex-wrap: wrap; }
.room-group-controls > .mg-form__label { min-width: 170px; margin: 0; }
.room-group-controls > .mg-form__label .mg-input { width: 100%; box-sizing: border-box; }
.room-group-controls .status { min-height: 24px; flex: 1 1 100%; }
.scanner-bulk-bar { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-bottom: .6rem; padding: .7rem .8rem; background: #e7f0ff; border: 1px solid #c9dcff; border-radius: 6px; }
.scanner-bulk-bar strong { margin-right: auto; }
.scanner-bulk-bar .mg-input { min-width: 220px; }
.scanner-result-summary { margin: 0 0 .5rem; color: #6f819f; font-size: .85rem; }
.scanner-table-wrap { overflow-x: auto; }
.scanner-select-cell { width: 32px; text-align: center; }
#adminScannerTable th, #adminScannerTable td { white-space: nowrap; }

/* MG Backoffice Forms ergänzen */
.mg-form { display: flex; flex-direction: column; gap: 1.5rem; max-width: 600px; }
.mg-form > div { display: flex; flex-direction: column; gap: .4rem; }
.mg-form__label { font-weight: 500; font-size: .9rem; color: var(--mg-color-text-default); }
.mg-input { padding: .52rem .65rem; min-height: 36px; font-size: .9rem; }

.scanner-form-section { margin: 0; padding: 1rem; background: #f8fafd; border: 1px solid var(--mg-color-neutral); border-radius: 8px; }
.scanner-form-section + .scanner-form-section { margin-top: .85rem; }
.scanner-form-section__heading { display: flex; align-items: flex-start; gap: .65rem; margin-bottom: .8rem; }
.scanner-form-section__heading h3 { margin: 0; color: var(--mg-color-text-default); font-size: .98rem; }
.scanner-form-section__heading p { margin: .2rem 0 0; color: #6f819f; font-size: .75rem; }
.scanner-form-icon { display: grid; place-items: center; width: 28px; height: 28px; flex: 0 0 28px; border-radius: 7px; background: #e5efff; color: #1769d1; font-weight: 700; }
.scanner-form-grid { display: grid; gap: .7rem; }
.scanner-form-grid--identity { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); }
.scanner-form-grid--assignment { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.scanner-form-grid--operation { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.scanner-form-grid--schedule { grid-template-columns: repeat(2, minmax(0, 1fr)) auto; align-items: end; }
.scanner-form-field { display: flex; min-width: 0; flex-direction: column; gap: .3rem; }
.scanner-form-field .mg-input { width: 100%; box-sizing: border-box; }
.scanner-form-help { color: #6f819f; font-size: .7rem; line-height: 1.3; }
.scanner-form-field .mg-input[readonly] { background: #edf2f8; color: #526680; cursor: not-allowed; }
.scanner-form-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: .9rem; }

/* Button Varianten */
.mg-btn--sm { padding: .3rem .6rem; min-height: 28px; font-size: .8rem; }

/* Peer-Matrix */
.peer-matrix-wrap { overflow-x: auto; }
.peer-matrix { border-collapse: collapse; }
.peer-matrix th, .peer-matrix td { text-align: center; padding: .4rem .5rem; border: 1px solid var(--mg-color-neutral); font-size: .8rem; white-space: pre-line; }
.peer-matrix th.pm-row { text-align: left; background: #f8f9fa; font-weight: 600; }
.peer-matrix th.pm-col { background: #f8f9fa; font-weight: 600; max-width: 110px; }
.pm-self { background: #f1f3f5; color: #adb5bd; }
.pm-none { background: #fff; }
.pm-cell { font-weight: 700; }
.pm-strong { background: #d4edda; color: #155724; }
.pm-medium { background: #fff3cd; color: #856404; }
.pm-weak { background: #f8d7da; color: #721c24; }
.pm-legend { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .8rem; }
.pm-chip { padding: .2rem .6rem; border-radius: 4px; font-size: .75rem; font-weight: 600; border: 1px solid var(--mg-color-neutral); }

/* Auth Card */
.mg-card { background: #fff; border: 1px solid var(--mg-color-neutral); border-radius: 8px; padding: 1.5rem; }
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 1.5rem;
}
.auth-screen > .mg-card,
.auth-screen > .mg-card:hover,
.auth-screen > .mg-card:focus-within {
  width: min(420px, 100%);
  box-sizing: border-box;
  transform: none;
  transition: none;
}
.auth-screen .mg-h1 { margin-top: 0; }
.auth-screen .mg-form { max-width: none; }
.auth-screen .mg-input { width: 100%; box-sizing: border-box; }
.login-status-info { display: block; }
.login-status-error { display: block; background: #f8d7da; border-color: #f5c6cb; color: #721c24; }

/* Heatmap */
.heatmap-toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}
.heatmap-toolbar-group { display: flex; align-items: flex-end; gap: .55rem; min-width: 0; padding: .7rem; background: #fff; border: 1px solid var(--mg-color-neutral); border-radius: 7px; }
.heatmap-toolbar-group .mg-form__label { min-width: 0; flex: 1 1 0; margin: 0; }
.heatmap-toolbar-group .mg-input { width: 100%; box-sizing: border-box; }
.heatmap-toolbar-group--plan { flex-wrap: wrap; }
.heatmap-toolbar-group--plan .mg-form__label { flex: 1 1 150px; }
.heatmap-toolbar-group--display { flex-wrap: wrap; }
.heatmap-toolbar-group--display .mg-form__label { flex: 1 1 160px; }
.heatmap-toolbar-group--timelapse { flex-wrap: wrap; align-items: center; }
.heatmap-toolbar-group--timelapse .mg-form__label { flex: 1 1 120px; }
.heatmap-toolbar-group--timelapse .mg-form__label--timelapse-datetime { flex: 1 1 210px; }
.heatmap-toolbar-group--timelapse .mg-btn { white-space: nowrap; }
#heatmapTimelapseStatus { min-height: 24px; flex: 1 1 100%; }
.heatmap-check { display: flex; align-items: center; gap: .35rem; min-height: 36px; color: var(--mg-color-text-default); font-size: .8rem; white-space: nowrap; }
.heatmap-weight-control { min-width: 180px; }
.heatmap-weight-control small { display: block; margin-top: .2rem; color: #6f819f; font-size: .75rem; }
.heatmap-weight-control .mg-input[type="range"],
.heatmap-settings-group .mg-input[type="range"] {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  accent-color: var(--mg-color-brand-primary);
}
.heatmap-toolbar input[type="checkbox"],
.heatmap-sidebar input[type="checkbox"] {
  accent-color: var(--mg-color-brand-primary);
}
.heatmap-settings-group { display: grid; gap: .55rem; padding: .65rem; border: 1px solid var(--mg-color-neutral); border-radius: 7px; background: #f9fbff; }
.heatmap-settings-group .mg-h4 { margin: 0 0 .25rem; font-size: .88rem; }
.heatmap-upload-hint { color: #6f819f; font-size: .72rem; font-weight: 400; white-space: nowrap; }
.heatmap-page-heading { align-items: center; margin-bottom: .8rem; }
.heatmap-page-heading .section-heading__title { font-size: 1.6rem; }

.heatmap-container {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
  background: #fff;
  border: 1px solid var(--mg-color-neutral);
  border-radius: 8px;
  padding: 1rem;
  min-height: max(600px, calc(100vh - 285px));
}

.heatmap-container--sidebar-collapsed {
  grid-template-columns: 1fr 42px;
}

.heatmap-map-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.heatmap-zoom-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .4rem;
  margin-bottom: .6rem;
}

.heatmap-zoom-controls span {
  min-width: 3.5rem;
  text-align: center;
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
}

.heatmap-viewport {
  position: relative;
  overflow: auto;
  background: #f8f9fa;
  border: 1px solid var(--mg-color-neutral);
  border-radius: 6px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  flex: 1 1 auto;
  min-height: max(500px, calc(100vh - 370px));
}

.heatmap-layers {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
}

.heatmap-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.heatmap-image {
  position: relative;
  display: block;
  max-width: 100%;
  height: auto;
  user-select: none;
  pointer-events: none;
}

.heatmap-canvas,
.heatmap-peer-canvas {
  pointer-events: none;
}

.heatmap-markers {
  pointer-events: none;
}

.heatmap-markers--hidden .heatmap-marker,
.heatmap-marker--hidden {
  opacity: 0;
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
  cursor: default;
}

.heatmap-markers--hidden .heatmap-marker:hover,
.heatmap-marker--hidden:hover {
  transform: none;
}

.heatmap-markers--hidden .heatmap-marker,
.heatmap-marker--hidden {
  pointer-events: auto;
}

.heatmap-marker {
  position: absolute;
  width: 28px;
  height: 28px;
  margin-left: -14px;
  margin-top: -14px;
  background: rgba(22, 89, 212, 0.9);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  cursor: grab;
  pointer-events: auto;
  transition: transform 0.1s, opacity 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  user-select: none;
}

.heatmap-marker:hover {
  transform: scale(1.15);
  z-index: 10;
}

.heatmap-marker.dragging {
  cursor: grabbing;
  transform: scale(1.2);
  z-index: 20;
}

.heatmap-marker.has-data {
  background: rgba(40, 167, 69, 0.95);
}

.heatmap-marker.stale {
  background: rgba(168, 102, 0, 0.9);
}

.heatmap-marker.offline {
  background: rgba(114, 28, 36, 0.85);
}

.heatmap-marker-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.5rem 0.7rem;
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  font-size: 0.75rem;
  line-height: 1.4;
  white-space: nowrap;
  border-radius: 4px;
  margin-bottom: 8px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 30;
}

.heatmap-marker:hover .heatmap-marker-tooltip {
  opacity: 1;
}

.heatmap-markers--hidden .heatmap-marker-tooltip,
.heatmap-marker--hidden .heatmap-marker-tooltip {
  opacity: 0 !important;
}

.heatmap-person-marker {
  position: absolute;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  margin-top: -6px;
  background: rgba(255, 193, 7, 0.8);
  border: 1px solid rgba(255, 152, 0, 1);
  border-radius: 50%;
  pointer-events: none;
  animation: pulse 2s ease-in-out infinite;
}

.heatmap-person-marker--ambiguous {
  background: rgba(251, 146, 60, 0.82);
  border-color: rgba(249, 115, 22, 1);
}

.heatmap-markers--dense .heatmap-person-marker {
  animation: none;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  margin-top: -4px;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
}

.heatmap-sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding-right: 0.5rem;
  transition: max-width .22s ease, min-width .22s ease, padding .22s ease;
}

.heatmap-sidebar-toggle {
  position: sticky;
  top: 0;
  align-self: flex-end;
  z-index: 2;
  min-width: 30px;
  padding: .15rem .45rem;
}

.heatmap-sidebar--collapsed {
  min-width: 42px;
  max-width: 42px;
  padding-right: 0;
  overflow: hidden;
}

.heatmap-sidebar--collapsed > *:not(.heatmap-sidebar-toggle) {
  display: none;
}

.heatmap-sidebar .mg-h3 {
  margin: 0 0 0.8rem 0;
  font-size: 1rem;
  border-bottom: 1px solid var(--mg-color-neutral);
  padding-bottom: 0.5rem;
}

.heatmap-sidebar .mg-form {
  gap: 1rem;
  max-width: 100%;
}

.heatmap-sidebar .mg-form > div {
  gap: 0.25rem;
}

.heatmap-scanner-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.heatmap-scanner-list--readonly .heatmap-scanner-item {
  cursor: default;
}

.heatmap-scanner-item {
  padding: 0.6rem;
  background: #f8f9fa;
  border: 1px solid var(--mg-color-neutral);
  border-radius: 6px;
  font-size: 0.85rem;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem;
  transition: background 0.2s;
}

.heatmap-scanner-details { min-width: 0; }
.heatmap-scanner-remove { flex: 0 0 auto; }

.heatmap-scanner-item:hover {
  background: #e9ecef;
}

.heatmap-scanner-item.positioned {
  border-color: #28a745;
  background: #e7f4ea;
}

.heatmap-scanner-item.has-data {
  border-left: 3px solid #28a745;
}

.heatmap-scanner-item.stale {
  border-left: 3px solid #ffc107;
}

.heatmap-scanner-item.offline {
  border-left: 3px solid #dc3545;
}

.heatmap-scanner-name {
  font-weight: 600;
  color: var(--mg-color-text-default);
}

.heatmap-scanner-meta {
  color: #6f819f;
  font-size: 0.75rem;
  line-height: 1.4;
}

@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .heatmap-container,
  .heatmap-container--sidebar-collapsed {
    grid-template-columns: 1fr;
    gap: 1rem;
    min-height: 0;
  }
  .heatmap-sidebar {
    max-height: none;
    max-width: none;
  }
  .heatmap-sidebar--collapsed {
    min-width: auto;
    max-width: none;
    overflow: visible;
    padding-right: .5rem;
  }
  .heatmap-sidebar--collapsed > *:not(.heatmap-sidebar-toggle) {
    display: block;
  }
  .heatmap-sidebar-toggle {
    display: none;
  }
  .heatmap-viewport {
    min-height: 500px;
  }
  .heatmap-toolbar {
    grid-template-columns: 1fr;
  }
  .section-heading { align-items: stretch; flex-direction: column; gap: .7rem; }
  .section-heading__controls { justify-content: flex-start; }
  .rooms-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; justify-content: center; border-right: 0; border-bottom: 1px solid var(--mg-color-neutral); }
  .topbar { height: auto; padding: .8rem 1rem; }
  .topbar h1 { font-size: 1.1rem; }
  .room-grid { grid-template-columns: 1fr; }
  .modal { padding: .5rem; }
  .modal-content { padding: 1rem; max-height: 95vh; }
  .ts-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ts-toolbar label, .ts-toolbar .mg-input { min-width: 0; width: 100%; }
  .ts-toolbar button { width: 100%; }
  .heatmap-toolbar { grid-template-columns: 1fr; }
  .heatmap-container { padding: 0.5rem; }
  .scanner-toolbar > label, .scanner-toolbar > button { flex: 1 1 100%; }
  .scanner-bulk-bar .mg-input, .scanner-bulk-bar button { width: 100%; }
  .room-controls { display: grid; grid-template-columns: 1fr 1fr; }
  .room-controls input[type="search"], .room-controls .mg-btn { width: 100%; box-sizing: border-box; }
  .room-controls .room-control:first-child, .room-controls .mg-btn { grid-column: 1 / -1; }
  .room-controls .mg-input { min-width: 0; width: 100%; box-sizing: border-box; }
  .rooms-kpis { grid-template-columns: 1fr 1fr; }
  .rooms-filter-panel { align-items: stretch; }
  .rooms-filter-panel > label, .rooms-filter-panel > button { flex: 1 1 100%; width: 100%; box-sizing: border-box; }
  .rooms-filter-panel .scanner-inline-check { min-height: 32px; }
  .room-group-controls { align-items: stretch; }
  .room-group-controls > .mg-form__label, .room-group-controls > .mg-btn { flex: 1 1 100%; width: 100%; box-sizing: border-box; }
  .dashboard-controls { align-items: stretch; }
  .dashboard-control, .dashboard-controls > label { flex: 1 1 100%; min-width: 0; }
  .dashboard-heading-actions { justify-content: flex-start; }
  .scanner-form-grid--identity, .scanner-form-grid--assignment, .scanner-form-grid--operation, .scanner-form-grid--schedule { grid-template-columns: 1fr; }
  .scanner-form-actions { flex-direction: column-reverse; }
  .scanner-form-actions .mg-btn { width: 100%; }
  .detections-filter-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detections-filter-panel > button { width: 100%; }
}

@media (max-width: 460px) {
  .kpis { grid-template-columns: 1fr; }
  .room-grid { grid-template-columns: 1fr; }
  .rooms-kpis { grid-template-columns: 1fr; }
  .dashboard-kpis { grid-template-columns: 1fr; }
  .ts-toolbar { grid-template-columns: 1fr; }
  .heatmap-toolbar { grid-template-columns: 1fr; }
  .detections-filter-panel { grid-template-columns: 1fr; }
}
