:root {
  --bg-deep: #0c1412;
  --bg-mid: #14201c;
  --bg-panel: rgba(22, 38, 33, 0.82);
  --ink: #e8f0ec;
  --muted: #9bb0a6;
  --accent: #3d9b72;
  --accent-hot: #e8a54b;
  --danger: #d45d5d;
  --line: rgba(232, 240, 236, 0.12);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --font-display: "Fraunces", "Palatino Linotype", Palatino, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 700px at 10% -10%, rgba(61, 155, 114, 0.22), transparent 55%),
    radial-gradient(900px 600px at 90% 0%, rgba(232, 165, 75, 0.12), transparent 50%),
    linear-gradient(165deg, var(--bg-deep), var(--bg-mid) 45%, #0a1210);
  background-attachment: fixed;
}

body {
  min-height: 100vh;
}

a {
  color: var(--accent-hot);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2rem, 5vw, 3.25rem);
  letter-spacing: -0.03em;
  line-height: 1;
  margin: 0;
}

.brand span {
  color: var(--accent);
}

.lede {
  color: var(--muted);
  margin: 0.65rem 0 0;
  max-width: 36ch;
  font-size: 1.05rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.nav-links {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.nav-links a,
.nav-links button.linkish {
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
}

.nav-links a:hover,
.nav-links button.linkish:hover,
.nav-links a.active {
  color: var(--ink);
  text-decoration: none;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  padding: 1.25rem;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(12, 20, 18, 0.55), rgba(12, 20, 18, 0.85)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%233d9b72' stroke-opacity='0.12'%3E%3Ccircle cx='20' cy='20' r='18'/%3E%3Ccircle cx='80' cy='90' r='28'/%3E%3Ccircle cx='140' cy='40' r='14'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover, 180px 180px;
  animation: drift 28s linear infinite;
  z-index: 0;
}

@keyframes drift {
  from { background-position: 0 0, 0 0; }
  to { background-position: 0 0, 180px 120px; }
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  padding: 2rem 1.75rem 1.75rem;
  animation: rise 0.7s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}

.login-card .brand {
  text-align: center;
}

.login-card .lede {
  text-align: center;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 1.5rem;
}

.form {
  display: grid;
  gap: 0.9rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
  color: var(--muted);
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(8, 14, 12, 0.65);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}

input:focus,
select:focus {
  outline: 2px solid rgba(61, 155, 114, 0.55);
  outline-offset: 1px;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1.2rem;
  background: var(--accent);
  color: #04110c;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, background 0.15s ease;
}

.btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-talk {
  background: var(--accent-hot);
  color: #1a1005;
  min-width: 9rem;
}

.btn-talk.active {
  background: var(--danger);
  color: #fff;
  animation: pulse 1s ease infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.error {
  color: #ffb4b4;
  min-height: 1.25rem;
  font-size: 0.92rem;
  margin: 0;
}

.status {
  color: var(--muted);
  font-size: 0.92rem;
}

.grid-cameras {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.camera-tile {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #050a08;
  cursor: pointer;
  padding: 0;
  text-align: left;
  color: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  animation: rise 0.45s ease both;
}

.camera-tile:hover {
  transform: translateY(-3px);
  border-color: rgba(61, 155, 114, 0.55);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.camera-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

.camera-tile .tile-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1.4rem 0.85rem 0.75rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  font-weight: 600;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 3rem 1.25rem;
  text-align: center;
  color: var(--muted);
}

.watch-stage {
  position: relative;
}

.watch-stage.is-fullscreen .grid-cameras,
.watch-stage.is-fullscreen .empty-state {
  display: none;
}

.fullscreen-view {
  display: none;
  position: relative;
  min-height: min(78vh, 820px);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #000;
  animation: rise 0.35s ease both;
}

.watch-stage.is-fullscreen .fullscreen-view {
  display: block;
}

.fullscreen-view video {
  width: 100%;
  height: min(78vh, 820px);
  object-fit: contain;
  background: #000;
  display: block;
}

.fullscreen-chrome {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.72));
  flex-wrap: wrap;
}

.preview-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #000;
  min-height: 280px;
}

.preview-wrap video {
  width: 100%;
  display: block;
  max-height: 70vh;
  object-fit: contain;
  background: #000;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin: 1rem 0;
}

.toolbar label {
  flex: 1 1 180px;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  text-align: left;
  padding: 0.7rem 0.4rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid var(--line);
  color: var(--muted);
}

.badge.on {
  color: #9dffcf;
  border-color: rgba(61, 155, 114, 0.5);
}

.badge.off {
  color: #ffb4b4;
  border-color: rgba(212, 93, 93, 0.45);
}

.stack {
  display: grid;
  gap: 1rem;
}

.row-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .shell {
    width: calc(100% - 1.25rem);
  }

  .fullscreen-view video {
    height: min(62vh, 640px);
  }
}
