:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1c1a;
  --muted: #6b6862;
  --border: #dedbd4;
  --accent: #2f6fdb;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --viewer: #eceae5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1f1f1d;
    --text: #ecebe8;
    --muted: #9c9993;
    --border: #34332f;
    --accent: #6c9cf0;
    --accent-text: #0d1424;
    --danger: #f2a39d;
    --viewer: #11110f;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}
header { display: flex; align-items: baseline; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
h1 { font-size: 17px; margin: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
main { flex: 1; display: grid; grid-template-columns: 240px 1fr 380px; min-height: 0; }
aside { padding: 16px; overflow-y: auto; background: var(--surface); }
#models { border-right: 1px solid var(--border); }
#panel { border-left: 1px solid var(--border); }

#model-list { list-style: none; margin: 0 0 12px; padding: 0; }
#model-list button {
  width: 100%; text-align: left; border: 0; background: none; color: inherit; font: inherit;
  padding: 7px 8px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px;
}
#model-list button:hover { background: var(--bg); }
#model-list button[aria-current="true"] { background: var(--accent); color: var(--accent-text); }
#model-list .tags { font-size: 11px; opacity: .75; white-space: nowrap; }
#drop {
  display: block; border: 1.5px dashed var(--border); border-radius: 8px; padding: 18px 10px;
  text-align: center; cursor: pointer;
}
#drop.over { border-color: var(--accent); background: var(--bg); }

#viewer { position: relative; background: var(--viewer); min-height: 300px; }
#canvas { position: absolute; inset: 0; }
#viewer-bar {
  position: absolute; left: 12px; right: 12px; top: 10px; display: flex; justify-content: space-between;
  gap: 12px; pointer-events: none;
}
#viewer-bar > * { pointer-events: auto; background: var(--surface); padding: 4px 10px; border-radius: 6px; border: 1px solid var(--border); }
#legend {
  position: absolute; left: 12px; bottom: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font-size: 12px;
}
#legend div { display: flex; align-items: center; gap: 6px; }
#legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

fieldset { border: 0; padding: 0; margin: 0 0 14px; }
fieldset legend { font-weight: 600; margin-bottom: 4px; }
fieldset label { display: block; padding: 2px 0; }
select { font: inherit; padding: 5px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: inherit; width: 100%; }
button, .button {
  font: inherit; border-radius: 6px; padding: 7px 14px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; display: inline-block;
}
#slice { background: var(--accent); color: var(--accent-text); border-color: var(--accent); width: 100%; font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }

.result { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-top: 12px; }
.result h3 { margin: 0 0 6px; font-size: 14px; display: flex; justify-content: space-between; }
.result dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0 0 8px; }
.result dt { color: var(--muted); }
.result dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.result ul { margin: 0 0 8px; padding-left: 16px; font-size: 12px; }
.result .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.warning { color: var(--danger); font-size: 12px; }
h2.section { margin-top: 26px; }
.row-actions { display: flex; gap: 6px; }
.row-actions button { flex: 1; padding: 6px 8px; }
#orientations { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; font-variant-numeric: tabular-nums; }
#orientations th { text-align: right; color: var(--muted); font-weight: 500; padding: 3px 4px; border-bottom: 1px solid var(--border); }
#orientations th:first-child, #orientations td:first-child { text-align: left; }
#orientations td { text-align: right; padding: 4px; border-bottom: 1px solid var(--border); white-space: nowrap; }
#orientations tr.current td { background: var(--bg); font-weight: 600; }
#orientations td.best { color: var(--accent); font-weight: 600; }
#orientations button { padding: 2px 8px; font-size: 12px; }
.error { color: var(--danger); }

#account { margin-left: auto; display: flex; gap: 4px; }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
#invite-box { padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
#invite-box p { margin: 0 0 6px; }
#invite-qr svg { display: block; margin: 0 auto 8px; background: #fff; border-radius: 8px; max-width: 240px; height: auto; }
#invite-url { width: 100%; font: inherit; font-size: 12px; padding: 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: inherit; }
#login { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 10; padding: 16px; }
#login[hidden] { display: none; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; width: min(360px, 100%); }
.login-card label { display: block; margin: 0 0 12px; }
.login-card input { display: block; width: 100%; margin-top: 4px; font: inherit; padding: 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: inherit; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); width: 100%; font-weight: 600; padding: 10px 14px; }
/* Utifrån: knapparna som verkar på WinServer (Bambu Connect, Bambu Studio) gör inget på telefonen. */
[data-remote] .result .actions { display: none; }

@media (max-width: 900px) {
  body { height: auto; min-height: 100%; }
  main { grid-template-columns: 1fr; grid-template-rows: auto 55vh auto; }
  #models, #panel { border: 0; }
  #models { border-bottom: 1px solid var(--border); }
  #model-list { max-height: 30vh; overflow-y: auto; }
  #drop { padding: 12px 10px; }
  #drop .desktop-only { display: none; }
  #viewer { touch-action: none; }
  #viewer-bar { flex-wrap: wrap; }
  #panel { padding-bottom: 32px; }
  #orientations { font-size: 11px; }
  button, .button, select { min-height: 40px; }
  #orientations button { min-height: 32px; }
}
