/* Chara Admin — purple theme, mobile-first. */
:root {
  --bg: #f8f5fe;
  --surface: #fff;
  --surface-2: #efe9fb;
  --border: #e4dbf6;
  --text: #17102b;
  --muted: #675d82;
  --accent: #7c3aed;
  --accent-2: #c026d3;
  --accent-soft: #ede4ff;
  --danger: #c0262d;
  --danger-soft: #fdecec;
  --success: #12804a;
  --grad: linear-gradient(115deg, var(--accent), var(--accent-2));
  --shadow: 0 1px 2px rgb(60 20 120 / .06), 0 12px 30px -16px rgb(60 20 120 / .25);
  --radius: 16px;
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Bricolage Grotesque", "DM Sans", system-ui, sans-serif;
  --topbar-h: 64px;
  --sidebar-w: 232px;
  --gutter: clamp(16px, 3vw, 28px);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; background: var(--bg); color: var(--text); font: 400 .95rem/1.55 var(--font); -webkit-font-smoothing: antialiased; }
html:has(dialog[open]) { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--display); letter-spacing: -.03em; line-height: 1.15; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.view:focus { outline: none; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; left: 12px; top: 12px; z-index: 300; padding: 10px 16px; border-radius: 999px; background: var(--text); color: #fff; transform: translateY(-200%); }
.skip-link:focus-visible { transform: none; }
.muted { color: var(--muted); }
.clamp-1 { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.clamp-2 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  border: 1px solid transparent; border-radius: 999px;
  background: var(--text); color: #fff;
  font-weight: 600; font-size: .9rem; text-decoration: none; white-space: nowrap;
  cursor: pointer; transition: transform .2s, box-shadow .2s, background-color .2s, opacity .2s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--grad); box-shadow: 0 10px 22px -10px rgb(124 58 237 / .7); }
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--ghost:hover:not(:disabled) { border-color: var(--text); }
.btn--danger { background: var(--danger); }
.btn--danger-ghost { background: var(--surface); color: var(--danger); border-color: #f2c4c6; }
.btn--small { min-height: 36px; padding: 6px 14px; font-size: .84rem; }
.btn--block { width: 100%; }
.btn[aria-busy="true"]::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
.link-btn { display: block; margin: 14px auto 0; min-height: 36px; padding: 0 6px; border: 0; background: none; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 50%; background: var(--surface); cursor: pointer; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font: 800 1.25rem var(--display); letter-spacing: -.04em; }
.brand small { font: 600 .72rem var(--font); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-left: 4px; }
.brand__mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50% 50% 50% 10px; background: var(--grad); color: #fff; font-size: .95rem; transform: rotate(-8deg); }

/* ---------- Boot + auth ---------- */
.boot { min-height: 100dvh; display: grid; place-content: center; grid-auto-flow: column; gap: 12px; align-items: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }

.auth { min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); background: radial-gradient(closest-side at 20% 20%, rgb(192 38 211 / .12), transparent), radial-gradient(closest-side at 80% 70%, rgb(124 58 237 / .14), transparent); }
.auth__card { width: min(420px, 100%); padding: clamp(24px, 5vw, 40px); border: 1px solid var(--border); border-radius: 28px; background: var(--surface); box-shadow: var(--shadow); }
.auth__card .brand { margin-bottom: 26px; }
.auth__title { margin-bottom: 18px; font-size: 1.7rem; }

/* ---------- Shell: fixed frame, only the page body scrolls ---------- */
.app { height: 100dvh; display: grid; grid-template-rows: var(--topbar-h) minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); overflow: hidden; }
.topbar { z-index: 50; display: flex; align-items: center; gap: 12px; padding: 0 var(--gutter); border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar__actions { display: flex; align-items: center; gap: 8px; margin-left: auto; min-width: 0; }
.topbar__user { display: none; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .85rem; }
#view-store { display: none; }

.sidebar { position: fixed; z-index: 40; top: var(--topbar-h); bottom: 0; left: 0; width: min(270px, 85vw); padding: 12px 10px 24px; overflow-y: auto; border-right: 1px solid var(--border); background: var(--surface); transform: translateX(-102%); transition: transform .3s; }
.sidebar.is-open { transform: none; box-shadow: var(--shadow); }
.sidebar__group { margin: 14px 12px 4px; font-size: .7rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.sidebar a { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 12px; border-radius: 10px; color: var(--text); font-weight: 500; font-size: .92rem; text-decoration: none; }
.sidebar a svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: .8; }
.sidebar a:hover { background: var(--surface-2); }
.sidebar a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-badge { margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--accent); color: #fff; font-size: .72rem; font-weight: 700; display: grid; place-items: center; }

.view { min-width: 0; min-height: 0; overflow: hidden; display: flex; background: var(--bg); }

@media (min-width: 900px) {
  .app { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .topbar { grid-column: 1 / -1; }
  .topbar__menu { display: none; }
  .topbar__user, #view-store:not([hidden]) { display: inline-flex; }
  .sidebar { position: static; height: auto; width: auto; transform: none; transition: none; }
}

/* ---------- Page frame ---------- */
.page { display: flex; flex-direction: column; width: 100%; max-width: 1180px; min-height: 0; height: 100%; margin-inline: auto; padding: 0 var(--gutter); }
.page--narrow { max-width: 900px; }
.page__head { flex: none; display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 16px; padding: 20px 0 14px; }
.page__head h1 { font-size: clamp(1.4rem, 2.6vw, 1.85rem); }
.page__head p { color: var(--muted); font-size: .9rem; max-width: 62ch; }
.page__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.page__toolbar { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding-bottom: 12px; }
.page__toolbar .field { margin: 0; flex: 1 1 220px; max-width: 360px; }
.page__body { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding-bottom: 28px; scrollbar-gutter: stable; }
.page__footer { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); background: var(--bg); }
.page__footer .spacer { flex: 1; }
.breadcrumb { display: inline-block; margin-bottom: 4px; font-size: .82rem; font-weight: 600; text-decoration: none; }

/* compact legacy helpers */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; margin-bottom: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.toolbar .field { margin: 0; flex: 1 1 220px; }

/* ---------- Tabs ---------- */
.tabs { flex: none; display: flex; gap: 4px; padding: 4px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow-x: auto; scrollbar-width: none; }
.tabs a, .tabs button { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-weight: 600; font-size: .88rem; text-decoration: none; white-space: nowrap; cursor: pointer; }
.tabs [aria-current="page"], .tabs [aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.tabs .tab-count { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .72rem; line-height: 20px; text-align: center; }
.tabs [aria-selected="true"] .tab-count { background: var(--accent); color: #fff; }

/* ---------- Data table (sticky header, compact rows) ---------- */
.table-wrap { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); overflow: hidden; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .88rem; }
.data-table th { position: sticky; top: 0; z-index: 1; padding: 10px 12px; background: var(--surface-2); color: var(--muted); font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background-color .15s; }
.data-table tbody tr:hover { background: #faf8ff; }
.data-table tr.is-clickable { cursor: pointer; }
.data-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.data-table .cell-main { font-weight: 600; }
.data-table .cell-sub { color: var(--muted); font-size: .78rem; }
.data-table .cell-thumb { width: 84px; }
.data-table .col-hide-sm { display: none; }
@media (min-width: 760px) { .data-table .col-hide-sm { display: table-cell; } }
.table-footer { display: flex; justify-content: center; padding: 12px; }
.icon-link { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: var(--muted); text-decoration: none; }
.icon-link:hover { background: var(--surface-2); color: var(--accent); }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; font-size: .82rem; color: var(--muted); }
.switch input { appearance: none; width: 40px; height: 22px; margin: 0; border-radius: 999px; background: #d9d3e8; position: relative; cursor: pointer; transition: background-color .2s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / .2); transition: transform .2s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
.switch input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* status select / pill */
.status-select { min-height: 34px; padding: 4px 28px 4px 10px; border: 1.5px solid transparent; border-radius: 999px; font: 600 .8rem var(--font); cursor: pointer; appearance: none; background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23675d82' stroke-width='2' d='M6 9l6 6 6-6'/%3E%3C/svg%3E") right 8px center / 14px no-repeat; }
.status--pending { background-color: #fff4e5; color: #9a5b00; }
.status--confirmed { background-color: #ede4ff; color: #6d28d9; }
.status--shipped { background-color: #e8f0ff; color: #1d4ed8; }
.status--delivered { background-color: #e7f6ee; color: #12804a; }
.status--cancelled { background-color: #fdecec; color: #b42318; }

/* ---------- Overview ---------- */
.stat-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 14px; }
@media (min-width: 1000px) { .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { padding: 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); text-decoration: none; color: inherit; }
.stat__label { color: var(--muted); font-size: .8rem; font-weight: 600; }
.stat__value { margin-top: 4px; font: 800 clamp(1.3rem, 2.4vw, 1.7rem) var(--display); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat__sub { color: var(--muted); font-size: .78rem; }
.stat--alert { border-color: #f5c27a; background: #fffaf2; }
a.stat:hover { border-color: var(--accent); }
.overview-grid { display: grid; gap: 14px; }
@media (min-width: 1000px) { .overview-grid { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); } }
.card { padding: 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); min-width: 0; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card__head h2 { font-size: 1rem; }
.chart { width: 100%; height: 200px; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar:hover { fill: var(--accent-2); }
.chart text { font: 500 10px var(--font); fill: var(--muted); }
.mini-list { list-style: none; padding: 0; display: grid; }
.mini-list li + li { border-top: 1px solid var(--border); }
.mini-list a { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 9px 4px; color: inherit; text-decoration: none; border-radius: 8px; }
.mini-list a:hover { background: var(--surface-2); }
.attention { list-style: none; padding: 0; display: grid; gap: 8px; }
.attention li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: #fffaf2; border: 1px solid #f5d7a8; font-size: .86rem; }
.attention li.is-ok { background: #f1faf5; border-color: #bfe5cf; }

/* ---------- Side drawer (order details) ---------- */
.side-drawer { position: fixed; inset: 0 0 0 auto; width: min(560px, 100%); height: 100dvh; max-height: 100dvh; margin: 0; padding: 0; border: 0; box-shadow: var(--shadow); }
.side-drawer::backdrop { background: rgb(23 16 43 / .4); }
.side-drawer__panel { display: flex; flex-direction: column; height: 100%; }
.side-drawer__head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.side-drawer__body { flex: 1; overflow: auto; padding: 16px 20px 24px; display: grid; gap: 14px; align-content: start; }
.side-drawer__foot { flex: none; display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
.kv { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 6px 12px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.order-items { list-style: none; padding: 0; display: grid; }
.order-items li { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.history { list-style: none; padding: 0; display: grid; gap: 6px; font-size: .85rem; }
.history li { display: flex; justify-content: space-between; gap: 10px; }
.sum-rows { display: grid; gap: 4px; font-size: .9rem; }
.sum-rows div { display: flex; justify-content: space-between; }
.sum-rows .grand { padding-top: 6px; border-top: 1px solid var(--border); font-weight: 800; }

/* ---------- Collapsible list items (categories, sizes, FAQ…) ---------- */
.crud-item { padding: 0; }
.crud-item > summary { display: flex; align-items: center; gap: 10px; padding: 12px 16px; min-height: 52px; cursor: pointer; list-style: none; }
.crud-item > summary::-webkit-details-marker { display: none; }
.crud-item > summary::after { content: "Edit"; margin-left: auto; color: var(--accent); font-weight: 600; font-size: .85rem; }
.crud-item[open] > summary::after { content: "Close"; }
.crud-item > summary h2 { font-size: .98rem; min-width: 0; }
.crud-item__body { padding: 0 16px 16px; border-top: 1px solid var(--border); padding-top: 14px; }
.crud-list { gap: 8px; }

/* ---------- Panels + forms ---------- */
.panel { margin-bottom: 18px; padding: clamp(16px, 3vw, 24px); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.panel__head h2 { font-size: 1.2rem; }
.panel--muted { background: var(--surface-2); box-shadow: none; }
.panel.is-dirty { border-color: var(--accent); }

.form-grid { display: grid; gap: 14px 18px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .field--wide { grid-column: 1 / -1; } }
@media (min-width: 1200px) { .form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.field { display: grid; gap: 6px; margin-bottom: 14px; min-width: 0; }
.form-grid .field { margin: 0; }
.field > label, .field > .label { font-weight: 600; font-size: .86rem; }
.field input:not([type="checkbox"]):not([type="color"]):not([type="file"]), .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 12px; background: var(--surface);
  transition: border-color .2s, box-shadow .2s;
}
.field textarea { min-height: 96px; resize: vertical; }
.field :is(input, select, textarea):focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(124 58 237 / .15); outline: none; }
.field :is(input, select, textarea)[aria-invalid="true"], .field :is(input, select, textarea):user-invalid { border-color: var(--danger); }
.hint { color: var(--muted); font-size: .8rem; }
.field-error { color: var(--danger); font-size: .8rem; font-weight: 600; }
.counter { justify-self: end; color: var(--muted); font-size: .75rem; font-variant-numeric: tabular-nums; }
.counter.is-over { color: var(--danger); }

.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.color-field { display: flex; align-items: center; gap: 10px; }
.color-field input[type="color"] { width: 48px; height: 44px; padding: 3px; border: 1.5px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; }
.color-field input[type="text"] { max-width: 120px; font-family: ui-monospace, monospace; }

.form-error { min-height: 1.2em; color: var(--danger); font-weight: 600; font-size: .85rem; margin-bottom: 10px; }
.form-error:empty { min-height: 0; margin: 0; }
.form-message { min-height: 1.2em; color: var(--success); font-weight: 600; font-size: .85rem; margin-bottom: 10px; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; }
.form-actions .spacer { flex: 1; }
.dirty-note { color: var(--accent); font-size: .8rem; font-weight: 600; }

/* ---------- Product list ---------- */
.product-list { display: grid; gap: 12px; list-style: none; padding: 0; }
.product-row {
  display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; align-items: center; gap: 14px;
  padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  color: inherit; text-decoration: none; transition: border-color .2s, box-shadow .2s;
}
.product-row:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.product-row.is-inactive { opacity: .65; }
.thumb { --c: var(--surface-2); width: 72px; aspect-ratio: 2 / 1; height: auto; border-radius: 10px; background: var(--c); display: grid; place-items: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; mix-blend-mode: multiply; }
.product-row__name { font-weight: 700; }
.product-row__meta { color: var(--muted); font-size: .8rem; }
.product-row__right { display: grid; justify-items: end; gap: 4px; }
.price { font-weight: 700; white-space: nowrap; }
.pills { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.pill { padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .72rem; font-weight: 600; white-space: nowrap; }
.pill--accent { background: var(--accent-soft); color: var(--accent); }
.pill--off { background: var(--danger-soft); color: var(--danger); }

.empty { padding: 40px 20px; border: 1.5px dashed var(--border); border-radius: var(--radius); text-align: center; color: var(--muted); }
.skeleton-row { height: 70px; border-radius: var(--radius); background: linear-gradient(100deg, var(--surface-2) 30%, #f9f6ff 50%, var(--surface-2) 70%) 0 0 / 300% 100%; animation: shimmer 1.4s linear infinite; }

/* ---------- Variants + images ---------- */
.variants { display: grid; gap: 16px; }
.variant { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .variant { grid-template-columns: 260px minmax(0, 1fr); } }

.image-drop { display: grid; gap: 10px; }
.image-preview { --c: var(--surface-2); position: relative; aspect-ratio: 2 / 1; border-radius: 14px; background: var(--c); overflow: hidden; display: grid; place-items: center; border: 1.5px dashed var(--border); }
.image-preview img { width: 100%; height: 100%; object-fit: contain; mix-blend-mode: multiply; }
.image-preview__empty { color: var(--muted); font-size: .85rem; text-align: center; padding: 10px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

.gallery { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); list-style: none; padding: 0; margin-top: 10px; }
.gallery li { display: grid; gap: 6px; padding: 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.gallery input[type="text"], .gallery input[type="number"] { min-height: 36px; padding: 6px 8px; border: 1.5px solid var(--border); border-radius: 8px; font-size: .8rem; width: 100%; }
.gallery .row { display: flex; gap: 6px; align-items: center; }

/* ---------- CRUD rows ---------- */
.crud-list { display: grid; gap: 14px; list-style: none; padding: 0; }
.crud-item.is-new { border-style: dashed; }

/* ---------- Confirm + toast ---------- */
.confirm { width: min(440px, calc(100% - 32px)); margin: auto; padding: 0; border: 0; border-radius: 22px; box-shadow: var(--shadow); }
.confirm::backdrop { background: rgb(23 16 43 / .45); backdrop-filter: blur(3px); }
.confirm__body { padding: 26px; }
.confirm__body h2 { font-size: 1.3rem; margin-bottom: 8px; }
.confirm__body p { color: var(--muted); }
.confirm__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.toast { position: fixed; z-index: 200; left: 50%; bottom: 24px; max-width: calc(100% - 32px); padding: 12px 20px; border-radius: 999px; background: var(--text); color: #fff; font-weight: 500; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 20px); transition: opacity .3s, transform .3s; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--danger); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
.variant > section { grid-column: 1 / -1; border-top: 1px solid var(--border); padding-top: 14px; }
.variant > section .panel__head { margin-bottom: 6px; }
.variant > section h3 { font-size: 1rem; }
.product-row__name, .product-row__meta { display: block; }
.product-row > span:nth-child(2) { min-width: 0; }
.image-drop { align-content: start; }
.image-drop .file-btn, .image-drop .form-actions { justify-self: start; }
.image-drop .form-actions { margin-top: 0; }
.file-btn input[type="file"] { width: 100%; height: 100%; font-size: 0; }
.gallery--videos { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.gallery--videos video { width: 100%; aspect-ratio: 1; height: auto; object-fit: contain; background: #000; border-radius: 8px; }
.gallery .check { min-height: 32px; font-size: .85rem; }
progress { width: 100%; height: 10px; margin: 6px 0; accent-color: var(--accent); }
.file-btn.is-disabled { opacity: .55; pointer-events: none; }
.stack { display: grid; gap: 14px; align-content: start; min-width: 0; }
.link-right { margin-left: auto; font-weight: 600; white-space: nowrap; }
.status-pill { display: inline-flex; align-items: center; justify-self: end; padding: 2px 10px; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.row-link { color: var(--text); text-decoration: none; display: block; }
.row-link:hover { color: var(--accent); }
.row-head { display: flex; align-items: center; gap: 10px; }
.toggle-row { display: flex; flex-wrap: wrap; gap: 4px 24px; }
.toggle .field, .toggle-row .field { margin: 0; }
.panel .toggle-row + .form-grid { margin-top: 12px; }
.advanced > summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }
.advanced[open] > summary { margin-bottom: 12px; }
.variants { gap: 12px; }
.panel { margin-bottom: 0; }
.stack > .panel, .variants > .panel { margin: 0; }
.dirty-note:not([hidden]) { display: inline-flex; }
.page__footer .form-error { margin: 0; }
.help-steps { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 6px; font-size: .88rem; color: var(--muted); }
.help-steps b { color: var(--text); }
.panel__head p.hint { margin-top: 2px; }
/* order panel items: name on one line, details below */
.order-items li { grid-template-columns: 72px minmax(0, 1fr) auto; }
.order-items li > span:nth-child(2) { min-width: 0; }
.order-items b.clamp-1, .order-items .cell-sub { display: block; }
/* tables scroll sideways inside their box on small screens (never the page) */
.table-wrap { overflow-x: auto; }
.data-table td:first-child .cell-main, .data-table .num { white-space: nowrap; }
.data-table .status-select { max-width: 132px; }
@media (max-width: 600px) {
  .data-table th, .data-table td { padding: 8px; }
  .page__toolbar .field { max-width: none; }
}

/* =============================================================================
   Phone fixes: nothing cut off, no sideways scrolling, 44px touch targets
   ============================================================================= */
/* Tabs wrap onto a second line instead of scrolling off-screen */
.tabs { flex-wrap: wrap; overflow: visible; }
.tabs a, .tabs button { flex: 1 1 auto; justify-content: center; min-height: 44px; }
@media (min-width: 760px) {
  .tabs { align-self: flex-start; }
  .tabs a, .tabs button { flex: none; min-height: 38px; }
}

/* Orders: products column width on wide screens only */
@media (min-width: 760px) { .data-table .cell-products { min-width: 240px; } }
.data-table .cell-customer .cell-sub { white-space: normal; }
@media (min-width: 760px) { .data-table .cell-customer .cell-sub { white-space: nowrap; } }

/* Orders on phones: each order is a card, nothing hidden or cut off */
@media (max-width: 759px) {
  .data-table--cards thead { display: none; }
  .data-table--cards, .data-table--cards tbody { display: block; }
  .data-table--cards tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "order total" "customer customer" "products products" "status status";
    gap: 8px 12px;
    padding: 14px;
    border-bottom: 1px solid var(--border);
  }
  .data-table--cards tr:last-child { border-bottom: 0; }
  .data-table--cards td { display: block; padding: 0; border: 0; }
  .data-table--cards td.col-hide-sm { display: none; }
  .data-table--cards .cell-order { grid-area: order; }
  .data-table--cards .cell-total { grid-area: total; align-self: start; font-size: 1rem; }
  .data-table--cards .cell-customer { grid-area: customer; }
  .data-table--cards .cell-products { grid-area: products; }
  .data-table--cards .cell-status { grid-area: status; }
  .data-table--cards .status-select { max-width: none; width: 100%; }
  .data-table--cards td.empty { grid-column: 1 / -1; }
}

/* Bigger touch targets on phones */
@media (max-width: 759px) {
  .status-select { min-height: 44px; font-size: .88rem; }
  .btn--small { min-height: 44px; }
  .switch { min-height: 44px; }
  .icon-link { width: 44px; height: 44px; }
}

/* --- phone fixes, round 2 --- */
/* The tab bar may shrink to the screen and wrap (it used to keep its full width and push past the edge). */
.page__toolbar > .tabs { flex: 1 1 100%; min-width: 0; max-width: 100%; margin-bottom: 0; }
@media (min-width: 760px) { .page__toolbar > .tabs { flex: 0 1 auto; } }
.page, .page__body, .page__toolbar { min-width: 0; }
.page__body > *, .crud-list > li, .crud-item { min-width: 0; max-width: 100%; }

/* Products on phones: photo | name + price | switch, nothing cut off */
@media (max-width: 759px) {
  .data-table--products thead { display: none; }
  .data-table--products, .data-table--products tbody { display: block; }
  .data-table--products tr {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr) auto;
    grid-template-areas: "thumb product toggle" "thumb price toggle";
    align-items: center;
    gap: 2px 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
  }
  .data-table--products tr:last-child { border-bottom: 0; }
  .data-table--products td { display: block; padding: 0; border: 0; text-align: left; }
  .data-table--products td.col-hide-sm { display: none; }
  .data-table--products .cell-thumb { grid-area: thumb; width: auto; }
  .data-table--products .cell-product { grid-area: product; }
  .data-table--products .cell-price { grid-area: price; text-align: left; }
  .data-table--products .cell-toggle { grid-area: toggle; }
  .data-table--products .switch span { display: none; } /* the switch itself shows the state */
  .data-table--products td.empty { grid-column: 1 / -1; }
}

/* Small links and fold-out headers: at least 44px to tap */
.breadcrumb { display: inline-flex; align-items: center; min-height: 44px; margin-bottom: 0; }
.advanced > summary, .crud-item > summary { min-height: 44px; }
.link-right, .card__head > a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; }
.side-drawer .close-btn, .close-btn { width: 44px; height: 44px; flex: none; }
@media (max-width: 759px) {
  .gallery input[type="text"], .gallery input[type="number"] { min-height: 44px; font-size: 1rem; }
  .row-link { padding: 4px 0; }
}
.crud-item > summary > span:first-of-type, .crud-item > summary > h2 { flex: 1 1 auto; min-width: 0; }
.crud-item > summary .cell-sub { display: block; }
@media (max-width: 759px) {
  .page__toolbar > .tabs { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(104px, 100%), 1fr)); }
  .page__toolbar > .tabs a, .page__toolbar > .tabs button { padding: 0 8px; }
}
