:root {
  --bg: var(--ng-color-background);
  --surface: var(--ng-color-surface);
  --ink: var(--ng-color-text);
  --muted: var(--ng-color-text-muted);
  --line: var(--ng-color-border-decorative);
  --control: var(--ng-color-border-control);
  --gold: var(--ng-color-accent);
  --good: var(--ng-color-success);
  --bad: var(--ng-color-error);
  --plain-gold: var(--ng-palette-gold);
  --wash: color-mix(in srgb, var(--gold) 8%, var(--surface));
  --radius: 16px;
  --sidebar: 224px;
  color-scheme: dark;
}
:root[data-ng-theme=light] { color-scheme: light; }
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 400 .94rem/1.65 Vazirmatn, Tahoma, "Segoe UI", sans-serif;
}
a { color: var(--gold); text-underline-offset: .27em; }
a:hover { text-decoration-thickness: 2px; }
p { margin: .35rem 0 .8rem; }
h1, h2, h3 { line-height: 1.3; margin: 0; font-weight: 690; }
h1 { font-size: clamp(1.65rem, 3vw, 2.45rem); letter-spacing: -.027em; }
h2 { font-size: 1.24rem; }
h3 { font-size: 1.03rem; }
small, .small { font-size: .82rem; }
small, .muted, .subtle { color: var(--muted); }
bdi[dir=ltr], .code { font: 500 .83em/1.5 Consolas, "Segoe UI", monospace; overflow-wrap: anywhere; }
button, input, select, textarea { color: inherit; font: inherit; }
button, input, select, textarea, .button {
  border: 1px solid var(--control);
  background: var(--bg);
  border-radius: 8px;
  min-height: 40px;
  padding: .42rem .72rem;
}
button, .button {
  cursor: pointer;
  text-decoration: none;
  font-weight: 620;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .32rem;
}
button:disabled { opacity: .55; cursor: default; }
button:hover:not(:disabled), .button:hover { border-color: var(--gold); color: var(--gold); }
button.primary, .button.primary { background: var(--plain-gold); border-color: var(--plain-gold); color: #20190e; }
button.primary:hover, .button.primary:hover { background: #d8bc85; color: #20190e; }
button[aria-pressed=true] { background: var(--wash); border-color: var(--gold); color: var(--gold); }
button.danger { color: var(--bad); }
input[type=checkbox] { accent-color: var(--gold); width: 1.05rem; height: 1.05rem; min-height: 0; margin: 0; vertical-align: middle; }
label { display: grid; gap: .22rem; font-size: .88rem; min-width: 0; }
label > :is(input, textarea, select) { width: 100%; min-width: 0; }
textarea { min-height: 5.2em; resize: vertical; }
:focus-visible { outline: 3px solid var(--ng-color-focus); outline-offset: 3px; }
.skip { position: fixed; z-index: 9; inset-block-start: -90px; inset-inline-start: 1rem; background: var(--surface); padding: .7rem; }
.skip:focus { inset-block-start: 1rem; }
.sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  z-index: 2;
  width: var(--sidebar);
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 13px;
}
.brand { display: flex; padding: 0 5px 15px; min-height: 75px; align-items: center; }
.brand img { width: 100%; display: block; object-fit: contain; }
.brand .logo-light, [data-ng-theme=light] .brand .logo-dark { display: none; }
[data-ng-theme=light] .brand .logo-light { display: block; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav a {
  color: var(--muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 10px;
  min-height: 44px;
  font-weight: 600;
  white-space: nowrap;
}
.sidebar nav a span { font-family: "Segoe UI Symbol", Tahoma, sans-serif; font-size: 1.07rem; width: 1.22em; text-align: center; }
.sidebar nav a:hover { background: var(--bg); color: var(--ink); }
.sidebar nav a[aria-current=page] { color: var(--gold); border-color: var(--line); background: var(--wash); }
.sidebar-foot { margin-block-start: auto; padding: .85rem .65rem 0; border-block-start: 1px solid var(--line); display: flex; align-items: center; gap: .6rem; }
.sidebar-foot small { display: block; }
.scope-dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--good); }
.shell { margin-inline-start: var(--sidebar); }
.topbar {
  min-height: 66px;
  padding: .55rem clamp(1rem, 3.2vw, 2.75rem);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .8rem;
  border-block-end: 1px solid var(--line);
  background: var(--bg);
}
.app-title { font-weight: 650; white-space: nowrap; }
.top-tools, .row, .actions, .chips { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.top-tools { justify-content: flex-end; }
.top-tools button { min-height: 36px; font-size: .81rem; }
.freshness { color: var(--muted); font-size: .79rem; }
#workspace { width: min(100%, 1512px); padding: 29px clamp(1rem, 3.2vw, 2.75rem) 50px; margin-inline: auto; }
.page-head { margin-block-end: 17px; display: flex; gap: 1.15rem; align-items: end; justify-content: space-between; flex-wrap: wrap; }
.page-head p { margin: .45rem 0 0; color: var(--muted); }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(.85rem, 1.6vw, 1.35rem);
  min-width: 0;
}
.panel + .panel, .stack > * + * { margin-block-start: .78rem; }
.grid > .panel, .metrics > .panel { margin: 0; }
.panel-head { margin-block-end: .9rem; }
.panel-head p { margin: .36rem 0 0; }
.between { justify-content: space-between; }
.start { align-items: start; }
.notice { padding: .7rem .9rem; border: 1px solid var(--control); border-radius: 9px; background: var(--wash); margin-block-end: .8rem; }
.notice[data-tone=error], #login-error { color: var(--bad); border-color: var(--bad); }
.tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  gap: .3rem;
  padding: .18rem .53rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.45;
  font-weight: 620;
}
.tag.gold { color: var(--gold); background: var(--wash); }
.tag.good { color: var(--good); }
.tag.bad { color: var(--bad); }
.grid { display: grid; gap: 14px; }
.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
.metrics { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; margin-block: 14px; }
.metric { min-height: 111px; text-decoration: none; color: inherit; }
.metric:hover { border-color: var(--gold); }
.metric strong { display: block; font-size: clamp(1.55rem, 2.4vw, 2.15rem); line-height: 1.35; margin-block: .26rem; font-weight: 720; }
.metric small { display: block; }
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, .85fr);
  gap: clamp(.85rem, 2.4vw, 2rem);
  align-items: center;
  padding: clamp(1.15rem, 2.65vw, 2.1rem);
  background: radial-gradient(ellipse at 4% 90%, color-mix(in srgb,var(--gold) 13%,transparent), transparent 66%), var(--surface);
}
.hero p { color: var(--muted); max-width: 52ch; }
.hero .actions { margin-block-start: 1.1rem; }
.hero-readiness { padding: .94rem 1rem; background: color-mix(in srgb,var(--bg) 75%,transparent); border: 1px solid var(--line); border-radius: 12px; }
.hero-readiness h2 { margin-block-end: .45rem; }
.gauge { display: grid; gap: .34rem; margin-block: .58rem .25rem; }
progress { width: 100%; height: .48rem; border: none; background: var(--line); border-radius: 8px; appearance: none; overflow: hidden; color: var(--gold); }
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { background: var(--gold); border-radius: 8px; }
progress::-moz-progress-bar { background: var(--gold); border-radius: 8px; }
.bar { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(36px,1fr) auto; align-items: center; gap: .62rem; padding: .34rem .36rem; border-radius: 6px; text-decoration: none; color: var(--ink); font-size: .88rem; }
a.bar:hover { background: var(--wash); color: var(--gold); }
.bar span:first-child { overflow-wrap: anywhere; }
.bar strong { min-width: 1.8rem; text-align: end; }
.action-list > * { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .57rem 0; border-block-end: 1px solid var(--line); }
.action-list > :last-child { border-block-end: 0; }
.selection { margin-block-end: .7rem; }
.filters { margin-block: .82rem .55rem; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: .65rem; }
.search { position: relative; max-width: 790px; }
.search input { min-height: 46px; padding-inline-start: .9rem; font-size: 1rem; }
.advanced { margin-block: .65rem; }
summary { cursor: pointer; font-weight: 640; color: var(--gold); overflow-wrap: anywhere; }
details > summary { padding-block: .36rem; }
details[open] > summary { margin-block-end: .36rem; }
.chip { padding: .24rem .62rem; border-radius: 2rem; min-height: 34px; font-size: .84rem; background: var(--surface); }
.chip.active { border-color: var(--gold); color: var(--gold); background: var(--wash); }
.check-label { display: flex; align-items: center; gap: .35rem; white-space: nowrap; }
.check-label input { width: auto; }
.results-head { margin-block: .8rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: start; font-size: .91rem; }
th, td { padding: .55rem .65rem; border-block-end: 1px solid var(--line); vertical-align: middle; text-align: start; }
th { font-size: .8rem; color: var(--muted); white-space: nowrap; }
tbody tr:hover { background: color-mix(in srgb,var(--gold) 4%,transparent); }
tbody tr:last-child td { border-block-end: none; }
.product-cell { display: flex; align-items: center; gap: .55rem; min-width: 172px; }
.thumb, .thumb-empty { width: 54px; height: 54px; object-fit: cover; border-radius: 7px; background: var(--bg); flex: none; }
.product-link { color: var(--ink); font-weight: 670; }
.product-cell small, .product-tile small { display: block; }
.gallery { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; }
.product-tile { display: grid; grid-template-rows: auto 1fr auto; gap: .48rem; padding: .7rem; border: 1px solid var(--line); border-radius: 11px; background: var(--bg); }
.product-tile .thumb, .product-tile .thumb-empty { width: 100%; height: auto; aspect-ratio: 1.55; display: block; }
.pagination { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; justify-content: center; margin-block-start: .95rem; }
.pagination .muted { min-width: 6.1rem; text-align: center; }
.empty { padding-block: 1.1rem; color: var(--muted); }
.breadcrumb { margin-block-end: .43rem; display: inline-block; }
.product-head { padding: 0; margin-block-end: 1rem; }
.product-head .identity { color: var(--muted); font-size: .9rem; }
.review-layout { display: grid; grid-template-columns: minmax(0,1fr) minmax(240px, .45fr); gap: 14px; align-items: start; }
.review-layout > .panel { margin: 0; }
.comparison { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .72rem; margin-block: .73rem .55rem; }
.comparison figure { min-width: 0; margin: 0; }
.comparison figcaption { font-size: .87rem; font-weight: 640; margin-block-end: .27rem; }
.comparison .photo {
  display: grid;
  place-items: center;
  width: 100%;
  height: clamp(185px, 24vw, 380px);
  padding: 0;
  background: #141613;
  color: #f5f0e6;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.comparison[data-bg=light] .photo { background: #f5f0e6; color: #242622; }
.comparison img { width: 100%; height: 100%; object-fit: contain; }
.photo > span { padding: .65rem; }
.comparison:hover .photo:hover { border-color: var(--gold); }
.compare-tools, .role-tabs { margin-block: .7rem; }
.compare-tools select { max-width: min(100%,16em); }
.compare-tools select, .compare-tools button, .role-tabs button { min-height: 36px; }
.role-tabs button { padding-inline: .55rem; }
.review-form { display: grid; gap: .64rem; }
.review-form .actions { align-items: stretch; }
.review-form .actions button { flex: 1 1 auto; }
.callout { border-inline-start: 3px solid var(--gold); padding: .4rem .7rem; background: var(--wash); border-radius: 6px; }
.definitions { display: grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); gap: .45rem 1rem; margin-block: .65rem; }
.definitions dt { color: var(--muted); font-size: .82rem; }
.definitions dd { margin: .11rem 0 0; font-weight: 610; overflow-wrap: anywhere; }
.case-list > details, .history-item { padding: .6rem 0; border-block-end: 1px solid var(--line); }
.case-list > :last-child, .history-item:last-child { border-block-end: 0; }
.case-meta { margin-inline-start: .45rem; vertical-align: middle; }
.case-body { padding: .68rem .82rem; margin-block: .45rem; background: var(--bg); border-radius: 9px; overflow-wrap: anywhere; }
.case-body .original { white-space: pre-wrap; border-inline-start: 1px solid var(--line); padding-inline-start: .7rem; color: var(--muted); }
.history-item p { margin-block: .15rem; white-space: pre-wrap; overflow-wrap: anywhere; }
dialog { width: min(100% - 2rem, 31rem); border: 1px solid var(--control); background: var(--surface); color: var(--ink); border-radius: var(--radius); max-height: calc(100dvh - 2rem); padding: 0; }
dialog::backdrop { background: #080907c9; }
.dialog-content { display: grid; gap: .78rem; padding: 1.15rem; }
#viewer { width: min(100% - 2rem, 1260px); }
#viewer .comparison { margin: 0; }
#viewer .photo { height: min(61vh, 640px); overflow: auto; display: block; cursor: grab; touch-action: pan-x pan-y; scrollbar-width: thin; }
#viewer .photo:active { cursor: grabbing; }
#viewer .photo img { display: block; object-fit: contain; height: auto; min-height: 100%; max-width: none; user-select: none; }
#viewer[data-zoom="1"] img { width: 100%; }
#viewer[data-zoom="2"] img { width: 175%; }
#viewer[data-zoom="3"] img { width: 250%; }
#viewer[data-zoom="4"] img { width: 380%; }
@media (max-width: 1090px) {
  :root { --sidebar: 176px; }
  .sidebar { padding-inline: 9px; }
  .gallery { grid-template-columns: repeat(3,minmax(0,1fr)); }
}
@media (max-width: 900px) {
  .sidebar { position: static; width: 100%; padding: .45rem 1rem; border: 0; border-block-end: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; justify-content: space-between; align-items: center; }
  .brand { width: 155px; padding: 0; min-height: 50px; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 1px; }
  .sidebar nav a { gap: .25rem; padding-inline: .43rem; font-size: .83rem; }
  .sidebar-foot { display: none; }
  .shell { margin: 0; }
  .topbar { min-height: 57px; }
}
@media (max-width: 680px) {
  .metrics, .three, .filters, .gallery { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .two, .hero, .review-layout { grid-template-columns: minmax(0,1fr); }
  .topbar { flex-wrap: wrap; }
  .freshness { display: none; }
  .comparison .photo { height: 180px; }
  #workspace { padding-block-start: 17px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
.hero-title { margin-block-start: .65rem; }
.metrics.three { grid-template-columns: repeat(3,minmax(0,1fr)); }
td > small { display: block; }
.page-head h1:focus, .product-head h1:focus { outline: none; }
@media (max-width: 680px) {
  .metrics.three { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

/* Phase 4.1 R2 review and catalogue surfaces. */
.explorer-head { margin-block-end: 12px; }
.explorer-head h1, .compact-product h1 { font-size: clamp(1.55rem, 2.3vw, 2.05rem); }
.explorer-panel .search { max-width: none; }
.explorer-panel .results-head { margin-block: .55rem; }
.explorer-panel .advanced { margin-block: .3rem; }
.explorer-toolbar {
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  margin-block: .46rem .22rem;
}
.explorer-toolbar select, #results [data-filter=sort] { min-height: 36px; padding-block: .28rem; }
.clear-filters, #results button, .open-product { min-height: 34px; font-size: .82rem; }
.explorer-table :is(th, td) { padding: .4rem .5rem; }
.explorer-table .thumb, .explorer-table .thumb-empty { width: 42px; height: 42px; }
.explorer-table .product-cell { min-width: 9rem; }
.explorer-table th:last-child, .explorer-table td:last-child { width: 1%; }
.explorer-table .open-product { white-space: nowrap; }
.product-tile .open-product { margin-inline-start: auto; }
.compact-product { margin-block-end: .6rem; }
.compact-product .breadcrumb { margin-block-end: .2rem; font-size: .85rem; }
.compact-product .identity { margin-block: .22rem; }
.compact-product .callout { margin-block: .4rem 0; }
.review-board { display: grid; gap: .64rem; }
.review-board > .panel + .panel { margin-block-start: 0; }
#comparison { padding: clamp(.56rem, 1.1vw, 1rem); }
.gallery-toolbar { margin-block-end: .6rem; }
.gallery-toolbar button, .gallery-toolbar select { min-height: 34px; padding: .25rem .55rem; font-size: .81rem; }
.review-gallery {
  /* Generated roles are first in RTL reading order. The source track sits physically left. */
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(0, 1fr);
  gap: .62rem;
  align-items: start;
}
.generated-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: .52rem; }
.review-role, .source-gallery {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: start;
  align-content: start;
  gap: .35rem;
  padding: .48rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.source-gallery { border-color: color-mix(in srgb, var(--line) 72%, var(--gold)); }
.image-heading { display: flex; align-items: center; flex-wrap: wrap; gap: .12rem .4rem; min-height: 26px; }
.image-heading h3 { font-size: .88rem; }
.image-heading .tag { font-size: .7rem; padding: .07rem .35rem; }
.review-photo {
  display: grid;
  place-items: center;
  width: 100%;
  padding: 0;
  aspect-ratio: 1;
  max-height: clamp(148px, 42vh, 365px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #141613;
  color: #f5f0e6;
}
.review-photo img { width: 100%; height: 100%; object-fit: contain; }
.review-gallery[data-bg=light] .review-photo { background: #f5f0e6; color: #242622; }
.missing-photo { background: var(--surface); color: var(--muted); text-align: center; padding: .5rem; font-size: .83rem; }
button.compare-link {
  border-color: transparent;
  color: var(--gold);
  min-height: 28px;
  font-size: .74rem;
  padding: .1rem .28rem;
}
.role-actions { width: 100%; display: flex; flex-wrap: wrap; gap: .24rem; }
.role-actions button { flex: 1; font-size: .79rem; padding: .18rem .28rem; min-height: 33px; }
.source-thumbs { width: 100%; display: flex; gap: .28rem; overflow-x: auto; padding: 3px; }
.source-thumbs button { flex: 0 0 39px; height: 39px; min-height: 0; padding: 2px; overflow: hidden; }
.source-thumbs img { width: 100%; height: 100%; object-fit: cover; border-radius: 4px; }
.decision-bar {
  position: sticky;
  top: .55rem;
  bottom: .55rem;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .4rem .65rem;
  background: var(--surface);
  border: 1px solid var(--control);
  border-radius: 11px;
  padding: .48rem .62rem;
  box-shadow: 0 5px 18px #0002;
}
.decision-bar button, .decision-bar a { min-height: 42px; }
.decision-note { flex: 1 1 8rem; font-size: .81rem; }
.decision-bar [aria-disabled=true] { opacity: .55; cursor: default; }
.shortcut-toggle { font-size: .78rem; color: var(--muted); }
.review-shortcuts { margin: 0 .2rem; }
.bad { color: var(--bad); }
#viewer .single-preview { grid-template-columns: minmax(0,1fr); }
#viewer .single-preview figure { width: min(100%, 660px); justify-self: center; }
.draft-fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .6rem; margin-block: .6rem; }
.draft-fields > :first-child { grid-column: 1 / -1; }
#draft-form textarea, #content-panel > label textarea { min-height: 3rem; }
#draft-result { margin-inline-start: .48rem; }
.draft-text { white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 900px) {
  .review-gallery { grid-template-columns: minmax(0,3.7fr) minmax(0,1.3fr); }
  .review-role, .source-gallery { padding: .35rem; }
  .decision-bar .decision-note { flex-basis: 9.5rem; }
}
@media (max-width: 660px) {
  .review-gallery { grid-template-columns: 1fr; }
  .source-gallery { grid-row: 1; grid-template-columns: minmax(5rem, 8rem) minmax(0, 1fr); align-items: start; }
  .source-gallery .image-heading { grid-column: 1 / -1; }
  .source-gallery .review-photo { max-height: 128px; }
  .generated-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .decision-note { order: 3; flex-basis: 100%; }
  .decision-bar .previous-product { display: none; }
  .draft-fields { grid-template-columns: minmax(0,1fr); }
}


/* Keep an exhausted thumbnail request actionable in its existing image slot. */
img[data-ng-failed] { display: none !important; }
.ng-image-retry {
  color: inherit;
  font: inherit;
  line-height: 1.45;
  margin: .25rem;
  text-decoration: underline;
}

.review-photo { position: relative; }
.ng-image-pending {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: .25rem;
  color: inherit;
  font: inherit;
  text-align: center;
  pointer-events: none;
}
