:root {
  --bg: #f5f5f2;
  --card: #ffffff;
  --ink: #161616;
  --muted: #6b6b66;
  --line: #e2e2dc;
  --soft: #f0f0eb;
  --ok: #1f7a45;
  --ok-bg: #e6f4ec;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --idle: #55554f;
  --idle-bg: #ecece6;
  --link: #1d4ed8;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--link); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 18px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 0; margin: 8px 0 0; font-size: 14px; }
.error:empty { display: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; flex-direction: column; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

main { padding: 16px; }
main.narrow { max-width: 520px; margin: 0 auto; }
main.wide { max-width: 1280px; margin: 0 auto; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}
.card.notice { border-color: #e9c46a; background: var(--warn-bg); }
.card.success { text-align: center; padding: 40px 16px; }
.big-text { font-size: 22px; font-weight: 600; color: var(--ok); margin: 0; }

.btn {
  font: inherit;
  border-radius: 10px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
}
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.primary { background: #111; color: #fff; border-color: #111; }
.btn.danger { color: var(--bad); border-color: #f1b8b2; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.big { min-height: 54px; font-size: 18px; margin-top: 16px; }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }

.question { margin: 20px 0 12px; font-size: 22px; }
.who { margin: 0; font-size: 14px; }
.types { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.type-btn.wide, .types-group { grid-column: 1 / -1; }
.type-btn.half { grid-column: span 3; }
.types-group { margin: 6px 0 -4px; font-size: 13px; color: var(--muted); }
.type-btn {
  font: inherit;
  font-size: 22px;
  font-weight: 600;
  min-height: 110px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
}
.type-btn:active { background: #111; color: #fff; }
.form-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }

.field { display: block; margin-top: 12px; }
.field > .label, .materials > .label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #111; outline-offset: -1px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row > .field { margin-top: 12px; }
details.more { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.pull-counts { margin: 8px 0; padding-inline-start: 18px; font-size: 14px; }
.pull-counts li { margin: 2px 0; }
#pull-name-issues ul { font-size: 13px; max-height: 280px; overflow: auto; }
.when-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.when-part { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; }
.when-row .btn { flex: 0 0 auto; }
.stock-warning { margin: 12px 0 0; font-size: 14px; color: var(--warn); background: var(--warn-bg); border: 1px solid #e9c46a; border-radius: 8px; padding: 8px 10px; }
.stock-warning:empty { display: none; }
.stock-warning p { margin: 4px 0; }
.stock-warning .strong { font-weight: 600; }
.stock-warning.unconfirmed { display: block; margin-top: 6px; font-size: 13px; }
.route-hint, .operational { margin: 8px 0 0; font-size: 13px; color: var(--muted); background: var(--soft); border-radius: 8px; padding: 8px 10px; }
.operational:empty { display: none; }

.segmented { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button { flex: 1; font: inherit; padding: 10px; border: 0; background: #fff; cursor: pointer; min-height: 44px; }
.segmented button.active { background: #111; color: #fff; }

.materials { margin-top: 12px; }
.material-line { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 6px; margin-bottom: 6px; align-items: start; }
.recipe-line { margin: 4px 0; }

.combo { position: relative; }
.combo-list {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 2px);
  max-height: 240px;
  overflow: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  z-index: 20;
}
.combo-list li { padding: 9px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.combo-list li.active, .combo-list li:hover { background: var(--soft); }
.combo-list li.selected { font-weight: 600; }
.combo-list li.empty { cursor: default; }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.status-SUBMITTED, .status-NEEDS_REVIEW { background: var(--warn-bg); color: var(--warn); }
.status-READY_FOR_ODOO { background: var(--idle-bg); color: var(--idle); }
.status-ODOO_POSTED { background: var(--ok-bg); color: var(--ok); }
.status-CANCELLED { background: var(--bad-bg); color: var(--bad); }
.readiness-READY { background: var(--ok-bg); color: var(--ok); }
.readiness-NEEDS_ODOO_SETUP { background: var(--warn-bg); color: var(--warn); }
.readiness-NEEDS_BUSINESS_INPUT { background: var(--bad-bg); color: var(--bad); }
.no-options { display: block; margin-top: 4px; }
#master-table td.small { min-width: 240px; }

.cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi {
  font: inherit;
  text-align: start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
}
.kpi b { display: block; font-size: 24px; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi small { display: block; color: var(--muted); font-size: 11px; }
.kpi.active { border-color: #111; }
.kpi:disabled { cursor: default; }

.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; align-items: end; }
.filters .field { margin-top: 0; }
.filters input, .filters select { min-height: 38px; padding: 7px 10px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--soft); }
tbody tr.current { background: #ebebe4; }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
td.nowrap { white-space: nowrap; }
.link-btn { font: inherit; background: none; border: 0; padding: 0; color: var(--link); cursor: pointer; text-decoration: underline; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.layout.with-detail { grid-template-columns: minmax(0, 1.25fr) minmax(360px, 1fr); }
.detail { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.detail section { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.detail section:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 8px 0 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.hint { font-size: 13px; color: var(--muted); background: var(--soft); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.history { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; }
.history li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
pre.json { background: var(--soft); border-radius: 8px; padding: 8px; font-size: 12px; overflow: auto; max-height: 220px; direction: ltr; text-align: left; }
.ops-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 8px; font-size: 14px; }
.ops-grid ul { margin: 4px 0 0; padding-inline-start: 18px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tabs button { font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; cursor: pointer; }
.tabs button.active { background: #111; color: #fff; border-color: #111; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 10px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.check input { width: auto; min-height: 0; }
.ok-text { color: var(--ok); font-size: 14px; }

@media (max-width: 960px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .layout.with-detail { grid-template-columns: minmax(0, 1fr); }
  .detail { position: static; max-height: none; }
}
@media (max-width: 520px) {
  .row { grid-template-columns: 1fr; }
  .material-line { grid-template-columns: 1fr 1fr; }
  .topbar { flex-wrap: wrap; }
}
