
:root {
  --header-h: 72px;
  --summary-h: 74px;
  --main-gap: clamp(10px, 0.7vw, 18px);
  --shell-pad: clamp(8px, 0.7vw, 14px);
  --app-vh: 100dvh;
  --content-max-h: calc(var(--app-vh) - 190px);
  --bottom-max-h: calc(var(--app-vh) - 430px);
}

html, body {
  min-height: 100%;
}

body {
  overflow: auto;
}

.dashboard-shell {
  min-height: var(--app-vh);
  height: var(--app-vh);
  padding: var(--shell-pad);
  display: grid;
  gap: var(--main-gap);
  grid-template-rows: auto auto auto minmax(360px, 1fr);
}

.top-header {
  min-height: var(--header-h);
  padding: clamp(12px, 0.9vw, 18px) clamp(14px, 1vw, 22px);
  display: grid;
  grid-template-columns: minmax(280px, 1.2fr) minmax(240px, 0.8fr) auto;
  gap: 14px;
  align-items: center;
}

.top-header__left,
.top-header__center,
.top-header__right {
  display: flex;
  align-items: center;
}

.top-header__left {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
}

.top-header__center {
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  text-align: center;
}

.top-header__right {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.top-header .eyebrow {
  margin-bottom: 4px;
}

.top-header .js-title {
  font-size: clamp(20px, 1.1vw, 24px);
  line-height: 1.2;
}

.live-dot--inline {
  padding: 5px 10px;
}

.headline-meta,
.panel-caption {
  color: var(--muted);
  font-size: var(--fs-small);
}

.top-summary-row {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(240px, 320px);
  gap: var(--main-gap);
  min-height: var(--summary-h);
}

.summary-grid--wide {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.summary-item {
  padding: clamp(10px, 0.8vw, 14px);
}

.summary-item strong {
  font-size: clamp(22px, 1.05vw, 28px);
}

.search-card--inline {
  display: flex;
  align-items: center;
}

.dashboard-main-grid {
  min-height: 0;
  max-height: var(--content-max-h);
  display: grid;
  grid-template-columns: minmax(300px, 23%) minmax(420px, 41%) minmax(360px, 36%);
  gap: var(--main-gap);
}

.dashboard-bottom-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(640px, 1.42fr) minmax(420px, 1fr);
  gap: var(--main-gap);
  align-items: start;
}

.left-panel,
.right-panel,
.center-panel,
.detail-card--wide,
.chart-card--wide {
  min-height: 0;
}

.left-panel,
.right-panel,
.center-panel {
  max-height: var(--content-max-h);
}

.scroll-panel {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sticky-title {
  position: sticky;
  top: 0;
  z-index: 4;
  background: linear-gradient(180deg, color-mix(in srgb, var(--panel) 96%, #fff 4%), color-mix(in srgb, var(--panel) 92%, transparent));
  padding-bottom: 10px;
}

.card-title-row,
.map-header {
  margin-bottom: 10px;
}

.card-title-row .js-subtitle,
.map-header .js-subtitle {
  font-size: clamp(16px, 0.95vw, 18px);
}

.device-list--tall,
.device-card-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 6px;
}

.center-panel {
  display: flex;
  flex-direction: column;
}

.map-slim {
  height: 100%;
  min-height: 240px;
  border-radius: 18px;
  overflow: hidden;
}

.device-card-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-content: start;
}

.device-overview-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: color-mix(in srgb, var(--panel-2) 92%, transparent);
  transition: 0.2s ease;
}

.device-overview-card:hover,
.device-overview-card.is-active {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--blue) 46%, transparent);
  box-shadow: 0 10px 24px rgba(0,0,0,0.18);
}

.device-overview-head,
.device-overview-meta,
.device-overview-actions,
.metric-inline-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.device-overview-head {
  margin-bottom: 8px;
}

.device-overview-name {
  font-size: calc(var(--fs-body) + 1px);
  font-weight: 700;
}

.device-overview-meta {
  color: var(--muted);
  font-size: var(--fs-small);
  margin-bottom: 8px;
}

.metric-inline-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.metric-inline-box {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  border-radius: 12px;
  padding: 8px 10px;
}

.metric-inline-box span {
  display: block;
  color: var(--muted);
  font-size: var(--fs-small);
  margin-bottom: 4px;
}

.metric-inline-box strong {
  font-size: var(--fs-body);
}

.device-overview-actions {
  margin-top: 4px;
}

.card-inline-link {
  font-size: var(--fs-small);
  color: var(--blue);
}

.detail-card--wide,
.chart-card--wide {
  padding: 14px 16px;
  align-self: start;
}

.detail-card--wide {
  max-height: var(--bottom-max-h);
  overflow: auto;
}

.chart-card--wide {
  max-height: min(420px, var(--bottom-max-h));
}

.chart-card--wide canvas {
  width: 100%;
  display: block;
}

.metric-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.metric-card, .sub-card {
  padding: 12px;
}

.metric-card strong {
  font-size: clamp(16px, 0.95vw, 20px);
}

.sub-grid {
  gap: 10px;
}

.camera-frame {
  aspect-ratio: 16 / 9;
}

.ai-box {
  max-height: 200px;
  overflow: auto;
}

@media (min-width: 2200px) {
  .dashboard-main-grid {
    grid-template-columns: minmax(340px, 22%) minmax(620px, 42%) minmax(460px, 36%);
  }

  .device-card-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1900px) {
  :root {
    --content-max-h: none;
    --bottom-max-h: none;
  }

  body {
    overflow: auto;
  }

  .dashboard-shell {
    height: auto;
    min-height: 100vh;
    grid-template-rows: auto auto auto auto;
  }

  .dashboard-main-grid,
  .dashboard-bottom-grid {
    max-height: none;
  }
}

@media (max-width: 1680px) {
  .dashboard-main-grid,
  .dashboard-bottom-grid {
    grid-template-columns: 1fr;
  }

  .scroll-panel,
  .device-list--tall,
  .device-card-list,
  .detail-card--wide {
    overflow: visible;
    max-height: none;
  }

  .center-panel {
    min-height: 460px;
  }

  .chart-card--wide {
    max-height: none;
  }
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .top-header,
  .top-summary-row {
    grid-template-columns: 1fr;
  }

  .top-header__center,
  .top-header__right {
    justify-content: flex-start;
    text-align: left;
  }

  .summary-grid--wide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-inline-grid,
  .metric-grid,
  .sub-grid {
    grid-template-columns: 1fr;
  }
}


.dashboard-shell--ops {
  grid-template-rows: auto auto minmax(420px, 1fr);
}

.top-summary-row--ops {
  grid-template-columns: minmax(760px, 1fr) minmax(260px, 340px);
}

.summary-grid--ops {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.summary-item--kpi {
  min-height: 92px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.summary-item--wide strong {
  font-size: clamp(16px, 0.95vw, 22px);
}

.dashboard-main-grid--ops {
  grid-template-columns: minmax(340px, 24%) minmax(620px, 46%) minmax(360px, 30%);
  max-height: calc(var(--app-vh) - 210px);
}

.center-panel--ops,
.right-panel--ops {
  padding-bottom: 14px;
}

.device-item--ops {
  padding: 15px;
}

.device-sub--time {
  margin-top: 2px;
}

.mini-metrics--ops div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mini-metrics--ops div span {
  color: var(--muted);
  font-size: var(--fs-label);
}

.map-footer-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: var(--fs-small);
}

.ai-placeholder-grid {
  display: grid;
  gap: 12px;
}

.ai-placeholder-card {
  min-height: 140px;
}

.ai-placeholder-body {
  color: var(--muted);
  line-height: 1.7;
}

.ai-preparing-box {
  border: 1px dashed color-mix(in srgb, var(--blue) 45%, var(--line));
  border-radius: 18px;
  padding: 18px;
  background: color-mix(in srgb, var(--blue) 8%, var(--panel));
}

.ai-preparing-box__title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.ai-preparing-box__desc {
  color: var(--muted);
  line-height: 1.7;
}

@media (max-width: 1900px) {
  .dashboard-shell--ops {
    grid-template-rows: auto auto auto;
  }

  .dashboard-main-grid--ops {
    max-height: none;
  }
}

@media (max-width: 1680px) {
  .summary-grid--ops {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard-main-grid--ops {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1080px) {
  .summary-grid--ops {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .top-summary-row--ops {
    grid-template-columns: 1fr;
  }
}

.ux-live-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 1.32fr);
  gap: var(--main-gap);
  align-items: stretch;
}

.card-title-row--compact { margin-bottom: 12px; }
.ticker-card, .trend-card { min-height: 0; }
.ticker-shell {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  min-height: 64px;
}
.live-ticker-track {
  display: flex;
  gap: 12px;
  align-items: center;
  width: max-content;
  min-width: 100%;
  padding: 12px 0;
  animation: ticker-scroll 42s linear infinite;
  will-change: transform;
}
.live-ticker-track:hover { animation-play-state: paused; }
.live-ticker-empty {
  padding: 0 16px;
  color: var(--muted);
  font-size: var(--fs-small);
}
.live-ticker-group {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-shrink: 0;
  padding-right: 12px;
}
.live-ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel-2) 90%, transparent);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
  transition: background-color 0.25s ease, border-color 0.25s ease, transform 0.25s ease;
}
.live-ticker-item.is-fresh {
  border-color: color-mix(in srgb, var(--blue) 45%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--blue) 26%, transparent), 0 6px 18px rgba(0,0,0,0.14);
}
.live-ticker-item__device { font-weight: 800; font-size: calc(var(--fs-ticker, var(--fs-small)) + 1px); }
.live-ticker-item__metric {
  color: var(--muted);
  font-size: var(--fs-ticker, var(--fs-small));
}
.live-ticker-item__metric strong { color: var(--text); font-size: calc(var(--fs-ticker, var(--fs-small)) + 1px); }
.live-ticker-item__status {
  font-size: var(--fs-ticker, var(--fs-small));
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
}
.live-ticker-item__status.status-stable { color: #10b981; background: rgba(16,185,129,0.12); }
.live-ticker-item__status.status-caution { color: #fbbf24; background: rgba(251,191,36,0.14); }
.live-ticker-item__status.status-warning { color: #f87171; background: rgba(248,113,113,0.14); }
.live-ticker-item__status.status-offline { color: #9ca3af; background: rgba(156,163,175,0.14); }
.live-led {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  display: inline-block;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}
.live-led--stable { background: #10b981; animation: led-blink-slow 2.2s infinite; }
.live-led--caution { background: #fbbf24; animation: led-blink-mid 1.3s infinite; }
.live-led--warning { background: #ef4444; animation: led-blink-fast 0.75s infinite; }
.live-led--offline { background: #6b7280; animation: none; opacity: 0.72; }
.live-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: var(--fs-small);
}
.live-update-badge {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
}
.live-update-badge.is-updated {
  border-color: color-mix(in srgb, var(--blue) 45%, transparent);
  color: var(--text);
}
.mini-trend-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.mini-trend-panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  padding: 12px;
  min-height: 0;
}
.mini-trend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.mini-trend-head span { color: var(--muted); font-size: 12px; }
.mini-trend-head strong { font-size: 15px; }
.mini-chart-wrap {
  position: relative;
  height: 128px;
  border-radius: 12px;
  overflow: hidden;
}
.mini-chart-wrap canvas {
  width: 100% !important;
  height: 128px !important;
  display: block;
}
@keyframes ticker-scroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}
@keyframes led-blink-slow { 0%, 100% { opacity: 1; box-shadow: 0 0 8px rgba(16,185,129,0.62); } 50% { opacity: 0.28; box-shadow: 0 0 2px rgba(16,185,129,0.18); } }
@keyframes led-blink-mid { 0%, 100% { opacity: 1; box-shadow: 0 0 8px rgba(251,191,36,0.62); } 50% { opacity: 0.22; box-shadow: 0 0 2px rgba(251,191,36,0.18); } }
@keyframes led-blink-fast { 0%, 100% { opacity: 1; box-shadow: 0 0 8px rgba(239,68,68,0.62); } 50% { opacity: 0.16; box-shadow: 0 0 2px rgba(239,68,68,0.14); } }

@media (max-width: 1500px) {
  .ux-live-grid { grid-template-columns: 1fr; }
}
@media (max-width: 980px) {
  body { overflow: auto; }
  .dashboard-shell { height: auto; min-height: var(--app-vh); }
  .top-summary-row, .dashboard-main-grid, .mini-trend-grid { grid-template-columns: 1fr; }
  .dashboard-main-grid { max-height: none; }
  .left-panel, .right-panel, .center-panel { max-height: none; }
}
.device-name { display: inline-flex; align-items: center; gap: 8px; }
.device-item.is-fresh { border-color: color-mix(in srgb, var(--blue) 46%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--blue) 20%, transparent), 0 8px 20px rgba(0,0,0,0.16); }
