:root {
  --canvas: #ffffff;
  --page: #fbfbfb;
  --ink: #3f4650;
  --heading: #333942;
  --muted: #7a828c;
  --line: #e4e4e4;
  --line-strong: #d7d7d7;
  --pink: #8d241b;
  --pink-dark: #6b2018;
  --coral: #aa2d00;
  --gold: #e4b21f;
  --soft: #f7f7f7;
  --success: #2f6a3a;
  --success-soft: #f4fbf5;
  --shadow: 0 8px 22px rgba(17, 24, 39, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 8px max(24px, calc((100vw - 1320px) / 2));
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid #e8e8e8;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--heading);
  text-decoration: none;
}

.brandMark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--pink);
  border-radius: 999px;
  color: var(--pink);
  background: #fff;
  font-size: 10px;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
  letter-spacing: 0;
}

.brand strong {
  color: #222;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.brand small {
  margin-top: 2px;
  color: #777;
  font-size: 10px;
}

.topbarActions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.viewSwitch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.viewButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: #555;
  background: transparent;
  font-size: 10px;
  font-weight: 900;
  text-decoration: none;
  text-transform: uppercase;
  white-space: nowrap;
}

.viewButton.isActive {
  border-color: var(--pink);
  color: var(--pink);
  background: #fff;
}

.statusPill {
  max-width: 310px;
  min-height: 30px;
  padding: 6px 11px;
  border: 1px solid #d8eadc;
  border-radius: 999px;
  color: var(--success);
  background: var(--success-soft);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.advisoryHero,
.advisoryShell {
  width: min(1320px, calc(100% - 48px));
  margin: 0 auto;
}

.advisoryHero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 30px;
  align-items: end;
  padding: 46px 0 34px;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
  color: var(--heading);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.eyebrow::before,
.eyebrow::after {
  content: "";
  display: block;
  width: 56px;
  height: 1px;
  background: var(--line);
}

.eyebrow::after {
  flex: 1;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 820px;
  margin-bottom: 14px;
  color: var(--heading);
  font-size: clamp(30px, 3.6vw, 48px);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  color: var(--heading);
  font-size: 24px;
  line-height: 1.18;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  color: var(--heading);
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

.intro,
#productDescription,
.summaryText,
.emptyState p,
.resultSection p,
.compactBlock li,
.sourceFooter,
.heroNote span {
  color: var(--muted);
  line-height: 1.65;
}

.intro {
  max-width: 760px;
  margin-bottom: 0;
  font-size: 16px;
}

.heroNote {
  position: relative;
  padding: 20px 0 0 22px;
  border-top: 1px solid var(--line);
}

.heroNote::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 0;
  width: 82px;
  height: 2px;
  background: var(--gold);
}

.heroNote strong,
.heroNote span {
  display: block;
}

.heroNote strong {
  margin-bottom: 8px;
  color: var(--heading);
  font-size: 15px;
  text-transform: uppercase;
}

.advisoryShell {
  display: grid;
  gap: 36px;
  padding-bottom: 54px;
}

.productRail,
.workSurface,
.resultSurface {
  min-width: 0;
}

.productRail {
  min-width: 0;
}

.railHeader {
  margin-bottom: 20px;
}

.railHeader .intro {
  font-size: 14px;
}

.productList {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.productButton {
  position: relative;
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  grid-template-rows: auto auto 1fr;
  column-gap: 18px;
  row-gap: 7px;
  width: 100%;
  min-height: 160px;
  padding: 0;
  overflow: hidden;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: var(--canvas);
  box-shadow: 0 2px 8px rgba(17, 24, 39, 0.05);
}

.productButton::before {
  content: attr(data-card-number);
  display: grid;
  grid-row: 1 / -1;
  min-height: 160px;
  place-items: end start;
  padding: 14px;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(40, 40, 40, 0.18), rgba(40, 40, 40, 0.64)),
    linear-gradient(135deg, #e9cf97, #d45d7a 42%, #4b6472);
  font-size: 34px;
  font-weight: 900;
}

.productButton:nth-child(2n)::before {
  background:
    linear-gradient(180deg, rgba(40, 40, 40, 0.12), rgba(40, 40, 40, 0.58)),
    linear-gradient(135deg, #f6d7c9, #c9d7d5 42%, #6b788a);
}

.productButton:nth-child(3n)::before {
  background:
    linear-gradient(180deg, rgba(40, 40, 40, 0.12), rgba(40, 40, 40, 0.58)),
    linear-gradient(135deg, #d7e4ec, #f1cbc5 44%, #9f6d78);
}

.productButton > span,
.productButton > strong,
.productButton > small {
  grid-column: 2;
  min-width: 0;
  padding-right: 18px;
}

.productButton span {
  align-self: start;
  padding-top: 24px;
  color: var(--pink);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.productButton strong {
  color: var(--heading);
  font-size: 18px;
  line-height: 1.2;
}

.productButton small {
  align-self: start;
  padding-bottom: 18px;
  color: var(--muted);
  line-height: 1.42;
}

.productButton.isActive {
  border-color: var(--gold);
  box-shadow: 0 6px 18px rgba(17, 24, 39, 0.1);
}

.productButton.isActive::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: var(--gold);
}

.mainGrid {
  display: grid;
  grid-template-columns: minmax(420px, 0.9fr) minmax(460px, 1.1fr);
  gap: 22px;
}

.workSurface,
.resultSurface {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--canvas);
  box-shadow: var(--shadow);
}

.workSurface {
  padding: clamp(20px, 2.6vw, 30px);
}

.resultSurface {
  min-height: 560px;
  padding: clamp(20px, 2.6vw, 30px);
}

.panelHeader {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.advisoryForm {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--heading);
  font-size: 13px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  color: var(--heading);
  background: #fff;
  outline: none;
}

.field input,
.field select {
  min-height: 44px;
  padding: 0 12px;
}

.field textarea {
  min-height: 132px;
  resize: vertical;
  padding: 12px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(233, 30, 99, 0.1);
}

.wideField,
.formActions {
  grid-column: 1 / -1;
}

.formActions {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

.panelTools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.secondaryAction,
.primaryAction {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 7px 15px;
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
}

.secondaryAction {
  border: 1px solid var(--line);
  color: var(--heading);
  background: #fff;
}

.primaryAction {
  border: 1px solid var(--pink);
  color: #fff;
  background: var(--pink);
}

.primaryAction:hover,
.viewButton.isActive:hover {
  border-color: var(--pink-dark);
  background: var(--pink-dark);
  color: #fff;
}

.emptyState {
  display: grid;
  min-height: 500px;
  align-content: center;
  justify-items: center;
  padding: 18px;
  text-align: center;
}

.emptyState h2 {
  max-width: 430px;
}

.emptyState p {
  max-width: 560px;
}

.resultCard {
  display: grid;
  gap: 18px;
}

.resultHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.confidenceBadge {
  flex: 0 0 auto;
  padding: 8px 11px;
  border-radius: 999px;
  color: var(--pink);
  background: #fff;
  border: 1px solid rgba(233, 30, 99, 0.28);
  font-size: 12px;
  font-weight: 900;
}

.sectionStack {
  display: grid;
  gap: 12px;
}

.resultSection,
.compactBlock {
  padding: 15px 0 0;
  border-top: 1px solid var(--line);
}

.resultSection p {
  margin-bottom: 0;
}

.compactBlock ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 19px;
}

.sourceFooter {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

@media (max-width: 1120px) {
  .advisoryHero,
  .mainGrid {
    grid-template-columns: 1fr;
  }

  .productRail {
    position: static;
  }

  .productList {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbarActions {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
  }

  .viewSwitch {
    flex-wrap: wrap;
  }

  .statusPill {
    width: 100%;
    max-width: none;
  }

  .advisoryHero,
  .advisoryShell {
    width: min(100% - 28px, 1320px);
  }

  .advisoryHero {
    padding-top: 30px;
  }

  h1 {
    font-size: 32px;
  }

  .productList,
  .advisoryForm {
    grid-template-columns: 1fr;
  }

  .productButton {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  .productButton::before {
    min-height: 112px;
    font-size: 28px;
  }

  .resultHeader {
    display: grid;
  }
}

/* Shared red-brown paper theme to keep advisory visually aligned with the
   main Tu Vi app. */
:root[data-theme="heritage"] {
  --canvas: #fffaf0;
  --page: #f2dfb7;
  --ink: #2b1712;
  --heading: #2b1712;
  --muted: #7a6258;
  --line: rgba(211, 169, 88, .62);
  --line-strong: rgba(143, 36, 29, .55);
  --pink: #982b22;
  --pink-dark: #6b2018;
  --gold: #d3a958;
  --soft: #fff3d7;
  --shadow: 0 20px 52px rgba(92, 31, 24, .08);
}

body[data-theme="heritage"] {
  background:
    linear-gradient(rgba(128, 88, 31, .10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(128, 88, 31, .10) 1px, transparent 1px),
    var(--page);
  background-size: 48px 48px;
}

body[data-theme="heritage"] .topbar {
  background: #641f17;
  border-bottom: 1px solid rgba(230, 190, 118, .42);
  color: #fff8e7;
}

body[data-theme="heritage"] .brand,
body[data-theme="heritage"] .brand strong,
body[data-theme="heritage"] .brand small,
body[data-theme="heritage"] .viewButton {
  color: #fff8e7;
}

body[data-theme="heritage"] .brandMark {
  background: #8c241d;
  color: #fff8e7;
  border-color: rgba(241, 198, 103, .58);
}

body[data-theme="heritage"] .viewSwitch {
  padding: 4px;
  border: 1px solid rgba(230, 190, 118, .52);
  border-radius: 999px;
  background: #fff2cf;
}

body[data-theme="heritage"] .viewButton {
  color: #7a4c3b;
}

body[data-theme="heritage"] .viewButton.isActive {
  border-color: transparent;
  background: #982b22;
  color: #fff8e7;
}

body[data-theme="heritage"] .advisoryHero,
body[data-theme="heritage"] .advisoryShell {
  color: var(--ink);
}

body[data-theme="heritage"] .heroNote,
body[data-theme="heritage"] .workSurface,
body[data-theme="heritage"] .productRail,
body[data-theme="heritage"] .resultPanel,
body[data-theme="heritage"] .fieldGroup,
body[data-theme="heritage"] .advisoryCard,
body[data-theme="heritage"] .sourcePolicy,
body[data-theme="heritage"] .questionBlock {
  background: rgba(255, 250, 238, .94);
  border-color: rgba(211, 169, 88, .64);
  box-shadow: var(--shadow);
}

:root[data-theme="sage"] {
  --canvas: #fbfdf9;
  --page: #edf6ee;
  --ink: #1f352b;
  --heading: #173326;
  --muted: #61736a;
  --line: #cfe2d4;
  --line-strong: #9fc5ad;
  --pink: #2f8f5b;
  --pink-dark: #1f6f45;
  --soft: #f3faf4;
  --shadow: 0 18px 44px rgba(31, 111, 69, .08);
}

:root[data-theme="neutral"] {
  --canvas: #ffffff;
  --page: #f3f4f6;
  --ink: #1f2937;
  --heading: #111827;
  --muted: #6b7280;
  --line: #d1d5db;
  --line-strong: #9ca3af;
  --pink: #4b5563;
  --pink-dark: #374151;
  --soft: #f9fafb;
  --shadow: 0 12px 30px rgba(17, 24, 39, .08);
}

.themeToggle {
  position: relative;
  width: 44px;
  min-width: 44px;
  height: 36px;
  padding: 0;
  font-size: 0;
  line-height: 0;
}

.themeToggle::before {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  margin: auto;
  border-radius: 999px;
  background: #e83f6f;
  box-shadow: inset 0 0 0 4px #fff1f4, 0 0 0 1px rgba(232, 63, 111, .35);
}

:root[data-theme="heritage"] .themeToggle::before {
  background: #982b22;
  box-shadow: inset 0 0 0 4px #fff2cf, 0 0 0 1px rgba(152, 43, 34, .35);
}

:root[data-theme="sage"] .themeToggle::before {
  background: #2f8f5b;
  box-shadow: inset 0 0 0 4px #effaf3, 0 0 0 1px rgba(47, 143, 91, .35);
}

:root[data-theme="neutral"] .themeToggle::before {
  background: #4b5563;
  box-shadow: inset 0 0 0 4px #f2f3f5, 0 0 0 1px rgba(75, 85, 99, .35);
}

/* Status dot */
.statusDot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  cursor: default;
  transition: background 0.3s;
}
.statusDot[data-mode="ready"]   { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,.18); }
.statusDot[data-mode="loading"] { background: #f59e0b; }
.statusDot[data-mode="error"]   { background: #ef4444; }

/* Ẩn legacy statusPill */
.statusPill {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}
