/* =====================================================================
   Agarwal Crockery World — Product Desk
   Shared styles for every page. Colours are tokens so light and dark
   themes stay in step (dark follows the device setting).
   ===================================================================== */
@import url("https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,700&family=Figtree:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500&display=swap");

:root {
  --bg: #F2F4F8;  --surface: #FFFFFF; --sunken: #E9EDF4; --ink: #141D33; --muted: #5A6580; --line: #D9DFEA;
  --accent: #1D4DBA; --accent-ink: #FFFFFF; --accent-soft: #E4EBFA;
  --good: #1C7549; --good-soft: #E2F2E9; --warn: #9A6200; --warn-soft: #FBF0DC; --bad: #B0261C; --bad-soft: #FBE6E4;
  --brand-bg: #1A43A6; --brand-ink: #FFFFFF; --brand-soft: #C9D6F5;
  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Figtree", "Segoe UI", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0C1220; --surface: #141C2E; --sunken: #101727; --ink: #E6EBF5; --muted: #98A3BB; --line: #25304A;
    --accent: #86A6FF; --accent-ink: #0C1220; --accent-soft: #1B284A;
    --good: #5CC491; --good-soft: #12301F; --warn: #E3AA4C; --warn-soft: #33260F; --bad: #F28B80; --bad-soft: #3A1715;
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--f-body); }
img, video { max-width: 100%; display: block; }
h1, h2, h3 { font-family: var(--f-display); margin: 0; letter-spacing: -.01em; text-wrap: balance; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 1400px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar .wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding-block: 10px; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; text-decoration: none; color: inherit; min-width: 0; }
.brand b { display: block; font-family: var(--f-display); font-size: 18px; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.nav { display: flex; gap: 4px; background: var(--sunken); padding: 4px; border-radius: 999px; }
.nav a { text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; padding: 6px 14px; border-radius: 999px; }
.nav a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.me { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.role-chip { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
main.wrap { padding-block: 20px 48px; }

/* ---------- buttons & fields ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); }
.btn.danger.solid { background: var(--bad); color: #FFFFFF; border-color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 12px 16px; font-size: 16px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after { content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid currentColor; border-color: var(--accent-ink) transparent var(--accent-ink) transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.btn:not(.primary).loading::after { border-color: var(--ink) transparent var(--ink) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.field > label .req { color: var(--bad); }
.input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 9px 11px; min-height: 40px; }
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 96px; resize: vertical; }
.field.has-error .input { border-color: var(--bad); }
.field-error { color: var(--bad); font-size: 13px; font-weight: 500; }
.field-hint { color: var(--muted); font-size: 12.5px; }
.input-group { display: flex; gap: 6px; }
.input-group .input { flex: 1; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; } .span-all { grid-column: 1 / -1; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--good-soft); color: var(--good); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--accent-soft); color: var(--accent); }

/* ---------- pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.in, .pill.on { background: var(--good-soft); color: var(--good); }
.pill.low { background: var(--warn-soft); color: var(--warn); }
.pill.out, .pill.off { background: var(--bad-soft); color: var(--bad); }
.tag { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 2px 7px; border-radius: 4px; background: var(--warn-soft); color: var(--warn); }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel + .panel { margin-top: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.panel-head h1, .panel-head h2 { font-size: 22px; }
.hint { color: var(--muted); font-size: 13.5px; max-width: 75ch; margin: 4px 0 0; }

/* ---------- catalog layout ---------- */
.catalog { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 20px; align-items: start; }
.rail { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); position: sticky; top: 76px; max-height: calc(100vh - 96px); display: flex; flex-direction: column; min-width: 0; }
.rail-head { padding: 14px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 36px; font-size: 15px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.chip { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 4px 11px; font-size: 13px; cursor: pointer; white-space: nowrap; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.count { font-size: 12px; color: var(--muted); }
.list { overflow-y: auto; flex: 1; min-height: 120px; }
.item { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; width: 100%; text-align: left; cursor: pointer; }
.item:hover { background: var(--sunken); }
.item[aria-current="true"] { background: var(--accent-soft); }
.thumb { width: 48px; height: 48px; border-radius: 8px; background: var(--sunken); object-fit: cover; display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.item .nm, .item .sub { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .nm { font-weight: 600; }
.item .sub { font-size: 12px; color: var(--muted); }
.item .pr { text-align: right; font-size: 14px; }
.item .pr small { display: block; font-size: 11px; color: var(--muted); font-family: var(--f-body); }
.rail-foot { padding: 10px 14px; display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); }
.empty { padding: 48px 24px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; color: var(--muted); }
.empty h2 { color: var(--ink); font-size: 21px; }

.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.sheet-in { padding: 24px; display: flex; flex-direction: column; gap: 24px; }
.back-btn { display: none; align-self: flex-start; }
.p-head { display: flex; gap: 16px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.p-head h1 { font-size: clamp(24px, 3vw, 32px); line-height: 1.15; }
.crumb { font-size: 12px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; margin-bottom: 6px; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.p-top { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 24px; }
.gallery { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.stage { aspect-ratio: 4 / 3; max-width: 100%; background: var(--sunken); border-radius: var(--r); overflow: hidden; display: grid; place-items: center; }
.stage.empty-stage { aspect-ratio: 16 / 9; }
.stage img, .stage video { width: 100%; height: 100%; object-fit: contain; }
.strip { display: flex; gap: 8px; overflow-x: auto; }
.strip button { flex: 0 0 64px; height: 64px; border-radius: 8px; overflow: hidden; border: 2px solid transparent; padding: 0; background: var(--sunken); cursor: pointer; position: relative; }
.strip button[aria-current="true"] { border-color: var(--accent); }
.strip img, .strip video { width: 100%; height: 100%; object-fit: cover; }
.strip .play { position: absolute; inset: 0; display: grid; place-items: center; color: #FFFFFF; background: rgba(0,0,0,.35); font-size: 14px; }
.no-media { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }

.prices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.price { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.price.key { background: var(--accent-soft); border-color: transparent; }
.price span { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.price strong { display: block; font-family: var(--f-mono); font-size: 22px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.price.key strong { color: var(--accent); }
.price em { font-style: normal; font-size: 12px; color: var(--muted); }
.stamp { font-size: 13px; color: var(--muted); }
.stamp b { color: var(--ink); font-weight: 600; }
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.price-form { border: 2px solid var(--accent); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.specs { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; margin: 0; }
.specs div { padding: 10px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; }
.specs dt { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .05em; text-transform: uppercase; }
.specs dd { margin: 2px 0 0; font-weight: 500; overflow-wrap: anywhere; }
.section h3 { font-size: 18px; margin-bottom: 10px; }
.desc { max-width: 68ch; white-space: pre-wrap; margin: 0; }

/* ---------- tables (become cards on phones) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); text-align: left; padding: 9px 12px; background: var(--sunken); white-space: nowrap; }
td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.up { color: var(--bad); } .down { color: var(--good); }
.old { color: var(--muted); text-decoration: line-through; }
.who { display: inline-flex; align-items: center; gap: 8px; }
.linkish { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-align: left; }
.linkish:hover { text-decoration: underline; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; font-size: 13px; color: var(--muted); }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; border-radius: 12px; background: var(--surface); color: var(--ink); width: min(820px, calc(100% - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 24px 60px -20px rgba(8,12,24,.5); }
dialog.small { width: min(460px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(8,12,24,.5); }
.dlg { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dlg-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dlg-h h2 { font-size: 20px; }
.dlg-b { padding: 20px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.dlg-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.dlg-f .right { display: flex; gap: 8px; margin-left: auto; }
.fieldset-title { font-size: 13px; font-weight: 700; color: var(--ink); margin: 6px 0 -4px; }

.media-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.mtile { width: 96px; height: 96px; border-radius: 8px; overflow: hidden; position: relative; background: var(--sunken); border: 1px solid var(--line); }
.mtile img, .mtile video { width: 100%; height: 100%; object-fit: cover; }
.mtile .x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #FFFFFF; cursor: pointer; line-height: 1; }
.mtile .cover { position: absolute; bottom: 4px; left: 4px; font-size: 10px; font-weight: 700; background: var(--accent); color: var(--accent-ink); padding: 1px 6px; border-radius: 4px; }
.mtile .make-cover { position: absolute; bottom: 4px; left: 4px; font-size: 10px; border: 0; border-radius: 4px; background: rgba(0,0,0,.6); color: #FFFFFF; padding: 2px 6px; cursor: pointer; }
.mtile.new { outline: 2px dashed var(--accent); outline-offset: -2px; }
.drop { width: 96px; height: 96px; border: 1.5px dashed var(--line); border-radius: 8px; display: grid; place-items: center; text-align: center; font-size: 12px; color: var(--muted); cursor: pointer; }
.drop:hover { border-color: var(--accent); color: var(--accent); }

.steps { display: flex; flex-direction: column; }
.step { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: 0; }
.step b { display: block; }
.step .hint { margin: 4px 0 10px; }
.step .num { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; font-size: 14px; }
.problems { margin: 6px 0 0; padding-left: 18px; font-size: 13px; max-height: 180px; overflow-y: auto; }

.creds { border: 1.5px dashed var(--accent); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--accent-soft); }
.creds dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; margin: 0; }
.creds dt { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding-top: 2px; }
.creds dd { margin: 0; font-family: var(--f-mono); overflow-wrap: anywhere; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(20px, env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 100; font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.error { background: var(--bad); color: #FFFFFF; }
.page-loading { padding: 80px 20px; text-align: center; color: var(--muted); }

/* ---------- responsive ---------- */
@media (min-width: 1600px) { .catalog { grid-template-columns: 420px minmax(0, 1fr); } }
@media (max-width: 1180px) {
  .catalog { grid-template-columns: 300px minmax(0, 1fr); gap: 16px; }
  .sheet-in { padding: 20px; }
  .price strong { font-size: 19px; }
}
@media (max-width: 1024px) {
  .p-top { grid-template-columns: minmax(0, 1fr); }
  .stage { aspect-ratio: 16 / 10; }
  .prices { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 767px) {
  main.wrap { padding-block: 12px 32px; }
  .catalog { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; max-height: none; }
  .catalog.has-selection .rail { display: none; }
  .catalog:not(.has-selection) .sheet { display: none; }
  .back-btn { display: inline-flex; }
  .sheet-in { padding: 16px; gap: 20px; }
  .prices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel { padding: 16px; }
}
@media (max-width: 640px) {
  .topbar .wrap { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding-block: 8px; }
  .brand b { font-size: 16px; }
  .brand svg { width: 28px; height: 28px; }
  .me .name, .lock-text { display: none; }
  .nav { grid-column: 1 / -1; order: 3; }
  .nav a { flex: 1; text-align: center; padding: 7px 8px; }
  .item { padding: 10px 12px; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; }
  .thumb { width: 44px; height: 44px; }
  .p-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .p-head .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .p-head .actions .btn:first-child { grid-column: 1 / -1; }
  .specs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rail-foot .btn { flex: 1; }
  .form-grid, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  /* tables → stacked cards */
  .table-wrap.cards { overflow: visible; border: 0; border-radius: 0; }
  .cards table, .cards tbody, .cards tr, .cards td { display: block; width: 100%; }
  .cards thead { display: none; }
  .cards tr { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; margin-bottom: 10px; background: var(--surface); }
  .cards td { border: 0; padding: 4px 0; display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: 10px; }
  .cards td::before { content: attr(data-label); font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding-top: 2px; }
  .cards td[data-label=""] { grid-template-columns: minmax(0, 1fr); }
  .cards td[data-label=""]::before { display: none; }
  .cards td.blank { display: none; }
  .cards td > .pill, .cards td > .role-chip { justify-self: start; }
  /* dialogs fill the screen */
  dialog, dialog.small { width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; margin: 0; }
  .dlg { height: 100%; max-height: 100%; }
  .dlg-b { flex: 1; padding: 16px; }
  .dlg-h { padding: max(12px, env(safe-area-inset-top)) 16px 12px; }
  .dlg-f { padding: 12px 16px max(12px, env(safe-area-inset-bottom)); }
  .dlg-f .right { flex: 1; } .dlg-f .right .btn { flex: 1; }
  .mtile, .drop { width: 84px; height: 84px; }
}
@media (max-width: 420px) {
  .price { padding: 10px 12px; }
  .price strong { font-size: 18px; }
  .item .pr small { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
