:root {
  --bg: #f4f7f8;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #61717b;
  --line: #d8e1e5;
  --accent: #006d77;
  --accent-2: #8f5f00;
  --danger: #b42318;
  --ok: #067647;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select,
a.button-link {
  font: inherit;
}

button,
a.button-link {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
}

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

button:hover,
a.button-link:hover {
  border-color: var(--accent);
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--panel);
  color: var(--ink);
}

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

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.login-panel h1,
.topbar h2 {
  margin: 0;
}

.login-panel button {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.error {
  color: var(--danger);
  min-height: 20px;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  background: #102a2f;
  color: white;
  padding: 18px;
}

.brand {
  display: grid;
  gap: 4px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255,255,255,.18);
}

.brand span {
  color: #bfd4d8;
  font-size: 13px;
}

nav {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

nav button {
  color: white;
  background: transparent;
  border-color: transparent;
  text-align: left;
}

nav button.active,
nav button:hover {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.18);
}

.workspace {
  min-width: 0;
}

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.actions,
.toolbar,
.inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.stack-form {
  display: grid;
  gap: 10px;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.view {
  display: none;
  padding: 24px;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.metric strong {
  display: block;
  font-size: 26px;
  margin-top: 8px;
}

.split {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  margin-top: 18px;
}

.split > section,
.table,
.list,
.storage-panel,
.map-canvas {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.split > section {
  padding: 14px;
}

.table {
  overflow-x: auto;
  margin-top: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-size: 14px;
}

td small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.row-actions {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.access-layout {
  grid-template-columns: minmax(360px, .9fr) minmax(460px, 1.1fr);
  margin-top: 0;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfc;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.check-row input {
  width: auto;
  min-height: auto;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-width: 520px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fbfc;
  color: var(--muted);
  font-size: 12px;
}

.list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.list-item {
  display: grid;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.list-item:last-child {
  border-bottom: 0;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
}

.dot.online {
  background: var(--ok);
}

.live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.feed {
  min-height: 190px;
  border-radius: 8px;
  background: #172026;
  color: white;
  padding: 12px;
  display: grid;
  align-content: space-between;
}

.feed .offline {
  color: #ccd6da;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 42, 47, .72);
}

.stream-player {
  width: min(1100px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.stream-player header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.stream-player h3 {
  margin: 0;
}

.video-shell {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #172026;
}

.video-shell video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gateway-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.video-shell .hidden {
  display: none;
}

.stream-overlay {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}

.stream-overlay span {
  background: rgba(23, 32, 38, .82);
  color: white;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
}

.map-canvas {
  height: 360px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px),
    #edf4f4;
  background-size: 40px 40px;
}

.marker {
  position: absolute;
  transform: translate(-50%, -50%);
  background: var(--accent);
  color: white;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
}

.storage-panel {
  padding: 16px;
  margin-bottom: 12px;
}

.bar {
  height: 14px;
  background: #dbe5e8;
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--accent-2);
}

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

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .metric-grid,
  .split,
  .access-layout {
    grid-template-columns: 1fr;
  }
}
