:root {
  --bg: #0e2233;
  --bg-2: #123046;
  --card: #ffffff;
  --ink: #16222e;
  --muted: #6b7683;
  --line: #e3e8ee;
  --acc: #0a7d4f;
  --acc-dark: #086a43;
  --danger: #c0392b;
  --ok: #0a7d4f;
  --warn: #b7791f;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
}

.hidden { display: none !important; }

#err-strip {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 99;
  padding: 12px 16px;
  background: #c0392b;
  color: #fff;
  font-size: 13px;
  text-align: center;
}

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: #ffffff;
  color: #16222e;
  box-shadow: 0 1px 6px rgba(0,0,0,.08);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .brand-logo { height: 30px; width: auto; display: block; }
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-name small { display: block; font-weight: 400; font-size: 12px; opacity: .75; }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-name { opacity: .9; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-link { background: none; border: none; color: #000; font-size: 13px; font-weight: 700; padding: 6px; }

/* ---------------------------------------------------------------- tabs */
.tabs {
  position: sticky;
  top: calc(58px + env(safe-area-inset-top));
  z-index: 19;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg);
}
.tab {
  padding: 12px 0;
  border: 1px solid rgba(91,128,171,.5);
  border-radius: 12px;
  background: #0e2233;
  color: #8fa8bf;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active { background: #5b80ab; border-color: #5b80ab; color: #fff; }

/* ---------------------------------------------------------------- screens */
.screen { padding: 6px 12px calc(24px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; }
.capture-form { display: grid; gap: 14px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.card h3 { margin: 0 0 12px; font-size: 15px; color: var(--bg); }

/* ---------------------------------------------------------------- photo */
.photo-box {
  border: 2px dashed #b8c4cf;
  border-radius: var(--radius);
  min-height: 150px;
  display: grid;
  place-items: center;
  text-align: center;
  position: relative;
  overflow: hidden;
  background: #f7fafc;
  cursor: pointer;
}
.photo-empty { padding: 18px; color: var(--muted); }
.cam-icon { display: block; font-size: 34px; margin-bottom: 6px; }
.photo-empty b { display: block; font-size: 15px; color: var(--ink); margin-bottom: 4px; }
.photo-btns { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.btn-cam {
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: #000000;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-block;
}
.btn-cam.ghost { background: #eef2f6; color: var(--ink); border: 1px solid var(--line); }
.photo-input { display: none; }
.photo-box img { width: 100%; display: block; }
.photo-remove {
  position: absolute;
  top: 8px; right: 8px;
  width: 30px; height: 30px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 15px;
}

/* ---------------------------------------------------------------- form */
.capture-form label {
  display: block;
  margin: 10px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.capture-form input,
.capture-form select,
.capture-form textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 12px 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  outline: none;
}
.capture-form input:focus,
.capture-form select:focus,
.capture-form textarea:focus { border-color: var(--acc); }
.capture-form input[readonly] { background: #f3f6f9; }

.qty-line {
  margin: 12px 0 4px;
  padding: 12px;
  background: #eaf6f0;
  border: 1px solid #cfe9dc;
  border-radius: 10px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}
.qty-line b { color: var(--acc-dark); font-size: 17px; }

.btn-save {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  background: #0044aa;
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0,68,170,.35);
  cursor: pointer;
}
.btn-save:disabled { opacity: .6; }

/* ---------------------------------------------------------------- login */
#login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #3a5a8c 0%, #5b80ab 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 18px;
  padding: 26px 22px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand .login-logo-img {
  max-width: 150px; max-height: 150px; width: auto; height: auto;
  object-fit: contain; display: block; margin: 0 auto 12px;
}
.login-brand .login-tagline {
  margin: 0 0 6px; font-size: 15px; font-weight: 700; color: var(--ink); text-align: center;
}
.login-mark {
  width: 54px; height: 54px;
  margin: 0 auto 10px;
  display: grid; place-items: center;
  background: var(--acc);
  color: #fff;
  border-radius: 16px;
  font-size: 28px;
  font-weight: 800;
}
.login-brand h1 { margin: 0; font-size: 22px; color: var(--ink); }
.login-brand p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.login-card label { display: block; margin: 12px 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 13px;
  font-size: 16px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
}
.login-card input:focus { outline: none; border-color: var(--acc); }
.err { color: var(--danger); font-size: 13px; margin: 8px 0; min-height: 18px; }
#login-view .btn-save {
  background: #3a5a8c;
  box-shadow: 0 4px 14px rgba(58,90,140,.4);
}
#login-view .btn-save:active { background: #5b80ab; }

/* ---------------------------------------------------------------- dips */
.dips-hint { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.dip-row {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.dip-row:last-child { border-bottom: none; }
.dip-label b { display: block; font-size: 15px; color: var(--ink); }
.dip-label span { display: block; font-size: 12px; color: var(--muted); }
.dip-row input {
  width: 100%;
  padding: 10px 10px;
  font-size: 16px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  text-align: right;
}
.dip-row input:focus { outline: none; border-color: var(--acc); }
.dip-row.skip { opacity: .45; }
.dip-row.skip input { background: #f3f6f9; }

/* ---------------------------------------------------------------- wizard steps */
.steps-progress { padding: 4px 2px 2px; color: #fff; }

.home-btns { display: grid; gap: 14px; margin-top: 18px; }
.logged-in { margin: 2px 0 0; font-size: 14px; font-weight: 600; color: #e8f0f7; }
.logged-in strong { color: #ffffff; }
.home-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  padding: 20px 18px;
  border: none;
  border-radius: 14px;
  background: #ffffff;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 5px 16px rgba(0, 0, 0, .3);
  cursor: pointer;
}
.home-btn:active { transform: scale(.99); }
.home-icon {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  font-size: 28px;
  border-radius: 13px;
  background: #e8f0f7;
}
.home-btn[data-go="receive"] .home-icon { background: #e7f5ea; color: #1e7a34; }
.home-btn[data-go="dispatch"] .home-icon { background: #e8f0f7; color: #1c5d99; }
.home-btn[data-go="dips"] .home-icon { background: #fdf3dc; color: #b07d10; }
.home-label { display: block; }
.home-sub { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-top: 2px; }
.progress-bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,.18);
  overflow: hidden;
  margin-bottom: 6px;
}
.progress-fill {
  height: 100%;
  width: 20%;
  border-radius: 3px;
  background: #5b80ab;
  transition: width .25s ease;
}
.progress-label { font-size: 13px; color: #b7c8da; font-weight: 600; }

.step-nav {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 2px;
}
.btn-back {
  flex: 1;
  padding: 14px;
  border: 1.5px solid rgba(255,255,255,.5);
  border-radius: var(--radius);
  background: transparent;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn-next {
  flex: 2;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: #0044aa;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0,68,170,.35);
  cursor: pointer;
}
.btn-next:active { background: #003a92; }
.btn-back:active { background: rgba(255,255,255,.12); }

.capture-form input.incomplete,
.capture-form select.incomplete,
.capture-form textarea.incomplete { border-color: var(--danger); background: #fdf1f0; }

.review-list {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
}
.review-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.review-row:last-child { border-bottom: none; }
.review-row span { color: var(--muted); font-weight: 600; }
.review-row b { color: var(--ink); text-align: right; }
.review-photo { margin-bottom: 14px; }
.review-img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
}

/* ---------------------------------------------------------------- success */
#success-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(14,34,51,.82);
  backdrop-filter: blur(4px);
}
.success-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: 18px;
  padding: 30px 24px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.success-check {
  width: 64px; height: 64px;
  margin: 0 auto 14px;
  display: grid; place-items: center;
  background: var(--ok);
  color: #fff;
  border-radius: 50%;
  font-size: 32px;
}
.success-card h2 { margin: 0 0 6px; color: var(--ink); }
.success-doc { font-size: 20px; font-weight: 700; color: var(--acc-dark); margin: 0 0 8px; }
.success-wa { font-size: 14px; color: var(--ok); margin: 0 0 20px; }
.success-actions { margin-top: 4px; }
.success-actions .btn-save { width: auto; padding: 13px 28px; }

/* ---------------------------------------------------------------- password toggle */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 40px; }
.pw-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 4px;
  color: var(--muted); line-height: 1; display: flex; align-items: center;
}
.pw-toggle:hover { color: var(--ink); }