:root {
  --ground: #F4F5F7;
  --surface: #FFFFFF;
  --line: #E3E5EA;
  --line-strong: #C9CDD6;
  --ink: #15171C;
  --muted: #5A606E;
  --accent: #C23B22;
  --accent-ink: #A3301B;
  --accent-soft: #FBECE8;
  --new: #2457A6;
  --new-soft: #E8F0FB;
  --new-ink: #1D4A8F;
  font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--ground); }
a { color: var(--accent-ink); }
a:hover { color: #7E2414; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--new); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Top bar ---------- */
.banner { background: #FFF6E0; color: #5C4000; border-bottom: 1px solid #F0DDA8; font-size: 13.5px; padding: 8px 16px; text-align: center; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-in { max-width: 1440px; margin: 0 auto; padding: 12px 24px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 18px; }
.brand:hover { color: var(--ink); }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; flex-shrink: 0; }

.trip { position: relative; min-width: 0; }
.trip-btn { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); text-align: left; min-width: 0; }
button.trip-btn { cursor: pointer; }
.trip-text { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.trip-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip-range { color: var(--muted); font-size: 14px; white-space: nowrap; }
.trip-menu { position: absolute; top: calc(100% + 6px); left: 0; min-width: 260px; max-height: 60vh; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(21, 23, 28, .12); padding: 6px; z-index: 30; }
.trip-menu a { display: block; padding: 10px 12px; border-radius: 8px; text-decoration: none; color: var(--ink); }
.trip-menu a:hover, .trip-menu a[aria-current="page"] { background: var(--ground); }
.trip-menu a[aria-current="page"] { font-weight: 600; }

.search { flex: 1 1 280px; display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 14px; background: var(--ground); border-radius: 10px; color: var(--muted); }
.search:focus-within { outline: 2px solid var(--new); outline-offset: 1px; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; font-size: 15px; color: var(--ink); outline: none; }
.search input::placeholder { color: #6B7180; }

.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; color: var(--ink); text-decoration: none; flex-shrink: 0; }
.icon-btn:hover { background: var(--ground); color: var(--ink); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.search-toggle { display: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); text-decoration: none; font-weight: 500; font-size: 15px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--ground); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #A93219; color: #fff; }
.btn-ghost { border-color: transparent; color: var(--accent-ink); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- Home layout ---------- */
.layout { max-width: 1440px; margin: 0 auto; padding: 24px; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 24px; }
.sidebar { flex: 1 1 260px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.side-label { padding: 6px 10px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; }
.side-sep { height: 1px; background: var(--line); margin: 10px 4px; }
.menu-item { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 10px; border-radius: 10px; text-decoration: none; color: var(--ink); font-size: 15px; font-weight: 500; }
.menu-item:hover { background: var(--ground); color: var(--ink); }
.menu-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.menu-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.menu-text > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-sub { font-size: 12.5px; font-weight: 400; color: var(--muted); }
.menu-item[aria-current="page"] .menu-sub { color: var(--accent-ink); }
.day-badge { width: 36px; height: 36px; border-radius: 9px; background: var(--ground); display: grid; place-items: center; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.menu-item[aria-current="page"] .day-badge { background: var(--accent); color: #fff; }
.count { min-width: 24px; height: 24px; padding: 0 7px; border-radius: 999px; background: var(--ground); color: var(--muted); font-size: 12px; font-weight: 600; display: grid; place-items: center; flex-shrink: 0; }
.menu-item[aria-current="page"] .count { background: #fff; }
.dot-new { width: 8px; height: 8px; border-radius: 50%; background: var(--new); flex-shrink: 0; }

.badge { font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 2px 8px; flex-shrink: 0; white-space: nowrap; }
.badge-new { color: #fff; background: var(--new); }
.badge-updated { color: var(--new-ink); background: var(--new-soft); }

.content { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 24px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.crumbs { font-size: 13px; color: var(--muted); }
.page-head h1 { margin: 4px 0 2px; font-size: 28px; line-height: 1.3; font-weight: 700; overflow-wrap: anywhere; }
.page-sub { font-size: 14px; color: var(--muted); }

.pinned-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 12px; }
.pin-card { display: flex; align-items: center; gap: 18px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; text-decoration: none; color: var(--ink); }
.pin-card:hover { color: var(--ink); }
.pin-card .tile { width: 56px; height: 56px; border-radius: 14px; }
.pin-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pin-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag-pin { font-size: 12px; font-weight: 600; color: var(--accent-ink); background: var(--accent-soft); border-radius: 999px; padding: 2px 10px; }
.pin-title { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
.pin-meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.pin-cta { display: flex; align-items: center; gap: 6px; height: 44px; padding: 0 16px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; flex-shrink: 0; }

.group { display: flex; flex-direction: column; gap: 12px; }
.group-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.group-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.group-date { font-size: 14px; color: var(--muted); }
.group-count { margin-left: auto; font-size: 13px; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 12px; }
.card { display: flex; align-items: center; gap: 14px; min-height: 76px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; text-decoration: none; color: var(--ink); min-width: 0; }
.card:hover, .pin-card:hover { border-color: var(--line-strong); box-shadow: 0 2px 10px rgba(21, 23, 28, .06); color: var(--ink); }
.card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.card-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--ground); border-radius: 999px; padding: 2px 9px; flex-shrink: 0; white-space: nowrap; }
.chev { display: none; color: var(--muted); flex-shrink: 0; }

.tile { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; }
.t-map { background: #E8F0FB; color: #2457A6; }
.t-budget { background: #E9F5EE; color: #23794A; }
.t-shop { background: #FFF1DE; color: #9A5300; }
.t-pdf { background: var(--accent-soft); color: var(--accent); }
.t-word { background: #E6ECFA; color: #1F4FB8; }
.t-sheet { background: #E9F5EE; color: #1E7044; }
.t-slides { background: #FFF1DE; color: #9A5300; }
.t-image { background: #F2ECFB; color: #6B3FB0; }
.t-text, .t-file { background: #EEF0F4; color: #3A3F4B; }

.empty { padding: 32px 24px; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: 14px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.6; }
.state-card { max-width: 560px; margin: 64px auto; padding: 32px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; text-align: center; color: var(--muted); line-height: 1.6; }
.state-card h2 { margin: 0 0 8px; color: var(--ink); font-size: 20px; }
.state-card code { background: var(--ground); padding: 1px 6px; border-radius: 6px; font-size: 13px; word-break: break-all; }
.state-card .btn { margin-top: 16px; }
.skeleton { height: 76px; border-radius: 14px; background: linear-gradient(90deg, #ECEEF2 25%, #F6F7F9 50%, #ECEEF2 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.chips, .bottom-nav, .v-bottom { display: none; }

/* ---------- Viewer ---------- */
.v-head-in { max-width: 1440px; margin: 0 auto; padding: 12px 24px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.v-titles { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; }
.v-titles h1 { margin: 0; font-size: 20px; line-height: 1.35; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.v-layout { max-width: 1440px; margin: 0 auto; padding: 24px; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 24px; }
.v-aside { flex: 1 1 280px; display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px 8px; }
.panel-head strong { font-size: 15px; }
.panel-head span { font-size: 12.5px; color: var(--muted); }
.rail-item { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 10px; border-radius: 10px; text-decoration: none; color: var(--ink); }
.rail-item:hover { background: var(--ground); color: var(--ink); }
.rail-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }
.rail-num { width: 28px; height: 28px; border-radius: 50%; background: var(--ground); display: grid; place-items: center; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.rail-item[aria-current="page"] .rail-num { background: var(--accent); color: #fff; }
.rail-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rail-text > span:first-child { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-item[aria-current="page"] .rail-text > span:first-child { font-weight: 600; }
.rail-text > span + span { font-size: 12.5px; color: var(--muted); }
.rail-item[aria-current="page"] .rail-text > span + span { color: var(--accent-ink); }
.details { padding: 16px 20px; gap: 10px; }
.details h2 { margin: 0; font-size: 15px; }
.details dl { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 16px; row-gap: 8px; font-size: 13.5px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.v-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.v-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 6px 6px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; font-size: 14px; color: var(--muted); }
.frame { position: relative; background: #DADDE3; border-radius: 16px; overflow: hidden; height: calc(100vh - 230px); min-height: 520px; }
.frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.frame:fullscreen { border-radius: 0; }
.frame-ph { position: absolute; inset: 24px; margin: auto; max-width: 560px; background: #fff; border-radius: 6px; box-shadow: 0 6px 24px rgba(21, 23, 28, .12); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center; color: var(--muted); }
.frame-ph strong { color: var(--ink); }
.pn { display: flex; flex-wrap: wrap; gap: 12px; }
.pn a, .pn span.pn-blank { flex: 1 1 240px; display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 10px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--ink); min-width: 0; }
.pn span.pn-blank { visibility: hidden; }
.pn a:hover { border-color: var(--line-strong); color: var(--ink); }
.pn .pn-next { justify-content: flex-end; text-align: right; }
.pn-text { display: flex; flex-direction: column; min-width: 0; }
.pn-text small { font-size: 12.5px; color: var(--muted); }
.pn-text span { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .topbar-in { padding: 12px 16px; gap: 8px; flex-wrap: wrap; }
  .brand-name, .hide-sm { display: none; }
  .brand-mark { width: 44px; height: 44px; border-radius: 12px; }
  .trip { flex: 1; }
  .trip-btn { width: 100%; height: 48px; }
  .trip-text { flex-direction: column; gap: 0; line-height: 1.3; }
  .trip-range { font-size: 12px; }
  .search { display: none; order: 10; flex-basis: 100%; height: 48px; }
  .topbar.searching .search { display: flex; }
  .search-toggle { display: grid; width: 48px; height: 48px; }

  .chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 12px; background: var(--surface); border-bottom: 1px solid var(--line); scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { position: relative; flex-shrink: 0; min-width: 56px; height: 56px; padding: 0 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.25; text-decoration: none; color: var(--ink); }
  .chip:hover { color: var(--ink); }
  .chip b { font-size: 14px; }
  .chip span { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
  .chip[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: #fff; }
  .chip[aria-current="page"] span { color: #fff; }
  .chip .dot-new { position: absolute; top: 5px; right: 5px; width: 9px; height: 9px; box-shadow: 0 0 0 2px #fff; }

  .layout { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); gap: 16px; }
  .sidebar { display: none; }
  .content { gap: 18px; }
  .page-head h1 { font-size: 20px; margin-top: 2px; }
  .crumbs { display: none; }

  .pin-card { padding: 14px; gap: 14px; }
  .pin-card .tile { width: 44px; height: 44px; border-radius: 11px; }
  .pin-title { font-size: 15px; }
  .pin-meta { font-size: 12px; }
  .pin-cta { display: none; }
  .pin-card .chev { display: block; }

  .group { gap: 10px; }
  .group-head h2 { font-size: 17px; }
  .cards { grid-template-columns: 1fr; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
  .card { border: 0; border-radius: 0; border-top: 1px solid var(--line); min-height: 68px; padding: 10px 14px; gap: 12px; }
  .card:first-child { border-top: 0; }
  .card:hover { box-shadow: none; background: var(--ground); }
  .card .tile { width: 40px; height: 40px; border-radius: 10px; }
  .card .chev { display: block; }
  .card .order { display: none; }

  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); gap: 4px; overflow-x: auto; }
  .bnav-item { flex: 1 0 80px; max-width: 160px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 56px; padding: 0 6px; border-radius: 12px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 500; min-width: 0; }
  .bnav-item span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bnav-item:hover { color: var(--ink); }
  .bnav-item[aria-current="page"] { color: var(--accent-ink); font-weight: 600; }

  /* viewer */
  .v-head-in { padding: 10px 8px; gap: 4px; flex-wrap: nowrap; }
  .v-head-in .btn-back { border: 0; width: 48px; padding: 0; }
  .v-head-in .btn-back .btn-label { display: none; }
  .v-titles { flex: 1 1 auto; }
  .v-titles .crumbs { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .v-titles h1 { font-size: 17px; }
  .v-actions .btn-dl, .v-actions .btn-label { display: none; }
  .v-actions .btn-drive { width: 48px; padding: 0; border: 0; background: transparent; color: var(--ink); }
  .v-layout { padding: 0; gap: 0; }
  .v-aside, .v-toolbar, .pn { display: none; }
  .v-main { gap: 0; }
  .frame { border-radius: 0; height: calc(100dvh - 69px - 80px - env(safe-area-inset-bottom)); min-height: 360px; }
  .v-bottom { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; align-items: stretch; gap: 6px; background: var(--surface); border-top: 1px solid var(--line); padding: 8px 8px calc(12px + env(safe-area-inset-bottom)); }
  .v-bottom .pn-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; min-height: 56px; padding: 0 8px; border-radius: 12px; text-decoration: none; color: var(--ink); }
  .v-bottom .pn-link.next { justify-content: flex-end; text-align: right; }
  .v-bottom .pn-link[aria-disabled="true"] { visibility: hidden; }
  .v-bottom .pn-text small { font-size: 11.5px; }
  .v-bottom .pn-text span { font-size: 13.5px; }
  .v-bottom .dl { width: 56px; height: 56px; flex-shrink: 0; border-radius: 14px; background: var(--accent); color: #fff; display: grid; place-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton, .icon-btn.spin svg { animation: none; }
}
