/* ============================================================
   SmartStock – huvudstylesheet
   Mobil-first, inga externa beroenden
   ============================================================ */

/* ---- Variabler ------------------------------------------ */
:root {
  --c-bg:          #f1f5f9;
  --c-surface:     #ffffff;
  --c-border:      #e2e8f0;
  --c-text:        #0f172a;
  --c-muted:       #64748b;
  --c-primary:     #2563eb;
  --c-primary-h:   #1d4ed8;
  --c-success:     #16a34a;
  --c-warning:     #d97706;
  --c-danger:      #dc2626;
  --c-sidebar-bg:  #111827;
  --c-sidebar-txt: #9ca3af;
  --c-sidebar-act: #2563eb;

  --radius-sm: 0.375rem;
  --radius:    0.5rem;
  --radius-lg: 0.75rem;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0/.06);
  --shadow:    0 1px 3px 0 rgb(0 0 0/.1), 0 1px 2px -1px rgb(0 0 0/.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0/.1), 0 2px 4px -2px rgb(0 0 0/.1);

  --sidebar-w: 240px;
  --topbar-h:  56px;
  --bottomnav-h: 64px;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  min-height: 100vh;
}

img, svg { display: block; max-width: 100%; }
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { list-style: none; }
button { cursor: pointer; font: inherit; }

/* ---- Typografi ------------------------------------------ */
h1 { font-size: 1.5rem;   font-weight: 700; line-height: 1.25; }
h2 { font-size: 1.25rem;  font-weight: 600; line-height: 1.3; }
h3 { font-size: 1.0625rem; font-weight: 600; }
h4 { font-size: 0.9375rem; font-weight: 600; }
p  { color: var(--c-muted); }

/* ---- Layout --------------------------------------------- */

/* Mobil: topbar + innehåll + bottom-nav */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  background: var(--c-sidebar-bg);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
}

.topbar-logo {
  font-size: 1.125rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.02em;
  flex: 1;
}

.topbar-logo span { color: var(--c-primary); }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--c-sidebar-txt);
  font-size: 0.875rem;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 600;
  flex-shrink: 0;
}

.main-content {
  padding: 1.25rem 1rem calc(var(--bottomnav-h) + 1.25rem);
  max-width: 1200px;
  margin: 0 auto;
}

/* Bottom navigation (mobil) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottomnav-h);
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  display: flex;
  align-items: stretch;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  color: var(--c-muted);
  font-size: 0.6875rem;
  font-weight: 500;
  text-decoration: none;
  padding: 0.5rem 0;
  transition: color 0.15s;
  position: relative;
}

.bottom-nav a.active {
  color: var(--c-primary);
}

.bottom-nav a svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.75;
}

/* Skanna-knapp i mitten – highlight */
.bottom-nav .scan-btn {
  flex: 0 0 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.bottom-nav .scan-btn .scan-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--c-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
  box-shadow: 0 2px 8px rgb(37 99 235 / 0.4);
  transition: transform 0.15s;
}

.bottom-nav .scan-btn:active .scan-circle {
  transform: scale(0.94);
}

.bottom-nav .scan-btn svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.75;
  stroke: #fff;
}

/* Desktop sidebar (dold på mobil som standard, visas bara från 768px) */
.sidebar { display: none; }

@media (min-width: 768px) {
  .topbar { display: none; }
  .bottom-nav { display: none; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--c-sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
  }

  .sidebar-logo {
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    border-bottom: 1px solid rgb(255 255 255 / 0.06);
    font-size: 1.125rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.02em;
    flex-shrink: 0;
  }

  .sidebar-logo span { color: var(--c-primary); }

  .sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
  }

  .sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius);
    color: var(--c-sidebar-txt);
    font-size: 0.9375rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
  }

  .sidebar-nav a:hover {
    background: rgb(255 255 255 / 0.06);
    color: #fff;
  }

  .sidebar-nav a.active {
    background: rgb(37 99 235 / 0.2);
    color: #fff;
  }

  .sidebar-nav a svg {
    width: 18px;
    height: 18px;
    stroke-width: 1.75;
    flex-shrink: 0;
  }

  .sidebar-nav .nav-divider {
    height: 1px;
    background: rgb(255 255 255 / 0.06);
    margin: 0.5rem 0;
  }

  .sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgb(255 255 255 / 0.06);
  }

  .sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--radius);
    transition: background 0.15s;
    text-decoration: none;
  }

  .sidebar-user:hover { background: rgb(255 255 255 / 0.06); }

  .sidebar-user-info { flex: 1; min-width: 0; }
  .sidebar-user-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .sidebar-user-role {
    font-size: 0.75rem;
    color: var(--c-sidebar-txt);
    text-transform: capitalize;
  }

  .main-content {
    margin-left: var(--sidebar-w);
    padding: 2rem 2.5rem;
    max-width: calc(var(--sidebar-w) + 1200px);
  }
}

/* ---- Sidor utan layout (login/register) ----------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  background: var(--c-bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
}

.auth-logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--c-text);
  text-align: center;
  margin-bottom: 0.25rem;
  letter-spacing: -0.03em;
}

.auth-logo span { color: var(--c-primary); }

.auth-subtitle {
  text-align: center;
  color: var(--c-muted);
  font-size: 0.875rem;
  margin-bottom: 1.75rem;
}

/* ---- Formulär ------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1rem;
}

label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--c-text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.5625rem 0.75rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 1rem;
  color: var(--c-text);
  background: var(--c-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.12);
}

input::placeholder { color: #94a3b8; }

textarea { resize: vertical; min-height: 80px; }

.form-hint {
  font-size: 0.8125rem;
  color: var(--c-muted);
}

.form-row {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 480px) {
  .form-row.cols-2 { grid-template-columns: 1fr 1fr; }
}

/* ---- Knappar -------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5625rem 1.125rem;
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }

.btn svg { width: 16px; height: 16px; flex-shrink: 0; stroke-width: 2; }

.btn-primary {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}
.btn-primary:hover { background: var(--c-primary-h); border-color: var(--c-primary-h); text-decoration: none; }

.btn-secondary {
  background: var(--c-surface);
  color: var(--c-text);
  border-color: var(--c-border);
}
.btn-secondary:hover { background: var(--c-bg); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--c-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--c-bg); color: var(--c-text); text-decoration: none; }

.btn-danger {
  background: var(--c-danger);
  color: #fff;
  border-color: var(--c-danger);
}
.btn-danger:hover { background: #b91c1c; text-decoration: none; }

.btn-full { width: 100%; }

.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }

/* ---- Kort ----------------------------------------------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--c-border);
  gap: 1rem;
}

.card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--c-text);
}

.card-body { padding: 1.25rem; }

/* ---- Statistik-rutor ------------------------------------ */
.stats-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

.stat-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 1.125rem;
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--c-muted);
  font-weight: 500;
  margin-bottom: 0.375rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--c-text);
  line-height: 1;
}

.stat-delta {
  font-size: 0.75rem;
  color: var(--c-muted);
  margin-top: 0.25rem;
}

/* ---- Del-kort (lagerlista) ------------------------------ */
.parts-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 600px) {
  .parts-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
  .parts-grid { grid-template-columns: repeat(3, 1fr); }
}

.part-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow 0.15s;
  text-decoration: none;
  color: inherit;
  display: block;
}

.part-card:hover {
  box-shadow: var(--shadow-md);
  text-decoration: none;
}

.part-card-image {
  aspect-ratio: 16/9;
  background: var(--c-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-muted);
  font-size: 0.8125rem;
  overflow: hidden;
}

.part-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.part-card-body {
  padding: 0.875rem 1rem;
}

.part-card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.part-card-meta {
  font-size: 0.8125rem;
  color: var(--c-muted);
  margin-bottom: 0.625rem;
}

.part-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.part-price {
  font-size: 1rem;
  font-weight: 700;
  color: var(--c-text);
}

.part-price-missing {
  font-size: 0.875rem;
  color: var(--c-muted);
  font-style: italic;
}

/* ---- Snabbskanning-overlay (kameraikonen i mobilnavigationen) --- */
.scan-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgb(15 23 42 / 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

/* Author-CSS med display:flex slår annars ut webbläsarens inbyggda
   [hidden] { display: none }, så overlayen skulle visas permanent
   oavsett hidden-attributet. Måste sättas explicit. */
.scan-overlay[hidden] {
  display: none;
}

@media (min-width: 480px) {
  .scan-overlay {
    align-items: center;
    padding: 1.5rem;
  }
}

.scan-overlay-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 210;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgb(255 255 255 / 0.9);
  color: var(--c-text);
  font-size: 1.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.scan-overlay-panel {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--c-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
}

@media (min-width: 480px) {
  .scan-overlay-panel {
    border-radius: var(--radius-lg);
  }
}

/* ---- Skanna-sida ------------------------------------------ */
.scan-preview-photo {
  display: block;
  width: 100%;
  max-height: 45vh;
  object-fit: contain;
  background: var(--c-bg);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.scan-result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .75rem;
  padding: .375rem 0;
  border-bottom: 1px solid var(--c-border);
}

.scan-result-row dt {
  flex-shrink: 0;
}

.scan-result-row dd {
  text-align: right;
  overflow-wrap: anywhere;
  min-width: 0;
}

/* ---- Bildgalleri (delvy) --------------------------------- */
.photo-grid {
  display: grid;
  gap: .75rem;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.photo-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-badge-primary {
  position: absolute;
  top: .375rem;
  left: .375rem;
  background: rgb(37 99 235 / 0.9);
  color: #fff;
  font-size: .6875rem;
  font-weight: 600;
  padding: .125rem .5rem;
  border-radius: 9999px;
}

.photo-item-actions {
  position: absolute;
  bottom: 0;
  right: 0;
  display: flex;
  gap: .125rem;
  padding: .25rem;
  background: linear-gradient(to top, rgb(0 0 0 / .35), transparent);
  width: 100%;
  justify-content: flex-end;
}

.photo-item-actions form { display: contents; }
.photo-item-actions .btn { background: rgb(255 255 255 / .9); }

/* ---- Badges --------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1875rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.badge-high    { background: #dcfce7; color: #15803d; }
.badge-medium  { background: #fef3c7; color: #b45309; }
.badge-low     { background: #fee2e2; color: #b91c1c; }
.badge-private { background: #f1f5f9; color: var(--c-muted); }
.badge-org     { background: #ede9fe; color: #6d28d9; }
.badge-public  { background: #dbeafe; color: #1d4ed8; }
.badge-sold    { background: #f1f5f9; color: var(--c-muted); text-decoration: line-through; }

/* ---- Flash-meddelanden ---------------------------------- */
.flash {
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
}

/* Samma sak som .scan-overlay: display:flex slår annars ut [hidden]. */
.flash[hidden] {
  display: none;
}

.flash-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.flash-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.flash-info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ---- Sektionsrubriker ----------------------------------- */
.page-header {
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.page-subtitle {
  font-size: 0.9375rem;
  color: var(--c-muted);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
}

/* ---- Sökfält + filter ----------------------------------- */
.search-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.search-bar input[type="search"] {
  flex: 1;
  min-width: 200px;
}

/* ---- Tommt tillstånd ------------------------------------ */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--c-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  stroke: #cbd5e1;
  stroke-width: 1.25;
}

.empty-state h3 {
  color: var(--c-text);
  margin-bottom: 0.375rem;
}

.empty-state p {
  font-size: 0.9375rem;
  margin-bottom: 1.25rem;
}

/* ---- Avdelare ------------------------------------------- */
.divider {
  height: 1px;
  background: var(--c-border);
  margin: 1.25rem 0;
}

.text-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--c-muted);
  font-size: 0.875rem;
  margin: 1.25rem 0;
}
.text-divider::before,
.text-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--c-border);
}

/* ---- Spinner -------------------------------------------- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Tabell --------------------------------------------- */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

th {
  text-align: left;
  padding: 0.625rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--c-muted);
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}

td {
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--c-bg); }

/* ---- Hjälpklasser --------------------------------------- */
.text-sm    { font-size: 0.875rem; }
.text-xs    { font-size: 0.75rem; }
.text-muted { color: var(--c-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-bold  { font-weight: 700; }
.font-semi  { font-weight: 600; }

.flex       { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.items-center { align-items: center; }
.gap-1      { gap: 0.25rem; }
.gap-2      { gap: 0.5rem; }
.gap-3      { gap: 0.75rem; }
.gap-4      { gap: 1rem; }
.justify-between { justify-content: space-between; }

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
