:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #dfe4eb;
  --line-soft: #edf0f4;
  --ink: #2d3442;
  --ink-2: #5d6675;
  --muted: #8992a1;
  --brand: #d97528;
  --brand-dark: #b85b17;
  --brand-soft: #fff3e8;
  --success: #46966f;
  --warning: #d59a27;
  --danger: #c9564d;
  --video: #303540;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 3px 10px rgba(16, 24, 40, .05);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Inter, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, summary, select { cursor: pointer; }

.console { max-width: 1560px; margin: 0 auto; padding: 16px 22px 48px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 2px 16px;
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font: 700 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.brand h1 { margin: 0; font-size: 15px; line-height: 1.25; letter-spacing: .01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 11px; font-weight: 500; }

.status-pills { display: flex; gap: 7px; flex-wrap: wrap; margin-left: auto; }
.status-pill, .card-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  white-space: nowrap;
}
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(70, 150, 111, .14); }
.status-pill.warning i { background: var(--warning); box-shadow: 0 0 0 3px rgba(213, 154, 39, .14); }
.status-pill b { color: var(--ink-2); font-weight: 600; text-transform: none; letter-spacing: 0; }

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

.video-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 165px);
  overflow: hidden;
  background: var(--video);
  cursor: crosshair;
}
.video-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(135deg, rgba(255, 255, 255, .018) 0 12px, transparent 12px 24px);
  pointer-events: none;
}
#remoteVideo { position: relative; z-index: 2; width: 100%; height: 100%; object-fit: contain; outline: 0; }
.video-card.has-video .video-hint { display: none; }
#remoteVideo:focus { box-shadow: inset 0 0 0 2px var(--success); }
.video-wrap.control-active { box-shadow: inset 0 0 0 3px var(--success); }
.video-wrap.control-active::before {
  content: "CONTROL ACTIVE";
  position: absolute;
  z-index: 4;
  top: 12px;
  right: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(20, 30, 28, .7);
  color: #bff5d7;
  font: 600 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .06em;
  pointer-events: none;
}
.video-hint { position: absolute; z-index: 3; display: flex; flex-direction: column; align-items: center; color: #c8cdd6; text-align: center; pointer-events: none; }
.video-hint strong { color: #aeb5c0; font: 600 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .14em; }
.video-hint span { margin-top: 9px; color: #d9dde4; font-size: 15px; font-weight: 600; }
.video-hint small { margin-top: 4px; color: #8e96a3; font: 500 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }

.video-toolbar { display: flex; align-items: center; gap: 9px; padding: 11px 14px; border-top: 1px solid var(--line-soft); flex-wrap: wrap; }
.session-field { position: relative; }
.session-field span { position: absolute; top: 4px; left: 11px; z-index: 1; color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.session-field input { width: 148px; height: 40px; padding: 14px 11px 2px; }
.toolbar-spacer { flex: 1; min-width: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font-weight: 650;
  white-space: nowrap;
  transition: background .13s, border-color .13s, color .13s, transform .13s;
}
.btn:hover { background: var(--panel-soft); }
.btn:active { transform: translateY(1px); }
.btn.primary { border-color: var(--brand); background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.success { border-color: var(--success); background: var(--success); color: #fff; }
.btn.danger { border-color: var(--danger); background: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--panel-soft); color: var(--ink); }
.btn.small { min-height: 31px; padding: 0 10px; font-size: 12px; }
.btn.align-end { align-self: end; }
.button-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .8; }
.grow { flex: 1; }

input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
input, select { height: 36px; padding: 0 10px; }
textarea { width: 100%; padding: 10px 12px; resize: vertical; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(217, 117, 40, .13); }

.dashboard-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.card { display: flex; min-width: 0; flex-direction: column; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-7 { grid-column: span 7; }
.span-12 { grid-column: span 12; }

.card-head { display: flex; align-items: center; gap: 11px; min-height: 61px; padding: 13px 16px; border-bottom: 1px solid var(--line-soft); }
.card-head .card-badge { margin-left: auto; color: var(--brand-dark); background: var(--brand-soft); border-color: #f1d5bc; }
.card-icon { display: grid; place-items: center; min-width: 30px; height: 30px; padding: 0 7px; border-radius: 8px; background: var(--brand-soft); color: var(--brand-dark); font: 650 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.card-head h2 { margin: 0; font-size: 14px; letter-spacing: .01em; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 11.5px; }
.card-body { display: flex; flex: 1; flex-direction: column; gap: 13px; padding: 15px 16px 16px; }

.desktop-status { display: flex; align-items: center; gap: 8px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-soft); color: var(--muted); font: 650 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.video-wrap.control-active + .video-toolbar { border-top-color: rgba(70, 150, 111, .4); }
.check-row { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 12.5px; }
.check-row input { width: auto; height: auto; accent-color: var(--brand); }
.note { margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.5; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.controller-source { display: grid; grid-template-columns: minmax(130px, .65fr) minmax(220px, 1.35fr) auto; align-items: end; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field label, .rate-row label, .deadzone-field { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.full-row { grid-column: 1 / -1; }

.diagnostics, .profile-data { border-top: 1px solid var(--line-soft); padding-top: 10px; }
.diagnostics summary, .profile-data summary { color: var(--ink-2); font-size: 12px; font-weight: 650; }
.diagnostics[open] summary, .profile-data[open] summary { margin-bottom: 10px; }
.diagnostic-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.diagnostic-grid h3 { margin: 0 0 5px; color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }

.mapping-toolbar { display: flex; align-items: end; gap: 8px; flex-wrap: wrap; }
.deadzone-field { display: flex; align-items: center; gap: 8px; }
.deadzone-field input { width: 76px; font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: 11px; }
.mapping-table { width: 100%; min-width: 760px; border-collapse: collapse; }
.mapping-table th { padding: 10px 12px; background: var(--panel-soft); color: var(--muted); font-size: 10px; letter-spacing: .08em; text-align: left; text-transform: uppercase; }
.mapping-table td { padding: 8px 12px; border-top: 1px solid var(--line-soft); vertical-align: middle; }
.mapping-table tbody tr:hover { background: #fffaf5; }
.mapping-table tbody tr.learning { outline: 2px solid rgba(217, 117, 40, .55); outline-offset: -2px; background: var(--brand-soft); }
.mapping-table select, .mapping-table input[type="number"] { min-width: 70px; max-width: 95px; height: 31px; padding: 0 8px; font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.mapping-table input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); }
.mapping-table .learn-btn { min-height: 29px; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink-2); font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.mapping-table .learn-btn:hover { background: var(--panel-soft); }
.mapping-table .now { min-width: 86px; color: var(--brand-dark); font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; }
.rate-row { display: flex; align-items: center; gap: 10px; }
.rate-row select { width: min(100%, 250px); }

pre { margin: 0; white-space: pre-wrap; overflow: auto; word-break: break-word; }
.metric-box, .diagnostics pre { min-height: 118px; max-height: 280px; padding: 11px 12px; border: 1px solid var(--line-soft); border-radius: 10px; background: var(--panel-soft); color: var(--ink-2); font: 500 11.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
.metric-box.compact { min-height: 100px; }
.log-box { min-height: 176px; max-height: 310px; padding: 11px 12px; border: 1px solid var(--line-soft); border-radius: 10px; background: var(--panel-soft); color: var(--ink-2); font: 500 12px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; }

@media (max-width: 1100px) {
  .span-4, .span-5, .span-7 { grid-column: span 12; }
  .video-wrap { max-height: none; }
}

@media (max-width: 760px) {
  .console { padding: 12px 12px 32px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .status-pills { margin-left: 0; }
  .video-toolbar { align-items: stretch; }
  .session-field, .session-field input { width: 100%; }
  .video-toolbar .btn { flex: 1; }
  .toolbar-spacer { display: none; }
  .controller-source, .diagnostic-grid { display: flex; flex-direction: column; align-items: stretch; }
  .btn.align-end { align-self: stretch; }
  .card-head { align-items: flex-start; }
  .card-head .card-badge { display: none; }
}
