:root {
  --bg: #f4efe8;
  --panel: #fffdf9;
  --text: #211a15;
  --muted: #766b61;
  --line: #ded4ca;
  --accent: #5c3927;
  --accent-dark: #3f2619;
  --low: #c7352b;
  --low-bg: #fff0ee;
  --selected: #dff2df;
  --shadow: 0 10px 30px rgba(55, 39, 27, .09);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
body { min-height: 100vh; }

.topbar {
  min-height: 72px;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #17130f;
  color: #fff;
}
.topbar h1 { margin: 0; font-size: clamp(21px, 3vw, 30px); }
.topbar p { margin: 2px 0 0; color: #cfc4bb; font-size: 13px; }
.top-actions { display: flex; align-items: center; gap: 7px; }
.status-pill {
  border: 1px solid #594c42;
  color: #d9cec5;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
}
.top-history-btn,
.top-reset-btn {
  border: 1px solid #594c42;
  background: #2a221c;
  color: #d9cec5;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
}
.top-history-btn { background: #2a221c; color: #d9cec5; border-radius: 999px; padding: 8px 12px; font-size: 12px; cursor: pointer; }
.top-history-btn:active, .top-reset-btn:active { background: #3a2f27; }

.app {
  height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 58% 42%;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}
.panel {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.ingredients-panel { display: flex; flex-direction: column; min-height: 0; }

.tabs {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  margin: 0 18px 9px;
  padding: 4px;
  border-radius: 10px;
  background: #eee7df;
}
.tab {
  min-width: 0;
  white-space: nowrap;
  border: 0;
  border-radius: 7px;
  padding: 9px 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.tab.active { background: #17130f; color: white; }

/* All Ingredients browser: category navigation on the left, ingredient list on the right. */
.inventory-browser {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(150px, 30%) 1fr;
  gap: 8px;
  padding: 0 10px 12px;
}
.category-pane {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 2px 8px;
  border-right: 1px solid var(--line);
}
.category-nav-item {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  margin-bottom: 5px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.category-nav-item:hover { background: #f7f1eb; }
.category-nav-item.active { background: #17130f; color: #fff; }
.category-nav-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.category-nav-name { line-height: 1.2; }
.category-progress {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}
.category-nav-item.active .category-progress { color: #cfcfcf; }
.category-check {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #55a957;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}
.category-list {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 2px 12px;
}

.low-mode .ingredients-panel { grid-column: 1 / -1; }
.low-mode .keypad-panel { display: none; }
.low-mode .inventory-browser {
  display: block;
  min-height: 0;
  height: 100%;
  padding: 0 14px 14px;
  overflow: hidden;
}
.low-mode .category-pane { display: none; }
.low-mode .category-list {
  height: 100%;
  min-height: 0;
  padding: 0 2px 12px;
  overflow-y: auto;
  overflow-x: hidden;
}
.low-mode .low-full-header { position: sticky; top: 0; z-index: 2; }
.low-mode .low-columns { position: sticky; top: 45px; z-index: 2; background: var(--panel); }

.category { margin-bottom: 12px; }
.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 11px;
  margin-bottom: 5px;
  border-radius: 9px;
  background: #000;
  color: #fff;
}
.category-header-static { position: relative; }
.category-title strong {
  display: block;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}
.category-title span {
  color: #c9c9c9 !important;
  font-size: 10px !important;
  margin-top: 2px;
}
.category-low {
  color: #ffb0ab !important;
  font-size: 10px !important;
  font-weight: 800;
}

.ingredient-row {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  margin-top: 4px;
  padding: 9px 10px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 9px;
  text-align: left;
  align-items: center;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.ingredient-row:hover { background: #f8f3ed; }
.ingredient-row.selected { background: var(--selected); border-color: #9fcb9f; }
.ingredient-row.low { background: var(--low-bg); }
.ingredient-row.low.selected { background: var(--selected); border-color: #9fcb9f; }
.item-main strong { display: block; font-size: 13px; }

.item-main {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.item-check {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #55a957;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}
.item-stock.out-stock-text {
  text-align: right;
  font-size: 12px;
  line-height: 1.1;
}

.item-stock { text-align: right; min-width: 64px; }
.item-stock strong { font-size: 15px; }
.warning-dot {
  width: 20px; height: 20px; display: grid; place-items: center;
  border-radius: 50%; background: var(--low); color: white; font-weight: 800; font-size: 11px;
}

.low-columns, .low-stock-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.5fr) minmax(150px, 1fr) minmax(140px, 1fr) minmax(120px, .8fr);
  align-items: center;
  column-gap: 14px;
}
.low-columns {
  padding: 7px 12px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.low-stock-row {
  min-height: 50px;
  margin-top: 4px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 12px;
}
.low-stock-row > strong { font-size: 13px; }
.low-stock-row > span { color: var(--muted); }
.remaining-stock { font-weight: 800; color: var(--text) !important; }
.order-cell { display: flex; align-items: center; }
.ordered-btn {
  min-width: 90px;
  border: 1px solid #c8c8c8;
  border-radius: 8px;
  padding: 7px 11px;
  background: #d6d6d6;
  color: #666;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}
.ordered-btn.is-ordered { background: #55a957; border-color: #55a957; color: #fff; }
.ordered-btn:active { transform: scale(.98); }
.list-empty {
  margin: 18px 8px;
  padding: 22px 12px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
}
.list-empty strong, .list-empty span { display: block; }
.list-empty strong { color: var(--text); margin-bottom: 4px; }

.keypad-panel {
  min-height: 0;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.editor {
  width: min(100%, 390px);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.keypad-item-name {
  min-height: 18px;
  text-align: center;
  font-size: 12px;
  line-height: 18px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.empty-state { text-align: center; color: var(--muted); padding: 25px; }
.empty-state h2 { color: var(--text); margin: 8px 0 4px; }
.empty-icon { font-size: 42px; }
.hidden { display: none !important; }

.measure-inputs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
}
.measure-input-box.packaging-input {
  min-height: 42px;
}
.measure-input-box {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #faf7f2;
  color: var(--text);
  padding: 4px 5px;
  text-align: left;
  cursor: pointer;
}
.measure-input-box.active {
  border-color: #55a957;
  background: #edf7ed;
}
.measure-input-box.single {
  grid-column: 1 / -1;
}
.measure-input-box span {
  display: block;
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
  text-transform: uppercase;
}
.measure-input-box strong {
  display: block;
  margin-top: 1px;
  font-size: 15px;
  line-height: 18px;
}
.measure-total {
  min-height: 17px;
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}
.measure-hint {
  min-height: 14px;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
}

.keypad-display {
  min-height: 44px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 0 14px;
  background: #17130f;
  color: white;
  border-radius: 10px;
  font-size: 29px;
  font-weight: 800;
  overflow: hidden;
}
.keypad-display.out-stock-display {
  background: #55a957;
  color: #fff;
  justify-content: center;
  letter-spacing: .04em;
  font-size: 20px;
}
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.keypad button {
  min-height: 47px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #faf7f2;
  color: var(--text);
  font-size: 21px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.keypad button:active { transform: scale(.98); background: #eee5dc; }
.keypad .out-stock-key {
  font-size: 11px;
  line-height: 1.1;
  padding: 4px;
  background: #f0eae3;
}
.save-btn {
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}
.save-btn:active { background: var(--accent-dark); }
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  background: #17130f;
  color: white;
  padding: 11px 15px;
  border-radius: 10px;
  transition: .2s ease;
  box-shadow: var(--shadow);
  font-size: 12px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .topbar { min-height: 62px; padding: 10px 13px; }
  .app { height: calc(100vh - 62px); grid-template-columns: 56% 44%; gap: 7px; padding: 7px; }
  .panel { border-radius: 12px; }
  .tabs { margin: 0 9px 7px; }
  .tab { padding: 7px 3px; font-size: clamp(8px, 1.3vw, 10px); }
  .inventory-browser { grid-template-columns: minmax(110px, 31%) 1fr; gap: 5px; padding: 0 6px 8px; }
  .category-nav-item { min-height: 48px; padding: 7px 7px; font-size: 10px; }
  .category-check { width: 17px; height: 17px; font-size: 10px; }
  .category-progress { font-size: 8px; }
  .category-header { padding: 7px 8px; }
  .category-title strong { font-size: 12px; }
  .category-title span, .category-low { font-size: 9px !important; }
  .ingredient-row { grid-template-columns: 1fr auto; padding: 8px 7px; }
  .ingredient-row .warning-dot { display: none; }
  .item-stock { min-width: 49px; }
  .item-stock strong { font-size: 13px; }
  .item-main strong { font-size: 11px; }
  .keypad-panel { padding: 8px; }
  .editor { gap: 7px; }
  .keypad-item-name { font-size: 10px; }
  .keypad-display { min-height: 42px; font-size: 24px; }
  .keypad { gap: 4px; }
  .keypad button { min-height: 45px; font-size: 19px; }
  .keypad .out-stock-key { font-size: 9px; }
  .keypad-display.out-stock-display { font-size: 16px; }
  .save-btn { min-height: 43px; font-size: 12px; }
  .top-actions { gap: 4px; }
  .status-pill { padding: 6px 8px; font-size: 9px; }
  .top-reset-btn { padding: 6px 8px; font-size: 9px; }
  .low-columns, .low-stock-row { grid-template-columns: 1.35fr 1fr .9fr .8fr; column-gap: 7px; }
  .low-columns { padding: 6px 7px; font-size: 8px; }
  .low-stock-row { padding: 8px 7px; font-size: 9px; }
  .low-stock-row > strong { font-size: 10px; }
  .ordered-btn { min-width: 65px; padding: 6px 7px; font-size: 9px; }
}

@media (max-width: 430px) {
  .app { grid-template-columns: 55% 45%; }
  .inventory-browser { grid-template-columns: minmax(94px, 32%) 1fr; }
  .category-nav-item { font-size: 9px; }
  .item-stock small { font-size: 8px; }
  .keypad-panel { padding: 6px; }
}

.previous-filter {
  border: 1px solid #5a5a5a;
  background: #2b2b2b;
  color: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}
.previous-filter.active { background: #55a957; border-color: #55a957; }
.previous-order-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 90px;
  padding: 7px 10px;
  border-radius: 8px;
  background: #d6d6d6;
  color: #666;
  font-size: 11px;
  font-weight: 800;
}
.previous-order-status.is-ordered { background: #55a957; color: #fff; }
.out-stock-text { color: #55a957 !important; font-weight: 900 !important; }
@media (max-width: 760px) {
  .top-actions { gap: 4px; }
  .top-history-btn, .top-reset-btn { padding: 7px 8px; font-size: 10px; }
}

.previous-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.today-inventory-btn {
  border: 1px solid #17130f;
  background: #17130f;
  color: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 800;
  cursor: pointer;
}

.today-inventory-btn:hover {
  opacity: .9;
}

@media (max-width: 760px) {
  .previous-actions {
    width: 100%;
    justify-content: stretch;
  }
  .previous-actions button {
    flex: 1 1 0;
  }
}

.supplier-group-header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 7px 10px;
  background: #111;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  border-top: 1px solid #222;
  border-bottom: 1px solid #222;
}
