:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --line: #e3e2dd;
  --ink: #17191e;
  --muted: #6b6e76;
  --accent: #2557e8;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefd;
  --ok: #17803d;
  --ok-soft: #e5f4ea;
  --low: #a8570a;
  --low-soft: #fdf0dc;
  --out: #c03221;
  --out-soft: #fbe6e3;
  --shadow: 0 1px 2px rgb(20 20 30 / .06), 0 4px 16px rgb(20 20 30 / .05);
  --radius: 14px;
  color-scheme: light;
}
/* Dark colours: when the device is dark (unless Light was picked), or when Dark was picked. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101217;
    --surface: #181b22;
    --surface-2: #20242d;
    --line: #2a2f39;
    --ink: #eceef2;
    --muted: #9196a1;
    --accent: #6d8eff;
    --accent-ink: #0b1020;
    --accent-soft: #1e2847;
    --ok: #5cc985;
    --ok-soft: #173123;
    --low: #f0a54a;
    --low-soft: #3a2a14;
    --out: #ff7a6b;
    --out-soft: #3d1c19;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101217;
  --surface: #181b22;
  --surface-2: #20242d;
  --line: #2a2f39;
  --ink: #eceef2;
  --muted: #9196a1;
  --accent: #6d8eff;
  --accent-ink: #0b1020;
  --accent-soft: #1e2847;
  --ok: #5cc985;
  --ok-soft: #173123;
  --low: #f0a54a;
  --low-soft: #3a2a14;
  --out: #ff7a6b;
  --out-soft: #3d1c19;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-weight: 550; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--out); border-color: transparent; background: transparent; }
.btn.danger:hover { background: var(--out-soft); }
.btn.icon { width: 40px; padding: 0; font-size: 22px; line-height: 1; }
.btn.icon svg { fill: currentColor; stroke: none; }
.btn.icon svg[hidden] { display: none; }

input, select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px 24px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px; text-align: center; align-items: center;
}
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card p { margin: 0; color: var(--muted); }
.login-card .btn { width: 100%; }
.error { color: var(--out) !important; min-height: 1.4em; font-size: 14px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 12px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 11px; }
.tab { border: 0; background: transparent; padding: 6px 14px; text-decoration: none; text-align: center; border-radius: 8px; cursor: pointer; font-weight: 550; color: var(--muted); }
.tab.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 220px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .15); padding: 6px;
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat {
  text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; cursor: pointer; box-shadow: var(--shadow);
}
.stat:disabled { cursor: default; color: inherit; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 550; }
.stat b { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat.low b { color: var(--low); }
.stat.out b { color: var(--out); }
.stat.on.low { border-color: var(--low); background: var(--low-soft); }
.stat.on.out { border-color: var(--out); background: var(--out-soft); }

/* ---------- toolbar ---------- */
.toolbar { display: grid; grid-template-columns: 1fr 180px 180px; gap: 10px; margin-bottom: 16px; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 38px; }
.model-hint { margin: -6px 0 14px; color: var(--muted); font-size: 14px; }

/* ---------- grid & cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgb(20 20 30 / .1); }
.ph { position: relative; aspect-ratio: 1 / 1; background: var(--surface-2); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.noimg { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); opacity: .6; }
.total {
  position: absolute; right: 10px; top: 10px; padding: 3px 10px; border-radius: 999px;
  background: rgb(0 0 0 / .62); color: #fff; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px);
}
.total.out { background: var(--out); }
.info { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.info h3 { margin: 0; font-size: 15px; line-height: 1.3; overflow-wrap: anywhere; }
.price { color: var(--muted); font-size: 13px; margin-top: -4px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 4px 2px 8px; border-radius: 7px;
  background: var(--surface-2); font-size: 12.5px; font-weight: 550; white-space: nowrap;
}
.chip b { min-width: 22px; text-align: center; padding: 0 5px; border-radius: 5px; background: var(--ok-soft); color: var(--ok); font-variant-numeric: tabular-nums; }
.chip.low b { background: var(--low-soft); color: var(--low); }
.chip.out { color: var(--muted); }
.chip.out b { background: var(--out-soft); color: var(--out); }
.chips .none { color: var(--muted); font-size: 13px; }

.quick { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.quick .qm { font-weight: 600; font-size: 13.5px; }

/* stepper used on cards and in the editor */
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.stepper button {
  width: 36px; height: 36px; border: 0; background: var(--surface-2); cursor: pointer;
  font-size: 18px; font-weight: 600; line-height: 1; touch-action: manipulation;
}
.stepper button:hover { background: var(--line); }
.stepper b, .stepper input {
  width: 46px; min-height: 36px; height: 36px; text-align: center; border: 0; border-radius: 0; padding: 0;
  font-weight: 700; font-variant-numeric: tabular-nums; display: grid; place-items: center; box-shadow: none;
}
.stepper .ok { color: var(--ok); } .stepper .low { color: var(--low); } .stepper .out { color: var(--out); }

.empty { text-align: center; padding: 60px 16px; color: var(--muted); }
.empty h3 { color: var(--ink); margin: 0 0 6px; font-size: 18px; }
.empty .btn { margin-top: 14px; }

/* ---------- history ---------- */
.history { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.history li { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; padding: 12px 16px; border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; }
.history .hmain { font-weight: 600; overflow-wrap: anywhere; }
.history .hmain span { color: var(--muted); font-weight: 500; }
.history .hchg { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.history .hmeta { color: var(--muted); font-size: 13px; }
.history .hnote { color: var(--muted); font-size: 13px; text-align: right; }
.up { color: var(--ok); } .down { color: var(--out); }
.by { display: inline-block; padding: 0 7px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--surface-2); margin-right: 6px; }
.by.agent { background: var(--accent-soft); color: var(--accent); }

/* ---------- dialogs ---------- */
dialog.sheet {
  width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink);
  box-shadow: 0 30px 80px rgb(0 0 0 / .3);
}
dialog.sheet.narrow { width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(10 12 18 / .5); backdrop-filter: blur(2px); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dh { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px 22px; border-bottom: 1px solid var(--line); }
.dh h2 { margin: 0; font-size: 18px; }
.dh .btn.icon { border: 0; background: transparent; }
.dscroll { overflow: auto; padding: 20px 22px; }
.df { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.sp { flex: 1; }

.dtop { display: grid; grid-template-columns: 240px 1fr; gap: 20px; }
.fields { display: flex; flex-direction: column; gap: 14px; }
.fields label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
.opt { color: var(--muted); font-weight: 450; font-size: 13px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.suffix { position: relative; display: block; }
.suffix span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 500; pointer-events: none; }
.suffix input { padding-right: 56px; }

.photo {
  position: relative; aspect-ratio: 1 / 1; border-radius: var(--radius); overflow: hidden; cursor: pointer;
  border: 2px dashed var(--line); background: var(--surface-2);
  display: grid; place-items: center; transition: border-color .15s;
}
.photo:hover, .photo.drag { border-color: var(--accent); }
.photo.has { border-style: solid; }
.photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 16px; color: var(--muted); }
.photo-empty b { color: var(--ink); }
.photo.has .photo-empty { display: none; }
.photo-busy { display: none; position: absolute; inset: 0; place-items: center; background: rgb(0 0 0 / .45); color: #fff; font-weight: 600; }
.photo.busy .photo-busy { display: grid; }
.photo-remove {
  position: absolute; left: 8px; bottom: 8px; border: 0; border-radius: 8px; padding: 5px 10px;
  background: rgb(0 0 0 / .62); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
}

.models-sec { margin-top: 22px; }
.sec-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.sec-h h3 { margin: 0; font-size: 16px; }
.rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
.mrow { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; border: 1px solid var(--line); border-radius: 12px; }
.mrow .mname { flex: 1; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.mrow .x { border: 0; background: none; width: 30px; height: 30px; border-radius: 8px; font-size: 20px; color: var(--muted); cursor: pointer; }
.mrow .x:hover { background: var(--out-soft); color: var(--out); }
.mrow.out { background: var(--out-soft); border-color: transparent; }
.mrow.low { background: var(--low-soft); border-color: transparent; }
.hint { margin: 0; color: var(--muted); font-size: 14px; grid-column: 1 / -1; }
.picker-h { margin: 18px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.picker { display: flex; flex-wrap: wrap; gap: 6px; }
.pick {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px;
  cursor: pointer; font-size: 13.5px; font-weight: 550;
}
.pick:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 550;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--out); color: #fff; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .top { flex-wrap: wrap; gap: 10px; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; }
  .top-actions .btn.primary { padding: 0 12px; }
  main { padding-top: 14px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 22px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .info { padding: 10px; }
  .quick { flex-direction: column; align-items: stretch; }
  .quick .stepper { justify-content: space-between; }
  .quick .stepper b { flex: 1; }
  dialog.sheet, dialog.sheet.narrow { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; border: 0; }
  dialog form { max-height: 100dvh; height: 100%; }
  .dscroll { padding: 16px; flex: 1; }
  .df { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .dtop { grid-template-columns: 1fr; }
  .photo { max-width: 260px; width: 100%; margin: 0 auto; }
  .rows { grid-template-columns: 1fr; }
}

/* ---------- model folders ---------- */
:root { --fold-back: #e8a920; --fold-front-1: #ffd766; --fold-front-2: #f6c23e; --fold-ink: #6b4500; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.folder {
  position: relative; display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 12px 8px 14px; border-radius: 14px; border: 1px solid transparent; background: none;
  color: inherit; text-decoration: none; cursor: pointer; font: inherit;
  transition: background .15s, border-color .15s;
}
.folder:hover { background: var(--surface); border-color: var(--line); }
.fold { position: relative; width: 100%; max-width: 140px; aspect-ratio: 1.28; margin-bottom: 10px; }
.fold-back {
  position: absolute; inset: 9% 0 0 0; background: var(--fold-back); border-radius: 4px 10px 10px 10px;
}
.fold-back::before {
  content: ''; position: absolute; left: 0; bottom: 100%; width: 40%; height: 12%;
  background: var(--fold-back); border-radius: 6px 6px 0 0;
  clip-path: polygon(0 0, 80% 0, 100% 100%, 0 100%);
}
.fold-papers { position: absolute; left: 7%; right: 7%; top: 0; bottom: 14%; }
.paper {
  position: absolute; bottom: 0; width: 46%; height: 100%; object-fit: cover; background: #fff;
  border: 2px solid #fff; border-radius: 6px; box-shadow: 0 1px 4px rgb(0 0 0 / .3);
  transition: transform .2s;
}
.paper.c { left: 27%; z-index: 3; }
.paper.w { left: 10%; width: 80%; z-index: 3; }
.folder:hover .paper.w { transform: translateY(-8%); }
.paper.l { left: 4%; transform: rotate(-9deg); z-index: 2; }
.paper.r { right: 4%; transform: rotate(9deg); z-index: 1; }
.paper.blank { background: #f4f1ea; }
.folder:hover .paper.c { transform: translateY(-8%); }
.folder:hover .paper.l { transform: rotate(-13deg) translate(-4%, -5%); }
.folder:hover .paper.r { transform: rotate(13deg) translate(4%, -5%); }
.fold-front {
  position: absolute; left: 0; right: 0; bottom: 0; height: 56%; z-index: 4;
  background: linear-gradient(180deg, var(--fold-front-1), var(--fold-front-2));
  border-radius: 7px 7px 10px 10px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .55), 0 -2px 8px rgb(0 0 0 / .14);
  transform-origin: bottom center; transition: transform .2s;
  display: grid; place-items: center; color: var(--fold-ink); font-size: 30px; font-weight: 300;
}
.folder:hover .fold-front { transform: perspective(320px) rotateX(-16deg); }
.fname { font-weight: 650; font-size: 15px; line-height: 1.25; overflow-wrap: anywhere; }
.fmeta { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.fbadge { margin-top: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; }
.fbadge.low { background: var(--low-soft); color: var(--low); }
.fbadge.out { background: var(--out-soft); color: var(--out); }
.folder.empty .fold { opacity: .5; filter: saturate(.6); }
.folder.empty .fname { color: var(--muted); }
.folder.new .fold-back, .folder.new .fold-back::before { background: var(--line); }
.folder.new .fold-front { background: var(--surface-2); box-shadow: inset 0 0 0 2px var(--line); color: var(--muted); }
.folder.new .fname { color: var(--muted); }
#folders > .empty { grid-column: 1 / -1; padding: 30px 16px; }
#emptyFoldersWrap { margin-top: 18px; }
.ghost-btn { background: transparent; border-color: transparent; color: var(--muted); padding: 0 8px; }
.ghost-btn:hover { color: var(--ink); }
#emptyFolders { margin-top: 10px; }

/* folder page header */
.folder-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.back {
  display: inline-flex; align-items: center; gap: 2px; padding: 6px 12px 6px 6px; border-radius: 10px;
  color: var(--accent); text-decoration: none; font-weight: 600;
}
.back:hover { background: var(--accent-soft); }
.fh-title { display: flex; align-items: center; gap: 10px; }
.fh-title h2 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.mini-folder { position: relative; width: 34px; height: 26px; }
.mini-folder::before { content: ''; position: absolute; inset: 3px 0 0 0; background: var(--fold-back); border-radius: 2px 5px 5px 5px; }
.mini-folder::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 66%; background: linear-gradient(var(--fold-front-1), var(--fold-front-2)); border-radius: 4px; }

/* cards inside a folder */
.total.low { background: var(--low); }
.also { color: var(--muted); font-size: 12.5px; }
.stepper.wide { display: flex; margin-top: auto; }
.stepper.wide button { width: 44px; height: 40px; }
.stepper.wide b { flex: 1; height: 40px; font-size: 17px; }
.stepper button:disabled { opacity: .4; cursor: default; }

@media (max-width: 640px) {
  .fgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .folder { padding: 10px 4px 12px; }
  .fname { font-size: 14px; }
  .fmeta { font-size: 12px; }
  .fh-title h2 { font-size: 20px; }
}
@media (max-width: 330px) {
  .fgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- bulk add ---------- */
dialog.sheet.wide { width: min(1100px, calc(100vw - 32px)); }
.bulk-bar { display: flex; flex-direction: column; gap: 12px; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.bb-models { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bb-label { font-weight: 600; font-size: 14px; }
.bb-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.bchip { display: inline-flex; align-items: center; gap: 2px; padding: 4px 4px 4px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 14px; }
.bchip button { border: 0; background: none; color: inherit; width: 24px; height: 24px; border-radius: 50%; cursor: pointer; font-size: 16px; line-height: 1; }
.bchip button:hover { background: rgb(0 0 0 / .1); }
.bb-need { color: var(--low); font-weight: 650; font-size: 14px; }
#bModelAdd { width: auto; min-width: 190px; }
.bb-row { display: grid; grid-template-columns: 150px 230px; gap: 12px; }
.bb-row label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
.bb-hint { margin: 0; color: var(--muted); font-size: 13px; }
.bgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.btile { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.bph { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.bph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bstate { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; text-align: center; }
.btile.wait .bstate, .btile.up .bstate { background: rgb(0 0 0 / .4); }
.btile.wait .bstate::after { content: 'Waiting…'; }
.btile.up .bstate::after { content: ''; width: 26px; height: 26px; border: 3px solid rgb(255 255 255 / .35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.btile.done .bstate { inset: auto 6px 6px auto; width: 24px; height: 24px; border-radius: 50%; background: var(--ok); box-shadow: 0 1px 3px rgb(0 0 0 / .3); }
.btile.done .bstate::after { content: '✓'; font-size: 14px; }
.btile.err .bstate { background: rgb(192 50 33 / .75); cursor: pointer; padding: 8px; }
.btile.err .bstate::after { content: 'Failed. Tap to retry'; }
@keyframes spin { to { transform: rotate(360deg); } }
.brm { position: absolute; top: 6px; right: 6px; z-index: 2; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgb(0 0 0 / .6); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; }
.btile .bn { min-height: 36px; padding: 6px 10px; font-size: 14px; }
.btile .stepper { display: flex; }
.btile .stepper button { width: 36px; height: 34px; }
.btile .stepper input { flex: 1; width: auto; min-width: 0; height: 34px; min-height: 34px; }
.badd { aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 12px; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer; font-weight: 600; }
.badd span { font-size: 34px; font-weight: 300; line-height: 1; }
.badd:hover { border-color: var(--accent); color: var(--accent); }
.bstatus { font-size: 14px; }
.lbl-short { display: none; }
.fh-bulk { margin-left: auto; }
#empty .btn + .btn { margin-left: 8px; }
@media (max-width: 640px) {
  .bgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .bb-row { grid-template-columns: 1fr 1.4fr; }
  #bModelAdd { flex: 1; min-width: 0; }
  #bulkDialog .df [data-close] { display: none; }
  .bstatus { font-size: 13px; }
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
  .fh-bulk { margin-left: 0; width: 100%; }
}
@media (max-width: 420px) { #shopName { display: none; } }
.fh-delete { display: inline-flex; align-items: center; gap: 6px; }
@media (max-width: 640px) { .fh-delete { width: 100%; justify-content: center; } }
/* Small phones: "Bulk add" becomes an icon so the light/dark button fits on the same row. */
@media (max-width: 370px) { #btnBulk { width: 40px; padding: 0; } #btnBulk span { display: none; } }
@media (max-width: 640px) {
  dialog.sheet.wide { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; border: 0; }
}

/* ---------- orders ---------- */
.orders { display: flex; flex-direction: column; gap: 12px; max-width: 760px; }
.order { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.order.cancelled { opacity: .6; }
.order header { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ometa { color: var(--muted); font-size: 13px; display: flex; gap: 6px; align-items: center; }
.pill { padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; }
.pill.out { background: var(--out-soft); color: var(--out); }
.order ul { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.order li { display: grid; grid-template-columns: 44px 1fr auto auto; gap: 12px; align-items: center; }
.order li img, .oimg { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); display: block; }
.oname { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.oname small { display: block; color: var(--muted); font-weight: 500; font-size: 12.5px; }
.oqty { font-weight: 700; font-variant-numeric: tabular-nums; }
.oprice { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 60px; text-align: right; }
.onote { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.odetails { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 12px 0 0; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; font-size: 14px; }
.odetails dt { color: var(--muted); font-weight: 600; }
.odetails dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.odetails a { color: var(--accent); }
.pill.low { background: var(--low-soft); color: var(--low); }
.order footer { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); min-height: 40px; }

/* ---------- connect agent ---------- */
.agent h3 { margin: 22px 0 4px; font-size: 16px; }
.agent .lead { margin: 0 0 14px; }
.small { font-size: 13px; margin: 0 0 8px; }
.warn { background: var(--low-soft); color: var(--low); padding: 10px 12px; border-radius: 10px; font-weight: 550; margin-bottom: 12px; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.kv { display: grid; grid-template-columns: 200px 1fr; gap: 10px 14px; align-items: center; }
.kv > span { font-weight: 600; font-size: 14px; }
.kv small { display: block; color: var(--muted); font-weight: 450; font-size: 12px; }
.copyrow { display: flex; gap: 6px; }
.copyrow input { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.codebox { position: relative; }
.codebox textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; line-height: 1.5; padding-right: 90px; }
.codebox .btn { position: absolute; top: 8px; right: 8px; height: 32px; padding: 0 12px; }
.testrow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .kv { grid-template-columns: 1fr; gap: 4px; }
  .kv .copyrow { margin-bottom: 10px; }
  .tab { padding: 6px 4px; font-size: 14px; }
}

/* Customer notes on an order (delivery time etc.) */
.odetails .onote { display: inline-block; padding: 2px 8px; border-radius: 6px; background: rgba(255, 196, 0, .18); font-weight: 600; white-space: pre-wrap; }

/* ---------- Bot tab: replies and cost charts ---------- */
:root { --bar: #2557e8; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bar: #5b7cf0; } }
:root[data-theme="dark"] { --bar: #5b7cf0; }
#view-bot .stat small { color: var(--muted); font-size: 12px; }
.bchart { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 10px; margin-bottom: 14px; }
.bhead { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.bhead h3 { margin: 0; font-size: 15px; font-weight: 650; }
.bhead span { font-size: 13px; }
.bplot { position: relative; padding-top: 18px; }
.bmax { position: absolute; top: 0; left: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bbars { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 2px; height: 150px; border-bottom: 1px solid var(--line);
         background: linear-gradient(var(--line), var(--line)) 0 0 / 100% 1px no-repeat; }
.bcol { position: relative; display: flex; flex-direction: column; justify-content: flex-end; min-width: 0; outline: none; cursor: default; }
.bcol:hover, .bcol:focus-visible { background: var(--surface-2); border-radius: 4px 4px 0 0; }
.bbar { background: var(--bar); border-radius: 4px 4px 0 0; width: 100%; max-width: 26px; margin: 0 auto; }
.bx { position: absolute; top: calc(100% + 4px); left: 0; font-size: 11px; color: var(--muted); white-space: nowrap; }
.bchart .bbars { margin-bottom: 20px; }
.bx.last { left: auto; right: 0; }
.btip { position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: var(--surface); font-size: 12.5px;
        padding: 6px 9px; border-radius: 8px; box-shadow: var(--shadow); white-space: nowrap; }
.btable { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; margin-bottom: 12px; }
.btable summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.btable table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; font-variant-numeric: tabular-nums; }
.btable th, .btable td { text-align: left; padding: 6px 4px; border-top: 1px solid var(--line); }
.bnote { font-size: 13px; line-height: 1.5; }
@media (max-width: 640px) { .bbars { height: 120px; } .bx { font-size: 10px; } }

/* Bot tab: AI model card */
.bmodel { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: flex-end; justify-content: space-between;
          background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.bm-now { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 260px; }
.bm-now span { font-size: 13px; font-weight: 550; }
.bm-now b { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.bm-now small { font-size: 12.5px; line-height: 1.45; }
.bm-pick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: 1 1 320px; justify-content: flex-end; }
.bm-pick label { font-size: 13px; font-weight: 600; color: var(--muted); flex-basis: 100%; }
.bm-pick select { min-width: 0; max-width: 100%; flex: 1 1 220px; }
.bm-unit { font-weight: 450; }

/* Bot tab: instructions card */
.binstr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; }
.binstr summary { cursor: pointer; font-size: 14px; }
.bi-title { font-weight: 650; }
.bi-status { font-size: 13px; }
.bi-help { font-size: 13px; line-height: 1.5; margin: 10px 0 8px; }
.binstr textarea { width: 100%; box-sizing: border-box; min-height: 320px; resize: vertical; font: 13.5px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
                   color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.binstr textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.bi-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.bi-count { font-size: 12.5px; margin-right: auto; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .binstr textarea { min-height: 260px; font-size: 13px; } }
