/* =========================================
   VARIABLES & THEMING
   ========================================= */
:root {
  /* Colors */
  --bg-top: #070b10;
  --bg-bottom: #0b0f14;
  --panel-bg: rgba(17, 24, 38, 0.62);
  --panel-alt-bg: rgba(10, 14, 20, 0.55);
  --line-color: rgba(34, 48, 65, 0.92);
  --text-primary: #e6edf3;
  --text-muted: #9fb1c1;

  /* Status Colors */
  --color-ok: #2dd4bf;
  --color-warn: #fbbf24;
  --color-bad: #fb7185;
  --color-info: #60a5fa;
  --color-danger-border: rgba(251, 113, 133, 0.35);

  /* Sizing & Spacing */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-pill: 999px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 10px;
  --space-lg: 12px;

  /* Typography */
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 14px;
}

/* =========================================
   RESET & BASE
   ========================================= */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background:
    radial-gradient(1200px 700px at 18% -10%, rgba(96, 165, 250, 0.25), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(45, 212, 191, 0.16), transparent 55%),
    radial-gradient(900px 650px at 80% 120%, rgba(251, 113, 133, 0.10), transparent 60%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  color: var(--text-primary);
  font-family: var(--font-mono);
  overflow: hidden;
  font-size: var(--text-sm);
  transition: background 180ms linear, filter 180ms linear;
}

@keyframes heat-flicker {
  0% { filter: saturate(1.00) brightness(1.00); }
  50% { filter: saturate(1.18) brightness(1.06); }
  100% { filter: saturate(1.00) brightness(1.00); }
}

body.temp-high {
  background:
    radial-gradient(1200px 700px at 18% -10%, rgba(255, 102, 0, 0.35), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(255, 0, 0, 0.28), transparent 55%),
    radial-gradient(900px 650px at 80% 120%, rgba(255, 196, 0, 0.24), transparent 60%),
    linear-gradient(180deg, #130807, #1c0a08);
  animation: heat-flicker 0.65s ease-in-out infinite;
}

body.temp-high .panel,
body.temp-high .topbar {
  border-color: rgba(255, 88, 46, 0.85);
  box-shadow: 0 0 20px rgba(255, 88, 46, 0.22), 0 12px 30px rgba(0, 0, 0, 0.45);
}

/* =========================================
   LAYOUT
   ========================================= */
.app-container {
  height: 100vh;
  width: 100vw;
  padding: var(--space-sm);
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  grid-template-rows: auto 1fr;
  gap: var(--space-sm);
}

.layout-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-height: 0;
}

.layout-col--left {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

.layout-col--left::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background: url("/assets/voronezh.gif") center / cover no-repeat;
  filter: blur(4px) saturate(0.8) brightness(1.7);
  transform: none;
  pointer-events: none;
}

.layout-col--left::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, rgba(7, 11, 16, 0.35), rgba(7, 11, 16, 0.78));
  pointer-events: none;
}

/* =========================================
   TOPBAR
   ========================================= */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
  padding: var(--space-sm) var(--space-lg);
  border: 1px solid var(--line-color);
  border-radius: var(--radius-md);
  background: var(--panel-bg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.topbar__brand {
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
  flex-shrink: 0;
}

.topbar__title {
  margin: 0;
  font-size: var(--text-base);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 800;
  white-space: nowrap;
}

.topbar__actions {
  display: flex;
  gap: var(--space-md);
  align-items: center;
  flex-shrink: 0;
}

/* =========================================
   PILL BADGE
   ========================================= */
.pill {
  display: inline-flex;
  gap: var(--space-sm);
  align-items: center;
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--line-color);
  border-radius: var(--radius-pill);
  background: rgba(6, 10, 14, 0.45);
  color: var(--text-muted);
  white-space: nowrap;
  font-size: var(--text-sm);
}
.pill b { color: var(--text-primary); }
.pill--clickable { cursor: pointer; }

/* =========================================
   PANEL
   ========================================= */
.panel {
  border: 1px solid var(--line-color);
  border-radius: var(--radius-md);
  background: var(--panel-bg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.panel--grow {
  flex: 1;
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-lg);
  background: rgba(6, 10, 14, 0.28);
  border-bottom: 1px solid rgba(34, 48, 65, 0.75);
}

.panel__title {
  font-size: var(--text-xs);
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 800;
}

.panel__body {
  padding: var(--space-sm);
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.panel__body--nopad {
  padding: 0;
}

/* =========================================
   CONTROL PANEL
   ========================================= */
.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
}

.control-group {
  border: 1px solid rgba(34, 48, 65, 0.55);
  border-radius: var(--radius-sm);
  padding: var(--space-sm);
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.control-group--danger {
  grid-column: 1 / -1;
  border-color: var(--color-danger-border);
  background: rgba(251, 113, 133, 0.03);
}

.control-group__legend {
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 800;
  padding: 0 var(--space-xs);
}
.control-group__legend--danger {
  color: var(--color-bad);
}

/* Forms & Controls */
.controls-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  flex-wrap: wrap;
}

.form-inline {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 800;
}

.input {
  border: 1px solid var(--line-color);
  border-radius: var(--radius-sm);
  background: rgba(6, 10, 14, 0.55);
  color: var(--text-primary);
  padding: 5px 8px;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
.input--sm { width: 60px; }
.input--md { width: 100px; }
.input--lg { width: 140px; }

.btn {
  cursor: pointer;
  border: 1px solid var(--line-color);
  border-radius: var(--radius-sm);
  background: rgba(6, 10, 14, 0.35);
  color: var(--text-primary);
  padding: 5px 10px;
  font-family: var(--font-mono);
  font-weight: 800;
  white-space: nowrap;
  font-size: var(--text-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover { border-color: rgba(96, 165, 250, 0.55); }
.btn--danger { border-color: rgba(251, 113, 133, 0.55); }
.btn--danger:hover { border-color: rgba(251, 113, 133, 0.95); }
.btn--fixed { width: 60px; height: 26px; padding: 0; }
.btn--sm { height: 26px; padding: 0 10px; font-size: var(--text-xs); }

.view-toggle { display: inline-flex; gap: 6px; align-items: center; }
.view-toggle .btn.is-active { border-color: rgba(45, 212, 191, 0.85); box-shadow: 0 0 0 1px rgba(45, 212, 191, 0.25) inset; }

.text-hint { color: var(--text-muted); font-size: var(--text-xs); line-height: 1.35; padding-top: var(--space-xs); }
.text-code { color: #c7d2fe; font-size: var(--text-xs); }
.text-msg { color: var(--text-muted); font-size: var(--text-sm); }

/* =========================================
   TABLES
   ========================================= */
.table-wrapper {
  height: 100%;
  overflow: auto;
  border-radius: var(--radius-md);
  border: 1px solid rgba(34, 48, 65, 0.75);
  background: var(--panel-alt-bg);
}

.panel__body--zones {
  overflow: auto;
  border-radius: var(--radius-md);
  border: 1px solid rgba(34, 48, 65, 0.75);
  background: rgba(8, 12, 18, 0.16);
}

.table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.table th, .table td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(34, 48, 65, 0.65);
  text-align: left;
}
.table th {
  position: sticky;
  top: 0;
  background: rgba(6, 10, 14, 0.55);
  z-index: 1;
  color: var(--text-muted);
  font-size: var(--text-sm);
  letter-spacing: 0.10em;
  text-transform: uppercase;
  font-weight: 800;
}

.table--zones th {
  background: rgba(7, 11, 16, 0.34);
}

.table--zones td {
  background: rgba(7, 11, 16, 0.06);
}

.table--zones tbody tr:nth-child(even) td {
  background: rgba(10, 14, 20, 0.12);
}

.zones-temp__chart {
  border-radius: var(--radius-md);
  border: 1px solid rgba(34, 48, 65, 0.75);
  background: rgba(6, 10, 14, 0.35);
  padding: var(--space-sm);
  height: 180px;
}

.zones-temp__chart canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.table--caravans th:last-child,
.table--caravans td:last-child { width: 80px; }
.btn-placeholder { width: 60px; height: 26px; display: inline-block; }

/* =========================================
   PROGRESS BARS
   ========================================= */
.progress-group {
  display: flex;
  gap: var(--space-md);
  align-items: center;
}
.progress-label {
  min-width: 44px;
}
.progress-bar {
  flex: 1;
  height: 10px;
  background: rgba(34, 48, 65, 0.7);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar__fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--color-ok), var(--color-info));
  width: 0%;
}
.progress-bar__fill--temp {
  background: linear-gradient(90deg, var(--color-info), var(--color-warn), var(--color-bad));
}

/* =========================================
   ALARMS
   ========================================= */
.alarm-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
}
.alarm-badge {
  padding: 2px 6px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: #fcd34d;
  background: rgba(251, 191, 36, 0.08);
}
.alarm-badge--bad {
  border-color: rgba(251, 113, 133, 0.45);
  color: #fda4af;
  background: rgba(251, 113, 133, 0.08);
}

/* =========================================
   AUDIT LOG
   ========================================= */
.audit-log {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 6px 10px;
  color: #cbd5e1;
}
.audit-log__line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 2px 0;
}
.audit-log__ts { color: #94a3b8; }
.audit-log__cs { color: #e2e8f0; }
.audit-log__ac { color: #93c5fd; }
.audit-log__pa { color: #a7f3d0; }

/* =========================================
   3D VIEW
   ========================================= */
.view-3d {
  width: 100%;
  height: 100%;
  min-height: 150px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(34, 48, 65, 0.75);
  background: rgba(6, 10, 14, 0.35);
  overflow: hidden;
}

.view-3d--main {
  min-height: 340px;
}

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 980px) {
  body { overflow: auto; }
  .app-container {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }
  .layout-col--left::before { filter: blur(3px) saturate(0.85) brightness(0.7); }
  .control-grid { grid-template-columns: 1fr; }
  .view-3d { min-height: 300px; }
}
