/* ==========================================================================
   HaNonn Commerce Agent Trace Workbench — Theme & Layout Tokens (v4)
   ปรับสี ฟอนต์ ระยะห่าง และความสูงกล่องเลื่อนได้ที่กลุ่มตัวแปร :root ด้านล่าง
   ========================================================================== */
:root {
  color-scheme: light;
  --navy: #172641;
  --terracotta: #993300;
  --terracotta-soft: #fdf3eb;
  --slate-blue: #3b6b94;
  --slate-blue-soft: #edf4fa;
  --emerald: #1b6a4f;
  --emerald-soft: #e8f6ef;
  --crimson: #b42318;
  --crimson-soft: #fef2f2;
  --amber: #94560f;
  --amber-soft: #fef6e4;
  --bg: #f3f6fa;
  --paper: #ffffff;
  --surface: #f8fafd;
  --ink: #172641;
  --body: #334155;
  --muted: #4b6073;
  --line: #dde5ef;
  --line-strong: #c3d2e1;
  --link: #1c4e80;
  --font-sans: "Noto Sans Thai", "IBM Plex Sans Thai", "Leelawadee UI", "Sarabun", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-size-base: 15px;
  --line-height-base: 1.64;
  --page-max-width: 1240px;
  --sidebar-width: 255px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(23, 38, 65, 0.05);
  --scroll-box-height: 360px;
  --scroll-box-sm-height: 205px;
  --quote-box-height: 145px;
  font: var(--font-size-base)/var(--line-height-base) var(--font-sans);
  color: var(--body);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--body); -webkit-font-smoothing: antialiased; }

/* Unified Sticky Masthead */
.masthead {
  position: sticky;
  top: 0;
  z-index: 60;
  background: linear-gradient(135deg, var(--navy) 0%, #21375c 100%);
  color: #ffffff;
  border-bottom: 3px solid var(--terracotta);
  box-shadow: 0 4px 16px rgba(15, 27, 48, 0.14);
}
.masthead-inner, main {
  width: min(var(--page-max-width), calc(100% - 2rem));
  margin: 0 auto;
}
.masthead-inner {
  padding: 0.65rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 1.2rem;
  align-items: center;
  justify-content: space-between;
}
.masthead-brand { display: flex; flex-direction: column; gap: 1px; }
.masthead-brand strong { font-size: 1rem; color: #ffffff; }
.masthead-brand span { font-size: 0.72rem; color: #cdd9ea; letter-spacing: 0.03em; }
.masthead nav { display: flex; flex-wrap: wrap; gap: 0.38rem; }
.masthead a {
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
  color: #e8f0fa;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.32rem 0.72rem;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.16);
  transition: background 0.15s ease;
}
.masthead a:hover { background: rgba(255, 255, 255, 0.2); color: #ffffff; }
.masthead a[aria-current="page"] { background: #ffffff; color: var(--navy); border-color: #ffffff; }

main { padding: 1.15rem 0 4.5rem; }

h1, h2, h3, h4, h5 { color: var(--ink); line-height: 1.36; overflow-wrap: anywhere; }
h1 { margin: 0 0 0.3rem; font-size: clamp(1.38rem, 2.7vw, 1.85rem); letter-spacing: -0.012em; }
h2 { margin: 0 0 0.5rem; font-size: 1.16rem; }
h3 { margin: 0 0 0.38rem; font-size: 1rem; }
h4, h5 { margin: 0.3rem 0 0.3rem; font-size: 0.9rem; }
p { margin: 0.28rem 0 0.55rem; }
a { color: var(--link); text-underline-offset: 0.18em; font-weight: 600; }
a:hover { color: var(--terracotta); }
a:focus-visible, button:focus-visible, .scroll-box:focus-visible { outline: 2.5px solid var(--terracotta); outline-offset: 2px; }
[id] { scroll-margin-top: 4.5rem; }
:target {
  border-color: var(--terracotta) !important;
  outline: 2.5px solid var(--terracotta);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(153, 51, 0, 0.13);
}
code {
  font-family: var(--font-mono);
  font-size: 0.83em;
  background: #eef2f7;
  color: var(--navy);
  padding: 0.08rem 0.34rem;
  border-radius: 5px;
  overflow-wrap: anywhere;
}
.muted { color: var(--muted); font-size: 0.84rem; }

/* Compact Hero + Tab Switcher */
.hero-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-top: 4px solid var(--navy);
  border-radius: var(--radius);
  padding: 0.95rem 1.15rem;
  box-shadow: var(--shadow);
  margin-bottom: 0.95rem;
}
.hero-top-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 0.9rem;
  align-items: center;
}
.tab-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  margin-top: 0.7rem;
  padding-top: 0.65rem;
  border-top: 1px dashed var(--line-strong);
}
.tab-buttons { display: flex; flex-wrap: wrap; gap: 0.38rem; }
.tab-btn {
  padding: 0.36rem 0.78rem;
  border-radius: 99px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--navy);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}
.tab-btn:hover { background: var(--terracotta-soft); border-color: var(--terracotta); color: var(--terracotta); }
.tab-btn[aria-current="location"] {
  background: var(--navy);
  color: #ffffff;
  border-color: var(--navy);
}
.tab-btn-all[aria-current="location"] { background: var(--terracotta); border-color: var(--terracotta); color: #ffffff; }

/* Workbench Sidebar + Main */
.workbench {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
.wb-sidebar {
  position: sticky;
  top: 4.35rem;
  max-height: calc(100vh - 5.2rem);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-top: 3px solid var(--navy);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.wb-side-head {
  padding: 0.65rem 0.8rem;
  background: #f4f7fb;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
}
.wb-side-head strong { font-size: 0.86rem; color: var(--navy); }
.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 2px;
  background: #e2eaf3;
  border-radius: 7px;
}
.mode-toggle button {
  border: 0;
  background: transparent;
  padding: 0.25rem 0.4rem;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  border-radius: 5px;
  color: var(--body);
  cursor: pointer;
}
.mode-toggle button[aria-pressed="true"] { background: var(--navy); color: #ffffff; }
.wb-nav-list {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: 0.45rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.wb-group-label {
  font-size: 0.71rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--terracotta);
  padding: 0.42rem 0.45rem 0.15rem;
  text-transform: uppercase;
}
.wb-group-label:first-child { padding-top: 0.15rem; }
.wb-nav-item {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.42rem 0.58rem;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.81rem;
  font-weight: 600;
  cursor: pointer;
}
.wb-nav-item:hover { background: #f1f6fb; border-color: var(--line); }
.wb-nav-item.is-active {
  background: #eaf2fb;
  border-color: var(--slate-blue);
  box-shadow: inset 3px 0 0 var(--terracotta);
  font-weight: 700;
}
.wb-tag {
  font-size: 0.67rem;
  font-weight: 700;
  padding: 0.05rem 0.4rem;
  border-radius: 99px;
  background: #e9eff6;
  color: var(--muted);
}
.wb-tag-c { background: var(--emerald-soft); color: var(--emerald); }
.wb-tag-b { background: #eef2f7; color: #475569; }
.wb-main { min-width: 0; }
.wb-hidden { display: none !important; }

/* Cards & Split Views */
.card, article, .case-group {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin: 0 0 1rem;
  box-shadow: var(--shadow);
}
article { border-top: 4px solid var(--navy); }
.case-group { border-top: 4px solid var(--slate-blue); }
.group-banner {
  padding: 0.65rem 0.9rem;
  background: #eef4fa;
  border: 1px solid #d1e0ee;
  border-left: 4px solid var(--terracotta);
  border-radius: var(--radius-sm);
  margin-bottom: 0.75rem;
}
.group-banner h2 { margin: 0 0 0.2rem; font-size: 1.08rem; }
.group-banner p { margin: 0.15rem 0; font-size: 0.84rem; }

.sub-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-left: 3.5px solid var(--slate-blue);
  border-radius: var(--radius-sm);
  padding: 0.68rem 0.82rem;
  margin: 0 0 0.55rem;
  font-size: 0.85rem;
  line-height: 1.54;
}
.sub-card:last-child { margin-bottom: 0; }
.sub-card-ok { border-left-color: var(--emerald); background: #fbfefc; }
.sub-card-risk { border-left-color: var(--crimson); background: #fffcfc; }
.sub-card-warn { border-left-color: var(--amber); background: #fffdf7; }

/* Scroll Boxes */
.scroll-box {
  max-height: var(--scroll-box-height);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #9cb3c9 #eef3f8;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0.6rem 0.72rem;
}
.scroll-box-sm { max-height: var(--scroll-box-sm-height); }
.scroll-box-tall { max-height: 540px; }
.scroll-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin: 0.75rem 0 0.35rem;
}
.scroll-head-top { margin-top: 0; }
.scroll-head h3, .scroll-head h4, .scroll-head h5 { margin: 0; }
.scroll-hint {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: #edf2f8;
  padding: 0.1rem 0.5rem;
  border-radius: 99px;
  white-space: nowrap;
}

/* Grids */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  align-items: start;
}
.split-parcel {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 1rem;
  align-items: start;
}
.grid-2 > *, .split-parcel > * { min-width: 0; }

/* Blockquotes & Tables */
blockquote {
  margin: 0.4rem 0 0.6rem;
  padding: 0.58rem 0.78rem;
  background: #eef4fa;
  border-left: 3.5px solid var(--slate-blue);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--navy);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: var(--quote-box-height);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  font-size: 0.89rem;
}
blockquote a {
  background: #fff1e2;
  padding: 0.08rem 0.34rem;
  border-radius: 4px;
  color: var(--terracotta);
  text-decoration: underline;
}
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; background: var(--paper); font-size: 0.83rem; }
thead th {
  background: #edf2f8;
  color: var(--navy);
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0.48rem 0.6rem;
  border-bottom: 2px solid var(--line-strong);
  text-align: left;
  vertical-align: top;
}
td { padding: 0.46rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: 0; }

/* Badges & Chips */
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 99px;
  padding: 0.11rem 0.54rem;
  font-size: 0.74rem;
  font-weight: 700;
  background: #e9eff5;
  color: var(--navy);
  margin-right: 0.32rem;
  vertical-align: middle;
}
.badge-ok { background: var(--emerald-soft); color: var(--emerald); }
.badge-risk { background: var(--crimson-soft); color: var(--crimson); }
.badge-warn { background: var(--amber-soft); color: var(--amber); }
.badge-info { background: var(--slate-blue-soft); color: #1c4e80; }
.badge-muted { background: #eef2f7; color: #4b6073; }

.chip-row { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.4rem 0 0.2rem; }
.chip-row a {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.14rem 0.48rem;
  border-radius: 6px;
  background: #f1f5f9;
  border: 1px solid #d5e0eb;
  color: var(--navy);
  text-decoration: none;
}
.chip-row a:hover { background: var(--terracotta-soft); border-color: var(--terracotta); color: var(--terracotta); }
.meta-line { font-size: 0.81rem; color: var(--muted); margin: 0.15rem 0 0.5rem; }
.blueprint-box {
  background: #fffaf5;
  border: 1px solid #eadfd9;
  border-left: 4px solid var(--terracotta);
  border-radius: var(--radius-sm);
  padding: 0.82rem 0.95rem;
  margin: 0 0 0.85rem;
}
.num-good { font-weight: 800; color: var(--emerald); }
.num-bad { font-weight: 800; color: var(--crimson); }
.num-warn { font-weight: 800; color: var(--amber); }

/* Mobile Dock & Drawer */
.mobile-dock, .drawer-backdrop { display: none; }

@media (max-width: 920px) {
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }
  .hero-top-grid, .workbench, .grid-2, .split-parcel { grid-template-columns: 1fr; }
  main, .masthead-inner { width: calc(100% - 1.2rem); }

  .wb-sidebar {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    top: auto;
    max-height: 65vh;
    z-index: 80;
    display: none;
    box-shadow: 0 16px 36px rgba(15, 27, 48, 0.25);
  }
  .wb-sidebar.is-drawer-open { display: flex; }
  .drawer-backdrop.is-drawer-open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 27, 48, 0.35);
    z-index: 75;
  }
  .mobile-dock {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 85;
    padding: 0.45rem 0.7rem calc(0.45rem + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line-strong);
    box-shadow: 0 -4px 16px rgba(15, 27, 48, 0.1);
  }
  .mobile-dock button {
    min-height: 42px;
    border-radius: 10px;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    color: var(--navy);
    cursor: pointer;
  }
  .mobile-dock button.dock-primary {
    background: var(--navy);
    border-color: var(--navy);
    color: #ffffff;
  }
}

:focus-visible { outline: 3px solid #245a91; outline-offset: 2px; }
.wb-nav-item, .tab-btn { text-decoration: none; }
.mobile-dock a { display: grid; place-content: center; min-height: 42px; border: 1px solid var(--line-strong); border-radius: 10px; color: var(--navy); background: var(--surface); text-decoration: none; font-weight: 700; font-size: .8rem; }
.mobile-dock a[aria-current="location"] { color: white; background: var(--navy); }
.wb-side-head .drawer-close { display: none; }
@media (max-width: 920px) {
  .wb-side-head .drawer-close { display: inline-block; align-self: start; border: 1px solid var(--line-strong); border-radius: 6px; background: white; color: var(--navy); padding: .3rem .55rem; font: inherit; cursor: pointer; }
  .tab-strip:target, .hero-card:target { scroll-margin-bottom: 5rem; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
