:root {
  color-scheme: light;
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-2: #eef1f3;
  --text: #1b1d1f;
  --muted: #667079;
  --line: #d9dee2;
  --accent: #007c89;
  --accent-2: #0f9d58;
  --warn: #b45f06;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.topbar a,
.filters a {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 7px 11px;
  cursor: pointer;
}

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

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

button.danger {
  color: var(--danger);
  border-color: rgba(179, 38, 30, 0.34);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 10px;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 190px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.topbar nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px;
}

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

.login-panel,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel {
  width: min(420px, 100%);
  padding: 26px;
}

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

.login-panel p {
  margin-top: 5px;
  margin-bottom: 20px;
  color: var(--muted);
}

.panel {
  overflow: hidden;
  padding: 16px;
}

.panel h2 {
  margin-bottom: 14px;
  font-size: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
}

.table-search {
  display: flex;
  gap: 8px;
  width: min(360px, 100%);
}

.table-search input {
  min-width: 0;
}

.form {
  display: grid;
  gap: 12px;
}

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

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
}

.check input {
  width: auto;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

legend {
  color: var(--muted);
  font-size: 12px;
  padding: 0 6px;
}

.check-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.inline-form,
.favorite-form {
  display: inline;
}

.inline-form button {
  min-height: 30px;
  padding: 4px 8px;
}

.alert {
  margin-bottom: 14px;
  border: 1px solid rgba(0, 124, 137, 0.25);
  border-radius: 8px;
  background: rgba(0, 124, 137, 0.08);
  padding: 10px 12px;
}

.alert.danger {
  border-color: rgba(179, 38, 30, 0.35);
  background: rgba(179, 38, 30, 0.08);
}

.summary-grid,
.server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.summary-card,
.server-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-card {
  display: grid;
  gap: 4px;
  padding: 15px;
}

.summary-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.summary-card strong {
  font-size: 28px;
}

.server-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.server-card strong,
.server-card span {
  display: block;
}

.server-card span,
.server-card p,
.pager-note {
  color: var(--muted);
  font-size: 12px;
}

.server-card p {
  margin: 0;
  word-break: break-word;
}

.server-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  margin: 0;
}

.server-card dt {
  color: var(--muted);
}

.server-card dd {
  margin: 0;
  font-weight: 650;
}

.pager {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.pager a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
}

.pager a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filters a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.camera-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.preview {
  position: relative;
  display: grid;
  place-items: center;
  height: 162px;
  background: var(--surface-2);
  color: var(--muted);
  overflow: hidden;
}

.preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-label {
  position: absolute;
  inset: auto 12px 12px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 6px;
  background: rgba(0, 124, 137, 0.92);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.preview:hover .preview-label,
.preview.no-preview .preview-label {
  opacity: 1;
}

.preview.no-preview {
  background: linear-gradient(135deg, #e4ecef, #f5f6f7);
}

.camera-meta {
  display: grid;
  gap: 3px;
  padding: 11px 44px 12px 12px;
}

.camera-meta span {
  color: var(--muted);
  font-size: 12px;
}

.favorite {
  position: absolute;
  right: 9px;
  bottom: 10px;
  min-width: 34px;
  padding: 4px 8px;
  font-size: 20px;
  line-height: 1;
}

.favorite.active {
  color: #b45f06;
  border-color: rgba(180, 95, 6, 0.38);
}

.map-panel {
  padding: 0;
}

.map {
  min-height: calc(100vh - 150px);
  height: 720px;
}

.camera-marker {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
}

.camera-marker::after {
  content: "";
  position: absolute;
  top: -14px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 18px solid rgba(0, 124, 137, 0.45);
  transform-origin: 50% 28px;
}

.player-page {
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr);
  gap: 12px;
  min-height: calc(100vh - 108px);
}

.player-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 10px 12px;
}

.player-toolbar div {
  display: grid;
  gap: 2px;
  text-align: right;
}

.player-toolbar span {
  color: var(--muted);
  font-size: 12px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 7px 12px;
}

.back-link::before {
  content: "←";
  margin-right: 7px;
}

.player-frame {
  width: 100%;
  min-height: calc(100vh - 174px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #000;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar nav {
    justify-content: flex-start;
  }

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

@media (max-width: 620px) {
  .workspace {
    padding: 10px;
  }

  .topbar {
    padding: 12px;
  }

  .topbar nav,
  .filters {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar a,
  .filters a,
  button {
    min-height: 42px;
    text-align: center;
  }

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

  .preview {
    height: 210px;
  }

  .player-page {
    min-height: calc(100vh - 154px);
  }

  .player-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .player-toolbar div {
    text-align: left;
  }

  .player-frame {
    min-height: calc(100vh - 240px);
  }

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

  .panel {
    padding: 12px;
  }

  .section-head,
  .table-search {
    align-items: stretch;
    flex-direction: column;
  }

  .table-search {
    width: 100%;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tr {
    border-bottom: 1px solid var(--line);
    padding: 8px 0;
  }

  td {
    border: 0;
    padding: 5px 0;
  }

  .map {
    height: calc(100vh - 145px);
    min-height: 460px;
  }
}
