:root {
  color-scheme: light;
  --navy: #123a52;
  --navy-2: #0b2a3c;
  --blue: #176d89;
  --teal: #248a88;
  --coral: #e66d4f;
  --sand: #f4eee4;
  --paper: #fffdf9;
  --line: #dce3e3;
  --muted: #68767c;
  --green: #2d7d57;
  --red: #a6413b;
  --shadow: 0 12px 30px rgba(18, 58, 82, 0.10);
}

* { box-sizing: border-box; }
html { background: var(--sand); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--navy-2);
  background: var(--sand);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 4px; color: var(--teal); font-size: 11px; font-weight: 800; letter-spacing: .13em; }
.muted { color: var(--muted); }
.offline-banner { position: fixed; z-index: 50; top: 0; left: 0; right: 0; padding: 8px 14px; background: #9d4c28; color: white; text-align: center; font-size: 12px; }

.login-screen {
  min-height: 100vh;
  max-width: 520px;
  margin: 0 auto;
  padding: max(54px, env(safe-area-inset-top)) 24px 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.brand-logo { width: 92px; height: 92px; display: block; margin-bottom: 28px; border-radius: 22px; box-shadow: 7px 7px 0 var(--coral); object-fit: cover; }
.login-screen h1 { max-width: 420px; margin: 8px 0 12px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(39px, 10vw, 58px); font-weight: 500; line-height: .96; letter-spacing: -.04em; }
.login-copy { max-width: 430px; color: #51636a; line-height: 1.55; }
.login-card { margin-top: 28px; padding: 20px; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow); }
label { display: block; margin: 0 0 7px; color: #506169; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 48px; border: 1px solid #bdc9ca; border-radius: 8px; background: white; color: var(--navy-2); padding: 10px 12px; outline: none; }
textarea { min-height: 86px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 109, 137, .13); }
#pin { margin-bottom: 12px; font-size: 26px; letter-spacing: .28em; text-align: center; }
.privacy-note { color: var(--muted); font-size: 12px; text-align: center; }
.designer-credit { margin: 8px 0 0; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: 13px; font-style: italic; text-align: center; }
.form-error { min-height: 18px; margin: 10px 0 0; color: var(--red); font-size: 13px; }

.primary, .secondary, .danger { min-height: 44px; border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 800; }
.primary { background: var(--navy); color: white; }
.primary:active { background: var(--navy-2); }
.secondary { border: 1px solid #b9c8ca; background: white; color: var(--navy); }
.danger { border: 1px solid #e5b9b6; background: #fff4f3; color: var(--red); }
.full { width: 100%; }

.app-shell { min-height: 100vh; max-width: 840px; margin: 0 auto; padding-bottom: calc(82px + env(safe-area-inset-bottom)); background: #f7f8f5; }
.topbar { position: sticky; z-index: 20; top: 0; min-height: 76px; display: flex; align-items: center; justify-content: space-between; padding: max(14px, env(safe-area-inset-top)) 18px 12px; color: white; background: var(--navy); box-shadow: 0 2px 12px rgba(11,42,60,.18); }
.topbar .eyebrow { color: #a9ded3; }
.topbar h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 24px; font-weight: 500; }
.topbar-brand { min-width: 0; display: flex; align-items: center; gap: 11px; }
.topbar-logo { width: 46px; height: 46px; flex: 0 0 46px; border-radius: 11px; object-fit: cover; box-shadow: 0 3px 10px rgba(0,0,0,.18); }
.topbar-credit { display: block; margin-top: 2px; color: #b9d2d6; font-family: Georgia, "Times New Roman", serif; font-size: 10px; font-style: italic; letter-spacing: .02em; }
.icon-button { width: 42px; height: 42px; border: 1px solid rgba(255,255,255,.28); border-radius: 8px; background: rgba(255,255,255,.1); color: inherit; font-size: 25px; line-height: 1; }
main { padding: 15px; }
.view { display: none; }
.view.active { display: block; }
.stack > * + * { margin-top: 12px; }

.loading-card, .panel, .metric, .product-card, .count-card { background: var(--paper); border: 1px solid var(--line); box-shadow: 0 5px 18px rgba(18,58,82,.06); }
.loading-card { padding: 26px; text-align: center; color: var(--muted); }
.hero-summary { position: relative; overflow: hidden; padding: 22px; background: var(--navy-2); color: white; box-shadow: var(--shadow); }
.hero-summary::after { content: ""; position: absolute; right: -34px; bottom: -42px; width: 150px; height: 150px; border: 24px solid rgba(169,222,211,.16); border-radius: 50%; }
.hero-summary p { color: #b9d2d6; margin: 0 0 8px; }
.hero-summary strong { position: relative; z-index: 1; display: block; font-family: Georgia, "Times New Roman", serif; font-size: 35px; font-weight: 500; }
.hero-summary small { position: relative; z-index: 1; display: block; margin-top: 6px; color: #b9d2d6; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin: 10px 0; }
.metric { min-height: 112px; padding: 15px; }
.metric.wide { grid-column: 1 / -1; }
.metric span { display: block; color: var(--muted); font-size: 12px; line-height: 1.25; }
.metric strong { display: block; margin-top: 9px; font-family: Georgia, "Times New Roman", serif; color: var(--navy); font-size: 24px; font-weight: 600; line-height: 1; }
.metric small { display: block; margin-top: 7px; color: var(--teal); font-size: 11px; font-weight: 700; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 2px 9px; }
.section-title h3 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 21px; font-weight: 600; }
.section-title small { color: var(--muted); }
.panel { padding: 14px; }
.rank-row, .alert-row, .distribution-row { display: grid; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid #e6ebea; }
.rank-row:last-child, .alert-row:last-child, .distribution-row:last-child { border-bottom: 0; }
.rank-row { grid-template-columns: 30px minmax(0,1fr) auto; }
.rank-number { width: 27px; height: 27px; display: grid; place-items: center; background: #e5f1ee; color: var(--teal); font-size: 12px; font-weight: 900; }
.row-name { min-width: 0; }
.row-name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.row-name small { color: var(--muted); }
.row-value { color: var(--navy); font-size: 12px; font-weight: 800; text-align: right; }
.alert-row { grid-template-columns: 7px minmax(0,1fr); }
.alert-dot { width: 7px; height: 34px; background: var(--coral); }
.alert-row strong, .alert-row small { display: block; }
.alert-row small { margin-top: 2px; color: var(--muted); }
.distribution-row { grid-template-columns: minmax(0,1fr) 110px; }
.bar { height: 7px; margin-top: 6px; background: #e5e9e8; }
.bar > span { display: block; height: 100%; background: var(--teal); }

.action-panel { margin-bottom: 14px; padding: 14px; background: #e7f0ed; border: 1px solid #cadbd7; }
.scan-button { width: 100%; display: flex; gap: 14px; align-items: center; margin-bottom: 12px; padding: 15px; border: 0; border-radius: 8px; background: var(--navy); color: white; text-align: left; }
.scan-glyph { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.35); font-size: 25px; }
.scan-button strong, .scan-button small { display: block; }
.scan-button small { margin-top: 3px; color: #b9d2d6; }
.search-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; }
.price-choice { width: 100%; display: block; padding: 14px; border: 1px solid var(--line); background: var(--paper); color: var(--navy-2); text-align: left; box-shadow: 0 5px 18px rgba(18,58,82,.06); }
.price-choice strong, .price-choice small { display: block; }
.price-choice small { margin-top: 5px; color: var(--muted); line-height: 1.35; }
.price-match-note strong, .price-match-note small { display: block; }
.price-match-note small { margin-top: 4px; color: var(--muted); }
.price-display { padding: 22px 16px 26px; border: 1px solid var(--line); background: var(--paper); text-align: center; box-shadow: var(--shadow); }
.price-product-meta { margin: -22px -16px 25px; padding: 15px 16px; background: var(--navy); color: white; text-align: left; }
.price-product-meta strong, .price-product-meta small { display: block; }
.price-product-meta strong { font-size: 15px; line-height: 1.35; }
.price-product-meta small { margin-top: 5px; color: #b9d2d6; font-size: 10px; line-height: 1.35; }
.price-display > span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .08em; }
.price-display-value { display: block; margin: 16px 0 13px; font-family: Georgia, "Times New Roman", serif; color: var(--navy); font-size: clamp(54px, 15vw, 88px); font-weight: 600; line-height: .95; letter-spacing: -.04em; }
.price-stock { display: block; color: var(--teal); font-size: 14px; font-weight: 800; }
.product-card { width: 100%; padding: 15px; color: inherit; text-align: left; }
button.product-card { border-radius: 0; }
.product-top { display: flex; justify-content: space-between; gap: 8px; }
.product-card h3 { margin: 4px 0 8px; font-size: 16px; line-height: 1.25; }
.code { color: var(--blue); font-size: 12px; font-weight: 800; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 7px; border: 1px solid #bdd8d3; border-radius: 4px; background: #eef8f5; color: var(--green); font-size: 10px; font-weight: 800; }
.price-strip { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 1px; margin: 12px -15px -15px; background: var(--line); border-top: 1px solid var(--line); }
.price-strip div { padding: 10px; background: #fbfcf9; }
.price-strip span, .price-strip strong { display: block; }
.price-strip span { color: var(--muted); font-size: 10px; }
.price-strip strong { margin-top: 3px; color: var(--navy); font-size: 12px; }
.detail-head { padding: 18px; background: var(--navy); color: white; }
.detail-head .code { color: #a9ded3; }
.detail-head h3 { margin: 5px 0; font-family: Georgia, "Times New Roman", serif; font-size: 24px; font-weight: 500; }
.detail-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1px; background: var(--line); }
.detail-grid div { min-height: 72px; padding: 12px; background: var(--paper); }
.detail-grid span, .detail-grid strong { display: block; }
.detail-grid span { color: var(--muted); font-size: 11px; }
.detail-grid strong { margin-top: 5px; font-size: 13px; overflow-wrap: anywhere; }
.price-facts { margin-bottom: 16px; border: 1px solid var(--line); }
.field input[readonly] { background: #eef4f3; color: var(--ink); font-weight: 700; }
.edit-form { padding: 15px; }
.edit-form .field { margin-bottom: 13px; }
.edit-form .two { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.edit-form .two .field { display: grid; grid-template-rows: minmax(40px,auto) auto; align-content: start; }
.edit-form .two .field > label { display: flex; align-items: flex-end; margin-bottom: 7px; }
.button-row { display: flex; gap: 8px; margin-top: 12px; }
.button-row > * { flex: 1; }

.count-card { padding: 16px; }
.count-card h3 { margin: 4px 0 6px; }
.count-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 13px; }
.count-stats { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; margin: 12px 0; }
.count-stats div { padding: 10px; background: #eff4f1; }
.count-stats span, .count-stats strong { display: block; }
.count-stats span { color: var(--muted); font-size: 10px; }
.count-stats strong { margin-top: 3px; }
.difference-positive { color: var(--green); }
.difference-negative { color: var(--red); }

.bottom-nav { position: fixed; z-index: 30; left: 50%; bottom: 0; width: min(100%,840px); transform: translateX(-50%); display: grid; grid-template-columns: repeat(4,1fr); padding: 6px 10px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid #d8dfde; background: rgba(255,253,249,.96); backdrop-filter: blur(12px); }
.nav-item { min-height: 56px; border: 0; border-radius: 8px; background: transparent; color: #6c7c80; }
.nav-item span, .nav-item small { display: block; }
.nav-item span { font-size: 22px; line-height: 1.1; }
.nav-item small { margin-top: 3px; font-weight: 700; }
.nav-item.active { background: #e7f0ed; color: var(--navy); }

dialog { color: var(--navy-2); }
.scanner-dialog, .sheet-dialog { width: min(calc(100% - 20px), 540px); padding: 0; border: 0; border-radius: 12px; background: var(--paper); box-shadow: 0 24px 80px rgba(0,0,0,.28); }
dialog::backdrop { background: rgba(9,29,40,.72); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; background: var(--navy); color: white; }
.dialog-head .eyebrow { color: #a9ded3; }
.dialog-head h3 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 21px; font-weight: 500; }
#reader { min-height: 270px; background: #071b27; }
.manual-barcode, .sheet-dialog form { padding: 16px; }
.sheet-dialog .dialog-head { margin: -16px -16px 16px; }
.quantity-input { height: 72px; margin: 12px 0; font-size: 34px; font-weight: 800; text-align: center; }
.toast { position: fixed; z-index: 80; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); transform: translate(-50%, 20px); padding: 11px 15px; border-radius: 8px; background: var(--navy-2); color: white; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.empty { padding: 28px 14px; color: var(--muted); text-align: center; }

@media (min-width: 700px) {
  .metric-grid { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .metric.wide { grid-column: span 2; }
  .dashboard-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .login-screen { padding-left: 36px; padding-right: 36px; }
}

@media (max-width: 390px) {
  .topbar { padding-left: 12px; padding-right: 12px; }
  .topbar-logo { width: 40px; height: 40px; flex-basis: 40px; border-radius: 9px; }
  .topbar h2 { font-size: 21px; }
  .topbar-credit { font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
