/* =====================================================================
   MagazynSerwis — motyw "MORO" (kamuflaż militarny), mobile-first
   ===================================================================== */
:root {
  --moro-900: #191d13;
  --moro-800: #23281c;
  --moro-700: #2e3423;
  --moro-600: #3f4a2d;
  --moro-500: #55603a;
  --moro-400: #6f7a4a;
  --khaki: #8a8663;
  --sand: #b9ac86;
  --brown: #6b5433;
  --accent: #b3c14a;
  --accent-2: #d5c93f;
  --danger: #b5533f;
  --danger-2: #d4694f;
  --warning: #d0a23c;
  --ok: #7fa04a;
  --text: #e8e6d5;
  --text-dim: #a9a68c;
  --line: rgba(179, 193, 74, 0.22);
  --panel: rgba(35, 40, 28, 0.86);
  --panel-2: rgba(46, 52, 35, 0.92);
  --radius: 14px;
  --radius-sm: 9px;
  --nav-h: 62px;
  --top-h: 54px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, "Roboto", sans-serif;
  color: var(--text);
  background-color: var(--moro-800);
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

/* --- kamuflażowe tło --- */
body::before {
  content: "";
  position: fixed;
  inset: -10%;
  z-index: -2;
  background-color: #2a3021;
  background-image:
    radial-gradient(ellipse 22% 15% at 12% 18%, var(--moro-500) 0%, transparent 70%),
    radial-gradient(ellipse 18% 13% at 38% 7%, #343b26 0%, transparent 70%),
    radial-gradient(ellipse 26% 17% at 72% 15%, #4a5432 0%, transparent 72%),
    radial-gradient(ellipse 20% 14% at 92% 30%, var(--moro-600) 0%, transparent 70%),
    radial-gradient(ellipse 24% 16% at 20% 52%, #3a4429 0%, transparent 72%),
    radial-gradient(ellipse 17% 12% at 55% 40%, var(--brown) 0%, transparent 68%),
    radial-gradient(ellipse 22% 15% at 85% 62%, var(--moro-500) 0%, transparent 72%),
    radial-gradient(ellipse 19% 13% at 8% 78%, #5c6440 0%, transparent 70%),
    radial-gradient(ellipse 25% 17% at 45% 88%, var(--moro-600) 0%, transparent 72%),
    radial-gradient(ellipse 18% 12% at 78% 95%, #3d472b 0%, transparent 70%);
  filter: blur(0.5px) saturate(0.9);
  opacity: 0.92;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(15, 18, 10, 0.72) 0%, rgba(15, 18, 10, 0.62) 45%, rgba(15, 18, 10, 0.82) 100%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.06) 0 2px, transparent 2px 4px);
}

.hidden { display: none !important; }

/* ============================ LOGOWANIE ============================ */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 26px 22px 22px;
  text-align: center;
  backdrop-filter: blur(6px);
}
.login-logo {
  width: 78px; height: 78px;
  margin: 0 auto 10px;
  display: grid; place-items: center;
  background: rgba(20, 24, 14, 0.7);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.login-card h1 { margin: 4px 0 2px; font-size: 26px; letter-spacing: 1px; text-transform: uppercase; }
.login-card h1 span { color: var(--accent); }
.login-sub { margin: 0 0 20px; color: var(--text-dim); font-size: 13px; }
.login-hint { margin: 16px 0 0; font-size: 12px; color: var(--text-dim); }
.login-error { color: var(--danger-2); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* ============================ FORMULARZE ============================ */
.field { display: block; text-align: left; margin-bottom: 13px; }
.field > span {
  display: block; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--text-dim); margin-bottom: 5px;
}
input, select, textarea {
  width: 100%;
  padding: 12px 13px;
  font-size: 16px; /* iOS: brak auto-zoom */
  font-family: inherit;
  color: var(--text);
  background: rgba(18, 22, 13, 0.85);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(179, 193, 74, 0.16);
}
textarea { min-height: 78px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(135deg, var(--accent) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
input[type="date"], input[type="datetime-local"] { color-scheme: dark; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 12px 16px;
  font-size: 15px; font-weight: 600; font-family: inherit;
  color: var(--text);
  background: var(--moro-600);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(180deg, var(--accent) 0%, #8d9a34 100%); color: #1c2010; border-color: #c3d05c; }
.btn-danger { background: linear-gradient(180deg, var(--danger-2), #96412f); border-color: #d4694f; }
.btn-ghost { background: rgba(20, 24, 14, 0.6); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn:disabled { opacity: .55; pointer-events: none; }

/* ============================== APP ============================== */
.app { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + var(--safe-b) + 10px); }

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--top-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  background: rgba(25, 29, 19, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.topbar-brand { display: flex; align-items: center; gap: 8px; font-size: 17px; letter-spacing: .6px; text-transform: uppercase; }
.topbar-brand b { color: var(--accent); font-weight: 700; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 18px; color: var(--text);
  background: rgba(20, 24, 14, 0.65);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }

.view-root { padding: 12px; max-width: 900px; margin: 0 auto; }

/* ========================== NAWIGACJA DOLNA ========================== */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(25, 29, 19, 0.97);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; cursor: pointer;
  color: var(--text-dim); font-family: inherit; font-size: 10px;
  padding: 6px 2px;
}
.nav-btn .nav-ico { font-size: 19px; line-height: 1; filter: grayscale(.35); }
.nav-btn.active { color: var(--accent); }
.nav-btn.active .nav-ico { filter: none; }
.nav-btn.active::before { content: ""; position: absolute; }
.nav-label { letter-spacing: .2px; }

/* ============================== KARTY ============================== */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 4px 2px 10px;
}
.section-title { font-size: 15px; text-transform: uppercase; letter-spacing: .8px; color: var(--accent); margin: 0; }
.section-sub { font-size: 12px; color: var(--text-dim); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  margin-bottom: 10px;
}
.card-head { display: flex; gap: 10px; align-items: flex-start; }
.card-title { font-weight: 700; font-size: 15px; margin: 0 0 2px; }
.card-meta { font-size: 12px; color: var(--text-dim); }
.row { display: flex; gap: 8px; align-items: center; }
.row-between { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.mt { margin-top: 10px; }
.mb { margin-bottom: 10px; }

.thumb {
  width: 58px; height: 58px; flex: 0 0 58px;
  border-radius: 10px; object-fit: cover;
  border: 1px solid var(--line);
  background: rgba(18, 22, 13, .8);
  display: grid; place-items: center; font-size: 22px; color: var(--khaki);
}

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .3px;
  background: rgba(179, 193, 74, .16); color: var(--accent);
  border: 1px solid var(--line);
}
.badge-warn { background: rgba(208, 162, 60, .18); color: var(--warning); }
.badge-danger { background: rgba(181, 83, 63, .2); color: var(--danger-2); }
.badge-ok { background: rgba(127, 160, 74, .18); color: var(--ok); }
.badge-dim { background: rgba(169, 166, 140, .12); color: var(--text-dim); }

.qty { font-size: 20px; font-weight: 800; color: var(--accent); line-height: 1; }
.qty small { font-size: 11px; color: var(--text-dim); font-weight: 500; }
.qty-low { color: var(--danger-2); }

.usage-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 9px; }
.usage-cell {
  background: rgba(18, 22, 13, .6);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 4px; text-align: center;
}
.usage-cell b { display: block; font-size: 15px; color: var(--accent-2); }
.usage-cell span { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }

.searchbar { display: flex; gap: 8px; margin-bottom: 10px; position: sticky; top: var(--top-h); z-index: 30; padding: 6px 0; background: linear-gradient(180deg, rgba(25,29,19,.95) 60%, rgba(25,29,19,0)); }
.searchbar input { flex: 1; }
.scan-btn { width: 48px; flex: 0 0 48px; font-size: 21px; padding: 0; }
.add-part-btn { margin-bottom: 14px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 7px 12px; font-size: 12.5px; white-space: nowrap;
  background: rgba(20, 24, 14, .7); border: 1px solid var(--line);
  border-radius: 999px; color: var(--text-dim); cursor: pointer; font-family: inherit;
}
.chip.active { background: rgba(179, 193, 74, .18); color: var(--accent); border-color: var(--accent); }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-tile {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 11px;
}
.stat-tile b { display: block; font-size: 22px; color: var(--accent); line-height: 1.1; }
.stat-tile span { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); }

.chart-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 12px; }
.chart-box h3 { margin: 2px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent); }
/* Na telefonie wykresy są niskie, żeby nie trzeba było przewijać ekranu w kółko;
   na większych ekranach mogą być wyższe. */
.chart-canvas-wrap { position: relative; height: 150px; }

.empty { text-align: center; padding: 34px 16px; color: var(--text-dim); }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; opacity: .7; }

/* ======================== LISTY / AKORDEONY ======================== */
.acc-item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 9px; overflow: hidden; }
.acc-head { display: flex; align-items: center; gap: 10px; padding: 12px; cursor: pointer; }
.acc-head .caret { margin-left: auto; color: var(--accent); transition: transform .2s; }
.acc-item.open .caret { transform: rotate(90deg); }
.acc-body { display: none; padding: 0 12px 12px; border-top: 1px dashed var(--line); }
.acc-item.open .acc-body { display: block; }

.repair {
  background: rgba(18, 22, 13, .55);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 9px 10px; margin-top: 9px;
}
.repair h4 { margin: 0 0 4px; font-size: 13.5px; color: var(--accent-2); }
.repair .muted { font-size: 12px; color: var(--text-dim); }
.parts-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.part-pill { font-size: 11.5px; padding: 3px 8px; border-radius: 999px; background: rgba(179,193,74,.12); border: 1px solid var(--line); color: var(--text); }

.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(179,193,74,.1); font-size: 13.5px; }
.list-plain li:last-child { border-bottom: 0; }

/* ============================ PANEL ADMINA ============================ */
.tabs { display: flex; gap: 4px; background: rgba(18,22,13,.7); border: 1px solid var(--line); border-radius: 11px; padding: 4px; margin-bottom: 12px; overflow-x: auto; }
.tab { flex: 1 0 auto; padding: 9px 12px; font-size: 13px; border-radius: 8px; background: none; border: 0; color: var(--text-dim); cursor: pointer; font-family: inherit; white-space: nowrap; }
.tab.active { background: var(--moro-500); color: var(--text); }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid rgba(179,193,74,.12); }
.data-table th { font-size: 11px; text-transform: uppercase; color: var(--text-dim); letter-spacing: .4px; }
.table-scroll { overflow-x: auto; }

/* ============================== DRAWER ============================== */
.drawer-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(10, 12, 6, .6); }
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(300px, 84vw);
  background: var(--panel-2);
  border-left: 1px solid var(--line);
  padding: 16px 12px calc(16px + var(--safe-b));
  display: flex; flex-direction: column; gap: 4px;
  animation: slideIn .18s ease-out;
  overflow-y: auto;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: none; } }
.drawer-user { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--moro-500); color: var(--accent); font-weight: 700; font-size: 18px; }
.drawer-item { text-align: left; padding: 12px 10px; font-size: 14.5px; font-family: inherit; color: var(--text); background: none; border: 0; border-radius: var(--radius-sm); cursor: pointer; }
.drawer-item:active, .drawer-item.active { background: rgba(179,193,74,.12); }
.drawer-item.danger { color: var(--danger-2); }
.drawer-sep { height: 1px; background: var(--line); margin: 8px 0; }
.drawer-version { margin-top: auto; text-align: center; font-size: 11px; color: var(--text-dim); padding-top: 12px; }

/* ============================== MODAL ============================== */
.modal-root { position: fixed; inset: 0; z-index: 70; display: flex; align-items: flex-end; justify-content: center; background: rgba(10, 12, 6, .66); }
.modal-sheet {
  width: 100%; max-width: 620px;
  max-height: 92dvh; overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--line); border-bottom: 0;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(20px + var(--safe-b));
  animation: sheetUp .2s ease-out;
}
@keyframes sheetUp { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 17px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent); }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.form-grid .full { grid-column: 1 / -1; }

/* ============================== SKANER ============================== */
.scanner-modal { position: fixed; inset: 0; z-index: 80; background: rgba(6, 8, 4, .93); display: flex; align-items: center; justify-content: center; padding: 14px; }
.scanner-frame { width: 100%; max-width: 460px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.scanner-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.scanner-reader { width: 100%; min-height: 240px; background: #000; }
.scanner-reader video { width: 100% !important; height: auto !important; }
.scanner-hint { text-align: center; font-size: 13px; color: var(--text-dim); padding: 10px 14px 0; margin: 0; }
.scanner-note { margin: 12px 14px 0; padding: 12px 14px; font-size: 13px; line-height: 1.5; color: var(--text); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; background: var(--panel); }
.scanner-manual { display: flex; gap: 8px; padding: 12px 14px 16px; }
.scanner-manual + .scanner-manual { padding-top: 0; }
.section-actions { display: flex; align-items: center; gap: 8px; }
.scanner-manual input { flex: 1; }
/* Podgląd do odczytu numeru seryjnego: prowadnica pokazuje, który pas obrazu czyta OCR. */
.ocr-stage { position: relative; background: #000; aspect-ratio: 3 / 4; max-height: 62vh; overflow: hidden; }
/* Kadr o proporcji zbliżonej do aparatu: cała klatka jest widoczna, więc ramka
   prowadząca pokrywa się z obszarem, który naprawdę czyta OCR. */
.ocr-stage video { display: block; width: 100%; height: 100%; object-fit: cover; }
.ocr-guide { position: absolute; left: 6%; right: 6%; top: 32%; height: 36%; border: 2px solid var(--accent); border-radius: 10px; box-shadow: 0 0 0 100vmax rgba(6, 8, 4, .35); }
/* Pasek „to widzi czytnik”: ten sam obraz, który trafia do OCR. Pozwala od razu
   zobaczyć, czy numer jest w ramce i czy jest ostry. */
.ocr-preview { display: flex; align-items: center; gap: 8px; padding: 8px 14px 0; }
.ocr-preview-label { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.ocr-preview canvas { height: 34px; width: auto; max-width: 60%; border: 1px solid var(--line); border-radius: 4px; background: #000; }
.ocr-diag { margin: 6px 14px 0; font-size: 11px; line-height: 1.4; color: var(--text-dim); word-break: break-word; }

/* Wyniki wyszukiwania po zdjęciu */
.photo-results { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 8px; max-height: 44vh; overflow-y: auto; }
.photo-info { margin: 0; font-size: 13px; line-height: 1.5; color: var(--text-dim); }
.photo-match { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; color: var(--text); }
.photo-match img { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; }
.photo-match-body { flex: 1; min-width: 0; }
.photo-match-body b { display: block; font-size: 14px; }
.photo-match-body small { color: var(--text-dim); font-size: 12px; }
.photo-match-score { font-weight: 700; color: var(--accent); flex: 0 0 auto; }

/* ============================== TOAST ============================== */
.toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b) + 12px); z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  max-width: 90%; padding: 11px 16px;
  background: rgba(25, 29, 19, .97);
  border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 11px; box-shadow: var(--shadow);
  font-size: 13.5px; animation: toastIn .18s ease-out;
}
.toast.err { border-left-color: var(--danger-2); }
.toast.warn { border-left-color: var(--warning); }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

.spinner { width: 22px; height: 22px; border: 3px solid rgba(179,193,74,.25); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 26px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.admin-only.hidden { display: none !important; }

@media (min-width: 620px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr 1fr; }
  .chart-canvas-wrap { height: 210px; }
}

/* Zdjęcie w formularzu części — podgląd przed zapisem */
.photo-field { display: flex; flex-direction: column; gap: 8px; }
.photo-field .hint { color: var(--text-dim); font-size: 12px; line-height: 1.4; }
.photo-preview { display: flex; align-items: center; justify-content: center; }
.photo-preview img { width: 100%; max-width: 240px; max-height: 180px; object-fit: contain;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }

/* Wynik wyszukiwania po zdjęciu, który jest tylko podpowiedzią */
.photo-match.hint { border-style: dashed; }
.photo-match.hint .photo-match-score { color: var(--text-dim); }
