:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b0d11;
  color: #f5f7fb;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; }
button, input, select { font: inherit; }

#app {
  --sidebar-width: 430px;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
  background: #0b0d11;
}

#viewer {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #202532 0%, #11141b 42%, #090b0f 100%);
}

#canvas-host, #canvas-host canvas { width: 100%; height: 100%; display: block; }

.viewer-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 22px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(9, 11, 15, .72), transparent);
}

.viewer-overlay h1 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -.02em; }
.viewer-overlay p { margin: 4px 0 0; color: #aeb6c5; font-size: 12px; }
#sidebar {
  position: absolute;
  z-index: 15;
  top: 0;
  right: 0;
  width: var(--sidebar-width);
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  border-left: 1px solid #252a35;
  background: rgba(17, 20, 26, 0.84);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  scrollbar-color: #414858 transparent;
  transform: translateX(0);
  transition: transform 220ms ease;
  will-change: transform;
}

#app.sidebar-hidden #sidebar {
  transform: translateX(100%);
  pointer-events: none;
}

/* Desktop resize strip: invisible until the panel edge is hovered/focused. */
.sidebar-resizer {
  position: absolute;
  z-index: 19;
  top: 0;
  right: calc(var(--sidebar-width) - 6px);
  width: 12px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
  outline: none;
}

.sidebar-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 4px;
  width: 4px;
  height: 54px;
  border-radius: 999px;
  background: #6b7484;
  opacity: 0;
  transform: translateY(-50%);
  transition: opacity 120ms ease, background 120ms ease;
}

.sidebar-resizer:hover::after,
.sidebar-resizer:focus-visible::after,
#app.sidebar-resizing .sidebar-resizer::after {
  opacity: .9;
  background: #9ebeff;
}

#app.sidebar-hidden .sidebar-resizer {
  display: none;
}

#app.sidebar-resizing,
#app.sidebar-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

#app.sidebar-resizing #sidebar,
#app.sidebar-resizing .sidebar-toggle {
  transition: none;
}

.sidebar-toggle {
  position: absolute;
  z-index: 20;
  top: 50%;
  right: var(--sidebar-width);
  width: 26px;
  height: 64px;
  min-height: 64px;
  padding: 0;
  transform: translateY(-50%);
  border-right: 0;
  border-radius: 8px 0 0 8px;
  color: #aeb8c9;
  background: #171b23;
  font-size: 18px;
  line-height: 1;
  transition: right 220ms ease, background 120ms ease, color 120ms ease;
}

.sidebar-toggle:hover {
  color: #eef2f8;
  background: #222834;
}

#app.sidebar-hidden .sidebar-toggle {
  right: 0;
}

.panel { padding: 18px; border-bottom: 1px solid #252a35; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 15px; }
.panel-heading.compact { align-items: center; margin-bottom: 12px; }
.panel-heading h2 { margin: 0; font-size: 13px; font-weight: 650; letter-spacing: .01em; }
.panel-heading p { margin: 3px 0 0; color: #7f899b; font-size: 11px; }

label { display: block; margin: 0 0 6px; color: #9da7b9; font-size: 11px; font-weight: 600; }
input, select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #343b49;
  border-radius: 7px;
  outline: none;
  color: #eef2f8;
  background: #171b23;
}
input:focus, select:focus { border-color: #6ba8ff; box-shadow: 0 0 0 2px rgba(107, 168, 255, .14); }

.row { display: grid; gap: 10px; margin-top: 11px; }
.two-columns { grid-template-columns: minmax(0, 1.5fr) minmax(0, .8fr); }
.two-columns > * { min-width: 0; }
.button-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 9px; margin-top: 13px; }
.button-row button { width: 100%; min-width: 0; }
button {
  min-height: 36px;
  border: 1px solid #353c4b;
  border-radius: 7px;
  color: #e9edf5;
  background: #1a1f29;
  cursor: pointer;
}
button:hover { background: #222834; }
button.primary { border-color: #4b82dc; background: #2f6bc8; }
button.primary:hover { background: #3877d6; }
button.active { border-color: #3f8d68; background: #1c4d36; }
button.active:hover { background: #245f43; }
button.subtle-button {
  border-color: transparent;
  color: #8b95a6;
  background: transparent;
  font-size: 12px;
}
button.subtle-button:hover {
  border-color: #2b313d;
  color: #c7cfdb;
  background: #171b23;
}
button.subtle-button.active {
  border-color: rgba(77, 151, 111, .28);
  color: #8ec8a8;
  background: rgba(28, 77, 54, .28);
}
button.subtle-button.active:hover {
  border-color: rgba(77, 151, 111, .42);
  color: #a8d9bd;
  background: rgba(28, 77, 54, .42);
}
button.text-button { min-height: auto; padding: 3px 0; border: 0; color: #8db8ff; background: transparent; font-size: 11px; }
button.text-button:hover { color: #b7d3ff; background: transparent; }

.status { min-width: 76px; padding: 4px 8px; border-radius: 999px; text-align: center; font-size: 10px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.status.idle { color: #aeb6c5; background: #272d38; }
.status.connecting { color: #f4ce78; background: #3a2f19; }
.status.connected, .status.demo { color: #92efbb; background: #173627; }
.status.error { color: #ff9b9b; background: #431e22; }

.hint { margin: 12px 0 0; color: #737d8e; font-size: 10.5px; line-height: 1.45; }

.server-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 10px;
  align-items: end;
}

.server-row > * { min-width: 0; }

.field-subtitle {
  margin: 5px 0 0;
  color: #737d8e;
  font-size: 9.5px;
  font-weight: 400;
  line-height: 1.25;
}

.server-port-field {
  align-self: start;
}

.display-scenes { margin-bottom: 12px; }
.display-scenes select { min-height: 34px; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.toggles label { margin: 0; display: flex; align-items: center; gap: 7px; font-weight: 500; color: #c5ccd8; }
.toggles input { width: 14px; min-height: 14px; margin: 0; accent-color: #68a3ff; }

.debug-panel { padding-bottom: 30px; }
.sticky-heading { position: sticky; top: 0; z-index: 2; padding: 2px 0 10px; background: rgba(17, 20, 26, 0.9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.debug-content { display: grid; gap: 9px; }
.empty-state { padding: 22px 14px; border: 1px dashed #303746; border-radius: 8px; color: #778194; text-align: center; font-size: 11px; line-height: 1.5; }

details { border: 1px solid #2b313d; border-radius: 8px; background: #151922; overflow: hidden; }
summary { padding: 10px 11px; color: #dbe1eb; cursor: pointer; font-size: 11px; font-weight: 650; user-select: none; }
details[open] summary { border-bottom: 1px solid #2b313d; }
.debug-block { padding: 10px 11px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 10px; line-height: 1.55; color: #aeb8c9; white-space: pre-wrap; overflow-wrap: anywhere; }
.debug-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.objects-table { table-layout: fixed; }
.objects-table .id-column { width: 19%; }
.objects-table .cluster-column { width: 55%; }
.objects-table .points-column { width: 26%; }
.objects-table td:nth-child(2) { white-space: nowrap; }
.debug-table th, .debug-table td { padding: 6px 8px; border-bottom: 1px solid #262c37; text-align: left; vertical-align: top; }
.debug-table th { color: #7f8b9f; font-weight: 650; }
.debug-table td { color: #c4ccd8; font-family: "SFMono-Regular", Consolas, monospace; overflow-wrap: anywhere; }
.debug-table tr:last-child td { border-bottom: 0; }
.muted { color: #6f798b; }

@media (max-width: 900px) {
  body { overflow: auto; }
  #app,
  #app.sidebar-hidden {
    height: auto;
    min-height: 100%;
    grid-template-columns: 1fr;
    grid-template-rows: 58vh auto;
    overflow: visible;
  }
  #sidebar,
  #app.sidebar-hidden #sidebar {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    border-left: 0;
    border-top: 1px solid #252a35;
    transform: none;
    pointer-events: auto;
  }
  .sidebar-toggle,
  .sidebar-resizer { display: none; }
  .viewer-overlay { padding: 16px; }
  .server-row { grid-template-columns: minmax(0, 1fr) 82px; }
}
