/* Studio Edit CMS — calm, clear, brown + cream. */
:root {
  --bg: #F5F0E9; --panel: #FFFFFF; --soft: #FAF7F2; --line: #E8DFD3; --line2: #F0E9DF;
  --text: #2B1E16; --mute: #85725F; --faint: #B5A592;
  --brand: #4A3426; --brand-2: #6B4E3A; --cream: #F6EEE2; --accent: #9C7653;
  --green: #3F6B47; --green-bg: #EAF2EA; --amber: #94661C; --amber-bg: #FBF1DE;
  --red: #A33A2C; --red-bg: #FBECE8; --blue: #3D5A80; --blue-bg: #E9EFF7; --violet: #6B4C8A; --violet-bg: #F1ECF7;
  --r: 12px; --sans: "Jost", "Helvetica Neue", Arial, sans-serif; --serif: "Cormorant Garamond", serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.ar { font-family: "IBM Plex Sans Arabic", var(--sans); direction: rtl; }

/* ---- Shell ---- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-inline-end: 1px solid var(--line); padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
.side-logo { padding: 4px 10px 10px; }
.side-logo img { height: 15px; width: auto; }
.side-logo span { display: block; font-size: 10px; letter-spacing: .28em; color: var(--faint); margin-top: 8px; }
.side nav { display: grid; gap: 2px; }
.side .grp { font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--faint); padding: 14px 12px 6px; }
.side nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px; color: #5a4636; font-size: 14px; }
.side nav a svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.5; flex: none; opacity: .8; }
.side nav a:hover { background: var(--soft); }
.side nav a.on { background: var(--brand); color: var(--cream); }
.side nav a .count { margin-inline-start: auto; background: var(--amber-bg); color: var(--amber); border-radius: 20px; font-size: 11px; padding: 1px 8px; font-weight: 500; }
.side nav a.on .count { background: rgba(255,255,255,.18); color: var(--cream); }
.side-foot { margin-top: auto; border-top: 1px solid var(--line2); padding: 14px 12px 0; display: grid; gap: 8px; font-size: 13px; color: var(--mute); }
.side-foot button { background: none; border: 0; padding: 0; text-align: start; color: var(--mute); }
.main { min-width: 0; padding: 26px clamp(16px, 3vw, 40px) 60px; }
.topbar { display: none; }
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 264px; z-index: 50; transform: translateX(-100%); transition: transform .3s; box-shadow: 0 0 40px rgba(0,0,0,.12); }
  .side.on { transform: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
  .topbar img { height: 13px; }
  .main { padding: 18px 16px 60px; }
}

/* ---- Page head ---- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head h1 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 34px; line-height: 1.1; }
.head .sub { color: var(--mute); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--brand); background: var(--brand); color: var(--cream); font-size: 13px; font-weight: 500; white-space: nowrap; transition: background .2s, border-color .2s; }
.btn:hover { background: #3a281d; }
.btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.btn.ghost { background: var(--panel); color: var(--brand); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--brand); }
.btn.sm { height: 30px; padding: 0 12px; font-size: 12px; }
.btn.danger { background: var(--panel); color: var(--red); border-color: #EBCFC9; }
.btn.green { background: var(--green); border-color: var(--green); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.linkish { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; background: none; border: 0; padding: 0; font-size: inherit; }

/* ---- Cards ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line2); }
.card-h h2 { margin: 0; font-size: 15px; font-weight: 500; }
.card-b { padding: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.stack { display: grid; gap: 16px; }

/* ---- KPI ---- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; display: grid; gap: 4px; }
.kpi .l { font-size: 12px; color: var(--mute); }
.kpi .v { font-size: 26px; font-weight: 500; letter-spacing: -.01em; }
.kpi .v small { font-size: 13px; color: var(--mute); font-weight: 400; }
.kpi .d { font-size: 12px; color: var(--mute); }
.kpi.dark { background: var(--brand); color: var(--cream); border-color: var(--brand); }
.kpi.dark .l, .kpi.dark .d, .kpi.dark .v small { color: #D7C6B2; }
.up { color: var(--green); } .down { color: var(--red); }

/* ---- Tabs + filters ---- */
.tabs { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.tabs a, .tabs button { padding: 6px 14px; border-radius: 999px; font-size: 13px; color: var(--mute); background: none; border: 0; white-space: nowrap; }
.tabs a.on, .tabs button.on { background: var(--brand); color: var(--cream); }
.tabs .n { opacity: .7; margin-inline-start: 4px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select { height: 36px; border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; background: var(--panel); min-width: 0; }
.filters input[type=search] { width: 240px; }

/* ---- Table ---- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: start; font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--mute); padding: 10px 14px; background: var(--soft); border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--soft); }
.tbl .num { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl .thumb { width: 44px; height: 58px; border-radius: 6px; background: var(--soft); object-fit: cover; border: 1px solid var(--line2); }
.strong { font-weight: 500; }
.muted { color: var(--mute); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.empty { padding: 36px 18px; text-align: center; color: var(--mute); }

/* ---- Pills ---- */
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--soft); color: var(--mute); border: 1px solid var(--line2); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.plain::before { display: none; }
.s-pending, .s-unpaid { background: #F3EFEA; color: #8A7B6D; }
.s-confirmed { background: var(--blue-bg); color: var(--blue); border-color: #D8E2EF; }
.s-preparing { background: var(--amber-bg); color: var(--amber); border-color: #F1E0BE; }
.s-out_for_delivery, .s-shipped { background: var(--violet-bg); color: var(--violet); border-color: #E2D8EE; }
.s-delivered, .s-paid { background: var(--green-bg); color: var(--green); border-color: #D3E4D3; }
.s-cancelled, .s-failed, .s-returned, .s-refunded { background: var(--red-bg); color: var(--red); border-color: #F0D5CF; }
.stock-ok { color: var(--green); } .stock-low { color: var(--amber); font-weight: 500; } .stock-out { color: var(--red); font-weight: 500; }

/* ---- Forms ---- */
.f { display: grid; gap: 6px; }
.f > label, .lbl { font-size: 12px; font-weight: 500; color: #5d4a3b; }
.f .hint, .hint { font-size: 12px; color: var(--faint); }
.inp, .f input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=color]), .f select, .f textarea {
  width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 9px; padding: 0 12px; background: var(--panel); outline: none; transition: border-color .15s, box-shadow .15s;
}
.f textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.inp:focus, .f input:focus, .f select:focus, .f textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(156,118,83,.12); }
.f .err, .err { color: var(--red); font-size: 12px; }
.money-inp { position: relative; }
.money-inp input { padding-inline-end: 48px !important; }
.money-inp span { position: absolute; inset-inline-end: 12px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--faint); }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; user-select: none; }
.switch input { appearance: none; -webkit-appearance: none; width: 38px; height: 22px; border-radius: 22px; background: #DDD2C4; position: relative; transition: background .2s; margin: 0; cursor: pointer; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.switch input:checked { background: var(--green); }
.switch input:checked::after { transform: translateX(16px); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.full { grid-column: 1/-1; }
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; border: 1px solid; }
.alert.ok { background: var(--green-bg); color: var(--green); border-color: #D3E4D3; }
.alert.bad { background: var(--red-bg); color: var(--red); border-color: #F0D5CF; }
.alert.warn { background: var(--amber-bg); color: var(--amber); border-color: #F1E0BE; }
.savebar { position: sticky; bottom: 0; z-index: 20; display: flex; justify-content: flex-end; gap: 10px; padding: 14px 0; background: linear-gradient(180deg, rgba(245,240,233,0), var(--bg) 35%); }

/* ---- Product editor ---- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.photo { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: var(--soft); border: 1px solid var(--line); cursor: grab; }
.photo img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.photo .x { position: absolute; top: 6px; inset-inline-end: 6px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(255,255,255,.92); color: var(--red); font-size: 15px; line-height: 1; display: grid; place-items: center; box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.photo .cover { position: absolute; bottom: 6px; inset-inline-start: 6px; background: var(--brand); color: var(--cream); font-size: 10px; padding: 2px 8px; border-radius: 20px; letter-spacing: .05em; }
.photo:not(:first-child) .cover { display: none; }
.photo.drag { opacity: .4; }
.photo.over { outline: 2px dashed var(--accent); outline-offset: 2px; }
.photo.removed { display: none; }
.photo select { position: absolute; bottom: 6px; inset-inline-end: 6px; max-width: 70%; height: 24px; font-size: 11px; border-radius: 6px; border: 1px solid var(--line); background: rgba(255,255,255,.95); }
.drop { aspect-ratio: 3/4; border: 1.5px dashed #D3C4B1; border-radius: 10px; display: grid; place-items: center; text-align: center; color: var(--mute); font-size: 12px; cursor: pointer; padding: 10px; background: var(--soft); transition: border-color .2s, background .2s; }
.drop:hover, .drop.hot { border-color: var(--accent); background: #F6EFE5; }
.drop svg { width: 26px; height: 26px; stroke: var(--accent); fill: none; stroke-width: 1.4; margin: 0 auto 6px; }
.tagbox { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 42px; border: 1px solid var(--line); border-radius: 9px; padding: 5px 8px; background: var(--panel); }
.tagbox:focus-within { border-color: var(--accent); }
.tagbox input[data-tag-input] { border: 0 !important; outline: none; height: 30px !important; flex: 1; min-width: 90px; padding: 0 4px !important; box-shadow: none !important; }
.tag { display: inline-flex; align-items: center; gap: 6px; background: var(--soft); border: 1px solid var(--line); border-radius: 999px; padding: 3px 6px 3px 10px; font-size: 13px; }
.tag i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); }
.tag button { border: 0; background: none; color: var(--mute); font-size: 14px; line-height: 1; padding: 0 3px; }
.tag input[type=color] { width: 18px; height: 18px; border: 0; padding: 0; background: none; cursor: pointer; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.presets button { border: 1px dashed var(--line); background: none; border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--mute); }
.presets button:hover { border-color: var(--accent); color: var(--accent); }
.matrix td { padding: 8px 10px; }
.matrix input { height: 34px !important; }
.stock-inp { width: 90px !important; text-align: center; }
.qty-step { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); }
.qty-step button { width: 32px; height: 34px; border: 0; background: var(--soft); font-size: 16px; color: var(--brand); }
.qty-step input { width: 64px; height: 34px; border: 0; text-align: center; outline: none; }

/* ---- Order view ---- */
.timeline { display: grid; gap: 12px; }
.timeline div { display: grid; grid-template-columns: 10px 1fr; gap: 10px; font-size: 13px; }
.timeline div::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 6px; }
.steps { display: flex; gap: 6px; flex-wrap: wrap; }
.steps form { display: contents; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--mute); }
.kv dd { margin: 0; }
.item-row { display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line2); }
.item-row:last-child { border-bottom: 0; }
.item-row img, .item-row .ph { width: 52px; height: 68px; object-fit: cover; border-radius: 6px; background: var(--soft); }

/* ---- Charts ---- */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 180px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; min-width: 0; position: relative; }
.bars .b span { width: 100%; max-width: 34px; background: linear-gradient(180deg, #8A6A50, var(--brand)); border-radius: 5px 5px 2px 2px; min-height: 2px; transition: opacity .2s; }
.bars .b.zero span { background: var(--line); }
.bars .b:hover span { opacity: .8; }
.bars .b em { font-style: normal; font-size: 10px; color: var(--faint); white-space: nowrap; }
.bars .b .tip { position: absolute; bottom: calc(100% - 4px); background: var(--text); color: #fff; font-size: 11px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; opacity: 0; pointer-events: none; transform: translateY(4px); transition: all .15s; z-index: 2; }
.bars .b:hover .tip { opacity: 1; transform: none; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; font-size: 13px; padding: 7px 0; }
.hbar .track { grid-column: 1/-1; height: 6px; border-radius: 6px; background: var(--line2); overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }

/* ---- Login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--brand); }
.login .box { width: min(400px, 100%); background: var(--panel); border-radius: 16px; padding: 34px 30px; display: grid; gap: 16px; }
.login .box img { height: 18px; width: auto; margin: 0 auto 6px; }

/* ---- Print ---- */
@media print {
  .side, .topbar, .no-print, .savebar { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  body { background: #fff; }
  .card { border: 0; }
}

.bars .b .stack-bar { display: flex; flex-direction: column; background: none !important; overflow: hidden; }
.bars .b .stack-bar i { display: block; width: 100%; min-height: 1px; }
.legend { display: flex; gap: 16px; margin-top: 12px; font-size: 12px; color: var(--mute); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }
.split-bar { display: flex; height: 10px; border-radius: 10px; overflow: hidden; background: var(--line2); margin: 10px 0 6px; }
.split-bar i { display: block; height: 100%; }
.kpi .mini { display: flex; justify-content: space-between; font-size: 12px; color: var(--mute); }
.chart-tabs { display: flex; gap: 6px; }

/* ---- Bilingual labels, required marks, guides, form checks ---- */
.bl { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 12px; font-weight: 500; color: #5d4a3b; }
.bl-ar { font-family: "IBM Plex Sans Arabic", var(--sans); font-weight: 500; color: var(--mute); font-size: 12.5px; }
.req { color: var(--red); margin-inline-start: 3px; font-weight: 600; }
.bh { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--faint); line-height: 1.45; }
.bh span[dir=rtl] { font-family: "IBM Plex Sans Arabic", var(--sans); text-align: right; }
.req-note { font-size: 12px; color: var(--mute); display: flex; justify-content: space-between; gap: 10px; margin: -6px 0 14px; }
.req-note b { color: var(--red); }
.guide { background: #FFFCF6; border: 1px solid #EADFCD; border-radius: var(--r); margin-bottom: 18px; }
.guide summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 12px 16px; font-weight: 500; }
.guide summary::-webkit-details-marker { display: none; }
.guide summary .g-ar { margin-inline-start: auto; }
.guide summary::after { content: "▾"; color: var(--mute); margin-inline-start: 8px; transition: transform .2s; }
.guide[open] summary::after { transform: rotate(180deg); }
.g-ico { width: 22px; height: 22px; border-radius: 50%; background: var(--brand); color: var(--cream); display: grid; place-items: center; font-size: 13px; flex: none; }
.g-ar { font-family: "IBM Plex Sans Arabic", var(--sans); color: #5d4a3b; }
.guide-body { padding: 4px 16px 16px; display: grid; gap: 10px; }
.gstep { display: grid; grid-template-columns: 26px 1fr; gap: 10px; font-size: 13.5px; line-height: 1.5; }
.gstep .gn { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--accent); color: var(--accent); display: grid; place-items: center; font-size: 12px; margin-top: 1px; }
.gstep > div { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 760px) { .gstep > div { grid-template-columns: 1fr; gap: 2px; } }
.gstep .g-ar { text-align: right; }
.f.missing input, .f.missing select, .f.missing textarea, .missing .tagbox, .missing.photos .drop { border-color: var(--red) !important; background: #FFF8F6; }
.f .miss-msg, .miss-msg { display: none; color: var(--red); font-size: 12px; justify-content: space-between; gap: 10px; }
.missing .miss-msg, .missing + .miss-msg { display: flex; }
.miss-msg span[dir=rtl] { font-family: "IBM Plex Sans Arabic", var(--sans); }
.check-banner { display: none; position: sticky; top: 10px; z-index: 30; }
.check-banner.on { display: block; }
.alert ul { margin: 6px 0 0; padding-inline-start: 18px; }

/* =========================================================
   Responsive: phone · iPad · desktop
   ========================================================= */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; align-items: start; }
.cat-card { overflow: hidden; display: flex; flex-direction: column; }
.cat-new { border-style: dashed; border-color: #D8C9B6; background: #FFFDF9; }
.cat-photo { position: relative; display: grid; place-items: center; aspect-ratio: 16/9; background: var(--soft); border-bottom: 1px solid var(--line2); cursor: pointer; overflow: hidden; color: var(--faint); font-size: 13px; }
.cat-photo img { width: 100%; height: 100%; object-fit: cover; }
.cat-photo em { position: absolute; bottom: 8px; inset-inline-end: 8px; font-style: normal; font-size: 11px; background: rgba(255,255,255,.92); color: var(--brand); padding: 3px 9px; border-radius: 20px; }
.cat-row { display: flex; gap: 14px; align-items: flex-end; justify-content: space-between; }
.cat-row .f { width: 110px; }
.cat-actions { display: flex; gap: 8px; padding: 0 18px 18px; flex-wrap: wrap; }
.cat-actions .btn { flex: 1; }
.scrim-cms { display: none; }

@media (max-width: 1200px) { .split { grid-template-columns: 1fr; } }

/* touch screens: bigger targets */
@media (pointer: coarse) {
  .btn { min-height: 42px; }
  .btn.sm { min-height: 36px; padding: 0 14px; }
  .tabs a, .tabs button { padding: 9px 14px; }
  .qty-step button { width: 40px; height: 40px; }
  .qty-step input { height: 40px; }
  .switch input { width: 44px; height: 26px; }
  .switch input::after { width: 20px; height: 20px; }
  .switch input:checked::after { transform: translateX(18px); }
  .inp, .f input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=color]), .f select { height: 44px; font-size: 16px; } /* 16px stops iOS zooming into fields */
  .f textarea { font-size: 16px; }
  .filters input, .filters select { height: 42px; font-size: 16px; }
}

/* iPad portrait and phones: menu slides in */
@media (max-width: 960px) {
  .scrim-cms.on { display: block; position: fixed; inset: 0; background: rgba(43,30,22,.35); z-index: 45; }
  .topbar { gap: 10px; }
  .topbar .btn { min-width: 0; }
  .head h1 { font-size: 28px; }
  .head .sub { font-size: 13px; }
  .filters input[type=search] { width: 100%; flex: 1 1 220px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
}

/* phones */
@media (max-width: 760px) {
  .main { padding: 14px 12px 90px; }
  .head { margin-bottom: 14px; }
  .head .actions { width: 100%; }
  .head .actions .btn, .head .actions form { flex: 1 1 auto; }
  .head .actions form .btn { width: 100%; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .v { font-size: 21px; }
  .card-h { padding: 14px; flex-wrap: wrap; }
  .card-b { padding: 14px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .filters { gap: 8px; }
  .filters > * { max-width: 100%; }
  .filters label { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; }
  .savebar { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
  .savebar .btn { flex: 1; }
  .guide summary { display: grid; grid-template-columns: 22px 1fr auto; column-gap: 10px; row-gap: 2px; align-items: center; }
  .guide summary .g-ico { grid-row: span 2; }
  .guide summary .g-ar { grid-column: 2; margin: 0; text-align: right; }
  .guide summary::after { grid-column: 3; grid-row: 1 / span 2; }
  .bl { flex-wrap: wrap; gap: 2px 10px; }
  .bh { flex-direction: column; gap: 1px; }
  .bh span[dir=rtl] { text-align: right; }
  .gstep > div { gap: 4px; }
  .cat-grid { grid-template-columns: 1fr; }
  .photos { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .photo select { max-width: 86%; font-size: 10px; }
  .matrix td { padding: 8px 6px; }
  .matrix th:first-child, .matrix td:first-child { padding-inline-start: 12px; }
  .matrix .qty-step { float: inline-end; }
  .steps .btn { flex: 1 1 45%; }
  .kv { grid-template-columns: 96px 1fr; }
  .alert { font-size: 13px; }

  /* tables become cards */
  table.tbl.cardify thead { display: none; }
  table.tbl.cardify, table.tbl.cardify tbody { display: block; width: 100%; }
  table.tbl.cardify tr { display: grid; grid-template-columns: 1fr; padding: 12px 14px; border-bottom: 1px solid var(--line2); gap: 2px; }
  table.tbl.cardify tr:last-child { border-bottom: 0; }
  table.tbl.cardify td { display: block; padding: 5px 0; border: 0; text-align: end; min-width: 0; overflow: hidden; }
  table.tbl.cardify td::before { content: attr(data-label); float: inline-start; margin-inline-end: 12px; padding-top: 2px; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); text-align: start; }
  table.tbl.cardify td.nowrap, table.tbl.cardify td:last-child:has(.btn) { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding-top: 8px; }
  table.tbl.cardify td[data-label=""]::before, table.tbl.cardify td:not([data-label])::before { display: none; }
  table.tbl.cardify td:first-child { text-align: start; font-size: 15px; }
  table.tbl.cardify td .thumb { width: 54px; height: 70px; }
  table.tbl.cardify td > div, table.tbl.cardify td > span { min-width: 0; }
  .tbl-wrap { overflow-x: visible; }
  .tbl-wrap:has(table:not(.cardify)) { overflow-x: auto; }
}

/* small phones */
@media (max-width: 380px) {
  .kpis { grid-template-columns: 1fr; }
}

.cat-photo:not(:has(img)) { aspect-ratio: auto; height: 70px; }

@media (max-width: 1200px) { .grid2.stack-md { grid-template-columns: 1fr; } }
.form-grid.pairs { grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .form-grid.pairs { grid-template-columns: 1fr; } }
