:root {
  --bg: #0e1116;
  --panel: #151a21;
  --panel-2: #1b2129;
  --border: #242b35;
  --fg: #d8dde4;
  --fg-muted: #8a94a3;
  --accent: #ffbf47;
  --accent-soft: #7cc7ff;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
body { display: grid; grid-template-columns: 340px 1fr; height: 100vh; overflow: hidden; }

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

#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#brand {
  display: block;
  padding: 16px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  transition: background .12s ease;
}
#brand:hover { background: #f3f6fa; }
#brand img { display: block; width: 100%; height: auto; }

#sidebar header { padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
#sidebar header h1 { margin: 0; font-size: 22px; letter-spacing: 0.02em; }
#sidebar header .sub { margin: 4px 0 0; color: var(--fg-muted); font-size: 14px; }

#scroll { flex: 1; overflow-y: auto; min-height: 0; }

.section-title {
  margin: 0;
  padding: 14px 20px 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--fg-muted);
}

#model-list { list-style: none; margin: 0; padding: 0 0 6px; }
#model-list .loading { padding: 8px 20px 16px; color: var(--fg-muted); font-style: italic; font-size: 14px; }
.model {
  padding: 10px 20px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .1s ease, border-color .1s ease;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  align-items: baseline;
}
.model:hover { background: var(--panel-2); }
.model.active { background: var(--panel-2); border-left-color: var(--accent); }
.model .name {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 14px; font-weight: 600;
}
.model .size {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  white-space: nowrap;
}
.model .note { grid-column: 1 / -1; color: var(--fg-muted); font-size: 12px; line-height: 1.35; }
.model.missing .name { color: var(--fg-muted); text-decoration: line-through; }
.model.missing .size { color: var(--danger); }

#stats { border-top: 1px solid var(--border); padding-bottom: 10px; }
#stats dl {
  margin: 0;
  padding: 0 20px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  font-size: 13px;
}
#stats dt { color: var(--fg-muted); }
#stats dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
#stats .empty { padding: 2px 20px 8px; margin: 0; color: var(--fg-muted); font-style: italic; font-size: 13px; }

#sidebar footer { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--panel-2); }
#sidebar footer .hint { margin: 0; font-size: 12px; line-height: 1.5; color: var(--fg-muted); }
#sidebar footer kbd {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
  color: var(--fg);
}

/* --- Stage -------------------------------------------------------------- */

#stage {
  position: relative; min-width: 0; min-height: 0;
  background: radial-gradient(ellipse at center, #1a2029 0%, #0b0d11 100%);
}
#stage.bg-light { background: radial-gradient(ellipse at center, #ffffff 0%, #c9d2dd 100%); }
#stage.bg-flat { background: #0b0d11; }
#view { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
#view:active { cursor: grabbing; }

#toolbar {
  position: absolute; top: 16px; right: 16px;
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px;
  max-width: calc(100% - 32px);
}
#toolbar button {
  background: rgba(21, 26, 33, 0.92);
  backdrop-filter: blur(6px);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .12s ease, color .12s ease, background .12s ease;
}
#toolbar button:hover { border-color: var(--accent); color: var(--accent); }
#toolbar button[aria-pressed="true"] {
  border-color: var(--accent);
  color: #1b2129;
  background: var(--accent);
}

#loading-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(11, 13, 17, 0.85);
  color: var(--fg-muted);
  font-size: 15px;
  gap: 16px;
  pointer-events: none;
  transition: opacity .3s ease;
}
#loading-overlay.hidden { opacity: 0; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { margin: 0; font-variant-numeric: tabular-nums; }

#error-box {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  max-width: min(560px, calc(100% - 48px));
  background: rgba(21, 26, 33, 0.96);
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  border-radius: 4px;
  padding: 18px 22px;
  font-size: 14px;
  line-height: 1.5;
}
#error-box h2 { margin: 0 0 8px; font-size: 16px; color: var(--danger); }
#error-box p { margin: 0 0 8px; }
#error-box p:last-child { margin-bottom: 0; }
#error-box code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  background: var(--panel-2);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--accent-soft);
  overflow-wrap: anywhere;
}

#hud {
  position: absolute; left: 16px; bottom: 16px;
  background: rgba(21, 26, 33, 0.92);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 10px 16px;
  font-size: 13px;
  line-height: 1.45;
  max-width: min(420px, calc(100% - 32px));
}
#hud strong {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 15px;
  display: block;
}
#hud span { color: var(--fg-muted); }

#drop-overlay {
  position: absolute; inset: 12px;
  display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: rgba(11, 13, 17, 0.75);
  color: var(--accent);
  font-size: 17px;
  pointer-events: none;
}

[hidden] { display: none !important; }

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #stage { order: 1; }
  #sidebar { order: 2; max-height: 48vh; border-right: 0; border-top: 1px solid var(--border); }
}
