:root {
  --bg0: #f4f7fb;
  --bg1: #e8eef7;
  --bg2: #f8fbff;
  --card: rgba(255, 255, 255, 0.96);
  --surface: rgba(255, 255, 255, 0.84);
  --text: #17202f;
  --muted: rgba(23, 32, 47, 0.68);
  --line: rgba(23, 32, 47, 0.12);
  --green: #1d6b3a;
  --green2: #0f4f2b;
  --red: #b3292f;
  --amber: #b37a00;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.10);
  --shadow-soft: 0 8px 24px rgba(23, 32, 47, 0.08);
  --accent: linear-gradient(135deg, #1d6b3a, #2e8f52);

  --radius: 18px;
  --radius2: 12px;
  --pad: 16px;
  --pad2: 12px;

  --font: "Poppins", "Avenir Next", "Segoe UI", "Trebuchet MS", "Futura", "Avenir", "Gill Sans", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-family: var(--font);
  background:
    radial-gradient(circle at 20% 8%, #eaf0fb 0%, transparent 45%),
    linear-gradient(180deg, var(--bg0), var(--bg1) 65%, var(--bg2));
  animation: appFadeIn 0.16s ease-out;
}

@keyframes appFadeIn {
  from { opacity: 0.985; }
  to { opacity: 1; }
}

a { color: inherit; text-decoration: none; }

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(255, 255, 255, 0.84));
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
}

.topbar-logo {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  border: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
  object-fit: contain;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.12));
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-inner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px 11px 16px;
  max-width: 1120px;
  margin: 0 auto;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  font-size: 16px;
  font-weight: 760;
  letter-spacing: 0.2px;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.topbar-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-end;
}

.topbar-signout {
  margin-top: 4px;
  padding: 6px 10px;
  font-size: 12px;
}

.app-version {
  font-size: 11px;
  color: var(--muted);
}

.content {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 16px 92px 16px; /* space for bottom nav */
  /* Extra space for iPhone "home indicator" safe area so the bottom nav doesn't cover content. */
  padding-bottom: calc(92px + env(safe-area-inset-bottom));
  flex: 1;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.06);
  padding: var(--pad);
  position: relative;
  overflow: hidden;
  animation: panelReveal 0.25s ease both;
}

.card:before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: var(--radius);
  border: 1px solid rgba(29, 107, 58, 0.06);
  pointer-events: none;
  opacity: 0.7;
}

@keyframes panelReveal {
  from {
    opacity: 0.98;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.row { display: flex; gap: 12px; align-items: center; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 10px; }
.spacer { flex: 1; }

.h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 780;
}

.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); }

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.checkrow {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: -2px;
  margin-bottom: 0;
}

.checkrow span {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.35;
  white-space: normal;
}

input, select, textarea {
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
  outline: none;
  border-color: rgba(29, 107, 58, 0.6);
  box-shadow: 0 0 0 3px rgba(29, 107, 58, 0.15);
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
}

input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.94);
  outline: none;
}

input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
  accent-color: var(--green);
}

textarea { min-height: 84px; resize: vertical; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

@media (max-width: 720px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .topbar-inner { padding-left: 14px; padding-right: 14px; }
  .content { padding-left: 14px; padding-right: 14px; }
  .topbar-signout { padding: 6px 8px; }
  .bottomnav-inner {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding-left: 10px;
    padding-right: 10px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .navbtn {
    flex: 0 0 88px;
    scroll-snap-align: center;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.86);
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.12s ease, background 0.12s ease;
  box-shadow: 0 1px 0 rgba(23, 32, 47, 0.05);
}

.btn:active { transform: translateY(1px); }
.btn:hover:not([disabled]) { box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08); }
.btn[disabled] {
  opacity: 0.58;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  border-color: rgba(29, 107, 58, 0.35);
  background: linear-gradient(180deg, rgba(29, 107, 58, 0.20), rgba(29, 107, 58, 0.06));
}
.btn-danger {
  border-color: rgba(179, 41, 47, 0.35);
  background: linear-gradient(180deg, rgba(179, 41, 47, 0.16), rgba(179, 41, 47, 0.06));
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
}

.btn.preset-active {
  border-color: rgba(29, 107, 58, 0.35);
  background: rgba(29, 107, 58, 0.12);
}

.pillbar { display: flex; flex-wrap: wrap; gap: 10px; }
.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.78);
  cursor: pointer;
}
.pill[aria-pressed="true"] {
  border-color: rgba(29, 107, 58, 0.35);
  background: rgba(29, 107, 58, 0.12);
}

.notice {
  border-radius: var(--radius2);
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
}
.notice.error { border-color: rgba(179, 41, 47, 0.35); }
.notice.ok { border-color: rgba(29, 107, 58, 0.35); }
.notice.warn { border-color: rgba(179, 122, 0, 0.35); }

.table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: var(--radius2);
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.78);
}
.table th, .table td {
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  background: rgba(251, 247, 238, 0.6);
}
.table tr:last-child td { border-bottom: 0; }

.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(250, 253, 255, 0.94), rgba(244, 247, 251, 0.99));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: auto;
  box-shadow: 0 -8px 30px rgba(23, 32, 47, 0.08);
  border-image: linear-gradient(90deg, transparent, rgba(23, 32, 47, 0.07), transparent) 1;
}

.bottomnav-inner {
  max-width: 980px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 8px;
  padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
}

.navbtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 64px;
  padding: 8px 3px 7px;
  border-radius: 12px;
  border: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.navbtn .icon { font-size: 17px; line-height: 1; }
.navbtn .label {
  font-size: 11px;
  line-height: 1.05;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  display: block;
}

.navbtn[aria-current="page"] {
  color: var(--text);
  border-color: rgba(29, 107, 58, 0.35);
  background: linear-gradient(180deg, rgba(29, 107, 58, 0.16), rgba(29, 107, 58, 0.06));
}

.navbtn:not([aria-current="page"]):active {
  color: var(--text);
  background: rgba(29, 107, 58, 0.06);
}

.navbtn .label {
  letter-spacing: 0.1px;
}

.navbtn .icon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.navbtn:active {
  transform: translateY(1px);
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 12px 0;
}

.cash-line-grid,
.cash-adjustment-grid {
  display: grid;
  gap: 10px;
  align-items: center;
}

.cash-line-grid {
  grid-template-columns: minmax(160px, 1.2fr) minmax(110px, 0.8fr) minmax(92px, 0.6fr) minmax(180px, 1.2fr) auto;
}

.cash-adjustment-grid {
  grid-template-columns: minmax(210px, 1.35fr) minmax(104px, 0.74fr) minmax(104px, 0.74fr) minmax(150px, 0.95fr) minmax(170px, 1fr) minmax(150px, 0.95fr);
}

.cash-line-grid > *,
.cash-adjustment-grid > * {
  min-width: 0;
}

.cash-line-grid-head,
.cash-adjustment-grid-head {
  font-size: 11px;
}

.cash-inline-box {
  min-height: 44px;
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,0.76);
  overflow: hidden;
}

.cash-inline-box > * {
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.cash-inline-value {
  font-size: 13px;
}

.cash-denomination-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.cash-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.cash-summary-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 110px;
}

.cash-summary-label {
  font-size: 12px;
  color: var(--muted);
}

.cash-summary-value {
  font-size: 19px;
  font-weight: 760;
  line-height: 1.2;
}

.cash-form-card .h1 {
  font-size: 20px;
}

.cash-form-intro,
.cash-section-note {
  font-size: 14px;
  line-height: 1.5;
}

.cash-pos-warning-wrap {
  margin: 6px 0 4px;
}

.cash-pos-warning {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(179, 122, 0, 0.34);
  background: linear-gradient(180deg, rgba(255, 245, 217, 0.94), rgba(255, 255, 255, 0.98));
  box-shadow: 0 10px 24px rgba(179, 122, 0, 0.08);
}

.cash-pos-warning-title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #8b5e00;
}

.cash-pos-warning-body {
  font-size: 15px;
  line-height: 1.55;
  font-weight: 720;
  color: var(--text);
}

.cash-pos-warning-note {
  font-size: 13px;
  line-height: 1.45;
}

.cash-form-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cash-form-label {
  margin-bottom: 0;
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
}

.cash-form-field input:not([type="checkbox"]):not([type="radio"]),
.cash-form-field select,
.cash-form-field textarea {
  font-size: 16px;
  padding: 14px 14px;
}

.cash-form-field textarea {
  min-height: 112px;
}

.cash-priority-block {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid rgba(29, 107, 58, 0.14);
  background: linear-gradient(180deg, rgba(29, 107, 58, 0.08), rgba(255, 255, 255, 0.92));
}

.cash-priority-title {
  font-size: 19px;
  font-weight: 780;
}

.cash-priority-note {
  font-size: 14px;
  line-height: 1.5;
}

.cash-priority-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.cash-priority-field {
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(23, 32, 47, 0.10);
  box-shadow: var(--shadow-soft);
}

.cash-priority-accent {
  border-color: rgba(29, 107, 58, 0.22);
  background: rgba(29, 107, 58, 0.08);
}

.cash-priority-field .cash-form-label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.35px;
}

.cash-priority-field input:not([type="checkbox"]):not([type="radio"]),
.cash-priority-field select {
  font-size: 22px;
  font-weight: 780;
  min-height: 60px;
}

.optional-mark {
  display: inline-block;
  font-size: 1.08em;
  font-weight: 820;
  letter-spacing: 0.02em;
  color: var(--text);
}

.cash-diff-ok {
  color: var(--green2);
}

.cash-diff-warn {
  color: var(--amber);
}

.cash-diff-error {
  color: var(--red);
}

.cash-printable {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cash-print-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cash-report-summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cash-report-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,0.7);
}

.cash-report-diff.cash-diff-ok {
  border-color: rgba(29, 107, 58, 0.2);
  background: rgba(29, 107, 58, 0.08);
}

.cash-report-diff.cash-diff-warn {
  border-color: rgba(179, 122, 0, 0.22);
  background: rgba(179, 122, 0, 0.08);
}

.cash-report-diff.cash-diff-error {
  border-color: rgba(179, 41, 47, 0.24);
  background: rgba(179, 41, 47, 0.08);
}

.cash-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 4px;
}

.cash-print-warning {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(179, 122, 0, 0.3);
  background: linear-gradient(180deg, rgba(255, 245, 217, 0.9), rgba(255, 255, 255, 0.98));
}

.cash-print-warning-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #8b5e00;
}

.cash-print-warning-body {
  font-size: 13px;
  line-height: 1.45;
  font-weight: 720;
}

.cash-print-warning-note {
  font-size: 12px;
  line-height: 1.4;
}

.cash-signature-line {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cash-print-grid {
  display: grid;
  gap: 12px;
}

.cash-print-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cash-print-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}


.right { text-align: right; }
.delta-pos { color: var(--green2); }
.delta-neg { color: var(--red); }

.thumbgrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
@media (max-width: 720px) {
  .thumbgrid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 430px) {
  .bottomnav-inner {
    gap: 7px;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  }
  .navbtn {
    min-height: 64px;
    flex-basis: 84px;
    padding: 7px 4px 6px;
  }
  .navbtn .icon {
    font-size: 17px;
    width: 22px;
    height: 22px;
  }
  .navbtn .label {
    font-size: 10.5px;
  }
}

@media (max-width: 1040px) {
  .cash-denomination-grid,
  .cash-summary-grid,
  .cash-signatures,
  .cash-priority-grid,
  .cash-print-grid-2,
  .cash-print-grid-3 {
    grid-template-columns: 1fr;
  }
  .cash-line-grid,
  .cash-adjustment-grid {
    grid-template-columns: 1fr;
  }
  .cash-line-grid-head,
  .cash-adjustment-grid-head {
    display: none;
  }
}
.thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.78);
}

.movement-lines-preview {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.58);
  gap: 0;
}

.movement-card {
  cursor: pointer;
  touch-action: manipulation;
}

.movement-line-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
}

.movement-line-item:last-child {
  border-bottom: 0;
}

.movement-line-sku {
  font-weight: 700;
}

.movement-line-qty {
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.modal {
  width: 100%;
  max-width: 980px;
  max-height: calc(100dvh - 32px - env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.45);
  background: rgba(251, 247, 238, 0.92);
  box-shadow: 0 18px 60px rgba(0,0,0,0.26);
  padding: 14px;
}

@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }

  body {
    background: #fff;
    font-size: 10px;
  }

  .topbar,
  .bottomnav,
  .no-print {
    display: none !important;
  }

  .content {
    max-width: none;
    padding: 0;
  }

  .card {
    box-shadow: none;
    border-color: #d8d8d8;
    background: #fff;
  }

  .card:before {
    display: none;
  }

  .cash-printable {
    gap: 6px;
    font-size: 9.6px;
  }

  .cash-printable .card {
    padding: 7px 8px;
    border-radius: 8px;
    break-inside: auto;
    page-break-inside: auto;
  }

  .cash-printable .h1 {
    font-size: 11px;
    margin-bottom: 2px;
  }

  .cash-print-header {
    gap: 2px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .cash-print-header .h1 {
    font-size: 13px;
  }

  .cash-printable .table th,
  .cash-printable .table td {
    padding: 4px 5px;
    font-size: 9px;
    line-height: 1.15;
  }

  .cash-printable .table th {
    font-size: 8px;
  }

  .cash-print-grid {
    gap: 6px;
  }

  .cash-print-grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cash-print-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .cash-report-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .cash-report-summary-row {
    padding: 5px 6px;
    gap: 8px;
    font-size: 9px;
  }

  .cash-signatures {
    margin-top: 2px;
    gap: 10px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .cash-signature-line {
    padding-top: 6px;
    gap: 3px;
  }

  .cash-print-warning {
    margin-top: 6px;
    padding: 6px 7px;
    gap: 3px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .cash-print-warning-title {
    font-size: 8.5px;
  }

  .cash-print-warning-body,
  .cash-print-warning-note {
    font-size: 8.5px;
    line-height: 1.25;
  }
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(251, 247, 238, 0.98);
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.camera-modal {
  max-width: 760px;
}

.camera-frame {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0e1723;
  min-height: 260px;
}

.camera-video {
  display: block;
  width: 100%;
  max-height: min(68dvh, 720px);
  object-fit: cover;
  background: #0e1723;
}
