:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #efebe3;
  --text: #1f2a24;
  --muted: #6b756f;
  --accent: #2f5d45;
  --accent-2: #3f7a58;
  --border: #d9d2c5;
  --danger: #b45309;
  --ok: #2f5d45;
  --warn-bg: #fff4e5;
  --warn-text: #b45309;
  --pool-bg: #ebe6dc;
  --order-bg: #ffffff;
  --dash: #9aa89a;
  --shadow: rgba(47, 93, 69, 0.12);
  --scroll: #2f5d45;
  --fs-base: 15;
  --radius: 14px;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html {
  scrollbar-gutter: stable;
}
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
    radial-gradient(900px 400px at 90% 0%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: calc(var(--fs-base) * 1px);
  line-height: 1.45;
}
body {
  overflow-y: scroll;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* thin themed scrollbars */
.pool, .orders-row, .waiting-list {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll) color-mix(in srgb, var(--accent) 12%, transparent);
}
.pool::-webkit-scrollbar,
.orders-row::-webkit-scrollbar,
.waiting-list::-webkit-scrollbar { height: 6px; width: 6px; }
.pool::-webkit-scrollbar-track,
.orders-row::-webkit-scrollbar-track,
.waiting-list::-webkit-scrollbar-track {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: 999px;
}
.pool::-webkit-scrollbar-thumb,
.orders-row::-webkit-scrollbar-thumb,
.waiting-list::-webkit-scrollbar-thumb {
  background: var(--scroll);
  border-radius: 999px;
}

.top {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 0 20px;
  height: 56px;
  min-height: 56px;
  max-height: 56px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-shrink: 0;
}
.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
  height: 56px;
}
.tab {
  border: 1px solid transparent;
  background: transparent;
  padding: 0 14px;
  height: 36px;
  min-height: 36px;
  max-height: 36px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  box-shadow: none;
  line-height: 34px;
  flex: 0 0 auto;
}
.tab[data-tab="layout"] { min-width: 110px; text-align: center; }
.tab[data-tab="waiting"] { min-width: 168px; text-align: center; }
.tab[data-tab="rules"] { min-width: 110px; text-align: center; }
.tab[data-tab="settings"] { min-width: 120px; text-align: center; }
.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: none;
}

/* full-width workspace — no centered narrow column */
main.panels {
  position: relative;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 16px 20px 32px;
  min-height: calc(100vh - 56px);
  box-sizing: border-box;
}
/* keep inactive panels out of flow without collapsing chrome */
.panel {
  display: none;
  width: 100%;
  min-width: 0;
}
.panel.active {
  display: block;
}
.page-title {
  font-family: var(--display);
  font-size: 1.45rem;
  margin: 0 0 14px;
  color: var(--accent);
  min-height: 1.6em;
}

.btn, .btn-parse {
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 10px 16px;
  font-weight: 700;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost {
  background: transparent; border-color: var(--border); color: var(--accent);
}
.btn-ghost:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.btn-sm { padding: 6px 10px; font-size: 0.85rem; }

.layout-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  width: 100%;
  min-width: 0;
}
.left-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 72px;
  width: 360px;
  max-width: 360px;
  min-width: 360px;
  justify-self: start;
}
.orders-block {
  min-width: 0;
  width: 100%;
}

.paste-form {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: none;
  min-height: 44px;
  width: 100%;
}
.paste-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: none;
  resize: none;
  max-height: 40px;
  padding: 10px 12px;
  background: transparent;
  line-height: 1.35;
  font-size: 0.85rem;
}
.paste-form:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}
.btn-parse {
  flex: 0 0 auto;
  min-width: 96px;
  margin: 0;
  border: 0;
  border-left: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: 0;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: color-mix(in srgb, var(--accent) 85%, var(--text));
  font-size: 0.85rem;
}
.hint { color: var(--muted); font-size: 0.88rem; margin: 8px 0 0; }

.block-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 0 0 10px;
}
.block-head h2 {
  margin: 0; font-size: 0.92rem; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted); font-weight: 800;
}
.head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent); border-radius: 999px; padding: 3px 8px; font-weight: 700; font-size: 0.78rem;
}
.totals { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 0.82rem; }
.totals strong { color: var(--accent); }

.pool {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
  padding: 10px;
  background: var(--pool-bg);
  border: 1px dashed color-mix(in srgb, var(--accent) 28%, var(--border));
  border-radius: calc(var(--radius) + 2px);
  min-height: 180px;
}
.pool.drag-over {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

.product-chip {
  flex: 0 0 auto;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  box-shadow: 0 4px 10px var(--shadow);
  cursor: grab;
  user-select: none;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 8px;
  align-items: center;
}
.product-chip:active { cursor: grabbing; }
.product-chip.dragging { opacity: 0.4; }
.product-chip .thumb {
  grid-row: 1 / span 2;
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, #fff), var(--surface-2));
  display: grid; place-items: center; overflow: hidden; font-size: 0.75rem;
}
.product-chip .thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-chip .name {
  font-weight: 700; font-size: 0.75rem; line-height: 1.2;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.product-chip .meta { display: none; }
.product-chip .price { font-weight: 800; color: var(--accent); font-size: 0.78rem; justify-self: end; }
.product-chip .badge-low {
  grid-column: 2; font-size: 0.65rem; font-weight: 700;
  background: var(--warn-bg); color: var(--warn-text);
  border-radius: 999px; padding: 1px 6px; width: fit-content;
}
.chip-del {
  border: 0; background: transparent; color: var(--muted); padding: 0 2px; font-size: 0.8rem;
  grid-column: 3; grid-row: 2;
}
.chip-del:hover { color: var(--danger); }

.orders-row {
  display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 10px; align-items: stretch;
}
.order-card, .order-add {
  flex: 0 0 270px; width: 270px;
  border-radius: 16px;
  min-height: 380px;
}
.order-card {
  background: var(--order-bg);
  border: 1px solid var(--border);
  box-shadow: 0 10px 24px var(--shadow);
  display: flex; flex-direction: column;
  padding: 10px;
}
.order-card.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.order-card.over-limit { border-color: var(--danger); }
.order-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px;
}
.order-title { font-weight: 800; margin: 0; font-size: 1rem; }

.order-items {
  flex: 1; display: flex; flex-direction: column; gap: 6px;
  min-height: 100px; padding: 2px; overflow-y: auto;
}
.order-item {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 6px; align-items: center;
  border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px;
  background: color-mix(in srgb, var(--surface) 80%, var(--surface-2));
  cursor: grab;
}
.order-item .mini {
  width: 28px; height: 28px; border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 12%, #fff);
  overflow: hidden; display: grid; place-items: center; font-size: 0.7rem;
}
.order-item .mini img { width: 100%; height: 100%; object-fit: cover; }
.order-item .n { font-size: 0.72rem; font-weight: 700; line-height: 1.2; }
.order-item .p { font-weight: 800; color: var(--accent); font-size: 0.75rem; }

.metrics {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px;
  background: var(--surface-2); border-radius: 10px; padding: 8px; margin-top: auto;
}
.metrics div { display: flex; flex-direction: column; gap: 1px; }
.metrics span { color: var(--muted); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.03em; }
.metrics strong { font-size: 0.86rem; }
.metrics .total { grid-column: 1 / -1; }
.metrics .total strong { color: var(--accent); font-size: 1.05rem; }

.order-foot {
  display: flex; justify-content: space-between; gap: 8px;
  color: var(--muted); font-size: 0.75rem; padding-top: 6px;
}
.order-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.order-add {
  border: 2px dashed var(--dash);
  background: color-mix(in srgb, var(--accent) 4%, transparent);
  display: grid; place-items: center; color: var(--accent);
  font-weight: 800; gap: 8px; cursor: pointer;
}
.order-add:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.order-add .plus { font-size: 2.2rem; line-height: 1; }

.waiting-list {
  display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px;
}
.waiting-card {
  flex: 0 0 300px; width: 300px;
  background: var(--order-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 10px 24px var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.waiting-card .pos {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 0.8rem; border-bottom: 1px dashed var(--border); padding: 4px 0;
}

.rules-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px;
}
.rule-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: none !important;
  filter: none;
}
#tab-rules .rule-card,
#tab-rules .rules-grid > * {
  box-shadow: none !important;
}
.rule-card h3 { margin: 0 0 12px; color: var(--accent); font-family: var(--display); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-weight: 600; font-size: 0.9rem; }
.field input, .cookies-input {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  background: var(--surface-2);
}
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.rules-actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }

.settings-layout {
  display: grid; grid-template-columns: 1.2fr 0.9fr; gap: 18px;
}
.scheme-wall {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px;
  align-content: start;
}
.scheme-card {
  position: relative; overflow: hidden; border-radius: 18px; min-height: 140px;
  border: 1px solid var(--border); cursor: pointer;
  box-shadow: 0 10px 24px var(--shadow);
  background: var(--surface);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
  transform: none !important;
}
.scheme-card:hover {
  transform: none !important;
  border-color: var(--accent);
  box-shadow: 0 12px 28px var(--shadow);
}
.scheme-swatch {
  display: grid; grid-template-columns: 1.4fr 1fr 0.7fr; min-height: 96px;
}
.scheme-swatch span { display: block; }
.scheme-meta { padding: 10px 12px; }
.scheme-meta strong { display: block; }
.scheme-meta small { color: var(--muted); }

.color-grid { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 14px; }
.color-row {
  display: grid; grid-template-columns: 1fr 52px; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px;
}
.color-row input[type="color"] {
  width: 48px; height: 34px; border: 0; background: transparent; padding: 0;
}
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input { flex: 1; }
.settings-side {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 16px; box-shadow: 0 12px 28px var(--shadow);
}
.settings-side h3 { margin: 0 0 8px; color: var(--accent); font-family: var(--display); }

.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  background: var(--accent); color: #fff; padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 12px 30px var(--shadow); max-width: 360px;
}

@media (max-width: 1100px) {
  .layout-grid {
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 14px;
  }
  .left-col {
    width: 300px;
    max-width: 300px;
    min-width: 300px;
  }
}

@media (max-width: 820px) {
  .tabs { flex-wrap: wrap; }
  .layout-grid { grid-template-columns: 1fr; }
  .left-col {
    position: static;
    width: 100%;
    max-width: none;
    min-width: 0;
  }
  .pool { max-height: 220px; flex-direction: row; overflow-x: auto; }
  .product-chip { width: 140px; flex: 0 0 140px; }
  .rules-grid, .settings-layout { grid-template-columns: 1fr; }
}
