: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: var(--bg);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: var(--acc);
  border-radius: 10px;
  font-weight: 800;
  font-size: 19px;
}
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.1; }
.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: #8fd8b6; font-size: 13px; padding: 6px; }

/* ---------------------------------------------------------------- tabs */
.tabs {
  position: sticky;
  top: calc(58px + env(safe-area-inset-top));
  z-index: 19;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg);
}
.tab {
  padding: 12px 0;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  background: var(--bg-2);
  color: #cfdce8;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active { background: var(--acc); border-color: var(--acc); 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: var(--acc);
  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: var(--acc);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(10,125,79,.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, var(--bg) 0%, #163a52 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-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; }

/* ---------------------------------------------------------------- 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; }