:root {
  --bg: #e7f1ec;
  --bg-2: #d7e8df;
  --ink: #14241f;
  --muted: #4d675e;
  --brand: #1b6b5a;
  --brand-2: #0f4a3e;
  --accent: #f0a04b;
  --accent-ink: #4a2c0a;
  --ok: #2a9d8f;
  --warn: #d4a017;
  --danger: #c44536;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #f7fbf8;
  --line: rgba(20, 36, 31, 0.1);
  --shadow: 0 18px 40px rgba(15, 50, 40, 0.12);
  --radius: 22px;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --bottom-nav-h: 0px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 10% -10%, #ffe7c2 0%, transparent 55%),
    radial-gradient(700px 380px at 100% 0%, #b8e0d2 0%, transparent 50%),
    linear-gradient(165deg, var(--bg), var(--bg-2));
  background-attachment: fixed;
  overscroll-behavior-y: none;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.28;
  background-image:
    linear-gradient(rgba(27, 107, 90, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(27, 107, 90, 0.07) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle at 50% 20%, #000 20%, transparent 75%);
}

.shell {
  width: min(1120px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0 calc(48px + var(--bottom-nav-h) + var(--safe-bottom));
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  animation: rise 0.5s ease both;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  color: #f4fff9;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.35rem;
  box-shadow: 0 10px 24px rgba(27, 107, 90, 0.35);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand-text strong {
  font-family: var(--display);
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.brand-text small {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}
.nav a {
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  font-size: 0.92rem;
  padding: 12px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.45);
  border: 1px solid var(--line);
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  transition: transform 0.15s ease, background 0.15s ease;
}
.nav a:hover { transform: translateY(-1px); background: #fff; }
.nav a.active {
  background: var(--brand);
  color: #f5fffb;
  border-color: transparent;
}
.nav-cta {
  background: var(--accent) !important;
  color: var(--accent-ink) !important;
  border-color: transparent !important;
}

.bottom-nav { display: none; }

.view { animation: rise 0.45s ease both; }

.hero {
  display: grid;
  gap: 18px;
  margin-bottom: 22px;
}
.hero h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.85rem, 5vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}
.hero p {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  max-width: 42ch;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.stat {
  background: var(--surface);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
}
.stat .label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat .value {
  margin-top: 8px;
  font-family: var(--display);
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
}

.panel {
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.panel h2 {
  margin: 0 0 14px;
  font-family: var(--display);
  font-size: 1.35rem;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 72px;
  border-radius: 18px;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--ink);
  border: 1px solid var(--line);
  background: #fff;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  padding: 14px;
  text-align: center;
}
.action:hover { transform: translateY(-2px); box-shadow: 0 12px 24px rgba(20,36,31,0.1); }
.action.primary {
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  color: #f4fff9;
  border: none;
}
.action.warm {
  background: linear-gradient(145deg, #f0a04b, #e8892d);
  color: var(--accent-ink);
  border: none;
}

.list { display: grid; gap: 10px; }
.row {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--line);
}
.row .time {
  font-weight: 800;
  color: var(--brand);
}
.row .meta { color: var(--muted); font-size: 0.9rem; }
.row .amount { font-weight: 800; font-size: 1.05rem; }

.alert {
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff4d6;
  border: 1px solid #f0d48a;
  color: #6a4b00;
  font-weight: 700;
  margin-bottom: 10px;
}
.alert a {
  color: inherit;
  font-weight: 800;
}

.period-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.period-tab {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.7);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  color: var(--ink);
}
.period-tab.active {
  background: var(--brand);
  color: #f4fff9;
  border-color: transparent;
}
.period-filters {
  grid-template-columns: 1fr auto;
  align-items: end;
}
@media (max-width: 860px) {
  .period-filters { grid-template-columns: 1fr; }
}

.products {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.product {
  border: none;
  text-align: left;
  padding: 16px;
  min-height: 120px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  font: inherit;
  color: inherit;
  -webkit-user-select: none;
  user-select: none;
}
.product:active { transform: scale(0.97); }
.product:hover { transform: translateY(-2px); border-color: var(--brand); }
.product:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.product .name { font-weight: 800; font-size: 1.05rem; }
.product .price {
  margin-top: 8px;
  font-family: var(--display);
  font-size: 1.25rem;
  color: var(--brand-2);
}
.product .stock {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}
.product.low .stock { color: var(--danger); }

.layout-sale {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  align-items: start;
}

.cart-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.qty-ctrl {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.qty-ctrl button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
}

.total-box {
  margin-top: 12px;
  padding: 16px;
  border-radius: 18px;
  background: linear-gradient(145deg, #12352d, #1b6b5a);
  color: #f4fff9;
}
.total-box .label { opacity: 0.8; font-weight: 700; }
.total-box .value {
  font-family: var(--display);
  font-size: 2.2rem;
  font-weight: 700;
  margin-top: 4px;
}

.pay-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}
.pay-btn {
  min-height: 58px;
  border: none;
  border-radius: 16px;
  font: inherit;
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
  color: #14241f;
}
.pay-btn.cash { background: #c8f0d8; }
.pay-btn.pix { background: #cfe8ff; }
.pay-btn.credit { background: #ffe3b5; }
.pay-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.btn-sm {
  min-height: 40px;
  padding: 0 12px;
  font-size: 0.85rem;
  border-radius: 12px;
}
.sale-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.sale-row {
  grid-template-columns: 64px 1fr auto;
}
.btn.ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.warn { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); color: #fff; }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.form-grid {
  display: grid;
  gap: 12px;
}
label {
  display: grid;
  gap: 6px;
  font-weight: 700;
  color: var(--muted);
  font-size: 0.9rem;
}
input, select {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 0 14px;
  font: inherit;
  background: #fff;
  color: var(--ink);
  font-size: 16px; /* evita zoom no iOS */
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}
.badge.quitado { background: #d6f5ef; color: #0f5f55; }
.badge.parcial { background: #fff1c7; color: #7a5a00; }
.badge.atraso { background: #ffd6d1; color: #8a2218; }

.table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td {
  text-align: left;
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stock-card, .customer-card {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 24, 20, 0.55);
  display: grid;
  place-items: end center;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  z-index: 40;
}
.modal {
  width: min(480px, 100%);
  background: #fff;
  border-radius: 22px 22px 18px 18px;
  padding: 18px;
  animation: rise 0.25s ease both;
  max-height: min(88vh, 720px);
  overflow: auto;
}
.modal h3 {
  margin: 0 0 12px;
  font-family: var(--display);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--bottom-nav-h) + var(--safe-bottom));
  transform: translateX(-50%);
  background: #14241f;
  color: #f4fff9;
  padding: 14px 18px;
  border-radius: 14px;
  font-weight: 700;
  z-index: 50;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease both;
  max-width: calc(100% - 32px);
  text-align: center;
}

.empty {
  color: var(--muted);
  font-weight: 600;
  padding: 18px 4px;
}

.sale-dock { display: none; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 860px) {
  :root { --bottom-nav-h: 72px; }

  .shell {
    width: calc(100% - 20px);
    padding-top: 12px;
  }

  .nav-desktop { display: none !important; }

  .topbar {
    margin-bottom: 14px;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    font-size: 1.15rem;
  }

  .brand-text strong { font-size: 1.28rem; }
  .brand-text small { display: none; }

  .hero { gap: 12px; margin-bottom: 14px; }
  .hero h1 { font-size: 1.75rem; }
  .hero p { font-size: 0.95rem; }

  .stats {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 4px;
    margin: 0 -10px;
    padding-left: 10px;
    padding-right: 10px;
    -webkit-overflow-scrolling: touch;
  }
  .stats::-webkit-scrollbar { display: none; }
  .stat {
    min-width: 68%;
    flex: 0 0 auto;
    scroll-snap-align: start;
    padding: 16px;
  }
  .stat .value { font-size: 1.7rem; }

  .panel {
    padding: 14px;
    border-radius: 20px;
    margin-bottom: 12px;
  }
  .panel h2 { font-size: 1.2rem; margin-bottom: 12px; }

  .actions { grid-template-columns: 1fr 1fr; gap: 10px; }
  .action {
    min-height: 88px;
    border-radius: 18px;
    font-size: 0.95rem;
  }

  .row {
    grid-template-columns: 52px 1fr;
    grid-template-rows: auto auto;
    gap: 4px 10px;
    padding: 14px;
  }
  .row .time { grid-row: 1 / span 2; align-self: center; font-size: 0.95rem; }
  .row .amount {
    grid-column: 2;
    justify-self: start;
    margin-top: 2px;
  }
  .sale-row {
    grid-template-columns: 52px 1fr;
  }
  .sale-row .sale-actions {
    grid-column: 2;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-top: 6px;
  }
  .sale-row .sale-actions .amount {
    margin-top: 0;
  }

  .layout-sale {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* No mobile, o carrinho vira dock fixo */
  .layout-sale .panel-cart-desktop { display: none; }

  .products {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .product {
    min-height: 110px;
    padding: 14px 12px;
    border-radius: 16px;
    box-shadow: 0 8px 18px rgba(15, 50, 40, 0.06);
  }
  .product .name { font-size: 0.98rem; line-height: 1.2; }
  .product .price { font-size: 1.2rem; margin-top: 10px; }

  .sale-dock {
    display: block;
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 10px);
    z-index: 30;
    background: rgba(247, 251, 248, 0.94);
    backdrop-filter: blur(14px);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 16px 40px rgba(15, 50, 40, 0.18);
    overflow: hidden;
  }
  .sale-dock-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    width: 100%;
    border: none;
    background: transparent;
    font: inherit;
    color: inherit;
    cursor: pointer;
    text-align: left;
  }
  .sale-dock-summary .dock-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .sale-dock-summary .dock-total {
    font-family: var(--display);
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--brand-2);
  }
  .sale-dock-summary .dock-count {
    background: var(--brand);
    color: #fff;
    min-width: 28px;
    height: 28px;
    border-radius: 999px;
    display: inline-grid;
    place-items: center;
    font-size: 0.85rem;
    font-weight: 800;
  }
  .sale-dock-body {
    display: none;
    padding: 0 14px 14px;
    border-top: 1px solid var(--line);
    max-height: 46vh;
    overflow: auto;
  }
  .sale-dock.open .sale-dock-body { display: block; }
  .sale-dock .pay-grid {
    grid-template-columns: 1fr;
  }
  .sale-dock .pay-btn { min-height: 52px; }

  body.sale-open .shell {
    padding-bottom: calc(170px + var(--bottom-nav-h) + var(--safe-bottom));
  }

  /* Tabelas viram cards */
  .table-wrap { overflow: visible; }
  .table.mobile-cards thead { display: none; }
  .table.mobile-cards,
  .table.mobile-cards tbody,
  .table.mobile-cards tr,
  .table.mobile-cards td {
    display: block;
    width: 100%;
  }
  .table.mobile-cards tr {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    margin-bottom: 10px;
  }
  .table.mobile-cards td {
    border: none;
    padding: 4px 0;
  }
  .table.mobile-cards td.actions-cell {
    padding-top: 10px;
  }
  .table.mobile-cards .btn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .table.mobile-cards .btn-row .btn {
    width: 100%;
    justify-content: center;
  }
  .table.mobile-cards .btn-row .btn-span {
    grid-column: 1 / -1;
  }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding: 6px 6px calc(6px + var(--safe-bottom));
    background: rgba(247, 251, 248, 0.92);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -10px 30px rgba(15, 50, 40, 0.08);
  }
  .bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 800;
    border-radius: 14px;
    min-height: 56px;
  }
  .bottom-nav a.active {
    color: var(--brand-2);
    background: rgba(27, 107, 90, 0.1);
  }
  .bottom-nav .bn-ico {
    font-size: 1.15rem;
    line-height: 1;
  }
  .bottom-nav .bn-main {
    transform: translateY(-10px);
  }
  .bottom-nav .bn-plus {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: linear-gradient(145deg, var(--accent), #e8892d);
    color: var(--accent-ink);
    font-size: 1.45rem;
    box-shadow: 0 10px 20px rgba(232, 137, 45, 0.35);
  }
  .bottom-nav .bn-main span:last-child {
    color: var(--accent-ink);
    margin-top: 2px;
  }
  .bottom-nav .bn-main.active .bn-plus {
    outline: 2px solid #fff;
    box-shadow: 0 10px 22px rgba(232, 137, 45, 0.45);
  }

  .modal-backdrop {
    place-items: end stretch;
    padding: 0;
  }
  .modal {
    width: 100%;
    border-radius: 24px 24px 0 0;
    padding: 18px 16px calc(18px + var(--safe-bottom));
  }

  .toast {
    bottom: calc(14px + var(--bottom-nav-h) + var(--safe-bottom));
  }
}

@media (max-width: 420px) {
  .actions { grid-template-columns: 1fr; }
  .action { min-height: 64px; flex-direction: row; justify-content: flex-start; padding-left: 18px; }
  .stat { min-width: 78%; }
}
