*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --surface-hover: #1e1e28;
  --border: #2a2a35;
  --border-hover: #3a3a4a;
  --text: #fff;
  --muted: #777;
  --faint: #555;
  --accent: #e05;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
/* Uten innlogging vises bare det som ikke endrer noe. */
body.guest [data-auth], body:not(.guest) [data-guest] { display: none !important; }

button, input, select { font: inherit; color: inherit; }

.view { width: 100%; max-width: 960px; margin: 0 auto; padding: 2rem 16px; }
.view.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; }

.label {
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

h1 { font-size: 22px; font-weight: 500; }
h2 { font-size: 18px; font-weight: 500; }
h3 {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-box h1 { margin-bottom: 2.5rem; }

input[type="password"], input[type="text"], select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus { border-color: #444; }
.login-box input { margin-bottom: 10px; }

input[type="file"] {
  width: 100%;
  font-size: 14px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
}
input[type="file"]::file-selector-button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 6px 12px;
  margin-right: 10px;
  cursor: pointer;
}

.btn-primary {
  width: 100%;
  background: #fff;
  color: var(--bg);
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.4; cursor: default; }

.btn-action {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #aaa;
  font-size: 13px;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  display: inline-block;
  transition: border-color 0.15s, color 0.15s;
}
.btn-action:hover { border-color: #444; color: #fff; }
.btn-action:disabled { opacity: 0.4; cursor: default; }
.btn-action.primary { color: #fff; border-color: #444; }
.btn-action.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-action.danger:hover { border-color: #5a2a2a; color: var(--accent); }
.btn-action.confirm { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn-link {
  background: none;
  border: none;
  color: var(--faint);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.btn-link:hover { color: #999; }
.btn-link.small { font-size: 11px; letter-spacing: 0; text-transform: none; }

.error { color: var(--accent); font-size: 13px; margin-top: 8px; min-height: 1em; }
.error:empty { display: none; }
.status { font-size: 12px; color: var(--faint); margin-top: 1rem; min-height: 18px; }
.hint { font-size: 12px; color: var(--faint); }

/* Bibliotek */
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 1.5rem; }
.actions { display: flex; align-items: center; gap: 12px; }

.filters { display: flex; gap: 8px; margin-bottom: 1rem; }
.chip {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  padding: 5px 12px;
  cursor: pointer;
}
.chip.active { background: var(--surface); color: #fff; border-color: #444; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: border-color 0.15s, background 0.15s;
}
.card:hover { border-color: var(--border-hover); background: var(--surface-hover); }
.card-thumb {
  aspect-ratio: 4 / 3;
  background: #14141a center / cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
}
.card-body { padding: 12px 14px; }
.card-title { font-size: 15px; font-weight: 500; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-desc { color: var(--faint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--faint);
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 3rem 1rem;
  font-size: 14px;
}

/* Skanning */
.scan-view { max-width: 1200px; padding-top: 1rem; }
.scan-top { display: flex; align-items: center; gap: 16px; margin-bottom: 1rem; }
.scan-top h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.scan-body { display: grid; grid-template-columns: 1fr 300px; gap: 16px; }

.viewer {
  position: relative;
  height: min(70vh, 720px);
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: #14141a;
  touch-action: none;
}
.viewer canvas { display: block; width: 100%; height: 100%; }
.viewer.measuring canvas { cursor: crosshair; }
.viewer-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 1rem;
  pointer-events: none;
}
.viewer-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.measure-label {
  position: absolute;
  left: 0;
  top: 0;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 6px;
  white-space: nowrap;
}
.toolbar {
  position: absolute;
  left: 12px;
  bottom: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  pointer-events: none;
}
.toolbar > * { pointer-events: auto; }
.toolbar .btn-action { background: rgba(26, 26, 34, 0.9); backdrop-filter: blur(6px); }
.toolbar .btn-action.active { background: var(--accent); }

.panel { display: flex; flex-direction: column; gap: 14px; }
.panel section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { text-align: right; font-variant-numeric: tabular-nums; }

.measure-list { list-style: none; font-size: 13px; margin-bottom: 8px; counter-reset: m; }
.measure-list li { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--border); counter-increment: m; }
.measure-list li::before { content: counter(m) '.'; color: var(--faint); margin-right: 8px; }
.measure-list li span { margin-left: auto; font-variant-numeric: tabular-nums; }

.downloads { display: flex; flex-wrap: wrap; gap: 8px; }

.floorplan { width: 100%; height: auto; display: block; margin-bottom: 12px; background: #14141a; border-radius: 10px; }
.floorplan line, .floorplan rect, .floorplan polygon { vector-effect: non-scaling-stroke; }
.fp-floor { fill: #20202a; }
.fp-wall { stroke: #ddd; stroke-width: 3; stroke-linecap: round; }
.fp-door { stroke: #e9a23b; stroke-width: 4; }
.fp-window { stroke: #4aa3df; stroke-width: 4; }
.fp-opening { stroke: #14141a; stroke-width: 4; }
.fp-object { fill: rgba(255, 255, 255, 0.06); stroke: #555; stroke-width: 1; }
.floorplan text { fill: #aaa; text-anchor: middle; dominant-baseline: middle; }

.object-list { list-style: none; font-size: 13px; margin-top: 10px; }
.object-list li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-top: 1px solid var(--border); }
.object-list li span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Dialog */
dialog {
  margin: auto;
  width: min(520px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
.upload-form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); flex: 1; }
.field small { color: var(--faint); }
.row { display: flex; gap: 12px; }
.preview { height: 240px; position: relative; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.preview canvas { display: block; width: 100%; height: 100%; }
.dialog-actions { display: flex; justify-content: flex-end; align-items: center; gap: 16px; }
.dialog-actions .btn-primary { width: auto; padding: 10px 24px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  z-index: 100;
  max-width: calc(100% - 32px);
}

@media (max-width: 760px) {
  .scan-body { grid-template-columns: 1fr; }
  .viewer { height: 60vh; }
  .top { flex-direction: column; }
  .row { flex-direction: column; }
}
