/* Nettklienten. Fargene og målene fra appen (app/theme/Theme.qml). */
:root {
  color-scheme: light dark;
  --background: #F7F6F2;
  --surface: #FFFFFF;
  --pressed: #EFEDE7;
  --text: #1D1C1A;
  --muted: #5E5A53;
  --line: #E3E0D8;
  --input-border: #8A857C;
  --accent: #0E6B5A;
  --accent-text: #FFFFFF;
  --accent-soft: #DCEFEA;
  --warning: #8A5100;
  --warning-soft: #FBEFD5;
  --danger: #B3261E;
  --snackbar: #2B2A27;
  --snackbar-text: #F7F6F2;
  --snackbar-action: #7FD6C3;
  --radius: 14px;
  --touch: 48px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #121211;
    --surface: #1C1C1A;
    --pressed: #2A2A27;
    --text: #ECEAE4;
    --muted: #A9A49B;
    --line: #2F2E2B;
    --input-border: #7D786F;
    --accent: #5FC4AE;
    --accent-text: #08201B;
    --accent-soft: #1D3A34;
    --warning: #F0B45A;
    --warning-soft: #3A2F14;
    --danger: #F2B8B5;
    --snackbar: #ECEAE4;
    --snackbar-text: #1D1C1A;
    --snackbar-action: #0E6B5A;
  }
}

* { box-sizing: border-box; }

/* Elementer med `hidden` skjules, også når en klasse gir dem en display. */
[hidden] { display: none !important; }

html, body { margin: 0; background: var(--background); color: var(--text); }

body { line-height: 1.4; -webkit-text-size-adjust: 100%; }

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

button { cursor: pointer; }

button:disabled { cursor: default; }

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

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

.icon { width: 24px; height: 24px; flex: none; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

/* --- Toppen ---------------------------------------------------------- */

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--background);
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid var(--line);
}

.title-row { display: flex; align-items: center; gap: 8px; min-height: var(--touch); }

.list-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: left;
}

.list-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.details, .status { margin: 0; color: var(--muted); font-size: 0.9375rem; }

.status-offline, .status-signed_out { color: var(--warning); }

.icon-button {
  width: var(--touch);
  height: var(--touch);
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: none;
  flex: none;
}

.icon-button:hover { background: var(--pressed); }

/* --- Listen ---------------------------------------------------------- */

.list { padding: 0 16px; flex: 1; }

.category {
  margin: 20px 0 4px;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.items { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }

.item { display: flex; align-items: center; min-height: 56px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }

.check {
  width: 56px;
  height: 56px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  padding: 0;
}

.check .icon {
  width: 28px;
  height: 28px;
  padding: 3px;
  border: 2px solid var(--input-border);
  border-radius: 50%;
  color: transparent;
}

.check.checked .icon { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.check:hover:not(:disabled) .icon { border-color: var(--accent); }

.item-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 16px 10px 0;
  border: 0;
  background: none;
  text-align: left;
  min-height: 56px;
  justify-content: center;
}

.item-name { font-size: 1.0625rem; }
.quantity { color: var(--muted); }
.item-details { color: var(--muted); font-size: 0.9375rem; }
.in-basket .item-name { text-decoration: line-through; color: var(--muted); }

.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.8125rem; }
.chip.warning { background: var(--warning-soft); color: var(--warning); }

.basket-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 20px 0 4px; }

.basket-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--touch);
  border: 0;
  background: none;
  padding: 0;
  font-weight: 600;
  color: var(--muted);
}

.basket-toggle[aria-expanded="true"] .icon { transform: rotate(180deg); }

.empty, .empty-list { text-align: center; color: var(--muted); padding: 32px 16px; }
.empty h2 { color: var(--text); }

/* --- Skrivefeltet -------------------------------------------------------- */

.add-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  background: var(--background);
  border-top: 1px solid var(--line);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
}

.add-bar > * { max-width: 608px; margin-left: auto; margin-right: auto; }

.add-row { display: flex; gap: 8px; }

.add-input, .form input, .form select {
  flex: 1;
  min-width: 0;
  min-height: var(--touch);
  padding: 0 14px;
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 1.0625rem;
}

/* Tilbakemeldingen (P1-23): flere linjer, ellers som feltene over. */
.form textarea {
  min-height: 120px;
  padding: 10px 14px;
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  font-size: 1.0625rem;
  resize: vertical;
}

.add-button {
  width: var(--touch);
  height: var(--touch);
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
}

.suggestions { list-style: none; margin: 0 auto 8px; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.suggestions:empty { display: none; }

.suggestion {
  width: 100%;
  min-height: var(--touch);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px;
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  text-align: left;
}

.suggestions li:first-child .suggestion { border-top: 0; }
.suggestion:hover { background: var(--pressed); }
.suggestion-category { color: var(--muted); font-size: 0.875rem; }

/* --- Knapper, ark og skjema ---------------------------------------------- */

.primary, .secondary {
  min-height: var(--touch);
  padding: 0 20px;
  border-radius: var(--radius);
  font-weight: 600;
}

.primary { border: 0; background: var(--accent); color: var(--accent-text); }
.secondary { border: 1.5px solid var(--line); background: var(--surface); }
.danger { color: var(--danger); }
.wide { width: 100%; }
/* En lenke som ser ut som en knapp («Åpne i Basko-appen»). */
a.primary, a.secondary { display: flex; align-items: center; justify-content: center; text-decoration: none; }

.sheet {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  border: 0;
  border-radius: var(--radius);
  padding: 8px 16px 16px;
  background: var(--background);
  color: var(--text);
}

.sheet::backdrop { background: rgb(0 0 0 / 0.4); }

.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; }

.picker { list-style: none; margin: 0 0 12px; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }

.picker-row {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  text-align: left;
}

.picker li:first-child .picker-row { border-top: 0; }
.picker-row.current { font-weight: 700; color: var(--accent); }
.picker-row:hover { background: var(--pressed); }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9375rem; color: var(--muted); }
.form label input, .form label select { color: var(--text); }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.stepper { display: flex; align-items: center; gap: 4px; }
.stepper .icon-button { background: var(--surface); border: 1.5px solid var(--line); }
.quantity-value { min-width: 3ch; text-align: center; font-size: 1.125rem; font-weight: 600; }
.stepper input { margin-left: 8px; }

/* --- Snackbar ------------------------------------------------------------ */

.snackbar {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  z-index: 4;
  transform: translate(-50%, 16px);
  width: min(560px, calc(100vw - 32px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 8px 6px 16px;
  min-height: var(--touch);
  border-radius: var(--radius);
  background: var(--snackbar);
  color: var(--snackbar-text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms, transform 150ms;
}

.snackbar.visible { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }

.snack-action { min-height: 40px; padding: 0 12px; border: 0; border-radius: 8px; background: none; color: var(--snackbar-action); font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  .snackbar { transition: none; }
}

/* --- Innlogging ------------------------------------------------------------ */

.signin { display: flex; flex-direction: column; align-items: stretch; gap: 12px; padding: 48px 24px; text-align: center; }
.signin .logo { align-self: center; border-radius: 18px; }
.signin h1 { margin: 8px 0 0; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }
/* Invitasjonen (/i/<token>): rådet til den som har appen, under innloggingen. */
.invite-intro { display: flex; flex-direction: column; gap: 8px; }
.invite-intro h1, .signin h1.invite { margin: 8px 0 0; font-size: 1.625rem; line-height: 1.25; }
.invite-intro p { margin: 0; }
.app-hint { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; padding: 16px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); }
.app-hint p { margin: 0; }
