/* Quiet, technical look: light chrome around the 3D view, one petrol accent
   for actions, focus and progress. All colours and sizes are tokens here so
   that new panels use the same values. */
:root {
  --ink: #1d2b2f;
  --muted: #5f6f73;
  --line: #d5dee0;
  --chrome: #f4f7f7;
  --surface: #ffffff;
  --accent: #1e6e78;
  --accent-strong: #165a62;
  --accent-soft: #e3eff0;
  --error: #b3261e;
  --viewer: #edf3f4; /* same as the WebGL clear colour in viewer.js */

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-small: 13px;
  --text: 14px;
  --text-title: 16px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --radius: 6px;
  --sidebar-width: 15rem;
}

/* Classes below set display; the hidden attribute must still win. */
[hidden] {
  display: none !important;
}

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

body {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-areas:
    "header header"
    "sidebar viewer";
  font: var(--text)/1.4 var(--font);
  color: var(--ink);
  background: var(--chrome);
}

/* Header ------------------------------------------------------------ */

.app-header {
  grid-area: header;
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--line);
}

.app-title {
  margin: 0;
  font-size: var(--text-title);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.status {
  margin-left: auto;
  min-width: 0;
}

.status-text {
  font-size: var(--text-small);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.status-text[data-tone="error"] {
  color: var(--error);
}

/* Grows along the bottom edge of the header while a file loads. */
.progress-line {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
}

/* Controls ---------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  padding: 6px var(--space-3);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

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

.button:has(:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.button.is-disabled {
  background: var(--line);
  color: var(--muted);
  cursor: not-allowed;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

input[type="checkbox"] {
  accent-color: var(--accent);
  margin: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

a {
  color: var(--accent);
}

/* Sidebar ----------------------------------------------------------- */

.app-sidebar {
  grid-area: sidebar;
  overflow: auto;
  padding: var(--space-4) var(--space-3);
  border-right: 1px solid var(--line);
}

.panel + .panel {
  margin-top: var(--space-4);
}

.panel h2 {
  margin: 0 0 var(--space-2);
  padding: 0 var(--space-2);
  font-size: var(--text-small);
  font-weight: 600;
  color: var(--muted);
}

.panel p {
  margin: 0;
  padding: var(--space-1) var(--space-2);
  color: var(--muted);
}

.panel label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
  cursor: pointer;
}

.panel label:hover {
  background: var(--accent-soft);
}

/* Viewer ------------------------------------------------------------ */

/* The canvas is positioned absolutely, so its pixel size never feeds back
   into the layout. */
.app-viewer {
  grid-area: viewer;
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--viewer);
}

.viewer-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* While nothing is shown, the whole view opens a file. */
.viewer-empty {
  position: absolute;
  inset: var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: transparent;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}

.viewer-empty:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.viewer-empty-title {
  font-size: var(--text-title);
  font-weight: 500;
  color: var(--ink);
}

.viewer-empty:hover .viewer-empty-title {
  color: var(--accent-strong);
}

.viewer-empty-detail {
  font-size: var(--text-small);
}

/* Shown while a file is dragged over the view; the model stays faintly
   visible behind it, the empty-state text is hidden so the texts do not overlap. */
.app-viewer.is-dragging .viewer-empty {
  visibility: hidden;
}

.viewer-drop {
  position: absolute;
  inset: var(--space-4);
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: rgb(227 239 240 / 0.85); /* --accent-soft */
  color: var(--accent-strong);
  font-size: var(--text-title);
  font-weight: 500;
  pointer-events: none;
}

.viewer-controls {
  position: absolute;
  left: var(--space-3);
  bottom: var(--space-3);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  margin: 0;
  padding: var(--space-1) var(--space-2);
  list-style: none;
  border-radius: var(--radius);
  background: rgb(255 255 255 / 0.7);
  color: var(--muted);
  font-size: var(--text-small);
  pointer-events: none;
}

.viewer-controls li {
  display: flex;
  align-items: center;
  gap: 5px;
}

.mouse-icon-outline {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.2;
}

.mouse-icon-part {
  fill: var(--accent);
}

.viewer-message {
  padding: var(--space-4);
}

/* Narrow screens: panels above the view instead of beside it. */
@media (max-width: 640px) {
  body {
    grid-template-rows: auto auto 1fr;
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "sidebar"
      "viewer";
  }

  .app-sidebar {
    max-height: 30vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .status {
    margin-left: 0;
    flex-basis: 100%;
  }
}
