:root {
  color-scheme: light;
  --ink: #16302d;
  --muted: #617774;
  --line: #dce7e5;
  --surface: #ffffff;
  --background: #f1f7f5;
  --brand: #0f766e;
  --brand-dark: #075f58;
  --brand-soft: #dff4ef;
  --warning: #9a5a00;
  --danger: #a23333;
  --shadow: 0 14px 34px rgba(16, 54, 49, .09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 95% 2%, rgba(22, 163, 146, .13), transparent 30rem),
    var(--background);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { touch-action: manipulation; }

.app-header {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: max(1rem, env(safe-area-inset-top)) 1rem 1rem;
  color: white;
  background: linear-gradient(125deg, #0b615a, #108579);
}

.app-header h1, .app-header p { margin: 0; }
.app-header h1 { font-size: 1.15rem; letter-spacing: .01em; }
.app-header p { margin-top: .1rem; color: #ccece7; font-size: .78rem; }
.app-header .icon-button { margin-left: auto; color: white; border-color: rgba(255,255,255,.35); }

.brand-mark {
  display: grid;
  width: 2.6rem;
  height: 2.6rem;
  place-items: center;
  border-radius: .8rem;
  color: var(--brand-dark);
  background: white;
  font-size: 1.08rem;
  font-weight: 800;
  box-shadow: 0 5px 16px rgba(0, 0, 0, .12);
}

main { width: min(100%, 48rem); margin: 0 auto; padding: 1rem; }

.scan-card, .state-panel {
  border: 1px solid rgba(204, 222, 219, .9);
  border-radius: 1.15rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.scan-card { padding: 1.15rem; }
.state-panel { margin-top: 1rem; padding: 1.15rem; min-height: 12rem; }

.section-title, .dialog-heading, .product-top, .store-heading, .batch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

h2 { margin: 0; font-size: 1.15rem; }
.eyebrow { margin: 0 0 .2rem; color: var(--brand); font-size: .68rem; font-weight: 800; letter-spacing: .12em; }
.hint { color: var(--muted); font-size: .87rem; line-height: 1.5; }

.badge {
  flex: none;
  padding: .32rem .58rem;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: .7rem;
  font-weight: 700;
}
.badge-muted { color: var(--muted); background: #edf2f1; }
.badge-error { color: var(--danger); background: #fae9e8; }

.reader {
  overflow: hidden;
  margin-top: 1rem;
  border: 2px solid var(--brand);
  border-radius: .9rem;
  background: #071b19;
}
.reader video { border-radius: .7rem; }
.reader img { display: none; }

.actions { display: flex; gap: .65rem; margin-top: 1rem; }
.primary-button, .secondary-button, .lookup-button {
  min-height: 2.85rem;
  border: 0;
  border-radius: .72rem;
  padding: .72rem 1rem;
  font-weight: 700;
  cursor: pointer;
}
.primary-button, .lookup-button { color: white; background: var(--brand); }
.primary-button:hover, .lookup-button:hover { background: var(--brand-dark); }
.secondary-button { color: var(--brand-dark); background: var(--brand-soft); }
.primary-button:disabled, .lookup-button:disabled { opacity: .6; cursor: wait; }
.full-width { width: 100%; }

.divider { display: flex; align-items: center; gap: .65rem; margin: 1rem 0; color: #7b908d; font-size: .72rem; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }

label { display: block; margin-bottom: .42rem; color: #38534f; font-size: .8rem; font-weight: 700; }
.input-row { display: flex; gap: .55rem; }
.name-input-wrap { position: relative; flex: 1; min-width: 0; }
input[type="text"], input[type="search"], input[type="password"] {
  width: 100%;
  min-width: 0;
  min-height: 2.9rem;
  border: 1px solid #bdcfcc;
  border-radius: .72rem;
  padding: .7rem .8rem;
  color: var(--ink);
  background: #fbfdfd;
  outline: none;
}
input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }
.name-search-hint { margin: .42rem 0 0; color: var(--muted); font-size: .72rem; }
.suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + .35rem);
  right: 0;
  left: 0;
  overflow: hidden;
  border: 1px solid #b9ceca;
  border-radius: .75rem;
  background: white;
  box-shadow: 0 15px 35px rgba(7, 55, 50, .18);
}
.suggestion {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: .7rem .8rem;
  color: var(--ink);
  background: white;
  text-align: left;
  cursor: pointer;
}
.suggestion:last-child { border-bottom: 0; }
.suggestion:hover, .suggestion:focus { background: var(--brand-soft); outline: none; }
.suggestion-name { display: block; font-size: .86rem; font-weight: 700; }
.suggestion-meta { display: block; margin-top: .18rem; color: var(--muted); font-size: .7rem; }

.empty-state, .loading-state, .message-state { padding: 1.35rem .5rem; text-align: center; }
.empty-state p, .loading-state p, .message-state p { color: var(--muted); line-height: 1.5; }
.empty-icon { margin: 0 auto .8rem; color: var(--brand); font-size: 2.4rem; }
.spinner { width: 2rem; height: 2rem; margin: 1rem auto; border: 3px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.result-summary { margin-bottom: 1rem; }
.result-summary p { margin: .25rem 0 0; color: var(--muted); font-size: .82rem; }
.product-card { border: 1px solid var(--line); border-radius: .9rem; overflow: hidden; }
.product-card + .product-card { margin-top: .9rem; }
.product-top { align-items: flex-start; padding: 1rem; background: linear-gradient(120deg, #f9fcfb, #edf8f5); }
.product-name { margin: 0; font-size: 1.06rem; }
.product-name-ar { margin: .25rem 0 0; color: #48615e; font-size: .94rem; }
.product-code { margin: .4rem 0 0; color: var(--muted); font-family: Consolas, monospace; font-size: .74rem; }
.quantity-block { flex: none; text-align: right; }
.quantity-value { display: block; color: var(--brand-dark); font-size: 1.55rem; font-weight: 800; }
.quantity-label { color: var(--muted); font-size: .67rem; text-transform: uppercase; }
.inactive { color: var(--warning); font-size: .72rem; font-weight: 700; }

.stores { padding: .35rem .85rem .85rem; }
.store { padding: .75rem .15rem; border-bottom: 1px solid var(--line); }
.store:last-child { border-bottom: 0; }
.store-heading h4 { margin: 0; font-size: .9rem; }
.store-heading span { color: var(--brand-dark); font-weight: 800; }
.store-ar { margin: .12rem 0 .55rem; color: var(--muted); font-size: .78rem; }
.batch-row { padding: .38rem .5rem; border-radius: .45rem; color: #526966; background: #f4f8f7; font-size: .73rem; }
.batch-row + .batch-row { margin-top: .28rem; }
.no-stock { padding: .85rem; color: var(--muted); text-align: center; font-size: .82rem; }

footer {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  width: min(100%, 48rem);
  margin: 0 auto;
  padding: .2rem 1.25rem max(1rem, env(safe-area-inset-bottom));
  color: #66807c;
  font-size: .67rem;
}

.icon-button {
  display: grid;
  width: 2.35rem;
  height: 2.35rem;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: .68rem;
  background: transparent;
  cursor: pointer;
}

dialog { width: min(calc(100% - 2rem), 25rem); border: 0; border-radius: 1rem; padding: 1.2rem; color: var(--ink); box-shadow: 0 30px 70px rgba(7, 44, 40, .3); }
dialog::backdrop { background: rgba(5, 35, 32, .58); backdrop-filter: blur(2px); }
dialog input[type="password"] { margin-bottom: .8rem; }
.checkbox-row { display: flex; align-items: center; gap: .5rem; margin: 0 0 1rem; font-weight: 500; }
.checkbox-row input { width: 1rem; height: 1rem; accent-color: var(--brand); }
.form-error { color: var(--danger); font-size: .78rem; }

[hidden] { display: none !important; }

@media (min-width: 42rem) {
  main { padding-top: 1.5rem; }
  .scan-card, .state-panel { padding: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; }
}
