:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --ink: #18211f;
  --muted: #66736f;
  --line: #d8e1de;
  --accent: #176b50;
  --accent-strong: #0f513d;
  --danger: #b42318;
  --warn: #a15c07;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  background: #eef4f1;
  color: var(--accent-strong);
  border: 1px solid #bdd2ca;
}

button.secondary:hover {
  background: #dfece7;
}

button.danger {
  background: var(--danger);
  color: #ffffff;
}

button.danger:hover {
  background: #8f1d15;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 20px;
}

#serverHint {
  margin-top: 4px;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(360px, 1fr);
  gap: 18px;
  padding: 18px;
}

.panel,
.preview {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.device-panel,
.controls,
.files,
.security {
  grid-column: 1;
}

.preview {
  grid-column: 2;
  grid-row: 1 / span 3;
  display: flex;
  flex-direction: column;
  min-height: 520px;
}

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

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

.status-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 14px;
}

.status-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #edf1ef;
}

.status-item span:first-child {
  color: var(--muted);
}

.status-good {
  color: var(--accent-strong);
}

.status-bad {
  color: var(--danger);
}

.status-warn {
  color: var(--warn);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.actions button {
  flex: 1 1 140px;
}

.compact {
  margin: 0;
}

.compact button {
  flex: 0 0 auto;
}

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

.viewport {
  position: relative;
  flex: 1;
  min-height: 420px;
  border: 1px solid #121716;
  border-radius: 8px;
  overflow: hidden;
  background: #101413;
}

#streamView {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #cbd5d1;
  text-align: center;
}

.record-progress {
  margin-top: 12px;
}

.record-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.progress-track {
  height: 10px;
  margin-top: 8px;
  border-radius: 6px;
  background: #e4ebe8;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: 6px;
  background: var(--accent);
  transition: width 180ms ease;
}

.form-grid {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.switch-row input {
  width: 22px;
  height: 22px;
  min-height: 22px;
}

.hint {
  color: var(--muted);
  font-size: 14px;
}

.file-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.file-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid #edf1ef;
  border-radius: 6px;
}

.file-item a {
  color: var(--accent-strong);
  text-decoration: none;
  word-break: break-all;
}

.file-item small {
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #18211f;
  color: #ffffff;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 150ms ease, transform 150ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

.login-box {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.login-box p {
  margin: 8px 0 16px;
  color: var(--muted);
}

.login-error {
  color: var(--danger) !important;
}

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

  .device-panel,
  .controls,
  .files,
  .security,
  .preview {
    grid-column: 1;
    grid-row: auto;
  }

  .preview {
    min-height: 420px;
  }

  .viewport {
    min-height: 320px;
  }
}

@media (max-width: 560px) {
  .topbar,
  .preview-head,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .layout {
    padding: 10px;
    gap: 10px;
  }

  .panel,
  .preview {
    padding: 12px;
  }
}
