:root {
  --bg: #111315;
  --surface: #191d20;
  --surface-2: #20262a;
  --surface-3: #283037;
  --line: #343d44;
  --text: #f3f5f2;
  --muted: #9aa5a7;
  --green: #36d399;
  --green-2: #14795a;
  --amber: #f3b34d;
  --danger: #f97373;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 8px;
}

* { box-sizing: border-box; }

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

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

.topbar {
  min-height: 64px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 19, 21, 0.92);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
}

.brand {
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--green);
  color: #07120f;
  font-weight: 900;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

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

.brand-copy strong { font-size: 16px; }
.brand-copy span { color: var(--muted); font-size: 13px; }

.topbar-status {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.connect-nav {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-left: auto;
}

.connect-nav a {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
}

.connect-nav a.active {
  color: #07120f;
  background: var(--green);
  border-color: var(--green);
}

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.control-strip {
  display: grid;
  grid-template-columns: 140px minmax(180px, 260px) minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.field { display: grid; gap: 6px; }

.field span, .eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0d0f11;
  color: var(--text);
  outline: none;
}

input, select { height: 40px; padding: 0 11px; }

textarea {
  min-height: 78px;
  resize: vertical;
  padding: 10px;
  line-height: 1.4;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(54, 211, 153, 0.13);
}

.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn, .text-btn, .icon-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.btn {
  min-height: 40px;
  padding: 0 13px;
  font-weight: 800;
}

.btn.primary { background: var(--green); color: #07120f; border-color: var(--green); }
.btn.danger { border-color: rgba(249, 115, 115, 0.55); color: #ffdede; }
.btn:hover, .text-btn:hover, .icon-btn:hover { border-color: var(--green); }

.content-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: stretch;
}

.viewer-panel, .side-panel { min-width: 0; }

.viewer-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

h1 {
  margin: 4px 0 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.status-pill {
  min-height: 28px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 800;
}

.status-pill.ok { color: #091410; background: var(--green); border-color: var(--green); }
.status-pill.warn { color: #1c1200; background: var(--amber); border-color: var(--amber); }
.status-pill.bad { color: #220a0a; background: var(--danger); border-color: var(--danger); }
.status-pill.muted { color: var(--muted); }

.video-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 420px;
  background: #050607;
  overflow: hidden;
  touch-action: none;
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #050607;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  padding: 20px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
}

.empty-state strong { color: var(--text); font-size: 18px; }
.empty-state span { font-size: 13px; }
.empty-state.hidden { display: none; }

.touch-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  cursor: crosshair;
}

.command-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: #141719;
}

.icon-btn {
  min-height: 42px;
  font-weight: 900;
}

.icon-btn.active {
  background: rgba(54, 211, 153, 0.16);
  color: var(--green);
  border-color: var(--green-2);
}

.side-panel {
  display: grid;
  gap: 14px;
  align-content: start;
}

.detail-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
  box-shadow: var(--shadow);
}

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

.text-btn {
  min-height: 28px;
  padding: 0 9px;
  font-size: 12px;
  color: var(--muted);
}

.qr-shell {
  margin-top: 10px;
  height: 168px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: var(--muted);
  background: repeating-linear-gradient(45deg, #111517, #111517 10px, #151a1d 10px, #151a1d 20px);
  font-size: 13px;
  text-align: center;
  padding: 12px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metrics div {
  min-width: 0;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}

.metrics strong { font-size: 18px; }

.event-log {
  min-height: 220px;
  max-height: 330px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
}

.event-log li {
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #101315;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

@media (max-width: 1080px) {
  .control-strip { grid-template-columns: 130px minmax(160px, 1fr) minmax(200px, 1fr); }
  .button-row { grid-column: 1 / -1; justify-content: stretch; }
  .btn { flex: 1 1 150px; }
  .content-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar { position: static; align-items: stretch; flex-direction: column; }
  .topbar-status { justify-content: flex-start; }
  .workspace { padding: 10px; }
  .control-strip { grid-template-columns: 1fr; }
  .viewer-header { align-items: stretch; flex-direction: column; }
  .video-stage { min-height: 260px; }
  h1 { font-size: 19px; }
}
