:root {
  --bg: #05080c;
  --panel: #0b1118;
  --panel-2: #111923;
  --border: rgba(255,255,255,.10);
  --text: #edf3f8;
  --muted: #8290a0;
  --live: #38cf79;
  --danger: #ff6b6b;
  --topbar-h: 58px;
  --pager-h: 46px;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.login-shell {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at top right, rgba(64,97,131,.16), transparent 34%),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
}

.brand-mark {
  margin-bottom: 6px;
  color: #a9b8c8;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .15em;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 27px;
}

.muted {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.login-card label {
  display: block;
  margin-bottom: 8px;
  color: #cbd5df;
  font-size: 13px;
  font-weight: 650;
}

.password-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.password-row input {
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: #070c12;
  color: var(--text);
  font-size: 16px;
}

.password-row input:focus {
  border-color: rgba(130,160,190,.7);
}

.primary-button,
.ghost-button,
.icon-button,
.page-button {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

.primary-button {
  width: 100%;
  height: 44px;
  margin-top: 12px;
  background: #1c2c3b;
  font-weight: 700;
}

.ghost-button,
.icon-button,
.page-button {
  background: var(--panel-2);
}

.ghost-button {
  padding: 0 12px;
}

.icon-button,
.page-button {
  width: 38px;
  padding: 0;
}

.form-error {
  min-height: 20px;
  margin-top: 12px;
  color: #ff9b9b;
  font-size: 13px;
}

.monitor-shell {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.topbar {
  display: flex;
  height: var(--topbar-h);
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: #080d13;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 10px;
}

.brand strong {
  white-space: nowrap;
  font-size: 15px;
  letter-spacing: .07em;
}

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

.topbar-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.status-chip,
.layout-control {
  display: flex;
  height: 38px;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: #b6c1cc;
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--live);
  box-shadow: 0 0 0 3px rgba(56,207,121,.11);
}

.layout-control select {
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-weight: 700;
}

.layout-control option {
  background: #111923;
  color: var(--text);
}

.monitor-main {
  height: calc(100% - var(--topbar-h));
}

.grid-mode {
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-rows: minmax(0, 1fr) var(--pager-h);
  gap: 6px;
  padding: 6px;
}

.camera-grid {
  display: grid;
  min-width: 0;
  min-height: 0;
  gap: 5px;
}

.camera-grid.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

.camera-grid.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
}

.camera-tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #020304;
  cursor: pointer;
}

.camera-tile:focus-visible {
  outline: 2px solid #8ba6be;
  outline-offset: -2px;
}

.camera-video {
  display: block;
  width: 100%;
  height: 100%;
  background: #020304;
  object-fit: contain;
  pointer-events: none;
}

.camera-label {
  position: absolute;
  top: 6px;
  left: 6px;
  display: flex;
  max-width: calc(100% - 12px);
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 5px;
  background: rgba(2,5,8,.78);
  backdrop-filter: blur(5px);
}

.camera-label strong {
  overflow: hidden;
  font-size: 10px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-badge {
  flex: 0 0 auto;
  color: #75e6a4;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .06em;
}

.stream-state {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 3px 6px;
  border-radius: 4px;
  background: rgba(2,5,8,.72);
  color: #91a0af;
  font-size: 9px;
}

.pagination {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.page-numbers {
  display: flex;
  gap: 4px;
}

.page-button {
  flex: 0 0 auto;
}

.page-button.active {
  border-color: #647b91;
  background: #27394a;
  font-weight: 750;
}

.page-button:disabled {
  cursor: default;
  opacity: .35;
}

.page-summary {
  min-width: 86px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.empty-state {
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
}

.error-state strong {
  color: #ff9c9c;
}

.single-mode {
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-rows: 50px minmax(0, 1fr);
  padding: 6px;
  gap: 6px;
}

.single-toolbar {
  display: grid;
  min-width: 0;
  align-items: center;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
}

.single-toolbar strong {
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.single-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #000;
}

.single-stage .camera-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@media (max-width: 820px) {
  .brand span,
  .status-chip,
  .layout-control > span {
    display: none;
  }

  .topbar {
    padding: 0 8px;
  }

  .ghost-button {
    padding: 0 9px;
  }
}
