/* =====================================================================
   Akutväska Lager — stil
   Mobilanpassad, en-handsanvändning: stora tryckytor, minimal text.
   ===================================================================== */

:root {
  --color-bg: #0f172a;
  --color-surface: #ffffff;
  --color-surface-2: #f1f5f9;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;

  --color-primary: #1e5aa8;
  --color-primary-dark: #163f78;
  --color-danger: #dc2626;
  --color-danger-dark: #b91c1c;

  --color-expired-bg: #fee2e2;
  --color-expired-border: #dc2626;
  --color-expired-text: #991b1b;

  --color-soon-bg: #fef3c7;
  --color-soon-border: #d97706;
  --color-soon-text: #92400e;

  --color-zero-bg: #f1f5f9;
  --color-zero-border: #94a3b8;
  --color-zero-text: #475569;

  --color-ok-bg: #ffffff;
  --color-ok-border: #cbd5e1;
  --color-ok-text: #0f172a;

  --radius: 14px;
  --radius-lg: 20px;
  --tap: 52px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* Garanterar att [hidden] alltid vinner, även över klasser som sätter
   display (t.ex. .btn-block) — annars vinner författarens CSS-regel
   över webbläsarens inbyggda "[hidden]{display:none}"-stil. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-surface-2);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
p { margin: 0 0 12px; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select {
  font-family: inherit;
  font-size: 16px; /* förhindrar auto-zoom på iOS */
}

/* ---------------------------------------------------------------------
   Views (enkel SPA-router: en synlig sektion i taget)
   --------------------------------------------------------------------- */
.view { display: none; }
.view.active { display: block; }

#views {
  padding: 16px 16px calc(96px + var(--safe-bottom));
  max-width: 560px;
  margin: 0 auto;
}

.print-only { display: none; }

/* ---------------------------------------------------------------------
   Header
   --------------------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-primary);
  color: white;
  padding: calc(14px + var(--safe-top)) 16px 14px;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------------------------------------------------------------------
   Bottom nav
   --------------------------------------------------------------------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding-bottom: var(--safe-bottom);
}

.nav-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: 600;
}

.nav-btn .nav-icon { font-size: 1.4rem; }

.nav-btn.active { color: var(--color-primary); }

/* ---------------------------------------------------------------------
   Knappar
   --------------------------------------------------------------------- */
.btn {
  border: none;
  border-radius: var(--radius);
  font-weight: 700;
  min-height: var(--tap);
  padding: 12px 20px;
  font-size: 1rem;
}

.btn-block { display: block; width: 100%; margin-bottom: 12px; }

.btn-lg { min-height: 56px; font-size: 1.05rem; }
.btn-xl { min-height: 64px; font-size: 1.15rem; }

.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:active { background: var(--color-primary-dark); }

.btn-secondary { background: var(--color-surface-2); color: var(--color-text); border: 2px solid var(--color-border); }

.btn-danger { background: var(--color-danger); color: white; }
.btn-danger:active { background: var(--color-danger-dark); }

.btn-danger-outline {
  background: white;
  color: var(--color-danger);
  border: 2px solid var(--color-danger);
}

.btn-link {
  background: transparent;
  color: var(--color-primary);
  font-weight: 600;
  min-height: 44px;
}

.btn-circle {
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  background: var(--color-surface-2);
  border: 2px solid var(--color-border);
  font-size: 1.6rem;
  line-height: 1;
  color: var(--color-text);
}

.btn-circle:active { background: var(--color-border); }

/* ---------------------------------------------------------------------
   Formulär
   --------------------------------------------------------------------- */
form label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-bottom: 14px;
}

form input,
form select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 2px solid var(--color-border);
  border-radius: 12px;
  min-height: var(--tap);
  background: white;
  color: var(--color-text);
}

form input:focus,
form select:focus {
  outline: none;
  border-color: var(--color-primary);
}

.sub-field { margin-top: -6px; }

.error-text {
  background: var(--color-expired-bg);
  color: var(--color-expired-text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-weight: 600;
}

/* ---------------------------------------------------------------------
   Importera produkter
   --------------------------------------------------------------------- */
textarea {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--color-border);
  border-radius: 12px;
  background: white;
  color: var(--color-text);
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 0.9rem;
  resize: vertical;
  margin-bottom: 12px;
}

textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.import-preview,
.import-result {
  background: var(--color-surface);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.import-result { background: #dcfce7; color: #166534; }

.import-error-list {
  margin: 8px 0 0;
  padding-left: 20px;
}

.import-error-list li {
  margin-bottom: 4px;
}

/* ---------------------------------------------------------------------
   Inloggning
   --------------------------------------------------------------------- */
.view-login {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: 24px;
}

.view-login.active { display: flex; }

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
}

.login-logo { font-size: 2.8rem; margin-bottom: 4px; }
.login-card h1 { font-size: 1.3rem; }
.login-card .subtitle { color: var(--color-text-muted); margin-bottom: 24px; }
.login-card form label { text-align: left; }

/* ---------------------------------------------------------------------
   Skanner
   --------------------------------------------------------------------- */
.scanner-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 16px;
}

#scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-frame {
  position: absolute;
  inset: 18% 10%;
  border: 3px solid rgba(255,255,255,0.85);
  border-radius: 16px;
  box-shadow: 0 0 0 999px rgba(0,0,0,0.35);
  pointer-events: none;
}

.scanner-status {
  text-align: center;
  color: var(--color-text-muted);
  font-weight: 600;
  min-height: 24px;
}

.scanned-code {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

/* ---------------------------------------------------------------------
   Produktkort (detalj)
   --------------------------------------------------------------------- */
.item-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
}

.item-card h2 { font-size: 1.4rem; margin-top: 6px; }

.item-barcode {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
}

.status-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.status-badge.status-expired { background: var(--color-expired-bg); color: var(--color-expired-text); }
.status-badge.status-soon { background: var(--color-soon-bg); color: var(--color-soon-text); }
.status-badge.status-zero { background: var(--color-zero-bg); color: var(--color-zero-text); }
.status-badge.status-ok { background: #dcfce7; color: #166534; }

.qty-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  margin: 20px 0;
}

.qty-number {
  font-size: 2.6rem;
  font-weight: 800;
  min-width: 72px;
}

.item-meta {
  display: flex;
  justify-content: space-around;
  margin: 16px 0;
  padding: 14px 0;
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}

.item-meta dt {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 4px;
}

.item-meta dd { margin: 0; font-weight: 700; }

.edit-form { text-align: left; margin-top: 16px; }

/* ---------------------------------------------------------------------
   Lista
   --------------------------------------------------------------------- */
.list-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

#list-search {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--color-border);
  min-height: var(--tap);
  background: white;
}

.list-filters {
  display: flex;
  gap: 10px;
}

.list-filters select {
  flex: 1;
  padding: 10px 8px;
  border-radius: 12px;
  border: 2px solid var(--color-border);
  min-height: 46px;
  background: white;
  font-size: 0.9rem;
}

.list-summary {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0 0 10px;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-ok-bg);
  border: 2px solid var(--color-ok-border);
  border-left-width: 6px;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  width: 100%;
}

.item-row.status-expired { background: var(--color-expired-bg); border-color: var(--color-expired-border); }
.item-row.status-soon { background: var(--color-soon-bg); border-color: var(--color-soon-border); }
.item-row.status-zero { background: var(--color-zero-bg); border-color: var(--color-zero-border); color: var(--color-zero-text); }

.item-row-main { flex: 1; min-width: 0; }

.item-row-name {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-row-sub {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.item-row.status-expired .item-row-sub,
.item-row.status-expired .item-row-name { color: var(--color-expired-text); }
.item-row.status-soon .item-row-sub,
.item-row.status-soon .item-row-name { color: var(--color-soon-text); }

.item-row-qty {
  font-weight: 800;
  font-size: 1.1rem;
  min-width: 28px;
  text-align: center;
}

.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: 40px 16px;
}

.list-actions { margin-top: 18px; }

/* ---------------------------------------------------------------------
   Dela (QR-kod)
   --------------------------------------------------------------------- */
.share-qr {
  display: flex;
  justify-content: center;
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  margin: 8px 0 16px;
}

.share-qr svg { width: 220px; height: 220px; }

.share-url {
  text-align: center;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  word-break: break-all;
  margin-bottom: 16px;
}

.share-qr-caption {
  text-align: center;
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------
   Toast
   --------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #0f172a;
  color: white;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

.toast.toast-error { background: var(--color-danger); }

/* ---------------------------------------------------------------------
   Utskrift
   --------------------------------------------------------------------- */
@media print {
  .no-print { display: none !important; }
  .print-only { display: block !important; }

  .app-header, .bottom-nav { display: none !important; }

  body, #views { background: white; padding: 0; max-width: none; }

  .view { display: none !important; }
  .view.active { display: block !important; }

  .item-row {
    break-inside: avoid;
    border: 1px solid #999 !important;
    background: white !important;
    color: black !important;
  }

  .item-row-name, .item-row-sub { color: black !important; }

  .share-qr { padding: 0; }
  .share-qr svg { width: 320px; height: 320px; }
}
