* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.4;
  background: #fff;
  color: #000;
}

a { color: inherit; }

.cell {
  border: 1px solid #000;
  padding: 5px 7px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.module .cell {
  border: 0;
  border-radius: 0;
  padding: 5px 7px;
}

.module > .panel-head {
  border-bottom: 1px solid #eee;
  padding-bottom: 6px;
}

.module > .meta {
  border-top: 1px solid #eee;
  padding-top: 6px;
}

header.cell {
  margin: 8px 8px 0;
  padding: 8px 10px;
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

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

.header-clock {
  flex: 0 0 auto;
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
  line-height: 1.2;
}

.header-clock:hover .doom-clock--header,
.header-clock:focus-visible .doom-clock--header {
  background: #fafafa;
  outline: 2px solid #000;
  outline-offset: 1px;
}

.doom-clock {
  display: flex;
  align-items: center;
  gap: 10px;
}

.doom-clock--header {
  gap: 8px;
  padding: 4px 8px;
  border: 1px solid #000;
  background: #fff;
}

.doom-clock--large {
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 16px 12px 12px;
  border: 1px solid #000;
  background: #fafafa;
  margin-bottom: 8px;
}

.doom-analog { flex: 0 0 auto; line-height: 0; }

.doom-analog-face {
  display: block;
  width: 52px;
  height: 52px;
}

.doom-clock--large .doom-analog-face {
  width: min(168px, 52vw);
  height: min(168px, 52vw);
}

.doom-digital {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: ui-monospace, "SF Mono", "Roboto Mono", "Cascadia Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.doom-digital--compact { min-width: 0; }

.doom-digital-wall {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.1;
}

.doom-digital-count {
  font-size: 15px;
  font-weight: 700;
  color: #c1121f;
  letter-spacing: 0.06em;
  line-height: 1;
}

.doom-digital-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 7px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.55;
}

.doom-digital--large { align-items: center; text-align: center; }

.doom-lcd {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px;
  border: 2px solid #111;
  background: #0a0a0a;
  min-width: min(280px, 88vw);
}

.doom-lcd-row {
  display: block;
  color: #ff3b3b;
  text-shadow: 0 0 8px rgba(255, 60, 60, 0.45);
  letter-spacing: 0.08em;
  line-height: 1;
}

.doom-lcd-row--wall {
  font-size: clamp(28px, 8vw, 40px);
  font-weight: 600;
  opacity: 0.92;
}

.doom-lcd-row--count {
  font-size: clamp(36px, 10vw, 52px);
  font-weight: 700;
}

.doom-digital-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.doom-digital-sec {
  font-size: 14px;
  font-weight: 700;
  color: #c1121f;
  letter-spacing: 0.12em;
}

.doom-digital-sec small {
  font-size: 10px;
  opacity: 0.7;
  letter-spacing: 0.14em;
}

.doom-digital--large .doom-digital-label {
  font-size: 10px;
}

@media (max-width: 520px) {
  .header-row { flex-wrap: wrap; }
  .header-clock { margin-left: auto; }
  .doom-analog-face { width: 44px; height: 44px; }
  .doom-digital-wall { font-size: 10px; }
  .doom-digital-count { font-size: 13px; }
}

h1 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 6px;
  font-size: 12px;
}

nav button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  font-size: 11px;
  opacity: 0.7;
}

#layout-hint { font-style: italic; opacity: 0.85; }

#summary { font-weight: 600; opacity: 0.9; }

.filter-wrap { display: inline-flex; align-items: center; }

.filter-wrap input {
  width: 7.5rem;
  max-width: 40vw;
  padding: 2px 6px;
  border: 1px solid #000;
  background: #fff;
  font: inherit;
  font-size: 11px;
}

#btn-alerts[aria-pressed="true"] { font-weight: 600; }

.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;
}

.module--loading .metric .big { opacity: 0.35; }

.module--loading .viz::after {
  content: "";
  display: block;
  height: 40px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}

.module--map.module--loading .viz::after { height: 72px; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.module[hidden] { display: none !important; }

.desk {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 8px;
  margin: 10px;
  align-items: start;
}

@media (min-width: 1200px) {
  .desk { grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); }
}

@media (min-width: 1600px) {
  .desk { grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); }
}

@media (max-width: 520px) {
  .desk { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
}

.module {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  border: 1px solid #000;
  background: #fff;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.module:hover,
.module:focus-visible {
  background: #fafafa;
  outline: 2px solid #000;
  outline-offset: -2px;
}

.module:active { background: #f0f0f0; }

.module--map .viz-map {
  aspect-ratio: 16 / 10;
  min-height: 72px;
  max-height: 88px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: nowrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.55;
  flex: 0 0 auto;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status.strong { opacity: 1; font-weight: 600; }

.metric {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 6px;
}

.metric .big {
  font-size: clamp(17px, 2.4vw, 22px);
  font-weight: 600;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.metric .unit {
  font-size: 11px;
  opacity: 0.65;
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.2;
}

.metric--center { justify-content: center; text-align: center; }

.sub {
  font-size: 11px;
  opacity: 0.6;
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta {
  font-size: 10px;
  opacity: 0.5;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: nowrap;
}

.meta .src {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta span:last-child { flex-shrink: 0; }

.viz { padding: 0; display: flex; flex-direction: column; min-height: 0; }

.viz-chart {
  width: 100%;
  aspect-ratio: 320 / 48;
  min-height: 40px;
  max-height: 52px;
  display: block;
}

.viz-chart--short {
  aspect-ratio: 320 / 40;
  min-height: 34px;
  max-height: 44px;
}

.viz-gauge-wrap { display: flex; justify-content: center; padding: 3px 4px; }
.viz-gauge {
  width: 100%;
  max-width: 140px;
  height: auto;
  aspect-ratio: 200 / 112;
  display: block;
}

.viz-clock { display: flex; justify-content: center; padding: 4px; }

.doom-clock--large { width: 100%; }

.viz-spiral {
  width: 100%;
  max-height: 72px;
  display: block;
}
.viz-spiral--large {
  max-height: none;
  width: min(320px, 100%);
  margin: 0 auto;
}

.viz-map {
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 72px;
  max-height: 88px;
  position: relative;
  padding: 0;
  overflow: hidden;
}

.viz-map > .map { position: absolute; inset: 0; width: 100%; height: 100%; }

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 9px;
  opacity: 0.75;
  padding: 0 2px 2px;
}

.map-legend span { display: inline-flex; align-items: center; gap: 3px; }
.map-legend i { width: 6px; height: 6px; border-radius: 50%; border: 1px solid rgba(0,0,0,.3); display: inline-block; }

.leaflet-container { background: #e8e8e8; font-size: 8px; }
.leaflet-control-zoom { display: none; }
.leaflet-control-attribution { font-size: 7px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leaflet-popup-content { margin: 6px 8px; font-size: 11px; line-height: 1.35; }
.leaflet-popup-content .meta-line { opacity: 0.65; font-size: 10px; margin-top: 2px; }

.bars { display: flex; flex-direction: column; gap: 4px; font-size: 11px; }
.bar.cell {
  display: grid;
  grid-template-columns: minmax(42px, 54px) minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
  padding: 4px 5px;
  border: 1px solid #eee;
}
.bar .name { opacity: 0.65; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.bar .track { height: 5px; background: #e8e8e8; overflow: hidden; }
.bar .fill { height: 100%; transition: width 0.5s ease; }
.bar .val { font-variant-numeric: tabular-nums; text-align: right; min-width: 20px; font-size: 10px; }

.list { font-size: 10px; max-height: 72px; overflow: auto; }
.list .row {
  display: flex;
  justify-content: space-between;
  gap: 5px;
  padding: 3px 0;
  border-top: 1px solid #eee;
}
.list .row:first-child { border-top: 0; }
.list .row .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .row .v { flex-shrink: 0; opacity: 0.7; font-variant-numeric: tabular-nums; }

.nodata { opacity: 0.45; font-size: 10px; padding: 6px; border: 1px solid #000; }
.err { font-size: 10px; opacity: 0.75; overflow-wrap: anywhere; }

footer.cell {
  margin: 0 8px 8px;
  font-size: 10px;
  opacity: 0.7;
  line-height: 1.5;
}

/* Detail modal */
.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.detail-overlay[hidden] { display: none; }

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(2px);
}

.detail-dialog {
  position: relative;
  width: min(920px, 100%);
  max-height: min(92vh, 900px);
  background: #fff;
  border: 1px solid #000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.detail-head-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.detail-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
}

.detail-close {
  border: 1px solid #000;
  background: #fff;
  width: 32px;
  height: 32px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.detail-close:hover { background: #f5f5f5; }

.detail-body {
  overflow: auto;
  padding: 0 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-metric {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 12px;
  border: 1px solid #000;
}

.detail-metric .big {
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.detail-metric .unit { font-size: 14px; opacity: 0.65; }

.detail-section {
  border: 1px solid #000;
  padding: 10px 12px;
}

.detail-section h3 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.detail-facts {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.55;
}

.detail-facts li + li { margin-top: 6px; }

.detail-note {
  font-size: 12px;
  opacity: 0.7;
  line-height: 1.5;
}

.detail-meta {
  font-size: 11px;
  opacity: 0.55;
  padding-top: 4px;
}

.detail-chart {
  width: 100%;
  aspect-ratio: 640 / 140;
  min-height: 100px;
  max-height: 180px;
  display: block;
}

.detail-chart--tall {
  aspect-ratio: 640 / 200;
  max-height: 220px;
}

.detail-map {
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 220px;
  max-height: 360px;
  position: relative;
  border: 1px solid #000;
}

.detail-map > .map { position: absolute; inset: 0; width: 100%; height: 100%; }

.detail-overlay .leaflet-control-zoom { display: block; }

.detail-list { font-size: 12px; max-height: 280px; overflow: auto; }
.detail-list .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid #eee;
}
.detail-list .row:first-child { border-top: 0; }

.detail-loading { padding: 24px; opacity: 0.6; font-size: 13px; }

.detail-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 640px) {
  .detail-grid-2 { grid-template-columns: 1fr; }
  .detail-overlay { padding: 8px; }
}
