/* รู้จักรถไฟ — ภาพหัวรถจักรในแผงขบวน (สไตล์ FlightRadar) + แกลเลอรี "รู้จักรถไฟไทย"
   ใช้ตัวแปรสีจาก app.css (ธีมมืด/สว่าง) */

/* ---------- แถบภาพใต้หัวแผงขบวน ---------- */
.dt-stock {
  flex: none;
  padding: 12px 14px 0;
}

.dt-stock:empty,
.dt-stock-info:empty {
  display: none;
}

.stk-hero {
  position: relative;
  height: clamp(112px, 17vh, 156px);
  margin: 0;
  overflow: hidden;
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 6px 16px rgb(0 0 0 / 14%);
}

.stk-img,
.stk-noimg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 55%;
}

.stk-noimg {
  background: linear-gradient(135deg, var(--card-hover), var(--card));
}

.stk-hit {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 8px 10px 9px;
  color: #fff;
  text-decoration: none;
  background:
    linear-gradient(to top, rgb(3 7 18 / 82%) 0%, rgb(3 7 18 / 38%) 42%, transparent 64%),
    linear-gradient(to bottom, rgb(3 7 18 / 42%), transparent 34%);
  border-radius: inherit;
  transition: background-color 0.15s;
}

.stk-hit:hover {
  background-color: rgb(255 255 255 / 6%);
}

.stk-hit:focus-visible {
  outline-offset: -3px;
}

.stk-chip {
  display: inline-flex;
  flex: none;
  gap: 6px;
  align-items: center;
  align-self: flex-start;
  height: 24px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border-radius: 999px;
}

.stk-chip::before {
  width: 7px;
  height: 7px;
  content: "";
  background: currentcolor;
  border-radius: 50%;
}

.stk-hit .stk-chip {
  color: #fff;
  background: rgb(3 7 18 / 62%);
  border: 1px solid rgb(255 255 255 / 22%);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.stk-hit .stk-chip.conf-high::before {
  background: #4ade80;
}

.stk-hit .stk-chip.conf-medium::before {
  background: #38bdf8;
}

.stk-hit .stk-chip.conf-low::before {
  background: #fbbf24;
}

.stk-cap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  text-shadow: 0 1px 3px rgb(0 0 0 / 60%);
}

.stk-cap small {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  opacity: 0.88;
}

.stk-cap b {
  display: flex;
  gap: 7px;
  align-items: center;
  min-width: 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
}

.stk-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ชิปรหัสหดก่อนชื่อ (flex-shrink สูงกว่ามาก) จนเหลือ ~3.5em แล้วชื่อค่อยหด */
.stk-cap b i {
  flex: 0 100 auto;
  min-width: 3.5em;
  max-width: 48%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.stk-cap b i,
.stk-codes {
  padding: 1px 7px;
  font: 600 12px/1.5 var(--mono);
  font-style: normal;
  background: rgb(255 255 255 / 18%);
  border-radius: 6px;
  text-shadow: none;
}

.stk-cap em {
  overflow: hidden;
  font-size: 12.5px;
  font-style: normal;
  line-height: 1.35;
  white-space: nowrap;
  text-overflow: ellipsis;
  opacity: 0.92;
}

/* เครดิตภาพ: มุมขวาบนของภาพเสมอ */
.stk-hero figcaption {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  max-width: 52%;
}

.stk-credit {
  display: block;
  overflow: hidden;
  padding: 2px 7px;
  font-size: 10.5px;
  line-height: 1.5;
  color: #fff;
  white-space: nowrap;
  text-overflow: ellipsis;
  background: rgb(3 7 18 / 68%);
  border-radius: 6px;
}

.stk-credit a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgb(255 255 255 / 45%);
  text-underline-offset: 2px;
}

/* ปุ่มขยายแถบภาพ ใช้เฉพาะมือถือ */
.stk-toggle {
  display: none;
}

/* ---------- การ์ดข้อมูลในแผงขบวน ---------- */
.stk-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stk-info-head {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
}

.stk-info-name {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
}

.stk-info .stk-chip.conf-high,
.stk-body .stk-chip.conf-high {
  color: var(--ok-t);
  background: color-mix(in srgb, var(--ok) 15%, transparent);
}

.stk-info .stk-chip.conf-medium {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.stk-info .stk-chip.conf-low {
  color: var(--warn-t);
  background: color-mix(in srgb, var(--warn) 15%, transparent);
}

.stk-specs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  overflow: hidden;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.stk-specs > div {
  min-width: 0;
  padding: 7px 10px 8px;
  background: var(--panel-solid);
}

.stk-specs > div:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.stk-specs dt {
  font-size: 11.5px;
  color: var(--muted);
}

.stk-specs dd {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.stk-fact {
  margin: 0;
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1.6;
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  border-left: 3px solid var(--accent);
  border-radius: 4px 12px 12px 4px;
}

.stk-fact b {
  color: var(--accent);
}

.stk-note a,
.stk-ref a {
  color: var(--accent);
}

.stk-note-main {
  display: block;
  color: var(--text);
}

.stk-alt {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.stk-alt a {
  padding: 3px 9px;
  font: 600 12px/1.5 var(--mono);
  color: var(--text);
  text-decoration: none;
  background: var(--card-hover);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stk-alt a:hover {
  border-color: var(--accent);
}

.stk-note {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

.stk-more {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: background 0.15s, transform 0.1s;
}

.stk-more:hover {
  background: var(--card-hover);
}

.stk-more:active {
  transform: scale(0.98);
}

/* ---------- ทางเข้าแกลเลอรีในแท็บโปรด ---------- */
.stk-entry {
  --i: 22px;

  display: flex;
  gap: 12px;
  align-items: center;
  margin: 12px 4px 8px;
  padding: 12px 14px;
  color: var(--text);
  text-decoration: none;
  background: linear-gradient(135deg, color-mix(in srgb, #0f766e 22%, var(--card)), var(--card));
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: background 0.15s, transform 0.1s;
}

.stk-entry:hover {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
}

.stk-entry:active {
  transform: scale(0.98);
}

.stk-entry-ico {
  display: grid;
  flex: none;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #fff;
  background: linear-gradient(150deg, #14b8a6, #0f766e);
  border-radius: 12px;
}

.stk-entry-txt {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.stk-entry-txt b {
  font-size: 15px;
}

.stk-entry-txt small {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
}

.stk-entry-go {
  flex: none;
  font-size: 18px;
  color: var(--accent);
}

/* ---------- แกลเลอรี "รู้จักรถไฟไทย" ---------- */
.stk-head {
  color: #fff;
  background: linear-gradient(150deg, #0f766e, #0b1f3a 78%);
}

.stk-head a.dt-btn {
  color: inherit;
}

.stk-title {
  margin: 12px 0 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.3;
}

.stk-sub {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.5;
  opacity: 0.94;
}

.stk-sec .sec-title {
  margin-top: 4px;
}

.stk-sec .count {
  color: var(--muted);
  background: var(--card-hover);
}

.stk-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stk-tile {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  text-decoration: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: transform 0.15s var(--ease), box-shadow 0.15s, border-color 0.15s;
}

.stk-tile:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.stk-tile:active {
  transform: scale(0.98);
}

.stk-tile-img {
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--card-hover);
}

.stk-tile-img img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.stk-tile-txt {
  display: flex;
  flex-direction: column;
  padding: 7px 10px 9px;
}

.stk-tile-txt b {
  display: -webkit-box;
  overflow: hidden;
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.stk-tile-txt em {
  margin-top: 2px;
  font-size: 12px;
  font-style: normal;
  color: var(--muted);
}

/* หน้ารายละเอียดรถแต่ละแบบ (ลูกของ flex column ห้ามหด) */
.stk-body > * {
  flex: none;
}

.stk-hero.big {
  height: auto;
  aspect-ratio: 16 / 9;
}

.stk-hero.big .stk-codes {
  position: absolute;
  top: 10px;
  left: 10px;
  color: #fff;
  background: rgb(3 7 18 / 62%);
}

.stk-hero.big figcaption {
  top: auto;
  bottom: 8px;
  max-width: calc(100% - 16px);
}

.stk-hero.big .stk-credit {
  white-space: normal;
}

.stk-live h3 {
  margin: 0 0 2px;
  font-size: 14.5px;
  font-weight: 700;
}

.stk-live-hint {
  margin: 0 0 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.stk-live ul {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stk-run {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
  padding: 6px 8px;
  color: var(--text);
  text-decoration: none;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.stk-run:hover {
  border-color: var(--accent);
}

.stk-run b {
  flex: none;
  min-width: 38px;
  padding: 1px 6px;
  font: 600 13px/1.6 var(--mono);
  color: var(--accent-ink);
  text-align: center;
  background: var(--accent);
  border-radius: 7px;
}

.stk-run small {
  overflow: hidden;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.stk-en {
  margin: -4px 2px 0;
  font-size: 12.5px;
  color: var(--muted);
}

.stk-duty h3,
.stk-facts h3 {
  margin: 0 0 6px;
  font-size: 14.5px;
  font-weight: 700;
}

.stk-duty p {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
}

.stk-facts {
  background: color-mix(in srgb, var(--accent) 7%, var(--card));
}

.stk-facts h3 {
  color: var(--accent);
}

.stk-facts ul {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stk-facts li {
  position: relative;
  padding-left: 18px;
  font-size: 14px;
  line-height: 1.6;
}

.stk-facts li::before {
  position: absolute;
  top: 0.62em;
  left: 3px;
  width: 7px;
  height: 7px;
  content: "";
  background: var(--accent);
  border-radius: 50%;
}

.stk-ref {
  margin: 0 2px;
  font-size: 12.5px;
  color: var(--muted);
}

@media (min-width: 900px) and (max-height: 780px) {
  .stk-hero {
    height: 112px;
  }
}

@media (max-width: 899px) {
  .dt-stock {
    padding: 10px 12px 0;
  }

  .stk-hero {
    height: 170px;
  }

  .stk-cap b {
    font-size: 17px;
  }

  .stk-toggle {
    position: absolute;
    right: 8px;
    bottom: 8px;
    z-index: 3;
    display: inline-flex;
    gap: 4px;
    align-items: center;
    height: 34px;
    padding: 0 12px;
    font-size: 12.5px;
    font-weight: 600;
    color: #fff;
    background: rgb(3 7 18 / 62%);
    border: 1px solid rgb(255 255 255 / 25%);
    border-radius: 999px;
  }

  .stk-toggle::after {
    font-size: 10px;
    content: "▲";
  }

  .stk-hero.is-open .stk-hit {
    padding-right: 84px;
  }

  /* แถวย่อ: ภาพย่อ + ชื่อ + เครดิต + ปุ่มดูเพิ่ม (ประหยัดที่ให้ไทม์ไลน์) */
  .stk-hero:not(.is-open, .big) {
    display: grid;
    grid-template-rows: auto auto;
    grid-template-columns: 88px minmax(0, 1fr) auto;
    column-gap: 10px;
    align-items: center;
    height: auto;
    padding: 6px 8px 6px 6px;
    background: var(--card);
    border: 1px solid var(--line);
    box-shadow: none;
  }

  .stk-hero:not(.is-open, .big) .stk-img,
  .stk-hero:not(.is-open, .big) .stk-noimg {
    grid-row: 1 / 3;
    grid-column: 1;
    width: 88px;
    height: 50px;
    border-radius: 9px;
  }

  .stk-hero:not(.is-open, .big) .stk-hit {
    position: static;
    grid-row: 1;
    grid-column: 2;
    gap: 1px;
    justify-content: flex-start;
    padding: 0;
    color: var(--text);
    background: none;
  }

  .stk-hero:not(.is-open, .big) .stk-chip {
    height: 18px;
    padding: 0;
    font-size: 11.5px;
    background: none;
    border: 0;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .stk-hero:not(.is-open, .big) .conf-high {
    color: var(--ok-t);
  }

  .stk-hero:not(.is-open, .big) .conf-medium {
    color: var(--accent);
  }

  .stk-hero:not(.is-open, .big) .conf-low {
    color: var(--warn-t);
  }

  .stk-hero:not(.is-open, .big) .stk-cap {
    text-shadow: none;
  }

  .stk-hero:not(.is-open, .big) .stk-cap small,
  .stk-hero:not(.is-open, .big) .stk-cap em {
    display: none;
  }

  .stk-hero:not(.is-open, .big) .stk-cap b {
    font-size: 15px;
  }

  .stk-hero:not(.is-open, .big) .stk-cap b i {
    color: var(--text);
    background: var(--card-hover);
  }

  .stk-hero:not(.is-open, .big) figcaption {
    position: static;
    grid-row: 2;
    grid-column: 2;
    max-width: none;
    min-width: 0;
  }

  .stk-hero:not(.is-open, .big) .stk-credit {
    padding: 0;
    font-size: 10.5px;
    color: var(--muted);
    background: none;
  }

  .stk-hero:not(.is-open, .big) .stk-toggle {
    position: static;
    grid-row: 1 / 3;
    grid-column: 3;
    color: var(--accent);
    background: var(--card-hover);
    border-color: var(--line);
  }

  .stk-hero:not(.is-open, .big) .stk-toggle::after {
    content: "▼";
  }

  .stk-head .dt-grip {
    --grip: #fff;
  }

  .stk-title {
    margin-top: 6px;
    font-size: 21px;
  }
}

@media (min-width: 560px) and (max-width: 899px) {
  .stk-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* มือถือแนวนอน: แผงแคบ (แผ่นด้านซ้าย) → แกลเลอรี 2 คอลัมน์ ภาพหัวรถจักรเตี้ยลง */
@media (max-width: 899px) and (max-height: 500px) {
  .stk-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stk-hero {
    height: 150px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stk-tile,
  .stk-more {
    transition: none;
  }

  .stk-tile:hover {
    transform: none;
  }
}
