/* JK Nimbahera Store IMS — mobile-first, industrial palette */

:root {
  --paper: #f6f4ef;
  --paper-2: #ede9de;
  --paper-3: #e3ddcd;
  --ink: #1a2332;
  --ink-2: #2d3944;
  --ink-3: #556270;
  --rule: #d9d3c6;
  --rule-2: #c6bfb0;
  --rust: #b8562f;
  --rust-soft: #e9c9b8;
  --steel: #3d5a7a;
  --steel-soft: #c9d3df;
  --good: #4a7c59;
  --good-soft: #d5e5d9;
  --warn: #c99742;
  --warn-soft: #f0e0c1;
  --crit: #a94436;
  --crit-soft: #efc9c3;
  --shadow-sm: 0 1px 2px rgba(26,35,50,0.06);
  --shadow-md: 0 2px 8px rgba(26,35,50,0.08), 0 1px 2px rgba(26,35,50,0.05);
  --radius: 6px;
  --radius-lg: 10px;
}

html[data-theme="night"] {
  --paper: #14181d;
  --paper-2: #1b2028;
  --paper-3: #232a34;
  --ink: #ece7db;
  --ink-2: #cfc9bb;
  --ink-3: #8b8778;
  --rule: #2a3038;
  --rule-2: #3b4250;
  --rust: #e07a4b;
  --rust-soft: #4a2a1e;
  --steel: #8ab0d1;
  --steel-soft: #253242;
  --good: #7cb389;
  --good-soft: #1e3025;
  --warn: #d9b06a;
  --warn-soft: #3a2f1c;
  --crit: #d67466;
  --crit-soft: #3b2321;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 2px 10px rgba(0,0,0,0.5), 0 1px 3px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--paper);
  color: var(--ink-2);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background-color 240ms ease, color 240ms ease;
}

/* ------------ Header ------------ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  background: var(--rust); color: #fff;
  font-family: Georgia, serif; font-weight: 700; font-size: 16px;
  border-radius: 4px;
  letter-spacing: -0.02em;
}
.brand-name {
  font-family: Georgia, serif;
  font-size: 15px;
  color: var(--ink);
  letter-spacing: -0.004em;
  line-height: 1.15;
}
.brand-sub {
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  margin-top: 1px;
}
.theme-btn {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  color: var(--ink-2);
  width: 40px; height: 40px;
  border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 180ms ease, color 180ms ease;
}
.theme-btn:hover { background: var(--paper-3); }
.theme-btn .ico-moon { display: none; }
html[data-theme="night"] .theme-btn .ico-sun { display: none; }
html[data-theme="night"] .theme-btn .ico-moon { display: block; }

/* ------------ Stage / views ------------ */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 20px 40px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}
.view { display: none; animation: fade 200ms ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ------------ Landing ------------ */
.landing-inner { padding-top: 32px; }
.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--rust);
  margin-bottom: 12px;
}
.landing-title {
  font-family: Georgia, serif;
  font-weight: 400;
  font-size: clamp(30px, 8vw, 40px);
  line-height: 1.1;
  color: var(--ink);
  margin: 0 0 14px;
  letter-spacing: -0.014em;
  text-wrap: balance;
}
.landing-lede {
  font-size: 15px;
  color: var(--ink-3);
  margin: 0 0 32px;
  max-width: 32em;
}

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%;
  padding: 18px 24px;
  background: var(--rust); color: #fff;
  border: none; border-radius: var(--radius-lg);
  font-size: 17px; font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 100ms ease, filter 180ms ease;
  min-height: 60px;
}
.btn-primary:active { transform: translateY(1px); filter: brightness(0.95); }
.btn-primary svg { flex-shrink: 0; }

.or {
  text-align: center;
  margin: 20px 0 12px;
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.manual { display: flex; gap: 8px; }
.manual input {
  flex: 1;
  padding: 14px 16px;
  border: 1px solid var(--rule);
  background: var(--paper-2);
  color: var(--ink);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
}
.manual input:focus { outline: 2px solid var(--rust); outline-offset: 1px; border-color: var(--rust); }
.manual button {
  padding: 0 22px;
  background: var(--ink); color: var(--paper);
  border: none; border-radius: var(--radius);
  font-weight: 600; cursor: pointer; font-size: 15px;
}

.recent { margin-top: 28px; }
.recent-label {
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 600; margin-bottom: 8px;
}
.recent-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.recent-list li {
  padding: 12px 14px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
  font-size: 14px;
}
.recent-list li:hover { border-color: var(--rust-soft); }
.recent-list .r-id { font-family: "SF Mono", Menlo, monospace; color: var(--rust); font-size: 13px; }
.recent-list .r-name { color: var(--ink); flex: 1; margin: 0 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-list .r-when { color: var(--ink-3); font-size: 12px; }

/* ------------ Scanner ------------ */
.scanner-shell {
  position: relative;
  aspect-ratio: 4 / 5;
  max-height: 70vh;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
  margin-bottom: 20px;
}
.reader, .reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
.reader { position: absolute; inset: 0; }
.reader__scan_region { padding: 0 !important; background: #000 !important; }
.reader__dashboard { display: none !important; }

.viewfinder {
  position: absolute; inset: 12%;
  pointer-events: none;
}
.vf {
  position: absolute; width: 34px; height: 34px;
  border: 3px solid var(--rust);
}
.vf.tl { top: 0; left: 0; border-right: none; border-bottom: none; border-top-left-radius: 4px; }
.vf.tr { top: 0; right: 0; border-left: none; border-bottom: none; border-top-right-radius: 4px; }
.vf.bl { bottom: 0; left: 0; border-right: none; border-top: none; border-bottom-left-radius: 4px; }
.vf.br { bottom: 0; right: 0; border-left: none; border-top: none; border-bottom-right-radius: 4px; }
.scanner-hint {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  padding: 6px 14px;
  background: rgba(0,0,0,0.6); color: #fff;
  font-size: 12px; letter-spacing: 0.06em;
  border-radius: 999px;
}
.scanner-controls { text-align: center; }

/* ------------ Loading ------------ */
.loading { text-align: center; padding: 80px 20px; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--rule);
  border-top-color: var(--rust);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--ink-3); font-size: 14px; }

/* ------------ Item detail ------------ */
.item { animation: fade 260ms ease; }
.item-topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.btn-back {
  background: transparent; border: none;
  color: var(--ink-2); font-size: 14px;
  display: inline-flex; align-items: center; gap: 4px;
  cursor: pointer;
  padding: 6px 10px 6px 4px;
  border-radius: 6px;
}
.btn-back:hover { color: var(--rust); }
.btn-ghost {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  color: var(--ink-2);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 14px; cursor: pointer;
  transition: background 180ms ease;
}
.btn-ghost:hover { background: var(--paper-3); border-color: var(--rule-2); }
.btn-ghost.btn-inline { padding: 8px 14px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }

.card {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.summary-card { padding: 22px; }

.tag-strip {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.tag-id {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--rust);
  letter-spacing: 0.04em;
  font-weight: 600;
}
.tag-type {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  border: 1px solid var(--rule-2);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.part-name {
  font-family: Georgia, serif;
  font-weight: 400;
  font-size: clamp(22px, 4.8vw, 26px);
  line-height: 1.2;
  color: var(--ink);
  margin: 0 0 6px;
  letter-spacing: -0.006em;
  text-wrap: balance;
}
.part-sub {
  font-size: 13px;
  color: var(--ink-3);
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
}
.part-sub .mono {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--ink-2);
}
.dot-sep { color: var(--rule-2); }

.qty-row {
  display: flex; align-items: baseline; gap: 20px;
  margin: 20px 0 18px;
  padding: 16px 0 4px;
  border-top: 1px solid var(--rule);
}
.qty-block { display: flex; align-items: baseline; gap: 6px; }
.qty-num {
  font-family: Georgia, serif;
  font-size: 44px;
  color: var(--ink);
  font-feature-settings: "tnum";
  line-height: 1;
}
.qty-uom {
  font-size: 14px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}
.qty-meta { flex: 1; font-size: 13px; }
.qty-meta-row { color: var(--ink-2); font-weight: 500; }
.qty-total { color: var(--ink-3); font-size: 12.5px; margin-top: 4px; }
.qty-total span { color: var(--ink); font-weight: 600; font-feature-settings: "tnum"; }

.pill-row {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 18px;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  border: 1px solid;
  background: var(--paper);
}
.pill.good { color: var(--good); border-color: var(--good); background: var(--good-soft); }
.pill.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.pill.crit { color: var(--crit); border-color: var(--crit); background: var(--crit-soft); }
.pill.rust { color: var(--rust); border-color: var(--rust); background: var(--rust-soft); }
.pill.neutral { color: var(--ink-2); border-color: var(--rule-2); background: var(--paper); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.loc-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--ink-3);
}
.loc-row svg { color: var(--rust); flex-shrink: 0; }
.loc-text { flex: 1; }
.loc-label {
  font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 600;
}
.loc-value {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 15px; color: var(--ink); font-weight: 600;
  margin-top: 2px;
}

.btn-toggle {
  width: 100%;
  padding: 14px 18px;
  background: transparent;
  border: 1px dashed var(--rule-2);
  color: var(--ink-2);
  border-radius: var(--radius);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-bottom: 14px;
  transition: background 180ms ease, border-color 180ms ease;
}
.btn-toggle:hover { border-color: var(--rust); color: var(--rust); background: var(--rust-soft); }
.btn-toggle .chev { transition: transform 220ms ease; }
.btn-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.btn-toggle[aria-expanded="true"] { border-style: solid; color: var(--rust); border-color: var(--rust); }

.details { display: flex; flex-direction: column; gap: 14px; animation: fade 260ms ease; }
.section-title {
  font-family: Georgia, serif;
  font-weight: 400;
  font-size: 17px;
  color: var(--ink);
  margin: 0 0 12px;
  display: flex; align-items: baseline; gap: 8px;
}
.count-badge {
  font-family: -apple-system, sans-serif;
  font-size: 11px;
  background: var(--rust-soft); color: var(--rust);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-feature-settings: "tnum";
}

.kv { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 8px 16px; margin: 0; }
.kv dt {
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
}
.kv dd { margin: 0; font-size: 14px; color: var(--ink); font-feature-settings: "tnum"; }
.kv dd.mono { font-family: "SF Mono", Menlo, monospace; font-size: 13px; }

.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px;
  width: 1px; background: var(--rule);
}
.timeline li {
  position: relative; padding-left: 26px; padding-bottom: 16px;
  font-size: 13.5px;
}
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: 3px; top: 5px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--paper-2); border: 2px solid var(--rust);
}
.timeline li.audit_scan::before { border-color: var(--steel); }
.timeline li.issue::before { border-color: var(--warn); }
.timeline .t-kind {
  font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--rust); font-weight: 600; margin-bottom: 2px;
}
.timeline li.audit_scan .t-kind { color: var(--steel); }
.timeline li.issue .t-kind { color: var(--warn); }
.timeline .t-when { color: var(--ink-3); font-size: 12px; font-feature-settings: "tnum"; }
.timeline .t-note { color: var(--ink-2); margin-top: 2px; }
.timeline .t-actor { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.timeline .t-actor::before { content: "· "; }

/* ------------ Error ------------ */
.error-panel {
  text-align: center;
  padding: 60px 20px;
  max-width: 380px;
  margin: 0 auto;
}
.error-icon {
  color: var(--crit);
  margin-bottom: 16px;
}
.error-title {
  font-family: Georgia, serif;
  font-size: 22px;
  color: var(--ink);
  margin-bottom: 6px;
}
.error-body {
  color: var(--ink-3);
  font-size: 14px;
  margin-bottom: 24px;
}
.error-actions { display: flex; flex-direction: column; gap: 10px; }

/* ------------ Footer ------------ */
.app-footer {
  padding: 16px 20px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 11px;
  color: var(--ink-3);
  border-top: 1px solid var(--rule);
  letter-spacing: 0.06em;
}

/* ------------ Motion ------------ */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
