:root {
  color-scheme: light;
  --green: #1b6b3a;
  --green-dark: #14532d;
  --green-soft: #e5f2e9;
  --bg: #f4f7f2;
  --text: #1c241e;
  --muted: #5c6b62;
  --line: #d5e0d8;
  --danger: #9b2c2c;
  --warn-bg: #f3e2b8;
  --warn-text: #6b4a08;
  --white: #fff;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(20, 50, 32, 0.08);
  --shell: 480px;
  --nav-space: calc(92px + env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  background: #d7e3da;
  color: var(--text);
}

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

input, select, textarea {
  font-size: max(16px, 1em);
  scroll-margin-top: 112px;
  scroll-margin-bottom: calc(140px + env(safe-area-inset-bottom, 0px) + env(keyboard-inset-bottom, 0px));
}

button { cursor: pointer; }

button:disabled { cursor: default; opacity: 0.65; }

:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

.shell {
  width: min(var(--shell), 100%);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
}

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  background: var(--green);
  color: var(--white);
  padding: calc(16px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 14px max(16px, env(safe-area-inset-left, 0px));
}

.brand, .top-row, .top-status, .sync { width: 100%; }

.top h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.85rem;
  opacity: 0.9;
}

.top-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-top: 12px;
  min-width: 0;
}

.top-vendor, .top-total { margin: 0; font-weight: 700; }

.top-vendor {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-total { font-size: 1.25rem; white-space: nowrap; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.chip.is-online { background: rgba(255, 255, 255, 0.2); }

.chip.is-offline {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.sync-label {
  margin: 10px 0 0;
  font-size: 0.85rem;
  opacity: 0.92;
}

.sync {
  min-height: 48px;
  margin-top: 10px;
  border: 0;
  border-radius: 12px;
  background: var(--white);
  color: var(--green-dark);
  font-weight: 700;
}

.sync:active { background: var(--green-soft); }

main {
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(var(--nav-space) + env(keyboard-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}

.boot { color: var(--muted); }

.sale-layout, .sale-catalog, .sale-checkout { min-width: 0; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 14px;
  font-weight: 700;
  min-width: 0;
}

.field input, .field select, .pay-field input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  border: 1px solid #c5d4cb;
  border-radius: 12px;
  padding: 8px 12px;
  background: var(--white);
  font-weight: 400;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 14px;
}

.search-row .field { margin-bottom: 0; }

.icon-button {
  min-width: 48px;
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--green);
  color: var(--white);
  font-weight: 700;
  padding: 0 14px;
}

.icon-button:active, .primary:active { background: var(--green-dark); }

.section-title {
  margin: 18px 0 10px;
  font-size: 1.05rem;
}

.card, .product, .cart-item, .sale {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card { padding: 14px; margin-bottom: 14px; }

.composer-price { margin: 0 0 10px; color: var(--muted); font-weight: 400; }

.primary, .ghost {
  width: 100%;
  min-height: 52px;
  border-radius: 12px;
  font-weight: 700;
}

.primary {
  border: 0;
  background: var(--green);
  color: var(--white);
}

#finalize, #composer-add, #vendor-select, #search-input {
  scroll-margin-bottom: calc(var(--nav-space) + env(keyboard-inset-bottom, 0px));
}

.ghost {
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--green-dark);
}

.product-list, .cart-list, .history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.product, .sale-summary {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
}

.product.is-selected { border-color: var(--green); background: var(--green-soft); }

.product-text { display: flex; flex-direction: column; min-width: 0; }

.product-name, .sale-vendor { font-weight: 700; }

.product-name, .cart-top strong, .receipt-item {
  overflow-wrap: anywhere;
}

.product-meta, .sale-when, .muted { color: var(--muted); font-size: 0.9rem; }

.product-price, .sale-total {
  font-weight: 700;
  color: var(--green-dark);
  white-space: nowrap;
}

.cart-item, .sale { padding: 12px; }

.cart-top, .sale-summary {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.sale-summary {
  display: grid;
  border: 0;
  box-shadow: none;
  padding: 0;
  min-height: 48px;
}

.cart-top strong {
  flex: 1;
  min-width: 0;
}

.cart-edit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.cart-edit .field { margin-bottom: 0; }

.remove {
  flex: 0 0 auto;
  min-height: 48px;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-weight: 700;
  padding: 0 4px;
}

.subtotal { margin: 8px 0 0; font-weight: 700; }

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

.pay-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 700;
  font-size: 0.95rem;
  min-width: 0;
}

.pay-status {
  min-height: 1.4em;
  margin: 12px 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.pay-status.is-ok { color: var(--green-dark); }

.pay-status.is-bad { color: var(--danger); }

.pay-status.is-idle { color: var(--muted); font-weight: 400; }

.empty, .notice {
  margin: 8px 0 14px;
  color: var(--muted);
}

.notice {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: 12px;
  padding: 12px;
}

.nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(var(--shell), 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  background: var(--white);
  border-top: 1px solid var(--line);
  padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  z-index: 6;
}

.nav button {
  min-height: 56px;
  border: 0;
  background: var(--white);
  color: var(--muted);
  font-weight: 700;
}

.nav button[aria-current="page"] {
  color: var(--green-dark);
  box-shadow: inset 0 3px 0 var(--green);
}

.sale-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "when total"
    "vendor badge";
  width: 100%;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.sale-when { grid-area: when; }
.sale-vendor { grid-area: vendor; min-width: 0; }
.sale-total { grid-area: total; justify-self: end; }
.sale .badge { grid-area: badge; justify-self: end; }

.badge {
  display: inline-block;
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

.sale-detail { margin-top: 10px; }

.sale-detail p { margin: 4px 0; overflow-wrap: anywhere; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px) + env(keyboard-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(440px, calc(100% - 24px));
  background: #1c241e;
  color: var(--white);
  border-radius: 12px;
  padding: 12px 14px;
  z-index: 40;
}

.camera-layer {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #000;
  display: flex;
  flex-direction: column;
}

.camera-layer video {
  width: 100%;
  max-width: 100%;
  flex: 1;
  min-height: 0;
  object-fit: cover;
  background: #000;
}

.camera-bar {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: #111;
  color: var(--white);
}

.camera-bar p { margin: 0 0 8px; }

.receipt {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 40, 28, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.receipt-card {
  width: min(480px, 100%);
  max-height: 92dvh;
  overflow: auto;
  background: var(--white);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}

.receipt-card h2 { margin: 0 0 12px; color: var(--green-dark); }

.receipt-total, .receipt-change { font-weight: 700; font-size: 1.15rem; }

.receipt-saved { color: var(--green-dark); font-weight: 700; }

body.modal-open { overflow: hidden; }

@media (max-width: 360px) {
  .pay-grid, .cart-edit { grid-template-columns: minmax(0, 1fr); }
}

@media (min-width: 720px) {
  :root { --shell: 720px; }

  .receipt {
    align-items: center;
    padding: 24px;
  }

  .receipt-card {
    border-radius: 20px;
    max-width: 440px;
  }
}

@media (min-width: 960px) {
  :root { --shell: 1120px; }

  .top {
    position: static;
    gap: 12px 20px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .brand, .top-row, .top-status, .sync { width: auto; }

  .brand { flex: 0 0 auto; }

  .top-row { flex: 1; margin-top: 0; }

  .chips, .sync { margin-top: 0; }

  .sync-label { margin: 4px 0 0; }

  .sync { min-width: 168px; }

  main { padding-top: 20px; }

  .sale-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
    gap: 8px 24px;
    align-items: start;
  }

  .sale-checkout {
    position: sticky;
    top: 16px;
    max-height: calc(100dvh - 16px - var(--nav-space));
    overflow: auto;
    padding-bottom: 8px;
  }

  .sale-checkout .pay-grid,
  .sale-checkout .cart-edit { grid-template-columns: minmax(0, 1fr); }

  #view-historico { max-width: 720px; }
}
