/* ========== Aslan Finance News — Design Tokens ========== */
:root {
  /* Colors */
  --ink: #0A0F1C;
  --ink-2: #1A2238;
  --navy: #0B1E3F;
  --navy-2: #12305F;
  --paper: #FAFAF7;
  --paper-2: #F2F0EA;
  --line: #E5E2D8;
  --line-2: #D4D0C3;
  --muted: #6B6B6B;
  --muted-2: #8E8E8E;
  --gold: #B88A3E;
  --gold-2: #9C7130;
  --up: #0B8A4C;
  --down: #C8321F;
  --chip-bg: #EEEBE2;

  /* Type */
  --serif: 'IBM Plex Serif', 'Noto Serif Thai', Georgia, serif;
  --sans: 'Inter', 'Sarabun', -apple-system, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;

  /* Spacing */
  --pad: 24px;
  --maxw: 1320px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { overflow-x: clip; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.55;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--navy-2); }
img { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--pad); }

/* ========== TOP UTILITY BAR ========== */
.util-bar {
  background: var(--ink);
  color: #D9D6CC;
  font-size: 12px;
  letter-spacing: 0.02em;
}
.util-bar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 32px;
}
.util-left { display: flex; gap: 18px; color: #C3BFB3; }
.util-left .date { color: #FAFAF7; font-weight: 500; }
.util-right { display: flex; gap: 16px; align-items: center; }
.util-right a { color: #C3BFB3; transition: color 0.15s; }
.util-right a:hover { color: #FAFAF7; }
.lang-toggle {
  display: inline-flex; border: 1px solid #2A2F3D; border-radius: 2px;
  overflow: hidden;
}
.lang-toggle button {
  padding: 3px 8px; font-size: 11px; color: #8E8B82;
}
.lang-toggle button.active { background: #FAFAF7; color: var(--ink); }

/* ========== HEADER / MASTHEAD ========== */
.masthead {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.masthead-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 22px 0 18px;
  gap: 24px;
}
.mast-left, .mast-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.mast-right { justify-content: flex-end; }
.logo-wrap {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.logo {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 42px;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1;
  font-style: italic;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.logo-img {
  height: 1em;
  width: auto;
  display: block;
  object-fit: contain;
}
.logo .dot { color: var(--gold); }
.logo-tag {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--muted);
  text-transform: uppercase;
}

.search-btn, .icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  font-size: 12px; color: var(--ink-2);
  background: transparent;
  transition: border-color 0.15s;
}
.search-btn:hover, .icon-btn:hover { border-color: var(--navy); }
.subscribe-btn {
  background: var(--navy); color: #FAFAF7;
  padding: 8px 16px; border-radius: 2px;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.subscribe-btn:hover { background: var(--navy-2); color: #FAFAF7; }

/* Nav */
.mainnav {
  border-top: 1px solid var(--line);
  border-bottom: 2px solid var(--ink);
  position: relative;
}
.mainnav .container {
  display: flex;
  justify-content: center;
  gap: 4px;
  overflow: visible;
}
.mainnav a {
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-2);
  white-space: nowrap;
  position: relative;
  transition: color 0.15s;
}
.mainnav a:hover { color: var(--navy); }
.mainnav a.active { color: var(--navy); font-weight: 600; }
.mainnav a.active::after {
  content: '';
  position: absolute;
  left: 18px; right: 18px; bottom: -2px;
  height: 2px; background: var(--gold);
}

/* Nav dropdown */
.nav-dropdown-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
}
.nav-dropdown-wrap > a {
  display: flex;
  align-items: center;
  gap: 5px;
}
.nav-caret {
  flex-shrink: 0;
  opacity: 0.5;
  transition: transform 0.2s ease, opacity 0.2s;
}
.nav-dropdown-wrap:hover .nav-caret,
.nav-dropdown-wrap:focus-within .nav-caret {
  transform: rotate(180deg);
  opacity: 1;
}
.nav-dropdown {
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  position: absolute;
  top: 100%;
  left: 50%;
  translate: -50% 0;
  min-width: 180px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-top: 2px solid var(--gold);
  border-radius: 0 0 6px 6px;
  box-shadow: 0 8px 24px rgba(10,15,28,0.10), 0 2px 6px rgba(10,15,28,0.06);
  z-index: 200;
  padding: 10px 0 8px;
}
/* small notch under the trigger */
.nav-dropdown::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  translate: -50% 0;
  width: 10px;
  height: 6px;
  background: var(--gold);
  clip-path: polygon(0% 100%, 50% 0%, 100% 100%);
}
.nav-dropdown-wrap:hover .nav-dropdown,
.nav-dropdown-wrap:focus-within .nav-dropdown {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.nav-dropdown a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
  position: static;
  transition: background 0.12s, color 0.12s, padding-left 0.12s;
}
.nav-dropdown a:first-child {
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
  padding-bottom: 11px;
  font-weight: 600;
  color: var(--navy);
}
.nav-dropdown a:hover {
  background: var(--paper-2);
  color: var(--navy);
}
/* Section header inside dropdown — non-clickable group label */
.nav-dropdown-header {
  padding: 10px 20px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.nav-dropdown-header:first-child { border-top: none; margin-top: 0; }
/* Mobile drawer section header */
.mobile-nav-header {
  padding: 14px 20px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  border-top: 1px solid var(--line);
  margin-top: 8px;
}
.nav-dropdown a.active {
  color: var(--gold);
  font-weight: 600;
}
.nav-dropdown a.active::after { display: none; }

/* ─── Mega-menu (multi-column dropdown for Markets) ─────────────── */
.nav-dropdown-wrap.has-mega { position: static; }
.nav-mega {
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  position: absolute;
  top: 100%;
  left: 50%;
  translate: -50% 0;
  width: min(780px, calc(100vw - 32px));
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-top: 2px solid var(--gold);
  border-radius: 0 0 8px 8px;
  box-shadow: 0 12px 32px rgba(10,15,28,0.12), 0 2px 8px rgba(10,15,28,0.06);
  z-index: 200;
  padding: 12px 16px 14px;
}
.nav-dropdown-wrap.has-mega:hover .nav-mega,
.nav-dropdown-wrap.has-mega:focus-within .nav-mega {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.nav-mega-lead {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.mainnav .nav-mega-lead-link {
  font-size: 12px;
  font-weight: 600;
  color: var(--navy);
  padding: 2px 0;
  transition: color 0.12s;
}
.mainnav .nav-mega-lead-link:hover { color: var(--gold); }
.nav-mega-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px 12px;
}
.nav-mega-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.nav-mega-title {
  display: block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 4px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--line);
}
.mainnav .nav-mega-title-link {
  padding: 0 0 4px 0;
  margin-bottom: 2px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: normal;
  transition: color 0.12s;
}
.mainnav .nav-mega-title-link:hover { color: var(--gold); }
.mainnav .nav-mega-link {
  display: block;
  padding: 3px 0;
  margin: 0;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
  line-height: 1.3;
  letter-spacing: normal;
  transition: color 0.12s;
  white-space: normal;
}
.mainnav .nav-mega-link:hover { color: var(--gold); }
.mainnav .nav-mega-link.depth-1 {
  padding: 5px 0 3px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink);
}
.mainnav .nav-mega-link.depth-2 {
  padding: 3px 0 3px 14px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.mainnav .nav-mega-link.depth-2:hover { color: var(--gold); }
/* Narrower viewport — collapse to 3 columns */
@media (max-width: 1100px) {
  .nav-mega-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .nav-mega { width: min(560px, calc(100vw - 32px)); }
}

/* Mobile nav group */
.mobile-nav-group {
  display: flex;
  flex-direction: column;
}
.mobile-nav-label {
  padding: 14px 24px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
}
.mobile-nav-sub {
  padding: 10px 24px 10px 36px !important;
  font-size: 13px;
}

/* ========== TICKER ========== */
.ticker {
  background: var(--ink);
  color: #FAFAF7;
  overflow: clip;
  width: 100%;
  border-bottom: 1px solid #1f2433;
}
.ticker-inner {
  display: flex;
  animation: tickerScroll 90s linear infinite;
  width: max-content;
}
.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 22px;
  font-size: 12.5px;
  font-family: var(--mono);
  border-right: 1px solid #1f2433;
  white-space: nowrap;
}
.ticker-item .sym { color: #C3BFB3; font-weight: 500; }
.ticker-item .price { color: #FAFAF7; font-weight: 500; }
.ticker-item .chg.up { color: #3ED598; }
.ticker-item .chg.down { color: #FF6A5A; }
.ticker-item .arr { font-size: 10px; }
@keyframes tickerScroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* ========== HEADLINES / CARDS ========== */
.kicker {
  font-size: 11px;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.kicker.red { color: var(--down); }
.kicker.navy { color: var(--navy); }
.byline {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
  row-gap: 2px;
}
.byline > span { white-space: nowrap; }
.byline .dot { color: var(--line-2); }
.hed {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0 0 10px;
  text-wrap: balance;
}
.dek {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 10px;
  text-wrap: pretty;
}

/* Section heading */
.sec-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-top: 2px solid var(--ink);
  padding-top: 10px;
  margin: 28px 0 16px;
}
.sec-head h2 {
  font-family: var(--serif);
  font-size: 22px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.sec-head .more {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.sec-head .more:hover { color: var(--navy); }

/* Chip/badges */
.chip {
  display: inline-block;
  padding: 3px 8px;
  background: var(--chip-bg);
  color: var(--ink-2);
  font-size: 11px;
  letter-spacing: 0.04em;
  border-radius: 2px;
}

/* Market pill (up/down) */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
}
.pill.up { color: var(--up); }
.pill.down { color: var(--down); }
/* pill on <td> must stay as table-cell, not inline-flex */
td.pill { display: table-cell; }

/* Footer */
.footer {
  background: var(--ink);
  color: #C3BFB3;
  padding: 48px 0 24px;
  margin-top: 60px;
}
.footer a { color: #C3BFB3; }
.footer a:hover { color: #FAFAF7; }
.footer-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr 1fr;
  gap: 32px;
}
.footer h3,
.footer h4 {
  font-family: var(--sans);
  font-size: 11px; color: #FAFAF7;
  letter-spacing: 0.16em; text-transform: uppercase;
  margin: 0 0 14px;
}
.footer ul { list-style: none; margin: 0; padding: 0; }
.footer li { margin-bottom: 8px; font-size: 13px; }
.footer .logo-footer {
  font-family: var(--serif);
  font-size: 28px;
  font-style: italic;
  color: #FAFAF7;
  margin-bottom: 12px;
}
.footer .legal {
  border-top: 1px solid #1f2433;
  margin-top: 32px;
  padding-top: 20px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #8E8B82;
}

/* Utility */
.divider { border-bottom: 1px solid var(--line); }
.divider-thick { border-bottom: 2px solid var(--ink); }
.stack > * + * { margin-top: var(--gap, 12px); }
.row { display: flex; gap: 12px; }
.grow { flex: 1; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* Scrollbar polish */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
::-webkit-scrollbar-track { background: var(--paper-2); }

/* Lang-aware nav labels */
.lang-en .nav-th { display: none; }
.lang-th .nav-en { display: none; }

/* ========== HAMBURGER & MOBILE DRAWER ========== */
/* Mobile search icon in mast-left */
.mast-search-mobile {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 6px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  color: var(--ink);
}
.mast-search-mobile:hover { border-color: var(--navy); }

.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
}
.hamburger-btn span {
  display: block;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}

.mobile-drawer {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 280px;
  height: 100%;
  background: var(--paper);
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  box-shadow: 4px 0 24px rgba(0,0,0,0.12);
}
.mobile-drawer.open { transform: translateX(0); }
.mobile-drawer-inner {
  padding: 60px 0 24px;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.mobile-drawer-inner a {
  padding: 14px 24px;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-2);
  border-bottom: 1px solid var(--line);
}
.mobile-drawer-inner a.active { color: var(--navy); font-weight: 600; }

.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
}
.mobile-overlay.open { display: block; }

/* Across the Desks */
.desk-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 32px;
}
@media (max-width: 768px) {
  .desk-grid { grid-template-columns: 1fr; gap: 24px; }
}

/* Responsive */
@media (max-width: 900px) {
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .util-left { gap: 10px; }
  .util-left .date { display: none; }
}

@media (max-width: 768px) {
  /* Util bar */
  .util-bar .container { height: auto; padding: 6px var(--pad); flex-wrap: wrap; gap: 4px; }
  .util-left { font-size: 11px; }
  .util-right a:not(.lang-toggle) { display: none; }

  /* Masthead */
  .masthead-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 10px 0;
    gap: 8px;
  }
  .mast-left { display: block; visibility: hidden; width: 36px; flex-shrink: 0; }
  .mast-search-mobile { display: flex; }
  .mast-right { display: flex; gap: 6px; justify-content: flex-end; padding-right: 16px; }
  .logo-wrap { align-items: center; }
  .logo { font-size: 26px; }
  .logo-tag { display: none; }
  .icon-btn { display: none; }
  .search-btn { display: none; }
  .subscribe-btn { display: none; }

  /* Show hamburger, hide desktop nav */
  .hamburger-btn { display: flex; }
  .mainnav { display: none; }

  /* Show mobile drawer elements */
  .mobile-drawer { display: block; }
  .mobile-overlay { display: none; } /* shown via JS .open class */

  /* Hero 3-col → 1 col */
  .container > div[style*="grid-template-columns:1.6fr"],
  main > div[style*="grid-template-columns:1.6fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Hide right sidebar (Market widget) inside hero on mobile */
  .container > div[style*="grid-template-columns:1.6fr"] > div:last-child,
  main > div[style*="grid-template-columns:1.6fr"] > div:last-child {
    display: none;
  }

  /* Any 3-col grid → 1 col */
  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns: repeat(3, 1fr)"],
  [style*="grid-template-columns:1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Any 2-col grid → 1 col */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Article hero (news/category) 2-col → 1 col */
  [style*="grid-template-columns:1fr 1fr;gap:40px"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Latest feed item (120px + 1fr) → keep as-is, just shrink thumb */
  [style*="grid-template-columns:120px 1fr"] {
    grid-template-columns: 80px 1fr !important;
    gap: 10px !important;
  }

  /* Footer */
  .footer-grid { grid-template-columns: 1fr 1fr; gap: 24px; }
  .footer { margin-top: 32px; }
}

/* ========== MARKETS PAGE ========== */

/* Desktop: info cell hidden, pct arrow hidden, badge is plain text */
.mkt-info-cell { display: none; }
.mkt-pct-arrow { display: none; }
.tab-short { display: none; }
.tab-full { display: inline; }
.mkt-badge {
  font-weight: 600;
  color: var(--ink);
  font-family: var(--sans);
}
/* Fix alignment: name-cell is nth-child(3) but mkt-info-cell(2) is hidden,
   so nth-child(2) rule misses it — override explicitly */
.name-cell { text-align: left !important; font-family: var(--sans) !important; }
.mkt-mobile-hero { display: none; }

/* ── Markets related-articles section (defect #24) ── */
.mkt-related {
  margin-top: 56px;
  padding-top: 28px;
  border-top: 2px solid var(--ink);
}
.mkt-related-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.mkt-related-head h2 {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.mkt-related-all {
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--navy);
  text-transform: uppercase;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.mkt-related-all:hover { text-decoration: underline; }
.mkt-related-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}
.mkt-related-card {
  border: 1px solid var(--line);
  background: #fff;
}
.mkt-related-card a { display: block; color: inherit; text-decoration: none; }
.mkt-related-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
}
.mkt-related-body { padding: 14px 16px 16px; }
.mkt-related-body .kicker {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--gold);
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.mkt-related-body h3 {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  margin: 0 0 10px;
  color: var(--ink);
}
.mkt-related-body .byline {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.mkt-related-body .dot { color: var(--line-2); }
@media (max-width: 900px) {
  .mkt-related { margin-top: 32px; padding: 24px 16px 0; }
  .mkt-related-grid { grid-template-columns: 1fr; gap: 0; }
  .mkt-related-head h2 { font-size: 18px; }
  /* Mobile: switch card from img-on-top stack → text-left + thumb-right (mirrors .news-card pattern) */
  .mkt-related-card { border: none; background: transparent; }
  .mkt-related-card a {
    display: grid;
    grid-template-columns: 1fr 140px;
    gap: 14px;
    align-items: start;
    padding: 16px 0;
    border-bottom: 1px solid var(--line);
  }
  .mkt-related-card img {
    order: 2;
    width: 140px;
    height: 90px;
    aspect-ratio: auto;
    object-fit: cover;
  }
  .mkt-related-body {
    order: 1;
    padding: 0;
    min-width: 0;
  }
  .mkt-related-body h3 { font-size: 15px; line-height: 1.3; margin: 4px 0 6px; }
  .mkt-related-body .kicker { font-size: 10px; margin-bottom: 4px; }
  .mkt-related-body .byline { font-size: 11px; margin-top: 6px; }
}
.mkt-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--ink);
}
.mkt-clock-wrap { text-align: right; }
.mkt-clock-num { font-size: 24px; margin-top: 4px; }

.mkt-summ-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  border: 1px solid var(--line);
}
.mkt-summ-card {
  padding: 20px 22px;
  background: #fff;
  border-left: 1px solid var(--line);
}
.mkt-summ-card:first-child { border-left: none; }
.mkt-summ-price { font-size: 26px; margin: 8px 0 4px; font-weight: 500; }

.mkt-main-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 40px;
}

.mkt-hero-title {
  font-family: var(--serif);
  font-size: 48px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.mkt-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--ink);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  padding-right: 24px;
}
.mkt-tabs::-webkit-scrollbar { display: none; }

.mkt-table-wrap { overflow-x: auto; }

.mkt-heat-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}
.mkt-heat-cell {
  padding: 16px 12px;
  min-height: 80px;
}

.mkt-cal-wrap { overflow-x: auto; }

/* ─── Economic Calendar table (shared: /markets + home) ───────── */
.mkt-table { width: 100%; border-collapse: collapse; font-family: var(--sans); }
.mkt-table thead th {
  font-size: 10px; letter-spacing: 0.14em; color: var(--muted);
  text-transform: uppercase; text-align: right; padding: 10px 12px;
  border-bottom: 2px solid var(--ink); font-weight: 600;
}
.mkt-table thead th:first-child,
.mkt-table thead th:nth-child(2),
.mkt-table thead th:nth-child(3) { text-align: left; }
.mkt-table td {
  padding: 12px; border-bottom: 1px solid var(--line);
  text-align: right; font-size: 13px; font-family: var(--mono);
}
.mkt-table td:nth-child(1),
.mkt-table td:nth-child(2),
.mkt-table td:nth-child(3) { text-align: left; font-family: var(--sans); }
/* Country column: flag + name reads left — keep th aligned with td */
.mkt-table thead th.mkt-col-country,
.mkt-table td.mkt-col-country { text-align: left; }
.mkt-table tbody tr:last-child td { border-bottom: none; }
.mkt-table tbody tr { transition: background 0.12s; }
.mkt-table tbody tr:hover { background: var(--paper-2); }

/* Home-page calendar card wrapper — fixed height (~10 rows), scroll for the rest */
.home-econcal {
  border: 1px solid var(--line);
  background: #fff;
  padding: 0 20px;
  max-height: 480px;
  overflow-y: auto;
}
.home-econcal .mkt-table thead th {
  border-bottom-width: 1px;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

@media (max-width: 1120px) {
  .mkt-main-grid { grid-template-columns: 1fr; }

  .mkt-summ-grid { grid-template-columns: repeat(3, 1fr); }
  .mkt-summ-card:nth-child(1) { border-left: none; }
  .mkt-summ-card:nth-child(4) { border-left: none; }

  .mkt-heat-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Name subtitle inside Symbol cell — hidden on desktop */
.mkt-sym-name { display: none; }

/* Desktop: hide subtitle (Name shown as separate column) */
@media (min-width: 769px) {
  .mkt-sym-name { display: none !important; }
}

@media (max-width: 768px) {
  /* ── Hero ── */
  .mkt-desktop-hero { display: none; }
  .mkt-mobile-hero {
    display: block;
    background: var(--paper);
    border-bottom: none;
  }
  .mkt-mobile-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: var(--muted);
    text-transform: uppercase;
  }
  .mkt-icon-btn {
    width: 36px; height: 36px;
    border: 1px solid var(--line);
    background: #fff;
    display: flex; align-items: center; justify-content: center;
    border-radius: 2px;
    color: var(--ink);
  }
  .mkt-mobile-title {
    font-family: var(--serif);
    font-style: italic;
    font-size: 40px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 6px;
    color: var(--ink);
  }
  .mkt-mobile-desc {
    font-size: 13px;
    line-height: 1.55;
    color: var(--ink-2);
    margin: 4px 0 10px;
  }
  .mkt-mobile-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.04em;
  }

  /* ── Summary cards ── */
  .mkt-summ-outer { margin-top: 0 !important; padding: 8px 16px 0; }
  .mkt-summ-grid {
    grid-template-columns: repeat(2, 1fr);
    border: 1px solid var(--line);
    gap: 0;
    background: var(--line);
  }
  .mkt-summ-card {
    padding: 14px 12px;
    border-left: none !important;
    border-top: none;
    background: #fff;
    overflow: hidden;
  }
  /* card 5 ถ้าเป็น odd จำนวน ให้ span เต็ม row */
  .mkt-summ-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    border-top: 1px solid var(--line);
  }
  .mkt-summ-label { font-size: 11px; letter-spacing: 0.08em; }
  .mkt-summ-price { font-size: 22px; margin: 6px 0 4px; }
  .mkt-summ-spark { display: none; }

  /* ── Tabs ── */
  .tab-full { display: none; }
  .tab-short { display: inline; }
  .tab-btn { padding: 10px 12px; font-size: 10px; }

  /* ── Table: full mobile reflow ── */
  .mkt-table-wrap { overflow: visible; padding: 0; margin: 0 16px; }
  .mkt-table,
  .mkt-table tbody { display: block; width: 100%; max-width: 100%; border-collapse: separate !important; }
  .mkt-thead-desktop { display: none; }

  /* Grid-based row: badge | info | price | pct */
  .mkt-row {
    display: grid;
    grid-template-columns: 40px 1fr auto auto;
    align-items: center;
    column-gap: 8px;
    padding: 7px 0;
    border-bottom: 1px solid var(--line);
    background: none;
    width: 100%;
    box-sizing: border-box;
  }
  .mkt-row:hover { background: var(--paper-2); }
  .mkt-row td { display: block; border: none !important; padding: 0 !important; }

  /* Badge */
  .mkt-sym-cell { grid-column: 1; }
  .mkt-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--paper-2);
    border: 1px solid var(--line);
    font-size: 9px;
    font-weight: 700;
    font-family: var(--mono);
    letter-spacing: 0.02em;
    color: var(--ink-2);
    text-align: center;
    border-radius: 2px;
  }

  /* Info block */
  .mkt-info-cell {
    display: block;
    grid-column: 2;
    min-width: 0;
    overflow: hidden;
  }
  .mkt-info-sym {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
    font-family: var(--sans);
    line-height: 1.2;
  }
  .mkt-info-name {
    font-size: 10px;
    color: var(--muted);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Price */
  .mkt-price-cell {
    grid-column: 3;
    font-size: 12px;
    font-family: var(--mono);
    color: var(--ink);
    white-space: nowrap;
    text-align: right;
    padding: 0 !important;
  }

  /* %Chg */
  .mkt-pct-cell {
    grid-column: 4;
    font-size: 10px;
    font-family: var(--mono);
    font-weight: 600;
    white-space: nowrap;
    text-align: right;
    min-width: 52px;
    padding: 2px 4px !important;
  }
  .mkt-pct-arrow { display: inline; font-size: 8px; margin-right: 1px; }

  /* Hide columns not needed on mobile */
  .mkt-col-name { display: none !important; }
  .mkt-col-chg  { display: none !important; }
  .mkt-col-trend { display: none !important; }

  /* Economic Calendar */
  .mkt-col-country  { display: none !important; }
  .mkt-col-forecast { display: none !important; }

  /* Heatmap */
  .mkt-heat-grid { grid-template-columns: repeat(3, 1fr); }
  .mkt-heat-cell { padding: 12px 8px; min-height: 64px; overflow: hidden; }

  .mkt-main-grid { gap: 0; margin-top: 0; }
  .mkt-main-grid > * { min-width: 0; overflow: hidden; }
  .mkt-main-container { padding: 0; margin-top: 0 !important; }
  .mkt-table-wrap { margin: 0; padding: 0 16px; overflow: visible; }
  .sec-head { margin: 28px 16px 12px; }
  .mkt-heat-grid { margin: 0 16px; }
  .mkt-cal-wrap { padding: 0 16px; overflow-x: auto; }
  .mkt-tabs { padding: 0 16px; margin-top: 0; }
  .mkt-sidebar { padding: 0 16px; margin-bottom: 40px; min-width: 0; }
}

@media (max-width: 480px) {
  .mkt-summ-grid { grid-template-columns: repeat(2, 1fr); font-size: 13px; }
  .mkt-summ-price { font-size: 18px; }
  .mkt-heat-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ========== Sub-tab cascade (shared: /markets + home) ========== */
.subtab-cascade {
  margin: 4px 0 0;
}

/* ========== Sub-tab chip strips (shared: /markets + home) ========== */
.subtab-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.subtab-strip[hidden] { display: none; }
.subtab-strip:last-of-type { border-bottom: none; padding-bottom: 12px; }
.subtab-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--paper-2);
  border: 1px solid var(--line);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  font-family: inherit;
}
.subtab-chip:hover {
  color: var(--ink);
  border-color: var(--ink);
}
.subtab-chip.active {
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
  font-weight: 600;
}
@media (max-width: 640px) {
  .subtab-strip {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 8px;
  }
  .subtab-strip::-webkit-scrollbar { display: none; }
}
/* Scrollable table container with sticky thead */
.mkt-table-scroll {
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.mkt-table-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.mkt-table-scroll::-webkit-scrollbar-track { background: transparent; }
.mkt-table-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.mkt-table-scroll .mkt-table thead th,
.mkt-table-scroll .hm-mkt-table thead th {
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 1;
}
@media (max-width: 640px) {
  .mkt-table-scroll {
    max-height: calc(100vh - 260px);
  }
}

/* ─── Freshness bar ────────────────────────────────────────────── */
.mkt-freshness-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 8px 0 6px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--sans);
}

.mkt-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 2px;
}

.mkt-status-open  { color: #16a34a; background: rgba(22,163,74,0.08); }
.mkt-status-closed{ color: var(--muted); background: var(--paper-2); }

/* ─── Pulse dot ────────────────────────────────────────────────── */
.mkt-pulse-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.mkt-status-open .mkt-pulse-dot {
  animation: mkt-pulse 2s ease-in-out infinite;
}

/* No animation rule for .mkt-status-closed — dot renders static */

@keyframes mkt-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(1.35); }
}

@media (prefers-reduced-motion: reduce) {
  .mkt-status-open .mkt-pulse-dot { animation: none; }
}

.mkt-freshness-time {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0;
}

/* ─── Intro paragraph ──────────────────────────────────────────── */
.mkt-intro-para {
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink-2);
  margin: 0 0 14px;
  font-family: var(--sans);
}

@media (max-width: 640px) {
  .mkt-freshness-bar { gap: 6px; }
  .mkt-intro-para    { font-size: 13px; }
}

/* ─── Market Pulse Widget (M-FRESH-3) ──────────────────────────── */
.mkt-pulse-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 12px 0 16px;
}
.mkt-pulse-card {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border, #e2e2e2);
  background: var(--paper);
}
.mkt-pulse-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--line);
}
.mkt-pulse-icon { font-size: 18px; flex-shrink: 0; }
.mkt-pulse-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.mkt-pulse-rows { display: flex; flex-direction: column; }
.mkt-pulse-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  text-decoration: none;
  color: var(--ink);
  min-width: 0;
}
.mkt-pulse-row + .mkt-pulse-row { border-top: 1px solid var(--line); }
.mkt-pulse-row:hover .mkt-pulse-primary { color: var(--navy-2); }
.mkt-pulse-primary {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mkt-pulse-secondary {
  flex-shrink: 0;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
  white-space: nowrap;
}
.pulse-hot .mkt-pulse-label   { color: var(--gold); }
.pulse-new .mkt-pulse-primary { font-family: var(--sans); font-size: 12px; font-weight: 600; }
.pulse-gain .mkt-pulse-secondary { color: var(--up); font-weight: 600; }
.pulse-lose .mkt-pulse-secondary { color: var(--down); font-weight: 600; }

@media (max-width: 900px) {
  .mkt-pulse-strip { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .mkt-pulse-strip { grid-template-columns: 1fr; gap: 8px; }
}

/* ─── Sector Heat Map (M-TOOL-1) ──────────────────────────────── */
.sector-heat-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.sector-heat-group {
  display: flex;
  align-items: stretch;
  min-height: 48px;
}
.sector-heat-label {
  width: 72px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--bg-subtle, #f7f7f7);
  color: var(--muted);
  border-right: 1px solid var(--line);
  padding: 4px;
  text-align: center;
}
.sector-heat-cells {
  display: flex;
  flex-wrap: wrap;
  flex: 1;
  gap: 1px;
}
.sector-heat-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  min-width: 56px;
  flex: 1 1 56px;
  text-decoration: none;
  transition: opacity 0.12s;
}
.sector-heat-cell:hover { opacity: 0.8; }
.shc-sym {
  font-size: 11px;
  font-weight: 700;
  font-family: var(--mono);
  white-space: nowrap;
}
.shc-chg {
  font-size: 10px;
  font-family: var(--mono);
  margin-top: 1px;
}
@media (max-width: 640px) {
  .sector-heat-label { width: 52px; font-size: 9px; }
  .sector-heat-cell { min-width: 44px; flex: 1 1 44px; padding: 4px 2px; }
  .shc-sym { font-size: 9px; }
  .shc-chg { font-size: 8px; }
}

/* ─── Economic Calendar Impact Badges ─────────────────────────── */
.ecal-impact {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.ecal-impact-high { background: rgba(200,50,31,0.15); color: var(--red, #c8321f); }
.ecal-impact-medium { background: rgba(255,180,0,0.15); color: #b8860b; }
.ecal-impact-low { background: var(--bg-subtle, #f0f0f0); color: var(--muted); }

/* ── AI Assist Search (M-AI-1/2) ── */
.ai-assist { margin: 4px 0 36px; }
.ai-assist-card {
  position: relative;
  background: linear-gradient(180deg, rgba(201,168,76,0.06) 0%, rgba(201,168,76,0.02) 100%);
  border: 1px solid rgba(201,168,76,0.35);
  border-radius: 4px;
  padding: 20px 22px 18px;
}
/* Chatbot layout: when a chat thread is visible, swap so messages appear
   above the input — matches ChatGPT/Claude/LINE convention so the input
   stays accessible at the bottom of a long conversation. CSS `:has()` is
   supported in Safari 15.4+, Chrome 105+, Firefox 121+; older browsers
   keep the current input-on-top layout (acceptable degradation). */
.ai-assist-card:has(#ai-chat:not([hidden])) {
  display: flex;
  flex-direction: column;
}
.ai-assist-card:has(#ai-chat:not([hidden])) .ai-assist-badge { order: 1; }
.ai-assist-card:has(#ai-chat:not([hidden])) #ai-chat         { order: 2; margin-top: 8px; }
.ai-assist-card:has(#ai-chat:not([hidden])) .ai-assist-form  { order: 3; margin-top: 14px; }
.ai-assist-card:has(#ai-chat:not([hidden])) .ai-assist-chips { order: 4; }
.ai-assist-card:has(#ai-chat:not([hidden])) .ai-assist-foot  { order: 5; }
.ai-assist-card:has(#ai-chat:not([hidden])) .ai-assist-results { order: 6; }
.ai-assist-badge {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 12px; font-family: var(--mono);
}
.ai-assist-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #4ade80; box-shadow: 0 0 0 0 rgba(74,222,128,0.7);
  animation: aiPulse 2s infinite;
}
@keyframes aiPulse {
  0% { box-shadow: 0 0 0 0 rgba(74,222,128,0.6); }
  70% { box-shadow: 0 0 0 8px rgba(74,222,128,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}
.ai-assist-form {
  display: grid; grid-template-columns: 24px 1fr auto;
  align-items: center; gap: 12px;
  background: var(--paper); border: 1.5px solid var(--ink);
  padding: 12px 16px; border-radius: 2px;
}
.ai-assist-icon { width: 20px; height: 20px; color: var(--muted); }
.ai-assist-input {
  border: 0; outline: 0; background: transparent;
  font-family: var(--serif); font-size: 18px; color: var(--ink);
  width: 100%; padding: 4px 0;
}
.ai-assist-input::placeholder { color: var(--muted-2, var(--muted)); font-style: italic; }
.ai-assist-submit {
  border: 0; cursor: pointer;
  background: var(--gold); color: #1a1a1a;
  font-family: var(--sans, system-ui); font-weight: 700; font-size: 13px;
  letter-spacing: 0.04em; padding: 9px 16px; border-radius: 2px;
  transition: filter 0.15s;
}
.ai-assist-submit:hover { filter: brightness(1.08); }
.ai-assist-chips {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px;
}
.ai-assist-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 6px 12px;
  background: transparent; border: 1px solid var(--line);
  color: var(--ink); text-decoration: none; border-radius: 2px;
  transition: border-color 0.15s, background 0.15s;
}
.ai-assist-chip:hover { border-color: var(--gold); background: rgba(201,168,76,0.06); }
.ai-assist-foot {
  margin-top: 10px; font-size: 11px; color: var(--muted);
  font-family: var(--mono); letter-spacing: 0.04em;
}

/* Dropdown results */
.ai-assist-results {
  position: absolute; left: 0; right: 0; top: calc(100% - 1px);
  background: var(--paper); border: 1px solid var(--ink);
  border-top: 0; max-height: 420px; overflow-y: auto;
  z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.ai-assist-results[hidden] { display: none; }
.ai-assist-group { padding: 6px 0; border-top: 1px solid var(--line); }
.ai-assist-group:first-child { border-top: 0; }
.ai-assist-group-label {
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); padding: 6px 16px 4px; font-family: var(--mono);
}
.ai-assist-item {
  display: grid; grid-template-columns: 1fr auto;
  align-items: center; gap: 12px;
  padding: 10px 16px; text-decoration: none; color: var(--ink);
  border-left: 3px solid transparent;
}
.ai-assist-item:hover, .ai-assist-item.is-active {
  background: rgba(201,168,76,0.08); border-left-color: var(--gold);
}
.ai-assist-item-title { font-weight: 700; font-size: 14px; font-family: var(--serif); }
.ai-assist-item-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ai-assist-item-badge {
  font-size: 10px; padding: 2px 6px; border: 1px solid var(--line);
  border-radius: 2px; color: var(--muted); letter-spacing: 0.06em;
  font-family: var(--mono);
}
.ai-assist-empty, .ai-assist-loading {
  padding: 16px; font-size: 13px; color: var(--muted); text-align: center;
}
.ai-assist-took {
  font-size: 10px; color: var(--muted); text-align: right;
  padding: 6px 16px; font-family: var(--mono);
  border-top: 1px solid var(--line);
}

@media (max-width: 720px) {
  .ai-assist-form { grid-template-columns: 20px 1fr; padding: 10px 14px; }
  .ai-assist-submit { grid-column: 1 / -1; margin-top: 6px; width: 100%; }
  .ai-assist-input { font-size: 16px; } /* prevent iOS zoom */
  .ai-assist-chips { gap: 6px; }
  .ai-assist-chip { font-size: 11px; padding: 5px 10px; }
}

/* ── AI Chat Thread (M-AI-4) ── */
.ai-chat {
  margin-top: 14px;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  max-height: 600px;
}
.ai-chat[hidden] { display: none; }
.ai-chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.ai-chat-title {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.ai-chat-icon { color: var(--gold); font-size: 14px; }
.ai-chat-label { color: var(--ink); font-weight: 700; }
.ai-chat-status { color: var(--muted); font-size: 11px; text-transform: none; letter-spacing: 0.04em; }
.ai-chat-status.is-streaming::after {
  content: '▍';
  animation: aiBlink 1s steps(1) infinite;
  margin-left: 2px;
  color: var(--gold);
}
@keyframes aiBlink { 50% { opacity: 0; } }
.ai-chat-actions { display: flex; gap: 4px; align-items: center; }
.ai-chat-clear, .ai-chat-close {
  background: transparent; border: 1px solid transparent;
  cursor: pointer; color: var(--muted);
  padding: 2px 8px; border-radius: 2px;
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.04em;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.ai-chat-close { font-size: 18px; padding: 0 8px; line-height: 1; font-family: var(--sans); }
.ai-chat-clear:hover, .ai-chat-close:hover {
  color: var(--ink); border-color: var(--line); background: var(--paper);
}

.ai-chat-thread {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}
.ai-chat-thread:empty::before {
  content: '';
  display: block;
  height: 8px;
}

.ai-bubble { max-width: 92%; }
.ai-bubble-user {
  align-self: flex-end;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 12px 12px 2px 12px;
  padding: 10px 14px;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
}
.ai-bubble-assistant {
  align-self: flex-start;
  border-left: 2px solid var(--gold);
  padding: 4px 0 4px 12px;
  max-width: 100%;
}
.ai-bubble-meta {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-transform: uppercase;
}
.ai-bubble-meta-icon { color: var(--gold); }
.ai-bubble-sources {
  margin-bottom: 6px;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.ai-bubble-sources[hidden] { display: none; }
.ai-bubble-source-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--mono); font-size: 10px;
  padding: 2px 7px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--ink);
  text-decoration: none;
}
.ai-bubble-source-chip:hover { border-color: var(--gold); }
.ai-bubble-content {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.ai-bubble-content a {
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-color: var(--gold);
  text-underline-offset: 3px;
  font-weight: 600;
}
.ai-bubble-content a:hover { color: var(--gold); }
.ai-bubble-content ul, .ai-bubble-content ol { margin: 6px 0 6px 20px; }
.ai-bubble-content li { margin: 3px 0; }
.ai-bubble-stats {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--muted-2);
}
.ai-bubble-stats[hidden] { display: none; }

.ai-bubble-error {
  align-self: flex-start;
  background: var(--paper);
  border: 1px solid var(--down);
  border-radius: 4px;
  padding: 10px 14px;
  font-family: var(--serif);
  font-size: 14px;
  color: var(--ink);
}
.ai-bubble-error a {
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-color: var(--gold);
  font-weight: 600;
}

.ai-chat-foot {
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  background: var(--paper-2);
  border-top: 1px solid var(--line);
  text-align: right;
  flex-shrink: 0;
}

@media (max-width: 720px) {
  .ai-chat { max-height: 70vh; }
  .ai-bubble-user, .ai-bubble-assistant { max-width: 100%; }
  .ai-bubble-content { font-size: 14px; }
  .ai-chat-thread { padding: 12px 12px 8px; gap: 10px; }
}
