:root {
  --ink: #17201f;
  --muted: #64706d;
  --paper: #f6f4ee;
  --panel: rgba(255,255,255,.96);
  --line: #dedbd2;
  --shadow: 0 18px 45px rgba(31, 42, 39, .16);
  --radius: 18px;
  --topbar-h: 78px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin:0; width:100%; height:100%; overflow:hidden; overscroll-behavior:none; background:var(--paper); color:var(--ink); }
button, input { font:inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { height:100vh; height:100dvh; display:grid; grid-template-rows:var(--topbar-h) minmax(0,1fr); }
.topbar {
  z-index:20; display:flex; align-items:center; justify-content:space-between; gap:20px;
  padding:0 22px 0 26px; background:#fff; border-bottom:1px solid var(--line);
}
.brand-block h1 { margin:1px 0 0; font-size:clamp(20px,2vw,29px); letter-spacing:-.02em; font-weight:760; }
.brand-kicker, .eyebrow { font-size:11px; line-height:1; font-weight:800; letter-spacing:.15em; color:#8b7461; }
.topbar-actions { display:flex; gap:9px; align-items:center; }
.icon-button, .text-button {
  min-height:40px; border:1px solid var(--line); background:#fff; color:var(--ink); border-radius:12px;
  display:inline-flex; align-items:center; justify-content:center; text-decoration:none; cursor:pointer;
}
.icon-button { width:42px; font-size:22px; }
.text-button { padding:0 13px; font-size:13px; font-weight:700; }
.icon-button:hover, .text-button:hover { background:#f3f1ea; }

.main-layout { min-height:0; display:grid; grid-template-columns:310px minmax(0,1fr); }
.sidebar { min-height:0; overflow:auto; padding:20px 15px 18px 18px; border-right:1px solid var(--line); background:#fbfaf6; }
.sidebar-head { display:flex; justify-content:space-between; align-items:flex-end; gap:12px; padding:0 5px 14px; }
.sidebar h2 { margin:5px 0 0; font-size:23px; letter-spacing:-.02em; }
.site-total { display:flex; align-items:flex-end; gap:6px; color:var(--muted); font-size:11px; }
.site-total strong { color:var(--ink); font-size:20px; line-height:1; }
.search-box { height:42px; margin:2px 3px 14px; padding:0 12px; display:flex; align-items:center; gap:8px; border:1px solid #d9d5cb; border-radius:12px; background:#fff; }
.search-box span { color:#887f73; font-size:20px; }
.search-box input { width:100%; border:0; outline:0; background:transparent; color:var(--ink); }
.search-box input::placeholder { color:#9a9e99; }
.route-list { display:grid; gap:8px; }
.route-card { border:1px solid #dfdbd1; border-radius:15px; background:#fff; overflow:hidden; transition:.18s ease; }
.route-card.is-active { border-color:var(--route-color); box-shadow:0 8px 24px color-mix(in srgb, var(--route-color) 15%, transparent); }
.route-card.is-dimmed { opacity:.45; }
.route-head {
  width:100%; border:0; background:transparent; display:grid; grid-template-columns:5px 1fr auto; gap:10px; align-items:center;
  padding:12px 12px 12px 9px; text-align:left; cursor:pointer; color:var(--ink);
}
.route-swatch { align-self:stretch; border-radius:999px; background:var(--route-color); min-height:37px; }
.route-title { display:grid; gap:3px; }
.route-title strong { font-size:14px; line-height:1.25; }
.route-title small { color:var(--muted); font-size:11px; }
.route-count { width:27px; height:27px; display:grid; place-items:center; border-radius:50%; background:#f2efe7; font-size:11px; font-weight:800; }
.site-list { display:none; margin:0; padding:0 9px 10px 23px; list-style:none; }
.route-card.is-open .site-list, .route-card.has-search-match .site-list { display:grid; }
.site-list button { width:100%; border:0; border-radius:9px; background:transparent; padding:7px 7px; text-align:left; color:#3d4946; font-size:12px; cursor:pointer; }
.site-list button:hover, .site-list button.is-active { background:#f1eee6; color:#111; font-weight:700; }
.site-list li.is-hidden, .route-card.is-hidden { display:none; }
.sidebar-note { margin:16px 5px 0; padding:12px; border-radius:12px; background:#efece3; color:#66706d; font-size:11px; line-height:1.45; }
.sidebar-note strong { color:#3b4442; }

.map-stage { position:relative; min-width:0; min-height:0; background:#e6e2d8; }
.map-viewport { position:absolute; inset:0; overflow:hidden; cursor:grab; touch-action:none; user-select:none; outline:none; background:#ebe8df; }
.map-viewport.is-dragging { cursor:grabbing; }
.map-world { position:absolute; left:0; top:0; transform-origin:0 0; will-change:transform; overflow:hidden; }
.tile-layer, .route-overlay { position:absolute; inset:0; width:100%; height:100%; }
.tile-layer { pointer-events:none; background:#f1efe9; transition:filter .18s ease, opacity .18s ease; }
.map-viewport.has-focus .tile-layer { filter:saturate(.72) brightness(1.045); opacity:.78; }
.map-tile { position:absolute; width:512px; height:512px; max-width:none; max-height:none; pointer-events:none; user-select:none; }
.route-overlay { overflow:visible; pointer-events:auto; }
.route-visible { fill:none; stroke-linecap:round; stroke-linejoin:round; vector-effect:non-scaling-stroke; opacity:.82; transition:opacity .16s ease, stroke-width .16s ease, filter .16s ease; pointer-events:none; }
.route-hit { fill:none; stroke:rgba(0,0,0,0); stroke-width:24; stroke-linecap:round; stroke-linejoin:round; vector-effect:non-scaling-stroke; pointer-events:stroke; cursor:pointer; }
.route-group.is-active .route-visible { opacity:1; stroke-width:9 !important; filter:drop-shadow(0 1px 3px rgba(255,255,255,.95)) drop-shadow(0 2px 6px rgba(0,0,0,.32)); }
.route-group.is-dimmed .route-visible { opacity:.15; }
.site-marker { cursor:pointer; }
.site-halo { fill:rgba(255,255,255,.93); stroke:rgba(0,0,0,.18); vector-effect:non-scaling-stroke; stroke-width:1.5; }
.site-core { stroke:#fff; stroke-width:2.2; vector-effect:non-scaling-stroke; transition:opacity .15s ease; }
.site-marker.is-active .site-halo { filter:drop-shadow(0 2px 5px rgba(0,0,0,.35)); }
.site-marker.is-dimmed { opacity:.2; }
.site-hit { fill:rgba(0,0,0,0); stroke:none; pointer-events:all; }

.map-controls { position:absolute; left:16px; top:16px; z-index:8; display:grid; overflow:hidden; border:1px solid rgba(30,40,38,.15); border-radius:12px; box-shadow:0 6px 18px rgba(0,0,0,.12); }
.map-controls button { width:42px; height:40px; border:0; background:rgba(255,255,255,.96); font-size:22px; cursor:pointer; }
.map-controls button + button { border-top:1px solid #dedbd2; }
.map-controls button:hover { background:#f2efe7; }
.zoom-indicator { position:absolute; left:17px; top:105px; z-index:8; background:rgba(255,255,255,.9); border-radius:9px; padding:5px 8px; font-size:10px; font-weight:800; box-shadow:0 2px 7px rgba(0,0,0,.08); }
.map-credit { position:absolute; left:12px; bottom:9px; z-index:6; padding:4px 7px; border-radius:7px; color:#3b4442; background:rgba(255,255,255,.78); font-size:9px; backdrop-filter:blur(4px); }
.map-tooltip { position:absolute; z-index:30; pointer-events:none; opacity:0; transform:translate(12px,12px); max-width:260px; padding:7px 9px; border-radius:9px; background:rgba(23,32,31,.92); color:#fff; font-size:11px; line-height:1.25; box-shadow:0 4px 13px rgba(0,0,0,.22); transition:opacity .1s; }
.map-tooltip.is-visible { opacity:1; }

.info-panel {
  position:absolute; z-index:12; right:18px; top:18px; width:min(390px, calc(100% - 90px)); max-height:calc(100% - 36px); overflow:auto;
  background:var(--panel); border:1px solid rgba(50,60,56,.16); border-radius:var(--radius); box-shadow:var(--shadow); backdrop-filter:blur(10px);
}
.info-inner { padding:18px 18px 17px; }
.info-kicker { display:flex; align-items:center; gap:8px; color:#7c6e61; font-size:10px; font-weight:900; letter-spacing:.13em; text-transform:uppercase; }
.info-dot { width:9px; height:9px; border-radius:50%; flex:none; background:var(--accent,#6a5a4a); }
.info-panel h3 { margin:7px 0 5px; font-size:23px; line-height:1.12; letter-spacing:-.025em; }
.info-subtitle { margin:0 0 12px; color:#68726f; font-size:12px; line-height:1.42; }
.info-summary { margin:10px 0 14px; font-size:13px; line-height:1.55; color:#36413f; }
.info-grid { display:grid; grid-template-columns:88px 1fr; gap:7px 10px; margin:13px 0; padding:12px 0; border-top:1px solid #e6e2d8; border-bottom:1px solid #e6e2d8; font-size:11px; line-height:1.38; }
.info-grid dt { color:#7b8581; font-weight:700; }
.info-grid dd { margin:0; color:#303b38; }
.route-chip-row { display:flex; flex-wrap:wrap; gap:6px; margin:12px 0; }
.route-chip { padding:5px 8px; border-radius:999px; background:#f0ede6; font-size:10px; font-weight:750; }
.route-site-mini { margin:12px 0 0; padding:0; list-style:none; display:grid; grid-template-columns:1fr 1fr; gap:5px; }
.route-site-mini button { border:0; background:#f3f0e8; border-radius:8px; padding:7px 8px; text-align:left; font-size:10px; cursor:pointer; color:#37413f; }
.route-site-mini button:hover { background:#e9e4d9; }
.media-title { margin:14px 0 8px; font-size:11px; color:#7b8581; font-weight:800; text-transform:uppercase; letter-spacing:.08em; }
.media-links { display:grid; grid-template-columns:1fr 1fr; gap:7px; }
.media-link { min-height:37px; display:flex; align-items:center; gap:7px; padding:8px 9px; border:1px solid #ddd8ce; border-radius:10px; text-decoration:none; color:#283330; background:#fff; font-size:11px; font-weight:700; }
.media-link:hover { border-color:#aba397; background:#faf8f3; transform:translateY(-1px); }
.primary-link { grid-column:1/-1; background:#222e2b; color:#fff; border-color:#222e2b; justify-content:center; }
.primary-link:hover { background:#31403c; color:#fff; border-color:#31403c; }
.info-empty { padding:20px; }
.info-empty h3 { margin:3px 0 8px; }
.info-empty p { margin:0; color:#68726f; line-height:1.5; font-size:12px; }


.info-panel.is-hidden { display:none; }
.info-close {
  display:none; position:absolute; right:10px; top:10px; z-index:3; width:34px; height:34px; border:0;
  border-radius:50%; background:rgba(242,239,231,.95); color:#283330; font-size:20px; line-height:1; cursor:pointer;
}

@media (max-width: 900px) {
  :root { --topbar-h:62px; }
  .topbar { padding:0 10px 0 13px; }
  .brand-kicker { display:none; }
  .brand-block h1 { font-size:18px; }
  .text-button { display:none; }
  .icon-button { width:40px; min-height:38px; }

  .main-layout {
    grid-template-columns:1fr;
    grid-template-rows:auto minmax(0,1fr);
    min-height:0;
  }
  .sidebar {
    min-height:0;
    max-height:min(44dvh, 390px);
    overflow:auto;
    -webkit-overflow-scrolling:touch;
    border-right:0;
    border-bottom:1px solid var(--line);
    padding:8px 9px 8px;
    background:#fbfaf6;
  }
  .sidebar-head { padding:0 3px 6px; align-items:center; }
  .sidebar h2 { font-size:16px; margin-top:2px; }
  .eyebrow, .site-total, .sidebar-note { display:none; }
  .search-box { height:36px; margin:0 1px 7px; position:sticky; top:0; z-index:4; }

  .route-list { display:grid; gap:6px; overflow:visible; padding:0 0 2px; }
  .route-card { width:100%; min-width:0; }
  .route-card.is-dimmed { opacity:.68; }
  .route-head { min-height:46px; padding:7px 9px 7px 7px; grid-template-columns:5px 1fr auto; }
  .route-title strong { font-size:13px; }
  .route-title small { display:none; }
  .route-count { width:28px; height:28px; }

  /* Mobile accordion: danh sách điểm chỉ hiện khi hành trình đang mở. */
  .route-card .site-list { display:none; padding:0 8px 8px 19px; }
  .route-card.is-open .site-list,
  .route-card.has-search-match .site-list { display:grid; }
  .site-list button { min-height:40px; padding:8px 8px; font-size:12px; border-radius:9px; }

  .map-stage { min-height:0; }
  .map-controls { left:10px; top:10px; }
  .map-controls button { width:44px; height:44px; }
  .zoom-indicator { left:11px; top:105px; font-size:10px; }
  .map-credit { display:none; }
  .map-tooltip { display:none; }

  .info-panel {
    right:8px; left:8px; top:auto;
    bottom:calc(8px + env(safe-area-inset-bottom, 0px));
    width:auto;
    max-height:min(48dvh, 430px);
    border-radius:17px 17px 13px 13px;
    -webkit-overflow-scrolling:touch;
  }
  .info-panel.is-hidden { display:none; }
  .info-inner { padding:14px 14px calc(14px + env(safe-area-inset-bottom, 0px)); }
  .info-close { display:grid; place-items:center; }
  .info-panel h3 { font-size:19px; padding-right:34px; }
  .info-summary { font-size:12px; margin:7px 0 10px; }
  .info-grid { grid-template-columns:72px 1fr; gap:6px 8px; font-size:11px; margin:9px 0; padding:9px 0; }
  .route-site-mini { display:none; }
  .media-links { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .media-link { min-height:40px; font-size:10px; padding:8px; }
  .primary-link { grid-column:1/-1; }
}

@media (max-width: 560px) {
  :root { --topbar-h:58px; }
  .brand-block h1 { font-size:17px; }
  .sidebar { max-height:min(47dvh, 410px); padding:7px; }
  .search-box { height:34px; }
  .route-head { min-height:44px; }
  .site-list button { min-height:39px; }
  .info-panel { max-height:min(50dvh, 440px); }
  .media-links { grid-template-columns:1fr 1fr; }
}

@media (max-width: 390px) {
  .brand-block h1 { font-size:16px; }
  .sidebar { max-height:48dvh; }
  .info-panel { left:5px; right:5px; bottom:calc(5px + env(safe-area-inset-bottom, 0px)); }
}
.map-controls button:disabled { cursor:default; opacity:.42; background:rgba(255,255,255,.9); }


/* =========================================================
   v2.5 — MAP FIRST MOBILE
   Khi chọn một di tích: ẩn sidebar, ưu tiên bản đồ, hiển thị
   bottom sheet thu gọn và thanh điều hướng nổi.
   ========================================================= */
.mobile-context { display:none; }
.sheet-grip, .sheet-expand, .sheet-collapse { display:none; }

@media (max-width: 900px) {
  .app-shell.is-mobile-site .main-layout {
    grid-template-rows:minmax(0,1fr);
  }
  .app-shell.is-mobile-site .sidebar {
    display:none;
  }

  .mobile-context {
    position:absolute;
    z-index:15;
    left:64px;
    right:8px;
    top:8px;
    min-height:46px;
    display:none;
    grid-template-columns:auto minmax(0,1fr) 42px;
    align-items:center;
    gap:7px;
    padding:5px 6px 5px 7px;
    background:rgba(255,255,255,.95);
    border:1px solid rgba(50,60,56,.16);
    border-radius:14px;
    box-shadow:0 7px 22px rgba(31,42,39,.16);
    backdrop-filter:blur(9px);
  }
  .mobile-context.is-visible { display:grid; }
  .mobile-context-back,
  .mobile-context-locate {
    min-height:36px;
    border:0;
    border-radius:10px;
    background:#f3f0e8;
    color:#27312f;
    font-weight:800;
  }
  .mobile-context-back { padding:0 9px; font-size:11px; white-space:nowrap; }
  .mobile-context-locate { width:38px; font-size:20px; }
  .mobile-context-copy {
    min-width:0;
    display:grid;
    gap:1px;
  }
  .mobile-context-copy span,
  .mobile-context-copy strong {
    overflow:hidden;
    white-space:nowrap;
    text-overflow:ellipsis;
  }
  .mobile-context-copy span { font-size:9px; color:#7b8581; }
  .mobile-context-copy strong { font-size:12px; color:#202a27; }

  .app-shell.is-mobile-site .map-controls { top:62px; }
  .app-shell.is-mobile-site .zoom-indicator { top:157px; }

  .app-shell.is-mobile-site .info-panel {
    display:block;
  }

  .info-panel[data-sheet-state="peek"] {
    height:132px;
    max-height:132px;
    overflow:hidden;
  }
  .info-panel[data-sheet-state="half"] {
    height:min(49dvh, 440px);
    max-height:min(49dvh, 440px);
    overflow:auto;
  }
  .info-panel[data-sheet-state="full"] {
    height:min(82dvh, 720px);
    max-height:min(82dvh, 720px);
    overflow:auto;
  }

  .site-sheet {
    position:relative;
    min-height:100%;
    padding-top:10px;
  }
  .sheet-grip {
    width:64px;
    height:22px;
    margin:-5px auto 0;
    border:0;
    background:transparent;
    display:grid;
    place-items:center;
    touch-action:none;
    cursor:ns-resize;
  }
  .sheet-grip span {
    display:block;
    width:38px;
    height:5px;
    border-radius:99px;
    background:#cbc7bd;
  }

  .sheet-head { padding-right:34px; }
  .sheet-head .info-kicker {
    overflow:hidden;
    white-space:nowrap;
    text-overflow:ellipsis;
  }
  .sheet-head h3 {
    margin-top:5px;
    margin-bottom:2px;
    line-height:1.08;
  }
  .sheet-head .info-subtitle {
    margin-bottom:0;
    overflow:hidden;
    white-space:nowrap;
    text-overflow:ellipsis;
  }

  .sheet-peek-actions {
    display:flex;
    justify-content:flex-end;
    margin-top:7px;
  }
  .sheet-expand,
  .sheet-collapse {
    border:0;
    border-radius:10px;
    background:#f0ede5;
    color:#26312e;
    font-weight:800;
    font-size:11px;
    min-height:34px;
    padding:0 11px;
  }
  .sheet-expand { display:inline-flex; align-items:center; }
  .sheet-collapse {
    display:flex;
    align-items:center;
    justify-content:center;
    width:100%;
    margin-top:12px;
  }

  .info-panel[data-sheet-state="peek"] .sheet-detail {
    display:none;
  }
  .info-panel[data-sheet-state="half"] .sheet-detail,
  .info-panel[data-sheet-state="full"] .sheet-detail {
    display:block;
  }
  .info-panel[data-sheet-state="half"] .sheet-peek-actions,
  .info-panel[data-sheet-state="full"] .sheet-peek-actions {
    margin-top:7px;
  }
  .info-panel[data-sheet-state="full"] .sheet-detail {
    padding-bottom:calc(10px + env(safe-area-inset-bottom,0px));
  }

  .app-shell.is-mobile-site .map-viewport {
    background:#e8e5dc;
  }
}

@media (max-width: 560px) {
  .info-panel[data-sheet-state="peek"] {
    height:128px;
    max-height:128px;
  }
  .mobile-context { left:61px; }
  .mobile-context-back { padding:0 7px; }
}

@media (max-width: 390px) {
  .mobile-context {
    left:58px;
    right:5px;
    top:5px;
    gap:5px;
  }
  .mobile-context-back { font-size:10px; padding:0 6px; }
  .mobile-context-copy span { display:none; }
  .info-panel[data-sheet-state="peek"] {
    height:124px;
    max-height:124px;
  }
}
