:root {
  --navy: #173f5f;
  --navy-2: #235b82;
  --ink: #17212b;
  --muted: #687685;
  --line: #dbe4eb;
  --surface: #ffffff;
  --background: #f3f6f8;
  --green: #2d8a60;
  --green-soft: #e2f2e9;
  --red: #b44747;
  --red-soft: #f8e4e4;
  --orange: #a5651b;
  --orange-soft: #fff0dd;
  --blue-soft: #e6f0f7;
  --shadow: 0 8px 24px rgba(23, 63, 95, 0.09);
  --radius: 18px;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--background);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--background); }
body { margin: 0; min-height: 100%; background: var(--background); }
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(35, 91, 130, 0.28); outline-offset: 2px; }
[hidden] { display: none !important; }

.network-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  text-align: center;
  color: #fff;
  background: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, 0.15), transparent 35%),
    linear-gradient(155deg, #173f5f, #0f2b43);
}
.login-card {
  width: min(100%, 430px);
  padding: 34px 28px 26px;
  border-radius: 26px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}
.login-card img { display: block; margin: 0 auto 18px; border-radius: 22px; }
.login-card h1 { margin: 2px 0 8px; text-align: center; font-size: 30px; }
.login-card > .eyebrow, .login-card > .muted { text-align: center; }
.login-card form { margin-top: 26px; }
.login-card label { display: grid; gap: 8px; font-weight: 700; }
.login-card input {
  width: 100%;
  height: 58px;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 0 16px;
  text-align: center;
  font-size: 26px;
  letter-spacing: 8px;
}
.login-card .button { margin-top: 16px; }
.prototype-label { margin: 24px 0 0; padding-top: 18px; border-top: 1px solid var(--line); text-align: center; color: var(--orange); font-size: 11px; font-weight: 800; letter-spacing: 0.08em; }
.form-error { min-height: 20px; margin: 12px 0 0; color: var(--red); text-align: center; font-size: 14px; }

.app-shell { min-height: 100vh; padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(76px + env(safe-area-inset-top));
  padding: calc(14px + env(safe-area-inset-top)) 18px 12px;
  color: #fff;
  background: rgba(23, 63, 95, 0.97);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.12);
}
.topbar h1 { margin: 2px 0 0; font-size: 23px; }
.topbar .eyebrow { color: #cfe0ec; }
.profile-button {
  width: 46px;
  height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 800;
}
.app-content { max-width: 860px; margin: 0 auto; padding: 18px 16px 32px; outline: none; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(12px);
}
.nav-item {
  min-height: 58px;
  border: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-weight: 700;
}
.nav-item span { font-size: 23px; line-height: 1; }
.nav-item.active { color: var(--navy); background: var(--blue-soft); }

h2 { margin: 0; font-size: 20px; }
p { line-height: 1.45; }
.eyebrow { margin: 0; color: var(--navy-2); font-size: 11px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
.muted { margin: 5px 0; color: var(--muted); }
.optional { color: var(--muted); font-size: 12px; font-weight: 400; }

.button {
  min-height: 48px;
  padding: 11px 17px;
  border: 1px solid transparent;
  border-radius: 13px;
  font-weight: 800;
  cursor: pointer;
}
.button:disabled { opacity: 0.55; cursor: wait; }
.button.full { width: 100%; }
.button.compact { min-height: 46px; white-space: nowrap; }
.button.primary { color: #fff; background: var(--navy); }
.button.secondary { color: var(--navy); border-color: #b9ccd9; background: #fff; }
.button.entry-button { color: #fff; background: var(--green); }
.button.withdrawal-button { color: #fff; background: var(--red); }
.button.danger-outline { color: var(--red); border-color: #e2b8b8; background: #fff; }
.icon-button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 13px; color: var(--navy); background: #fff; font-size: 22px; }
.text-button, .back-button { border: 0; color: var(--navy-2); background: transparent; font-weight: 800; }
.back-button { padding: 8px 2px 14px; font-size: 16px; }

.welcome-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 17px; }
.welcome-row h2 { font-size: 24px; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.action-card {
  min-height: 150px;
  border: 0;
  border-radius: var(--radius);
  padding: 20px 15px;
  display: grid;
  justify-items: start;
  align-content: center;
  gap: 7px;
  text-align: left;
  color: #fff;
  box-shadow: var(--shadow);
}
.action-card.withdrawal { background: linear-gradient(145deg, #bf5555, #9e3939); }
.action-card.entry { background: linear-gradient(145deg, #3c9b70, #26784f); }
.action-card .action-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; background: rgba(255, 255, 255, 0.18); font-size: 28px; }
.action-card strong { margin-top: 3px; font-size: 18px; }
.action-card small { opacity: 0.84; }
.owner-note { display: grid; gap: 4px; margin-bottom: 18px; padding: 16px; border: 1px solid #bcd2e1; border-radius: 15px; color: var(--navy); background: var(--blue-soft); }
.owner-note span { font-size: 13px; }

.section-block, .scanner-card, .filter-card, .table-card, .supplier-card, .selected-article, .movement-form {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 17px;
  background: var(--surface);
  box-shadow: 0 3px 15px rgba(23, 63, 95, 0.045);
}
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-heading span { color: var(--muted); font-size: 12px; text-align: right; }
.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.metric-grid.three { grid-template-columns: repeat(3, 1fr); }
.metric-card { min-height: 92px; padding: 14px; border-radius: 14px; display: grid; align-content: center; gap: 4px; background: #eef2f5; }
.metric-card span { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric-card strong { font-size: 27px; }
.metric-card.stock { color: var(--navy); background: var(--blue-soft); }
.metric-card.good { color: #236c4b; background: var(--green-soft); }
.metric-card.warning { color: #885314; background: var(--orange-soft); }
.metric-card.danger { color: #913939; background: var(--red-soft); }
.daily-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.daily-summary > div { padding: 12px 8px; border-radius: 12px; text-align: center; background: var(--background); }
.daily-summary span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.daily-summary strong { display: block; margin-top: 5px; font-size: 22px; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.small-facts { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.small-facts span { padding: 6px 9px; border-radius: 20px; color: var(--muted); background: var(--background); font-size: 11px; }
.quick-links { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick-links button { min-height: 64px; border: 1px solid var(--line); border-radius: 14px; color: var(--navy); background: #fff; font-weight: 800; }

.sticky-tools { position: sticky; z-index: 10; top: calc(76px + env(safe-area-inset-top)); display: flex; gap: 9px; padding: 8px 0 12px; background: var(--background); }
.search-box { min-height: 48px; flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 13px; border: 1px solid #cbd8e1; border-radius: 13px; background: #fff; }
.search-box span { color: var(--muted); font-size: 22px; }
.search-box input { width: 100%; height: 44px; border: 0; outline: none; background: transparent; }
.result-count { margin: 2px 2px 10px; color: var(--muted); font-size: 12px; }
.article-list { display: grid; gap: 8px; }
.article-row, .order-row {
  width: 100%;
  min-height: 76px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  color: var(--ink);
  background: #fff;
}
.article-row > div:first-child, .order-row > div:first-child { min-width: 0; display: grid; gap: 4px; }
.article-row strong, .order-row strong { overflow: hidden; text-overflow: ellipsis; }
.article-row span, .order-row span { color: var(--muted); font-size: 11px; }
.stock-badge { min-width: 57px; padding: 7px 8px; border-radius: 11px; display: grid; place-items: center; }
.stock-badge strong { font-size: 19px; }
.stock-badge span { font-size: 9px; text-transform: uppercase; }
.stock-badge.good { color: #236c4b; background: var(--green-soft); }
.stock-badge.warning { color: #885314; background: var(--orange-soft); }
.stock-badge.danger { color: #913939; background: var(--red-soft); }

.order-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 15px; }
.order-summary > div { padding: 17px; border-radius: 16px; color: #fff; background: var(--navy); box-shadow: var(--shadow); }
.order-summary span { display: block; color: #d1e0ea; font-size: 12px; }
.order-summary strong { display: block; margin-top: 5px; font-size: 29px; }
.supplier-groups { display: grid; gap: 13px; }
.supplier-card { padding: 0; overflow: hidden; }
.supplier-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 15px 16px; color: #fff; background: var(--navy); }
.supplier-heading h2 { font-size: 17px; }
.supplier-heading span { font-size: 11px; }
.supplier-card .order-row { border: 0; border-radius: 0; border-bottom: 1px solid var(--line); }
.supplier-card .order-row:last-child { border-bottom: 0; }
.order-row b { min-width: 50px; padding: 7px 9px; border-radius: 10px; text-align: center; color: #885314; background: var(--orange-soft); }

.filter-card { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.filter-card label, .movement-form label { display: grid; gap: 7px; color: var(--ink); font-size: 13px; font-weight: 800; }
.filter-card input, .filter-card select, .movement-form select, .movement-form textarea {
  width: 100%;
  min-height: 47px;
  border: 1px solid #cbd8e1;
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
}
.filter-card .button { grid-column: 1 / -1; }
.chart { width: 100%; height: 260px; margin-top: 18px; border-radius: 12px; background: #fbfcfd; }
.stats-tables { display: grid; gap: 14px; }
.table-card h2 { margin-bottom: 12px; }
.responsive-table { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; }
td:last-child, th:last-child { text-align: right; }

.scanner-card h2 { margin-bottom: 5px; }
.reader { width: 100%; min-height: 270px; margin: 14px 0; overflow: hidden; border-radius: 14px; background: #0e1820; }
.reader video { border-radius: 14px; }
.scanner-status { min-height: 20px; margin: 10px 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.or-divider { display: flex; align-items: center; gap: 12px; margin: 17px 0; color: var(--muted); font-size: 11px; }
.or-divider::before, .or-divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }
.manual-results { margin-top: 8px; display: grid; gap: 5px; }
.manual-results button { min-height: 54px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 11px; display: grid; gap: 3px; text-align: left; color: var(--ink); background: #fff; }
.manual-results small { color: var(--muted); }
.selected-article { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; border-color: #a8c5d8; background: var(--blue-soft); }
.selected-article h2 { margin: 3px 0; }
.selected-article p { margin: 2px 0; }
.selected-stock { min-width: 70px; display: grid; justify-items: center; }
.selected-stock span { color: var(--muted); font-size: 11px; }
.selected-stock strong { color: var(--navy); font-size: 31px; }
.selected-article .text-button { grid-column: 1 / -1; justify-self: start; padding: 5px 0; }
.movement-form { display: grid; gap: 16px; }
.quantity-control { display: grid; grid-template-columns: 52px 1fr 52px; gap: 7px; }
.quantity-control button { border: 1px solid #b9ccd9; border-radius: 12px; color: var(--navy); background: var(--blue-soft); font-size: 26px; }
.quantity-control input { width: 100%; min-height: 54px; border: 1px solid #cbd8e1; border-radius: 12px; text-align: center; font-size: 24px; font-weight: 800; }
.quick-quantity { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: -8px; }
.quick-quantity button { min-height: 42px; border: 1px solid var(--line); border-radius: 10px; color: var(--navy); background: #fff; font-weight: 800; }

.dialog { width: min(calc(100% - 28px), 520px); max-height: calc(100vh - 36px); overflow: auto; border: 0; border-radius: 22px; padding: 25px 21px 21px; box-shadow: 0 25px 80px rgba(0, 0, 0, 0.3); }
.dialog::backdrop { background: rgba(7, 18, 27, 0.62); backdrop-filter: blur(3px); }
.dialog form { margin: 0; }
.dialog-close { position: absolute; top: 10px; right: 12px; width: 38px; height: 38px; border: 0; border-radius: 50%; color: var(--muted); background: var(--background); font-size: 25px; }
.small-dialog { width: min(calc(100% - 38px), 390px); }
.small-dialog h2 { margin: 8px 0; }
.small-dialog .button { margin-top: 10px; }
.role-pill { display: inline-block; margin: 0 0 15px; padding: 7px 10px; border-radius: 20px; color: var(--navy); background: var(--blue-soft); font-size: 12px; font-weight: 800; }
.article-stock-hero { margin: 18px 0 13px; padding: 17px; border-radius: 15px; display: flex; align-items: center; justify-content: space-between; color: #fff; background: var(--navy); }
.article-stock-hero strong { font-size: 35px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.detail-grid div { padding: 11px; border-radius: 11px; background: var(--background); }
.detail-grid dt { color: var(--muted); font-size: 11px; }
.detail-grid dd { margin: 3px 0 0; font-weight: 800; }
.state-line { color: var(--muted); font-size: 13px; }

.loading, .empty-state { min-height: 250px; display: grid; place-items: center; align-content: center; gap: 12px; text-align: center; color: var(--muted); }
.loading p, .empty-state p { margin: 0; }
.spinner { width: 34px; height: 34px; border: 4px solid #dbe5ec; border-top-color: var(--navy); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-inline { padding: 22px; border: 1px dashed #c6d3dc; border-radius: 14px; text-align: center; color: var(--muted); }
.empty-inline.error { color: var(--red); border-color: #dfb5b5; background: var(--red-soft); }
.toast { position: fixed; z-index: 1001; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); width: min(calc(100% - 32px), 460px); transform: translateX(-50%); padding: 14px 16px; border-radius: 13px; color: #fff; background: #263b4b; text-align: center; font-weight: 700; box-shadow: var(--shadow); }
.toast.error { background: var(--red); }

@media (min-width: 700px) {
  .action-grid { grid-template-columns: 1fr 1fr; }
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
  .metric-grid.three { grid-template-columns: repeat(3, 1fr); }
  .stats-tables { grid-template-columns: repeat(2, 1fr); }
  .stats-tables .table-card:last-child { grid-column: 1 / -1; }
}

@media (max-width: 390px) {
  .app-content { padding-left: 12px; padding-right: 12px; }
  .topbar { padding-left: 14px; padding-right: 14px; }
  .metric-grid.three { grid-template-columns: 1fr; }
  .metric-grid.three .metric-card { min-height: 70px; display: flex; align-items: center; justify-content: space-between; }
  .action-card { min-height: 137px; }
  .sticky-tools { flex-direction: column; }
  .filter-card { grid-template-columns: 1fr; }
  .filter-card .button { grid-column: auto; }
}
.reader { position: relative; }
.reader video { width: 100%; min-height: 270px; object-fit: cover; display: block; }
.scan-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(66vw, 260px);
  height: min(66vw, 260px);
  transform: translate(-50%, -50%);
  border: 3px solid rgba(255,255,255,.92);
  border-radius: 18px;
  box-shadow: 0 0 0 999px rgba(0,0,0,.28);
  pointer-events: none;
}
