:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  --bg: #080d0c;
  --sidebar: #0a100f;
  --panel: #0f1715;
  --panel-2: #121f1b;
  --line: #20322c;
  --text: #e8f2ee;
  --muted: #8ea19b;
  --green: #20d37a;
  --green-soft: rgba(32, 211, 122, 0.16);
  --danger: #f05d5d;
}

* { box-sizing: border-box; }

html,
body,
.app-root {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  color: var(--text);
  background:
    radial-gradient(circle at 74% 0%, rgba(32, 211, 122, 0.06), transparent 32rem),
    var(--bg);
}

button,
input { font: inherit; }

button {
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #16251f;
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--green); }
button:disabled { cursor: wait; opacity: 0.55; }
.hidden { display: none !important; }

.login-view {
  width: min(430px, calc(100% - 32px));
  margin: 0 auto;
  padding-top: clamp(60px, 12vh, 120px);
}

.login-brand,
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-brand img {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  box-shadow: 0 0 34px var(--green-soft);
}

.login-brand p,
.login-brand h1,
.brand strong,
.brand span { margin: 0; }

.login-brand p,
.panel-label,
.topbar p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-brand h1 {
  margin-top: 2px;
  font-size: 34px;
}

.login-lead {
  margin: 22px 0;
  color: var(--muted);
}

.login-card,
.panel {
  border: 1px solid var(--line);
  background: var(--panel);
}

.login-card {
  padding: 22px;
  border-radius: 8px;
}

.login-card label {
  color: var(--muted);
  font-size: 13px;
}

.login-card input {
  width: 100%;
  margin: 8px 0 14px;
  padding: 12px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  background: #07100d;
}

.login-card input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.login-card button {
  width: 100%;
  padding: 12px;
  color: #02100a;
  border-color: var(--green);
  background: var(--green);
  font-weight: 750;
}

.error {
  min-height: 18px;
  margin: 12px 0 0;
  color: #ffabab;
  font-size: 13px;
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}

.sidebar {
  min-height: 0;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.brand img {
  width: 38px;
  height: 38px;
  border-radius: 8px;
}

.brand strong,
.brand span { display: block; }
.brand strong { font-size: 18px; }
.brand span { color: var(--muted); font-size: 12px; }

.sidebar-nav {
  display: grid;
  gap: 7px;
}

.nav-item {
  padding: 10px 11px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 6px;
  text-decoration: none;
}

.nav-item:hover,
.nav-item.active {
  color: var(--text);
  border-color: var(--green);
  background: var(--green-soft);
}

.nav-icon {
  width: 17px;
  height: 17px;
  display: inline-block;
  border: 2px solid currentColor;
}

.camera-icon { border-radius: 4px; }
.camera-icon::after {
  content: "";
  width: 5px;
  height: 5px;
  display: block;
  margin: 4px;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.relay-icon {
  position: relative;
  border-radius: 50%;
}

.relay-icon::after {
  content: "";
  position: absolute;
  left: 7px;
  top: -4px;
  width: 2px;
  height: 10px;
  background: var(--sidebar);
  border-left: 2px solid currentColor;
}

.map-icon {
  position: relative;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
}

.map-icon::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  left: 4px;
  top: 4px;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.device-panel {
  margin-top: auto;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel-label { margin: 0 0 7px; }

.device-status {
  display: flex;
  align-items: center;
  gap: 9px;
}

.device-status strong { font-size: 14px; }
.device-panel > p:last-child {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  display: inline-block;
  border-radius: 50%;
  background: #65736e;
  box-shadow: 0 0 0 4px rgba(101, 115, 110, 0.12);
}

.status-dot.online,
.status-dot.compact.online {
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

.status-dot.compact {
  width: 7px;
  height: 7px;
  margin-right: 4px;
  background: #65736e;
}

.logout-button {
  padding: 9px;
  color: var(--muted);
  background: transparent;
}

.sidebar footer {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.workspace {
  min-width: 0;
  min-height: 0;
  padding: 16px 18px 18px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.topbar {
  min-height: 50px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.topbar p,
.topbar h1 { margin: 0; }
.topbar h1 { margin-top: 1px; font-size: 26px; }

.status-strip {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.status-strip > span,
.state-badge {
  padding: 7px 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 12px;
}

.dashboard-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 12px;
}

.panel { border-radius: 8px; }

.camera-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.panel-head {
  min-height: 58px;
  padding: 11px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
}

.panel-head .panel-label { margin-bottom: 3px; }

.image-meta {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.image-meta span {
  padding: 5px 8px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
}

.camera-feed {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  background:
    linear-gradient(rgba(32, 211, 122, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 211, 122, 0.025) 1px, transparent 1px),
    #050a09;
  background-size: 34px 34px;
}

.camera-feed img {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  object-fit: contain;
}

.empty-image {
  display: grid;
  place-items: center;
  gap: 10px;
  color: var(--muted);
}

.empty-image p { margin: 0; }

.empty-lens {
  width: 52px;
  height: 52px;
  border: 6px solid rgba(32, 211, 122, 0.58);
  border-radius: 50%;
  box-shadow: 0 0 28px var(--green-soft), inset 0 0 0 8px rgba(32, 211, 122, 0.06);
}

.camera-actions {
  min-height: 68px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-top: 1px solid var(--line);
  background: #0b1311;
}

.camera-actions strong { font-size: 14px; }
.camera-actions p {
  min-height: 17px;
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.primary-button {
  min-width: 170px;
  padding: 11px 14px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: #02100a;
  border-color: var(--green);
  background: var(--green);
  font-weight: 750;
}

.photo-buttons {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.cancel-button {
  padding: 10px 12px;
  color: #ffabab;
  border-color: rgba(240, 93, 93, 0.55);
  background: rgba(240, 93, 93, 0.08);
  font-weight: 700;
}

.button-lens {
  width: 13px;
  height: 13px;
  border: 3px solid currentColor;
  border-radius: 50%;
}

.control-column {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(270px, 1fr) minmax(185px, 0.68fr);
  gap: 12px;
}

.relay-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.state-badge.on {
  color: #02100a;
  border-color: var(--green);
  background: var(--green);
  font-weight: 750;
}

.relay-symbol {
  width: 84px;
  height: 84px;
  margin: clamp(18px, 4vh, 34px) auto 14px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #09110f;
  box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.34);
}

.relay-symbol span {
  width: 28px;
  height: 38px;
  border: 4px solid var(--muted);
  border-top-color: transparent;
  border-radius: 50%;
}

.relay-panel.relay-active .relay-symbol {
  border-color: var(--green);
  box-shadow: 0 0 30px var(--green-soft), inset 0 0 24px var(--green-soft);
}

.relay-panel.relay-active .relay-symbol span { border-color: var(--green); border-top-color: transparent; }

.relay-panel > p {
  margin: 0 14px 14px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.relay-actions {
  margin: auto 14px 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.relay-button {
  padding: 12px 8px;
  font-weight: 750;
}

.relay-on {
  color: #02100a;
  border-color: var(--green);
  background: var(--green);
}

.control-message {
  min-height: 31px;
  margin: 0 14px 11px !important;
  font-size: 11px !important;
}

.map-panel {
  min-height: 0;
  padding: 10px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  overflow: hidden;
}

.map-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.map-head h2,
.map-head .panel-label { margin: 0; }
.map-head h2 { font-size: 16px; }
.map-head > span {
  max-width: 125px;
  color: var(--muted);
  font-size: 10px;
  text-align: right;
}

.map-shell {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #06100c;
}

.map-shell iframe {
  width: 100%;
  height: 100%;
  min-height: 100px;
  border: 0;
  filter: saturate(0.72) brightness(0.78) contrast(1.08);
}

.map-empty {
  width: 100%;
  height: 100%;
  min-height: 100px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.map-empty p { margin: 0; }

.map-pin {
  width: 25px;
  height: 25px;
  position: relative;
  border: 2px solid var(--green);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 0 18px var(--green-soft);
}

.map-pin::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  left: 7px;
  top: 7px;
  border-radius: 50%;
  background: var(--green);
}

.map-open {
  color: var(--green);
  font-size: 11px;
  text-align: right;
  text-decoration: none;
}

@media (max-width: 900px), (max-height: 620px) {
  .app-shell { grid-template-columns: 176px minmax(0, 1fr); }
  .sidebar { padding: 13px; gap: 12px; }
  .dashboard-grid { grid-template-columns: minmax(0, 1fr) 230px; }
  .workspace { padding: 10px 12px 12px; gap: 8px; }
  .topbar { min-height: 42px; }
  .topbar h1 { font-size: 22px; }
  .control-column { grid-template-rows: minmax(245px, 1fr) 155px; }
  .relay-symbol { width: 66px; height: 66px; margin: 14px auto 10px; }
  .map-head > span { display: none; }
  .photo-buttons { gap: 5px; }
  .cancel-button { padding: 9px 8px; font-size: 11px; }
}

@media (max-width: 720px) {
  html,
  body,
  .app-root { height: auto; min-height: 100%; overflow: auto; }
  .app-shell { min-height: 100vh; grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .workspace { min-height: 100vh; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .camera-panel { min-height: 560px; }
  .control-column { grid-template-rows: auto 260px; }
  .relay-panel { min-height: 320px; }
}
