:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2321;
  --muted: #6b7570;
  --primary: #2e7d5b;
  --primary-dark: #235f45;
  --danger: #c0392b;
  --border: #e1e5e3;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

a { color: var(--primary); }

.wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 96px;
}

header.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

header.topbar h1 {
  font-size: 18px;
  margin: 0;
}

nav.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  background: var(--primary-dark);
  padding: 0 8px;
}

nav.tabs a {
  color: #fff;
  text-decoration: none;
  padding: 10px 12px;
  font-size: 14px;
  white-space: nowrap;
  opacity: 0.75;
  border-bottom: 3px solid transparent;
}

nav.tabs a.active {
  opacity: 1;
  border-bottom-color: #fff;
  font-weight: 600;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

h2 { font-size: 16px; margin: 0 0 12px; }

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

input, select {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus { outline: 2px solid var(--primary); }

button {
  font-size: 16px;
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}

button.secondary { background: var(--border); color: var(--text); }
button.danger { background: var(--danger); }
button.block { width: 100%; }
button:disabled { opacity: 0.5; cursor: default; }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.error {
  background: #fdecea;
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
  display: none;
}
.error.show { display: block; }

.muted { color: var(--muted); font-size: 13px; }

.suggestions {
  position: relative;
}
.suggestions ul {
  list-style: none;
  margin: 0;
  padding: 0;
  position: absolute;
  left: 0; right: 0;
  top: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 20;
  max-height: 220px;
  overflow-y: auto;
}
.suggestions li {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  cursor: pointer;
}
.suggestions li:last-child { border-bottom: none; }
.suggestions li:active { background: var(--bg); }

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: none; }
.item.checked .item-name { text-decoration: line-through; color: var(--muted); }
.item-name { flex: 1; font-size: 15px; }
.item-sub { font-size: 12px; color: var(--muted); }
.item-total { font-weight: 600; min-width: 72px; text-align: right; }
.item-qty {
  width: 56px;
  padding: 6px;
  margin: 0;
  text-align: center;
  font-size: 15px;
}
.icon-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 18px;
  padding: 4px 8px;
}
.icon-btn.confirm-armed {
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
}

.totalbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}
.totalbar .label { font-size: 13px; color: var(--muted); }
.totalbar .value { font-size: 22px; font-weight: 700; color: var(--primary); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

.necessidades-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 4px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-weight: normal;
}
.necessidades-header h2 { margin: 0; display: flex; align-items: center; gap: 6px; }
.necessidades-arrow {
  font-size: 18px;
  color: var(--muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.necessidades-box {
  display: none;
  flex-wrap: wrap;
}
.necessidades-box.open { display: flex; }
.necessidades-box.necessidades-scroll {
  max-height: 260px;
  overflow-y: auto;
  align-content: flex-start;
  padding-bottom: 2px;
}
.necessidades-arrow.expanded { transform: rotate(180deg); }
.chip-toggle {
  background: #fff;
  border-color: var(--primary);
  color: var(--primary-dark);
  font-weight: 600;
}

.stock-quick {
  display: flex;
  align-items: center;
  gap: 4px;
}
.stepper-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  line-height: 1;
  font-size: 16px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  flex-shrink: 0;
}
.stock-input {
  width: 48px;
  padding: 4px;
  margin: 0;
  text-align: center;
  font-size: 14px;
}
.falta-badge { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff3e0;
  color: #8a5a00;
  border: 1px solid #f2d199;
  padding: 8px 10px;
  border-radius: 20px;
  font-size: 13px;
  margin: 4px 4px 0 0;
  cursor: pointer;
}

.empty { text-align: center; color: var(--muted); padding: 24px 0; font-size: 14px; }

.center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.center-page .card { width: 100%; max-width: 360px; }
.brand { text-align: center; margin-bottom: 20px; }
.brand h1 { font-size: 22px; color: var(--primary); margin: 0; }
