:root {
  --bg: #12151d;
  --surface: #1b1f2a;
  --surface-2: #232838;
  --line: #2f3446;
  --text: #eef1f7;
  --muted: #99a0b5;
  --accent: #ffcb05;   /* Pokémon-gul */
  --accent-ink: #1b1f2a;
  --red: #e3350d;
  --green: #4ade80;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 14px calc(28px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: linear-gradient(var(--bg) 75%, transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand img { border-radius: 50%; }

/* --------------------------------------------------------- værdi-kort */

.value-card {
  background: linear-gradient(135deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.value-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.currency-switch {
  display: flex;
  flex: 0 0 auto;
  gap: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}

.cur {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.cur.is-active { background: var(--accent); color: var(--accent-ink); }

.sub.warn { color: #f6c177; margin-top: 4px; }
.sub.tiny { font-size: 12px; }
.delta-up { color: var(--green); }
.delta-down { color: #ff8a72; }

.value-card .label {
  margin: 0;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.value-card .total {
  margin: 4px 0 2px;
  font-size: 34px;
  font-weight: 800;
  color: var(--accent);
}

.value-card .sub, .sub { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 14px;
}

.tab {
  flex: 1;
  padding: 9px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.tab.is-active { background: var(--accent); color: var(--accent-ink); }

.view { display: none; }
.view.is-active { display: block; }

/* ------------------------------------------------------------- knapper */

button { font: inherit; cursor: pointer; }

.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 700;
}

.ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
}

.danger { background: transparent; color: var(--red); border: 1px solid var(--red); border-radius: 10px; padding: 9px 14px; }

button:disabled { opacity: 0.55; cursor: default; }

.refresh-icon { display: inline-block; }
.is-spinning .refresh-icon { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------------------------------------- felter */

input, select, textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
}

input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.filters form, #search-form { flex-direction: row; }
#search-form { display: flex; gap: 8px; }
#search-form input { flex: 1; }
.filter-row { display: flex; gap: 8px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label, .dialog-head + .two label, #item-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--muted);
}

.two { display: flex; gap: 10px; }
.two label { flex: 1; }
.req { color: var(--red); }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.photo-label input { padding: 8px; }

/* ---------------------------------------------------------------- grid */

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: left;
  padding: 0;
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.card .thumb {
  aspect-ratio: 245 / 342;
  width: 100%;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
}

.card .placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 30px;
}

.card .body { padding: 9px 10px 11px; display: flex; flex-direction: column; gap: 2px; }
.card .name { font-weight: 700; font-size: 14px; line-height: 1.25; }
.card .meta { color: var(--muted); font-size: 12px; }
.card .price { color: var(--green); font-weight: 700; font-size: 14px; margin: 2px 0 0; }
.price { color: var(--green); font-weight: 700; }

.badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }
.badge {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
}
.badge.qty { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.badge.photo { border-color: var(--accent); color: var(--accent); }

.empty { color: var(--muted); text-align: center; padding: 26px 10px; }
.hidden { display: none !important; }

/* -------------------------------------------------------------- dialog */

dialog {
  width: min(460px, calc(100vw - 28px));
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

#item-form { display: flex; flex-direction: column; gap: 12px; }

.dialog-head { display: flex; gap: 12px; align-items: flex-start; }
.dialog-head img { width: 84px; border-radius: 8px; background: var(--surface-2); }
.dialog-head h2 { margin: 0; font-size: 18px; }

.dialog-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

/* --------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  z-index: 20;
  max-width: calc(100vw - 32px);
}

.toast.error { border-color: var(--red); color: #ffb3a7; }

/* ---------------------------------------------------------------- scan */

.scan-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 18px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
}

.scan-button:active { border-color: var(--accent); }
.scan-icon { font-size: 34px; }
.scan-text { font-weight: 700; font-size: 17px; }
.scan-hint { color: var(--muted); font-size: 13px; max-width: 34ch; }

.scan-busy {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  color: var(--muted);
  padding: 14px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.scan-reading {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

.scan-reading img {
  width: 72px;
  border-radius: 8px;
  background: var(--surface-2);
}

.scan-read { margin: 2px 0; font-weight: 700; font-size: 16px; }
.scan-reading .ghost { margin-top: 8px; }
.wide { width: 100%; margin-top: 12px; }

/* ------------------------------------------------------- live-kamera */

.camera {
  position: relative;
  /* Stående format: et kort er højt, og rammen skal kunne være i feltet. */
  aspect-ratio: 3 / 4;
  max-height: 64vh;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  margin-bottom: 12px;
}

.camera video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

/* Rammen kortet skal ligge i — samme forhold som et rigtigt kort (63×88 mm). */
.card-guide {
  position: absolute;
  inset: 0;
  margin: auto;
  /* Højden styrer, så rammen aldrig kan blive højere end videofeltet. */
  height: 86%;
  width: auto;
  max-width: 92%;
  aspect-ratio: 63 / 88;
  border: 2px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

/* De to zoner der faktisk aflæses. */
.guide-zone {
  position: absolute;
  left: 4%;
  right: 4%;
  border: 1px dashed rgba(255, 203, 5, 0.75);
  border-radius: 4px;
}

.guide-name { top: 4%; height: 13%; }
.guide-number { bottom: 1.5%; height: 9%; }

.camera-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 10px 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}

.camera-status {
  margin: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
}



.camera-info {
  margin: 3px 0 0;
  text-align: center;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
}

.camera-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
}

.camera-tools .is-active { background: var(--accent); color: var(--accent-ink); }

.scan-alternatives { display: flex; gap: 8px; }
.scan-alt { flex: 1; text-align: center; cursor: pointer; }
.hint.center { text-align: center; }

/* Lys-knappen vises altid mens kameraet kører; er lampen utilgængelig,
   er knappen nedtonet og forklarer sig ved tryk. */
#camera-torch { font-size: 18px; line-height: 1; padding: 8px 11px; }
#camera-torch.unsupported { opacity: 0.45; }
