/* Cantina Faleagro — mobile-first */

:root {
  --green: #2d6a4f;
  --green-dark: #1b4332;
  --green-light: #d8f3dc;
  --amber: #e9c46a;
  --orange: #e76f51;
  --red: #c1121f;
  --red-soft: #fde8ea;
  --bg: #f7f5f0;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #5c5c5c;
  --border: #e0ddd4;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

button,
a,
input,
select,
textarea,
.qty-stepper,
.btn-falta,
.farm-btn,
.tab,
.chip,
.btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.header {
  background: var(--green);
  color: #fff;
  padding: 1rem 1.25rem 1.1rem;
  text-align: center;
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  opacity: 0.9;
}

/* Tabs */
.tabs {
  display: flex;
  background: var(--green-dark);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

.tab {
  flex: 1;
  min-height: var(--tap);
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.75rem 0.5rem;
  border-bottom: 3px solid transparent;
  -webkit-tap-highlight-color: transparent;
}

.tab.active {
  color: #fff;
  border-bottom-color: var(--amber);
  background: rgba(255, 255, 255, 0.06);
}

.tab:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: -2px;
}

.main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.filters {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.chip {
  min-height: 40px;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chip.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

/* Buttons */
.btn {
  min-height: var(--tap);
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.btn:active {
}

.btn-primary {
  background: var(--green);
  color: #fff;
}

.btn-primary:hover {
  background: var(--green-dark);
}

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-danger-outline {
  background: transparent;
  color: var(--red);
  border: 1.5px solid var(--red);
  width: 100%;
}

.btn-icon {
  min-width: 44px;
  min-height: 44px;
  padding: 0.4rem;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--muted);
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-icon.danger:hover {
  background: var(--red-soft);
  color: var(--red);
}

/* Lists */
.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.item {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.item.falta-item {
  border-left: 4px solid var(--red);
  background: #fffbfb;
}

.item-body {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-weight: 650;
  font-size: 1.05rem;
  margin: 0 0 0.15rem;
  word-break: break-word;
}

.item-meta {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  margin-left: 0.35rem;
  vertical-align: middle;
}

.badge-falta {
  background: var(--red-soft);
  color: var(--red);
}

.badge-cat {
  background: var(--green-light);
  color: var(--green-dark);
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}

.badge-extra {
  background: #fff3e0;
  color: #e65100;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.7rem;
}

.item-actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.15rem;
  align-items: center;
}

/* —— Linha rápida Estoque (cozinha) —— */
.stock-row {
  align-items: stretch;
  padding: 0.75rem 0.85rem;
}

.stock-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stock-name {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.25;
}

.qty-group {
  display: flex;
  align-items: stretch;
  flex: 1 1 160px;
  min-width: 0;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}

.qty-stepper {
  flex: 0 0 52px;
  min-width: 52px;
  min-height: 52px;
  padding: 0;
  border: none;
  background: #f3f7f3;
  color: var(--green-dark);
  cursor: pointer;
  font: inherit;
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.qty-stepper:first-child {
  border-right: 1px solid var(--border);
}

.qty-stepper:last-of-type {
  border-left: 1px solid var(--border);
}

.qty-stepper:hover {
  background: var(--green-light);
}

.qty-stepper:active {
  background: #b7e4c7;
}

.qty-stepper:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: -2px;
  position: relative;
  z-index: 1;
}

.qty-group:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.2);
}

.qty-num-input {
  flex: 1;
  min-width: 0;
  min-height: 52px;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 0.55rem 0.65rem;
  border: none !important;
  border-radius: 0;
  box-shadow: none !important;
  text-align: center;
}

.unit-label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.75rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  background: #fafaf7;
  border-left: 1px solid var(--border);
  min-width: 3.25rem;
}

.unit-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  flex: 0 0 auto;
  align-self: stretch;
  border-left: 1px solid var(--border);
  min-width: 4.2rem;
  max-width: 5.5rem;
}

.unit-stack .unit-chip {
  border-left: none;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  font-size: 0.85rem;
  padding: 0 0.45rem;
}

.unit-stack .pack-badge {
  border: none;
  border-bottom: 1px dashed var(--border);
  border-radius: 0;
  min-height: 22px;
  padding: 0.15rem 0.35rem;
  font-size: 0.68rem;
  line-height: 1.15;
  white-space: normal;
  text-align: center;
  width: 100%;
}

.unit-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 3.6rem;
  min-height: 52px;
  padding: 0 0.7rem;
  border: none;
  border-left: 1px solid var(--border);
  background: var(--green-light);
  color: var(--green-dark);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

.unit-chip:hover {
  background: #b7e4c7;
}

.unit-chip:active {
  background: #95d5b2;
}

.unit-chip:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: -2px;
  position: relative;
  z-index: 1;
}

.pack-badge {
  flex: 0 0 auto;
  align-self: center;
  border: 1.5px dashed var(--border);
  background: #fff8e7;
  color: #9a6700;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 36px;
}

.pack-badge:hover,
.pack-badge:focus-visible {
  border-color: var(--orange, #e76f51);
  outline: none;
}

.unit-dialog-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.unit-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 0.35rem 0 0.5rem;
}

.unit-option {
  min-height: 52px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--green-dark);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.unit-option.active {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

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

.unit-pack-fields {
  margin-top: 0.25rem;
  padding: 0.75rem;
  background: #fafaf7;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.qty-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--green-dark);
  font-weight: 600;
}

.stock-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
}

.dialog-qty-row {
  display: flex;
  gap: 0.5rem;
}

.dialog-qty-num {
  flex: 1;
  min-width: 0;
}

.dialog-qty-unit {
  flex: 1.2;
  min-width: 0;
}

.btn-falta {
  flex-shrink: 0;
  min-width: 88px;
  min-height: 52px;
  padding: 0.5rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}


.btn-falta.on {
  border-color: var(--red);
  background: var(--orange);
  color: #fff;
  box-shadow: 0 2px 0 rgba(193, 18, 31, 0.25);
}

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

/* legacy toggle kept for print hide if any */
.toggle-falta {
  min-width: 44px;
  min-height: 44px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  padding: 0.25rem;
  line-height: 1.1;
  -webkit-tap-highlight-color: transparent;
}

.toggle-falta.on {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--red);
}

.category-heading {
  margin: 1.1rem 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.category-heading:first-child {
  margin-top: 0;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
  margin: 0;
}

.top-actions {
  margin: 0 0 0.75rem;
  display: flex;
}

.top-actions .btn {
  width: 100%;
  min-height: 48px;
  font-size: 1.05rem;
  font-weight: 700;
}

.footer-actions {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.footer-actions .btn {
  flex: 1;
  min-width: 140px;
}

/* Sporadic */
.sporadic-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

.row {
  display: flex;
  gap: 0.5rem;
}

.row .input {
  flex: 1;
  min-width: 0;
}

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 0.65rem 0.9rem;
  font-size: 1rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}

.input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.2);
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%235c5c5c' d='M0 0l6 8 6-8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.5rem;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: var(--tap);
  font-weight: 500;
  cursor: pointer;
  margin: 0.5rem 0 0;
}

.check-label input {
  width: 1.35rem;
  height: 1.35rem;
  accent-color: var(--red);
}

/* Shopping list specifics */
.shopping .item {
  align-items: center;
}

.shopping .item-name {
  margin: 0;
}

.shopping-tag {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.15rem 0 0;
}

.toast {
  text-align: center;
  background: var(--green-dark);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-top: 0.75rem;
  font-weight: 600;
}

/* Dialog */
.dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  max-width: 420px;
  width: calc(100% - 2rem);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.dialog form {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.dialog h2 {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
}

.dialog .input {
  margin-bottom: 0.5rem;
}

.dialog-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.dialog-actions .btn {
  flex: 1;
}


/* —— Admin —— */
.admin-login-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  max-width: 400px;
  margin: 0 auto;
}

.admin-heading {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
}

.admin-subheading {
  margin: 1.25rem 0 0.5rem;
  font-size: 1.05rem;
}

.admin-error {
  color: var(--red);
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.admin-suggested-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.admin-table-wrap {
  display: none;
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.admin-table th,
.admin-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #fafaf7;
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.admin-cat {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.admin-num-unit {
  display: flex;
  align-items: stretch;
  max-width: 160px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

.admin-num-unit:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.2);
}

.admin-num-unit .admin-stepper {
  flex-basis: 40px;
  min-width: 40px;
  min-height: 44px;
  font-size: 1.45rem;
}


.admin-buy-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  border: none !important;
  border-radius: 0;
  box-shadow: none !important;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0.4rem 0.5rem;
}

.admin-unit {
  display: flex;
  align-items: center;
  padding: 0 0.55rem;
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--muted);
  background: #fafaf7;
  border-left: 1px solid var(--border);
  white-space: nowrap;
}

.admin-need {
  font-weight: 700;
}

.admin-need.need-buy,
.admin-card.need-item {
  color: var(--red);
}

.admin-card.need-item {
  border-left: 4px solid var(--orange);
}

.admin-cards .admin-num-unit {
  max-width: none;
}

.admin-cards .unit-label {
  border: none;
  border-left: 1px solid var(--border);
}

@media (min-width: 720px) {
  .admin-table-wrap {
    display: block;
  }
  .admin-cards {
    display: none;
  }
}

/* Print */
@media print {
  .header {
    background: none;
    color: #000;
    border-bottom: 2px solid #000;
    padding: 0 0 0.5rem;
    text-align: left;
  }

  .tabs,
  .no-print,
  .item-actions,
  .toggle-falta,
  .btn-falta,
  .qty-input,
  .qty-num-input,
  .unit-label,
  .unit-chip,
  .pack-badge,
  .qty-hint,
  .stock-controls,
  .filters,
  .toolbar,
  .sporadic-box,
  .hint,
  #panel-admin,
  .admin-login-box,
  .admin-toolbar {
    display: none !important;
  }

  .panel {
    display: none !important;
  }

  #panel-compras.panel,
  #panel-compras.panel.active {
    display: block !important;
  }

  body {
    background: #fff;
    padding: 0;
  }

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

  .item {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }

  .item::before {
    content: "☐ ";
    font-size: 1.1rem;
  }

  .badge-falta {
    display: none;
  }
}

@media (min-width: 640px) {
  .header h1 {
    font-size: 1.75rem;
  }

  .main {
    padding: 1.25rem 1.5rem;
  }

  .btn-falta {
    min-width: 100px;
  }
}

/* Farm switcher */
.farm-switcher {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.85rem;
  justify-content: center;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.farm-btn {
  flex: 1;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.95rem;
  font-weight: 650;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.farm-btn.active {
  background: #fff;
  color: var(--green-dark);
  border-color: #fff;
}

.farm-btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

@media print {
  .farm-switcher {
    display: none !important;
  }

  .header h1::after {
    content: " — " attr(data-farm-print);
    font-weight: 500;
    font-size: 0.9em;
  }
}
