/* Khung CSS trình chiếu dùng chung Trợ lý HIS - Phiên bản SL2 */
:root {
  --ink: #14283c;
  --accent: #174d83;
  --paper: #fffef9;
  --line: #b6c8d8;
  --red: #903232;
  --nav: 82px;
  --gap: 0.65em;
  --bg-card: #edf3f8;
  --bg-card-subtle: #f4f7fa;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: clamp(19px, min(2vw, 3.1vh), 50px);
  line-height: 1.25;
}

.slide {
  display: none;
  width: 100%;
  height: 100dvh;
  padding: 2.5vh 4.5vw calc(var(--nav) + 2vh);
  flex-direction: column;
  justify-content: flex-start;
  gap: var(--gap);
  position: relative;
  --scale: 1;
}

.slide.active { display: flex; }

header {
  border-bottom: 2px solid var(--line);
  padding: 0 0 0.3em;
  flex-shrink: 0;
  font-size: 1em;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.3em;
  line-height: 1.1;
  margin: 0;
  color: var(--accent);
}

h2 {
  font-size: 1.1em;
  line-height: 1.15;
  margin: 0 0 0.3em;
}

.body-slot {
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
  font-size: calc(1em * var(--scale));
}

.content {
  width: 100%;
  display: flex;
  flex: none;
  flex-direction: column;
  justify-content: center;
  gap: var(--gap);
  min-height: 0;
}

/* Hiệu ứng hiện dần */
.reveal {
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.5s ease;
  flex-shrink: 0;
}

.reveal.shown {
  visibility: visible;
  opacity: 0.95;
}

.reveal.current {
  opacity: 1;
}

.instant .reveal,
.instant .track i {
  transition: none !important;
}

.sentence {
  width: 100%;
  max-width: 72ch;
}

/* Thẻ số lớn */
.big-number {
  display: flex;
  gap: 0.8em;
  align-items: center;
  border-left: 5px solid var(--accent);
  background: var(--bg-card);
  padding: 0.4em 0.7em;
}

.big-number > span {
  max-width: 65%;
  font-size: 1em;
}

.big-number strong {
  font-size: 2.6em;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-family: Georgia, serif;
}

.track {
  height: clamp(22px, 2vw, 52px);
  background: #dbe4ec;
  margin-top: 0.2em;
  overflow: hidden;
}

.track i {
  display: block;
  width: var(--width, 0%);
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.8s ease;
}

.shown .track i { transform: scaleX(1); }

/* Thẻ cấu trúc lưới 01, 02... */
.structured .content {
  width: 92%;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55em;
}

.structured .reveal {
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  padding: 0.35em 0.65em;
  display: grid;
  grid-template-columns: 4.8em 1fr;
  gap: 0.65em;
  align-items: center;
  background: var(--bg-card-subtle);
  min-width: 0;
}

.card-heading {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0.35em;
}

.ordinal {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45em;
  line-height: 1;
  color: var(--accent);
  font-weight: 700;
}

.line-icon {
  width: 2.1em;
  height: 2.1em;
  stroke: var(--accent);
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* Quy trình Flow 4 - 5 bước */
.flow {
  display: grid;
  grid-template-columns: repeat(var(--flow-cols, 5), 1fr);
  gap: 1.1em;
  align-items: stretch;
  position: relative;
}

.flow-step {
  position: relative;
  border-top: 3px solid var(--accent);
  padding: 0.5em 0.5em;
  background: var(--bg-card);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0.35em;
  min-width: 0;
  font-size: 0.9em;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-align: left;
}

.step-number {
  font-weight: 700;
  color: var(--accent);
  font-size: 1.05em;
  text-align: left;
}

.flow-description {
  align-self: stretch;
  text-align: left;
  line-height: 1.25;
}

.time-tag {
  align-self: stretch;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.1em;
  line-height: 1.15;
  min-width: 0;
  overflow-wrap: anywhere;
}

.time-tag strong {
  font-size: 1.1em;
  color: var(--accent);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.time-tag small {
  font-size: 0.72em;
  color: #53718e;
  overflow-wrap: anywhere;
}

.flow-arrow {
  position: absolute;
  left: calc((100% + 1.1em) * var(--edge) / var(--flow-cols, 5) - 0.85em);
  top: 50%;
  transform: translateY(-50%);
  width: 0.75em;
  height: 0.45em;
  stroke: var(--accent);
  stroke-width: 5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  visibility: hidden;
  z-index: 2;
}

.flow-arrow.shown { visibility: visible; }

.clock-strip {
  padding: 0.3em 0.6em;
  background: var(--bg-card);
  border-left: 5px solid var(--accent);
}

.clock { font-size: 1em; }
.clock strong {
  color: var(--accent);
  font-size: 1.35em;
  font-family: Georgia, serif;
}

/* So sánh hai số */
.comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5em;
  padding: 0.4em 0.8em;
  background: var(--bg-card);
  border-top: 3px solid var(--accent);
}

.comparison-item {
  display: flex;
  align-items: center;
  gap: 0.6em;
  min-width: 0;
}

.comparison-item strong {
  font-size: 2.5em;
  color: var(--accent);
  line-height: 1;
  font-family: Georgia, serif;
}

.comparison-item > div {
  font-size: 0.95em;
  line-height: 1.2;
}

/* Cột giải pháp */
.solution-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  padding: 0.45em 0.65em;
  display: grid;
  grid-template-columns: 2.3em 1fr;
  gap: 0.6em;
  align-items: center;
  background: var(--bg-card);
}

.solution-copy { min-width: 0; }
.solution-panel h2 { font-size: 1.05em; margin: 0 0 0.2em; color: var(--accent); }
.solution-panel .sentence { font-size: 0.92em; }

/* Trang bìa */
.cover {
  text-align: center;
  padding-left: 8vw;
  padding-right: 8vw;
  gap: 0.65em;
  justify-content: center;
}

.cover header {
  border: 0;
  padding: 0;
  width: 100%;
}

.cover h1 {
  font-family: Arial, sans-serif;
  font-size: 0.85em;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.8;
}

.cover .content {
  align-items: center;
  gap: 0.7em;
  width: 100%;
}

.cover .reveal:first-child {
  position: relative;
  padding-bottom: 0.5em;
}

.cover .reveal:first-child::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: calc(50% - 2.5em);
  width: 5em;
  border-bottom: 4px solid var(--accent);
}

.cover h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(38px, min(4.8vw, 7.5vh), 94px);
  line-height: 1.15;
  margin: 0;
  color: var(--accent);
}

.cover .sentence {
  max-width: 52ch;
  font-size: 1em;
}

.cover .invitation {
  margin-top: 0.35em;
  font-weight: 600;
  color: var(--accent);
  font-size: 1.05em;
}

/* Gợi ý chạm trên điện thoại */
.tap-hint {
  display: none;
}

/* Lightbox overlay */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 60, 0.9);
  z-index: 1000;
  cursor: zoom-out;
  align-items: center;
  justify-content: center;
  padding: 2vw;
  backdrop-filter: blur(4px);
}

.lightbox.active { display: flex; }

.lightbox-content {
  max-width: 95vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 24px;
  background: none;
  border: none;
  color: white;
  font-size: 38px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
}

/* Khối liên hệ */
.contact-box {
  border: 2px solid var(--accent);
  background: #edf3f8;
  padding: 0.7em 1.1em;
  margin-top: 0.4em;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.8em;
}

.contact-info {
  display: flex;
  flex-direction: column;
  gap: 0.2em;
}

.contact-highlight {
  font-size: 1.15em;
  font-weight: 700;
  color: var(--accent);
}

.contact-person {
  font-size: 1em;
}

.contact-phone a {
  color: var(--red);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1em;
}

/* Phụ lục - Căn trên, không khoảng trắng lớn */
.appendix .body-slot {
  align-items: flex-start;
  justify-content: flex-start;
  padding-top: 0.4em;
}

.appendix .content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7em 2em;
  font-size: clamp(15px, min(1.15vw, 1.9vh), 26px);
  line-height: 1.3;
  align-items: start;
  justify-content: flex-start;
}

.appendix .reveal {
  border-left: 3px solid var(--line);
  padding-left: 0.65em;
}

/* Thanh điều hướng máy tính */
nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav);
  padding: 10px 3vw;
  background: var(--paper);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 100;
}

button {
  font: inherit;
  font-size: clamp(15px, 1.1vw, 24px);
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  padding: 7px 15px;
  min-height: 46px;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 3px;
}

button.secondary {
  background: var(--paper);
  color: var(--accent);
}

button:focus-visible {
  outline: 3px solid var(--red);
  outline-offset: 3px;
}

#position {
  font-size: clamp(15px, 1.1vw, 24px);
  white-space: nowrap;
  margin-left: auto;
  color: var(--ink);
  font-weight: 600;
}

#dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.dot {
  width: 8px;
  height: 8px;
  border: 1px solid var(--accent);
  border-radius: 50%;
}

.dot.done { background: var(--accent); }

.progress {
  position: absolute;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  width: 0;
  transition: width 0.3s ease;
}

/* Mục lục dialog */
dialog {
  width: min(960px, 92vw);
  max-height: 88vh;
  border: 2px solid var(--accent);
  padding: 2.5vh 3vw;
  background: var(--paper);
  color: var(--ink);
  font-size: clamp(18px, 1.35vw, 28px);
}

dialog::backdrop { background: rgba(20, 40, 60, 0.6); }

.toc-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 2vh;
}

dialog h2 { margin: 0; font-family: Georgia, serif; color: var(--accent); }

.toc-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toc-list button {
  text-align: left;
  white-space: normal;
  min-height: 54px;
  background: var(--bg-card);
  color: var(--ink);
  line-height: 1.25;
  border: 1px solid var(--line);
  font-size: 0.88em;
  padding: 8px 12px;
}

.toc-list button:hover {
  background: #dbe7f2;
}

#number-hint {
  font-size: 0.8em;
  color: #53718e;
  margin-top: 10px;
}

/* Responsive: Màn hình trung bình (<=1000px) */
@media (max-width: 1000px) {
  nav {
    flex-wrap: wrap;
    height: 110px;
    gap: 6px;
    padding: 6px 12px;
  }
  :root { --nav: 110px; }
  button {
    font-size: 15px;
    padding: 6px 10px;
    min-height: 42px;
  }
  #dots { display: none; }
}

/* Responsive: Điện thoại (≤760px) - Cuộn tự nhiên bằng chính Document */
@media (max-width: 760px) {
  html, body {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100% !important;
  }
  body {
    font-size: 17px !important;
    line-height: 1.35;
  }
  :root {
    --nav: 54px !important;
  }
  .slide {
    display: none !important;
    width: 100% !important;
    height: auto !important;
    min-height: 100dvh !important;
    padding: 16px 14px calc(var(--nav) + 24px) !important;
    overflow: visible !important;
    justify-content: flex-start !important;
    gap: 16px !important;
  }
  .slide.active {
    display: flex !important;
    flex-direction: column !important;
  }
  .body-slot {
    display: block !important;
    flex: none !important;
    font-size: 17px !important;
    width: 100% !important;
  }
  header {
    border-bottom: 2px solid var(--line);
    padding-bottom: 6px;
    flex-shrink: 0;
  }
  h1 { font-size: 22px !important; }
  h2 { font-size: 19px !important; }
  .content {
    gap: 16px !important;
    width: 100% !important;
  }
  /* Trên điện thoại: hiển thị từng bước đồng bộ như máy tính */
  .reveal:not(.shown) {
    display: none !important;
  }
  .reveal.shown {
    animation: revealSlideUp 0.32s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  }
  .instant .reveal.shown {
    animation: none !important;
  }
  @keyframes revealSlideUp {
    from {
      opacity: 0;
      transform: translateY(12px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .tap-hint {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    padding: 7px 16px;
    background: rgba(23, 77, 131, 0.08);
    border: 1px solid var(--accent);
    border-radius: 20px;
    color: var(--accent);
    font-size: 14px;
    font-weight: 600;
    animation: pulseTap 1.8s ease-in-out infinite;
  }
  .tap-icon {
    font-size: 16px;
    display: inline-block;
    animation: bounceTap 1s ease-in-out infinite alternate;
  }
  @keyframes pulseTap {
    0%, 100% { opacity: 0.85; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.03); }
  }
  @keyframes bounceTap {
    from { transform: translateX(0); }
    to { transform: translateX(4px); }
  }
  .structured .content {
    display: flex;
    flex-direction: column;
    font-size: 17px;
    width: 100% !important;
  }
  .structured .reveal {
    padding: 10px 12px;
    gap: 10px;
    grid-template-columns: 40px 1fr;
  }
  .structured .card-heading {
    flex-direction: column;
    gap: 0.15em;
  }
  .structured .ordinal { font-size: 1.25em; }
  .structured .line-icon { width: 28px; height: 28px; }
  
  .columns, .flow {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .flow-step {
    padding: 12px !important;
    gap: 6px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    text-align: left !important;
  }
  .flow-step .step-number,
  .flow-step .flow-description,
  .flow-step .time-tag {
    text-align: left !important;
    align-self: stretch !important;
    width: 100% !important;
    margin: 0 !important;
  }
  .flow-arrow, .solution-arrow { display: none !important; }
  .solution-panel {
    padding: 10px 12px;
    grid-template-columns: 36px 1fr;
    gap: 10px;
  }
  .big-number {
    padding: 12px !important;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25em;
  }
  .big-number strong { font-size: 40px !important; }
  .big-number > span { max-width: 100% !important; font-size: 16px; }
  
  .comparison {
    padding: 10px 12px;
    gap: 10px;
    grid-template-columns: 1fr;
  }
  .comparison-item strong { font-size: 34px; }
  
  .cover {
    padding-top: 24px;
    padding-bottom: 60px;
  }
  .cover h1 { font-size: 15px; }
  .cover h2 { font-size: 28px; }
  .cover .sentence { font-size: 17px; }
  
  .appendix .content {
    display: flex;
    flex-direction: column;
    font-size: 14px;
    gap: 12px;
  }
  
  /* Thanh nav gọn trên mobile: ‹ Trước | 6/13 · Mục lục | Sau › */
  nav {
    height: var(--nav) !important;
    padding: 5px 10px !important;
    gap: 6px !important;
    justify-content: space-between !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
  }
  nav button#home,
  nav button#prev,
  nav button#next,
  #dots {
    display: none !important;
  }
  nav button#page-prev {
    order: 1 !important;
    font-size: 14px !important;
    padding: 6px 12px !important;
    min-height: 42px !important;
    flex: 0 0 auto !important;
    border-radius: 4px;
  }
  #position {
    order: 2 !important;
    font-size: 13px !important;
    margin: 0 0 0 auto !important;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
  }
  #position::after {
    content: " ·";
    margin-right: 2px;
    font-weight: 400;
    color: var(--line);
  }
  nav button#toc-open {
    order: 3 !important;
    font-size: 13px !important;
    margin: 0 auto 0 0 !important;
    padding: 4px 6px !important;
    min-height: 42px !important;
    background: transparent !important;
    color: var(--accent) !important;
    border: none !important;
    text-decoration: underline;
  }
  nav button#page-next {
    order: 4 !important;
    font-size: 14px !important;
    padding: 6px 12px !important;
    min-height: 42px !important;
    flex: 0 0 auto !important;
    border-radius: 4px;
  }
  
  .progress {
    top: 0 !important;
    bottom: auto !important;
    height: 3px !important;
  }

  .toc-list { grid-template-columns: 1fr; }
  dialog { padding: 14px; }
  
  .lightbox-close {
    top: 10px;
    right: 14px;
    font-size: 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
