/*
File: app/web/static/css/base.css
Version: 0.1.0
Date: 2026-08-03
Purpose: Styles the responsive full-screen monitor and protected administration overlays.
Changes:
- 0.1.0: Initial implementation.
*/

:root {
  color-scheme: dark;
  --bg: #071018;
  --panel: rgba(13, 27, 38, 0.88);
  --panel-solid: #0d1b26;
  --line: rgba(171, 207, 226, 0.17);
  --text: #eff8fc;
  --muted: #91a9b7;
  --accent: #21d4a7;
  --danger: #ff5c6c;
  --focus: #76d7ff;
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-right: max(12px, env(safe-area-inset-right));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
  --safe-left: max(12px, env(safe-area-inset-left));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.monitor {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 320px;
  overflow: hidden;
  background:
    radial-gradient(circle at 68% 14%, rgba(33, 212, 167, 0.08), transparent 28%),
    linear-gradient(160deg, #09141e, var(--bg) 58%);
}

#historyCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: pan-y;
}

.brand-overlay {
  position: fixed;
  z-index: 4;
  top: var(--safe-top);
  left: var(--safe-left);
  display: flex;
  align-items: center;
  gap: 9px;
  color: rgba(239, 248, 252, 0.66);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.03em;
  pointer-events: none;
}

.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid rgba(33, 212, 167, 0.52);
  border-radius: 9px;
  color: var(--accent);
  font-size: 12px;
}

.menu-button {
  position: fixed;
  z-index: 30;
  top: var(--safe-top);
  right: var(--safe-right);
  display: grid;
  width: 52px;
  height: 52px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(13, 27, 38, 0.72);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  backdrop-filter: blur(16px);
}

.menu-button span {
  display: block;
  align-self: center;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
}

.control-overlay {
  position: fixed;
  z-index: 8;
  top: var(--safe-top);
  left: 50%;
  display: flex;
  gap: 8px;
  transform: translateX(-50%);
}

.segmented {
  display: flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(13, 27, 38, 0.75);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(14px);
}

.segmented button {
  min-height: 40px;
  padding: 0 13px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segmented button.active {
  background: rgba(33, 212, 167, 0.16);
  color: #baffed;
}

.segmented button:disabled {
  opacity: 0.32;
  cursor: not-allowed;
}

.legend-toggle {
  display: none;
}

.legend-overlay {
  position: fixed;
  z-index: 7;
  top: calc(var(--safe-top) + 68px);
  left: var(--safe-left);
  width: min(260px, calc(100vw - 24px));
  max-height: min(52vh, 440px);
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(13, 27, 38, 0.72);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(14px);
}

.legend-title {
  display: flex;
  justify-content: space-between;
  padding: 2px 6px 9px;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.legend-rows {
  display: grid;
  gap: 4px;
}

.legend-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 10px;
  cursor: pointer;
}

.legend-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

.legend-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.legend-name {
  overflow: hidden;
  font-size: 14px;
  font-weight: 620;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-color {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 3px;
}

.device-state {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #687a84;
}

.device-state.current {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(33, 212, 167, 0.12);
}

.device-state.stale {
  background: #ffb02e;
}

.live-cards {
  position: fixed;
  z-index: 6;
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  display: grid;
  max-width: min(380px, calc(100vw - 24px));
  gap: 6px;
  pointer-events: none;
}

.live-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(7, 16, 24, 0.68);
  backdrop-filter: blur(12px);
}

.live-card-name {
  overflow: hidden;
  font-size: 12px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-card-value {
  grid-row: span 2;
  align-self: center;
  font-size: clamp(16px, 2vw, 23px);
  font-variant-numeric: tabular-nums;
  font-weight: 720;
}

.live-card-meta {
  font-size: 11px;
  color: var(--muted);
}

.connection-badge {
  position: fixed;
  z-index: 9;
  left: var(--safe-left);
  bottom: var(--safe-bottom);
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(7, 16, 24, 0.72);
  color: var(--muted);
  font-size: 12px;
  backdrop-filter: blur(12px);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.connection-badge.connecting .status-dot {
  background: #ffb02e;
}

.connection-badge.offline .status-dot {
  background: var(--danger);
}

.chart-tooltip {
  position: fixed;
  z-index: 20;
  max-width: min(290px, calc(100vw - 24px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(7, 16, 24, 0.94);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  font-size: 12px;
  pointer-events: none;
}

.tooltip-time {
  margin-bottom: 6px;
  color: var(--muted);
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 3px;
}

.admin-drawer {
  position: fixed;
  z-index: 50;
  inset: 0;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(8px);
}

.drawer-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1180px, 100%);
  height: 100%;
  margin-left: auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel-solid);
  box-shadow: -20px 0 70px rgba(0, 0, 0, 0.45);
}

.drawer-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.drawer-header h2,
.modal-card h1,
.modal-card h2 {
  margin: 2px 0 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.icon-close {
  display: grid;
  width: 48px;
  height: 48px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 28px;
  cursor: pointer;
}

.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
}

.admin-nav button {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.admin-nav button.active {
  background: rgba(33, 212, 167, 0.13);
  color: var(--text);
}

#logoutButton {
  margin-top: auto;
}

.admin-content {
  overflow: auto;
  padding: clamp(18px, 3vw, 34px);
}

.admin-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.admin-titlebar h3 {
  margin: 0;
  font-size: clamp(22px, 3vw, 34px);
}

.plus-button {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #052119;
  font-size: 30px;
  font-weight: 500;
  cursor: pointer;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: 12px;
}

.info-card,
.device-card {
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.025);
}

.info-card h4,
.device-card h4 {
  margin: 0 0 12px;
}

.key-value {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 14px;
  font-size: 13px;
}

.key-value dt {
  color: var(--muted);
}

.key-value dd {
  margin: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

.device-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 14px;
}

.secondary-button,
.danger-button,
.primary-button {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 11px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: #052119;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.08);
}

.danger-button {
  background: var(--danger);
  color: #260208;
}

.modal {
  width: auto;
  max-width: none;
  height: auto;
  max-height: none;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(7px);
}

.modal-card {
  position: relative;
  display: grid;
  width: min(430px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  gap: 16px;
  overflow: auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel-solid);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}

.modal-card-wide {
  width: min(760px, calc(100vw - 24px));
}

.modal-card .icon-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.modal-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.modal-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.modal-card input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #09151f;
  color: var(--text);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.toggle-row,
.danger-toggle {
  display: flex !important;
  min-height: 48px;
  align-items: center;
  gap: 10px;
}

.toggle-row input,
.danger-toggle input {
  width: 22px;
  min-height: 22px;
  accent-color: var(--accent);
}

.danger-toggle {
  color: #ff9aa4 !important;
}

.form-error {
  min-height: 20px;
  color: #ff9aa4 !important;
}

.muted {
  color: var(--muted);
}

.code-block,
.version-history {
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #08131c;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  z-index: 100;
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  max-width: min(420px, calc(100vw - 24px));
  padding: 13px 16px;
  border: 1px solid rgba(33, 212, 167, 0.35);
  border-radius: 12px;
  background: #123229;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
}

.hidden {
  display: none !important;
}

@media (max-width: 820px), (pointer: coarse) {
  .control-overlay {
    top: auto;
    right: auto;
    bottom: calc(var(--safe-bottom) + 46px);
    width: calc(100% - var(--safe-left) - var(--safe-right));
    flex-direction: column;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    min-width: 44px;
    min-height: 46px;
    flex: 1;
    padding: 0 6px;
  }

  .legend-toggle {
    position: fixed;
    z-index: 8;
    top: calc(var(--safe-top) + 60px);
    left: var(--safe-left);
    display: block;
    min-width: 92px;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    cursor: pointer;
    backdrop-filter: blur(12px);
  }

  .legend-overlay {
    top: calc(var(--safe-top) + 112px);
    max-height: 46vh;
  }

  .legend-overlay.collapsed {
    display: none;
  }

  .live-cards {
    display: none;
  }

  .drawer-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
    border-radius: 18px;
  }

  .admin-nav {
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .admin-nav button {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  #logoutButton {
    margin-top: 0;
  }
}

@media (max-width: 520px) {
  .brand-overlay span:last-child {
    display: none;
  }

  .modal-card {
    padding: 24px 18px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .admin-content {
    padding: 16px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .control-overlay {
    right: calc(var(--safe-right) + 64px);
    bottom: var(--safe-bottom);
    left: auto;
    width: min(620px, calc(100vw - 170px));
    flex-direction: row;
    transform: none;
  }

  .legend-toggle {
    top: var(--safe-top);
    left: calc(var(--safe-left) + 45px);
  }

  .legend-overlay {
    top: calc(var(--safe-top) + 52px);
    max-height: calc(100dvh - 120px);
  }

  .connection-badge {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
