:root {
  --bg: #0f0f12;
  --card: #16161a;
  --text: #e6e6e9;
  --muted: #9aa0a6;
  --accent: #5aa7ff;
  --muted-accent: #487bb4;
  /* Subtle, dark, muted accent used for radial background glow */
  --bg-accent-muted: rgba(72, 123, 180, 0.14);
  --border: #2a2a31;
  --border-strong: #252532;
  --divider: #23232a;
  --hover: #1b1b22;
  --hover-strong: #2a2a37;
  --text-on-accent: #101015;
  --accent-border: #3e87db;
  --control-border: #3a3a49;
  --modal-backdrop: rgba(0,0,0,0.6);
  --shadow-rgb: 0,0,0;
  --image-bg: #0b0b12;
  --text-soft: #cfd3d8;
  --error: #ffb4b4;
  --favicon-bg: var(--divider);
}

/* Light theme overrides (manual) */
[data-theme="light"] {
  --bg: #f7f9fc;
  --card: #ffffff;
  --text: #101015;
  --muted: #5f6670;
  --accent: #5aa7ff;
  --muted-accent: #487bb4;
  --bg-accent-muted: rgba(72, 123, 180, 0.10);
  --border: #d6dae3;
  --border-strong: #c8ced9;
  --divider: #e6e8ee;
  --hover: #eef2f8;
  --hover-strong: #e6ecf6;
  --text-on-accent: #101015;
  --accent-border: #4891e0;
  --control-border: #cbd5e1;
  --modal-backdrop: rgba(0,0,0,0.5);
  --shadow-rgb: 0,0,0;
  --image-bg: #f6f8fe;
  --text-soft: #4a5562;
  --error: #d64545;
  --favicon-bg: var(--divider);
}

/* Light theme overrides (system preference, unless manually set to dark) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f9fc;
    --card: #ffffff;
    --text: #101015;
    --muted: #5f6670;
    --accent: #5aa7ff;
    --muted-accent: #487bb4;
    --bg-accent-muted: rgba(72, 123, 180, 0.10);
    --border: #d6dae3;
    --border-strong: #c8ced9;
    --divider: #e6e8ee;
    --hover: #eef2f8;
    --hover-strong: #e6ecf6;
    --text-on-accent: #101015;
    --accent-border: #4891e0;
    --control-border: #cbd5e1;
    --modal-backdrop: rgba(0,0,0,0.5);
    --shadow-rgb: 0,0,0;
    --image-bg: #f6f8fe;
    --text-soft: #4a5562;
    --error: #d64545;
    --favicon-bg: var(--divider);
  }
}
/* Desktop: keep tabs below the search bar, matching mobile */
.site-header { flex-wrap: wrap; row-gap: 8px; }
.search-form.inline { flex: 1 1 auto; }
.tabs { margin-left: 0; align-self: auto; flex-basis: 100%; justify-content: flex-start; overflow-x: scroll; scrollbar-width: none; }

* { box-sizing: border-box; }
body { margin:0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial; 
  background: var(--bg); 
  color: var(--text); }

/* Home theme toggle */
.theme-toggle-wrap { position: fixed; top: 12px; right: 12px; z-index: 30; }
.theme-toggle { display:flex; align-items:center; justify-content:center; width:36px; height:36px; border-radius: 18px; background: var(--card); color: var(--text); border: 1px solid var(--control-border); cursor: pointer; }
.theme-toggle:hover { background: var(--hover); }
.theme-toggle svg { width: 18px; height: 18px; }

header.hidden { display: none; }
.search-form.hidden { display: none; }
.site-header { display:flex; align-items:center; gap:16px; padding:16px 20px; border-bottom: 1px solid var(--divider); position: sticky; top:0; background: var(--bg); z-index: 10; }
.logo { font-weight: 700; display:inline-flex; align-items:center; text-decoration:none; }
.logo-img { height: 30px; display:block; margin-bottom: -6px; margin-right: 10px; }
.tabs { display:flex; align-items:flex-end; gap:10px; margin-left:auto; align-self: flex-end; background: var(--card); border-radius:10px; padding: 0 8px;  margin-bottom: -16px; background: transparent; margin-top: -10px;}
.tab { position: relative; padding:10px 12px; border-radius: 0px; border: none; text-decoration:none; color: var(--text); background: transparent; border-bottom: 2px solid transparent; width: fit-content; text-wrap: nowrap; }
.tab:hover { background: var(--hover); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.home { display:flex; align-items:center; justify-content:center; height: calc(100vh - 80px); padding: 20px; }
.home-hero { display:flex; flex-direction: column; align-items:center; gap: 12px; }
.home-search { width: 100%; display:flex; justify-content:center; }
.search-form { display:flex; flex-direction:column; gap:0px; width: min(700px, 100%); position: relative; }
.search-form.inline { flex-direction: row; gap:0px; width: min(80dvw, 1000px); }
/* Home-specific overrides removed; rely on wrapper centering to avoid altering search form */
.input-wrap { position: relative; flex: 1; }
.search-form input { padding:12px 14px; border-radius: 8px; border:1px solid var(--border); background: var(--card); color: var(--text); font-size: 16px; width: 100%; -webkit-appearance: none; appearance: none; }
.search-form input:focus, .search-form input:focus-visible { outline: none; box-shadow: none; }
.home .logo-img{
  height: 100px;
  margin-bottom: 22px;
}
.search-form input { 
  border: 0px;
  border: 2px solid var(--border-strong);
  border-radius: 8px 0px 0px 8px;
  border-right: none;
 }

.input-wrap::after {
  content: '';
  position: absolute;
  left: 10px;
  right: 0px;
  bottom: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 220ms ease;
  pointer-events: none;
}
.input-wrap:focus-within::after { transform: scaleX(1); }
.search-form button { 
  display:inline-flex; 
  align-items:center; 
  gap:8px; 
  padding:12px 16px; 
  background: var(--accent); 
  color: var(--text-on-accent); 
  font-weight: 600; 
  cursor: pointer; 
  border-radius: 0px 8px 8px 0px; 
  border: 2px solid var(--accent-border);
  border-left: none;   
}
.search-form button:hover { filter: brightness(1.05); }
/* Icon inside submit button */
.search-form button .btn-icon { width:18px; height:18px; flex:0 0 18px; }
.search-form button .btn-text { display:inline; }

.suggestions { position:absolute; top: calc(100% + 4px); left:0; right:0; background: var(--card); border:1px solid var(--border); border-radius:8px; overflow:hidden; z-index: 20; }
.suggestions.hidden { display:none; }
.suggestions.loading { display:block; }
.suggestion-item { padding:10px 12px; border-bottom: 1px solid var(--divider); cursor: pointer; }
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: var(--hover); }

/* Route start input beneath header search on maps tab */
/* Navigation open button */
.nav-button { display:inline-flex; align-items:center; gap:8px; padding:10px 14px; background: var(--accent); color: var(--text-on-accent); font-weight:600; border: 2px solid var(--accent-border); border-radius:8px; cursor:pointer; }
.nav-button:hover { filter: brightness(1.05); }
.nav-button .btn-icon { width:18px; height:18px; flex:0 0 18px; }

/* Maps side panel visibility and layout */
.map-sidebar.hidden { display: none; }
.map-sidebar .close-panel { margin-left: auto; background: transparent; border: 1px solid var(--control-border); color: var(--text); border-radius: 6px; padding: 6px 8px; cursor: pointer; 
  padding: 0;
  align-items: center;
  justify-content: center;
  display: flex;
  width: 34px;
  height: 34px;
}
.map-sidebar .close-panel:hover { background: var(--hover); }
.map-sidebar .close-panel svg{
  width: 18px;
  height: 18px;
}
.nav-section { padding: 12px 14px; display: grid; gap: 8px; border-bottom: 1px solid var(--border-strong); }
.nav-type-switch { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.nav-type-option { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border: 1px solid var(--control-border); border-radius: 8px; background: var(--card); color: var(--text); cursor: pointer; user-select: none; }
.nav-type-option:hover { background: var(--hover); }
.nav-type-option.active { background: var(--accent-weak); border-color: var(--accent); color: var(--text); }
.nav-type-option img { display: inline-block; }
.nav-label { color: var(--muted); font-size: 12px; }
.nav-section .input-wrap { position: relative; }
.nav-section input { padding:12px 14px; border-radius: 8px; border: 2px solid var(--border-strong); background: var(--card); color: var(--text); font-size: 16px; width: 100%; -webkit-appearance: none; appearance: none; }
.nav-section .input-wrap::after { content: ''; position: absolute; left: 10px; right: 0; bottom: 0; height: 2px; background: var(--accent); border-radius: 2px; transform: scaleX(0); transform-origin: left center; transition: transform 220ms ease; pointer-events: none; }
.nav-section .input-wrap:focus-within::after { transform: scaleX(1); }

/* Sidepanel typeahead suggestions styling */
.map-sidebar .suggestions { list-style: none; margin: 4px 0 0; padding: 0; box-shadow: 0 8px 18px rgba(var(--shadow-rgb), 0.35); max-height: 240px; overflow-y: auto; border: 1px solid var(--control-border); }
.map-sidebar .suggestions li { padding: 8px 10px; }
.map-sidebar .suggestions li:hover { background: var(--hover-strong); }
.map-sidebar .suggestions a { display: block; color: var(--text); text-decoration: none; }
.map-sidebar .suggestions .suggestion-secondary { color: var(--muted); font-size: 12px; }
.map-sidebar .suggestions .suggestion-business { color: var(--muted); font-size: 12px; }
.map-sidebar .suggestions [aria-busy="true"] { padding: 10px 12px; }

/* Typeahead loading indicator */
.typeahead-dots { display:flex; align-items:center; justify-content:center; gap:6px; padding:10px 12px; }
.typeahead-dot { width:5px; height:5px; background: var(--muted); border-radius:50%; opacity:0.4; animation: aiDots 1.2s infinite ease-in-out; }
.typeahead-dot:nth-child(2) { animation-delay: 0.2s; }
.typeahead-dot:nth-child(3) { animation-delay: 0.4s; }

.results { padding: 20px; max-width: 100%; overflow-x: hidden; }
.search-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; align-items: start; }
.search-main { display: block; max-width: 100%; min-width: 0; }
.results-row { display: grid; grid-template-columns: minmax(0, 1fr) max(360px, 30dvw); gap: 16px; align-items: start; width: 100%; min-width: 0; }
.side-panel { height: 100%; display: flex; flex-direction: column; gap: 12px; }
.side-panel.hidden { display: none; }
.chart-card.hidden { display: none; }
.panel-card { background: var(--card); border:1px solid var(--border-strong); border-radius:10px; overflow:hidden; }

/* Asset price emphasis */
.asset-price {
  font-weight: 700;
  font-size: 24px;
  color: var(--text);
}

/* Asset logo and separator */
.asset-price-row .sep { background: var(--border); width: 1px; height: 24px; }
.asset-logo { width: 24px; height: 24px; border-radius: 50%; object-fit: contain; background: var(--card-strong); }
.changes-title { color: var(--muted); font-size: 13px; font-weight: 600; margin-top: 8px; }

/* FX converter fields */
.fx-info .fx-field { display: flex; flex-direction: column; gap: 6px; }
.fx-code { font-weight: 600; color: var(--text); font-size: 13px; letter-spacing: 0.01em; }
.fx-amount {
  font-weight: 700;
  font-size: 24px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  padding-right: 44px; /* room for custom stepper */
}
.fx-amount:focus { border-color: var(--accent); }
.fx-amount::placeholder { color: var(--muted); }
/* FX swap button in header */
.fx-title-row { display: flex; align-items: center; gap: 8px; }
.fx-swap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: color-mix(in oklab, var(--card) 70%, var(--card-strong) 30%);
  color: var(--text);
  cursor: pointer;
}
.fx-swap:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.fx-swap svg { width: 16px; height: 16px; display: block; }
/* Hide native number spinners; we provide themed ones */
.fx-amount::-webkit-outer-spin-button,
.fx-amount::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.fx-amount[type="number"] { -moz-appearance: textfield; }

/* Themed stepper overlay */
.fx-amount-wrap { position: relative; }
.fx-stepper {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.fx-stepper button {
  background: color-mix(in oklab, var(--card) 70%, var(--card-strong) 30%);
  border: 1px solid var(--border-strong);
  color: var(--text);
  width: 28px;
  height: 18px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.fx-stepper button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.fx-stepper button:active { transform: translateY(0.5px); }
.side-panel .map-card { order: 1; }
.side-panel .wiki-card { order: 2; }
.side-panel .wiki-card.top { order: 0; }
.side-panel .video-card { order: 3; }
.panel-header { padding: 12px 14px; border-bottom:1px solid var(--border-strong); font-weight:700; display:flex; align-items:center; justify-content: space-between; gap: 10px; }
.panel-body { padding: 12px 14px; }
.panel-footer { padding: 10px 14px; border-top:1px solid var(--border-strong); display:flex; align-items:center; justify-content: flex-end; }
.panel-link { color: var(--muted-accent); font-weight: 600; text-decoration: none; }
.panel-link:hover { text-decoration: underline; }

/* Range tabs in panel headers, styled like header tabs */
.range-tabs { display:flex; align-items:flex-end; gap:10px; margin: 0; background: transparent; padding: 0; transform: translateY(14px); margin-top: -12px;}
.range-tabs .tab { padding:10px 12px; padding-bottom: 22px; }
/* Push range tabs to the right side of header on wider screens */
.panel-header .range-tabs { margin-left: auto; flex-basis: auto; }

/* Responsive: stack range tabs below title/swap on mobile */
@media (max-width: 640px) {
  .chart-card .panel-header { flex-direction: column; align-items: flex-start; }
  .chart-card .fx-title-row { width: 100%; display:flex; align-items:center; justify-content: space-between; }
  .chart-card .range-tabs { margin-left: 0; width: 100%; padding-top: 6px; flex-basis: 100%;  }
}

/* Map preview card */
.map-card .map-preview { width: 100%; height: 200px; border-top:1px solid var(--border-strong); border-bottom:1px solid var(--border-strong); background: #aad3df; }
.map-card .address-line { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* Directions list in navigation panel */
.detail-directions { margin-top: 4px; }
.directions-list { list-style: none; margin: 0; padding: 0; }
.dir-item { padding: 8px 0; border-bottom: 1px solid var(--divider); }
.dir-item:hover { background: var(--hover); }
.dir-item:hover .dir-icon-svg circle,
.dir-item.hover .dir-icon-svg circle { fill: var(--accent) !important; opacity: 1 !important; }
.dir-sep { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.dir-line { flex: 1; border-top: 1px solid var(--divider); height: 0; }
.dir-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.dir-content { display: flex; align-items: center; gap: 10px; padding: 8px 2px 2px; }
.dir-icon { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; color: var(--text); }
.dir-icon-svg { display: block; width: 22px; height: 22px; }
.dir-text { font-size: 15px; font-weight: 600; color: var(--text); }

/* Map step icons, matching directions icon colors */
.dir-map-icon { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; color: var(--text); }
.dir-map-icon svg { display: block; width: 22px; height: 22px; }
.dir-map-icon.hover svg circle { fill: var(--muted-accent) !important; opacity: 1; }
.dir-map-icon.hover { transform: scale(1.5); transform-origin: center center; }
.dir-map-icon svg circle { fill: var(--favicon-bg) !important; opacity: 0.5; }

/* Wikipedia card */
.wiki-summary { color: var(--text-soft); line-height: 1.5; }
.wiki-thumb { width: 100%; max-height: 300px; object-fit: contain; border-radius: 8px; border: 1px solid var(--border-strong); margin-bottom: 8px; }

/* YouTube card */
.video-frame { width: 100%; border: none; border-radius: 8px; overflow: hidden; aspect-ratio: 1.6; }
.video-meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.ai-summary { border-radius: 10px; padding: 16px; margin-bottom: 16px; overflow: hidden; transition: max-height 260ms ease, margin-bottom 260ms ease; }
.ai-summary.hidden { display: none; }
.ai-summary.compact { margin-bottom: 8px; }
.ai-summary-title { font-weight:700; margin-bottom: 8px; }
.ai-summary-content { color: var(--text); line-height: 1.5; overflow-wrap: anywhere; word-break: break-word; }
/* Clamp AI summary to three lines by default */
.ai-summary-content { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ai-summary-content.expanded { display: block; -webkit-line-clamp: initial; overflow: visible; min-height: 0; }
/* Loading dots state keeps same height as clamped view */
.ai-summary-content.loading { display:flex; align-items:center; justify-content:center; min-height: 4.5em; }
.ai-summary-dots { display:inline-flex; gap:6px; }
.ai-summary-dot { width:6px; height:6px; background: var(--muted); border-radius:50%; opacity:0.4; animation: aiDots 1.2s infinite ease-in-out; }
.ai-summary-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-summary-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes aiDots { 0%, 80%, 100% { opacity:0.3; transform: translateY(0); } 40% { opacity:1; transform: translateY(-2px); } }

.search-results { display:flex; flex-direction: column; gap: 18px; min-width: 0; }
.image-results { border-radius: 10px; margin-bottom: 16px; overflow: hidden; transition: max-height 260ms ease, opacity 200ms ease, margin-bottom 260ms ease; max-height: 160px; }
.image-results.collapsed { max-height: 0; opacity: 0; margin-bottom: 0; }
.youtube-results { border-radius: 10px; margin-bottom: 16px; overflow: hidden; transition: max-height 260ms ease, opacity 200ms ease, margin-bottom 260ms ease; max-height: 120px; }
.youtube-results.collapsed { max-height: 0; opacity: 0; margin-bottom: 0; }
.youtube-strip { display:flex; align-items:center; gap:16px; overflow:hidden; position: relative; min-height: 44px; overflow-x: scroll; scrollbar-width: none; }
.youtube-loading { position: absolute; inset:0; display:flex; align-items:center; justify-content:center; pointer-events:none; }
.youtube-loading.hidden { display:none; }
.youtube-pill { 
  display:inline-flex; 
  align-items:left; 
  gap:8px; 
  padding:8px 12px; 
  border-radius:10px; 
  border:1px solid var(--border-strong); 
  background: var(--card); 
  color: var(--text); 
  text-decoration:none; 
  white-space: nowrap; 
  max-width: 100%; 
  overflow: hidden; 
  text-overflow: ellipsis; 
  width: fit-content; 
  transition: width 0.75s ease, padding 0.25s ease, gap 0.25s ease, max-width 0.75s ease;  
  min-width: 34px;
}
.youtube-pill:hover { outline: 1px solid var(--border); }
.youtube-icon { width:16px; height:16px; flex:0 0 16px; }
.youtube-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Dynamic host label used by chat search attempt pills */
.youtube-pill .pill-host { font-size: 12px; opacity: 0.85; overflow: hidden; text-overflow: ellipsis; }
/* Compact square pill state after fetch completes */
.youtube-pill.compact { gap: 0; padding: 8px; justify-content: left; }
.youtube-pill.compact .pill-host { display: none; }
.image-title { font-weight: 700; margin-bottom: 8px; }
.image-strip { display:flex; flex-wrap: nowrap; gap: 16px; overflow: hidden; padding-bottom: 2px; -ms-overflow-style: none; scrollbar-width: none; position: relative; min-height: 120px; overflow-x: scroll; }
.image-strip::-webkit-scrollbar { display: none; }
.image-card, .image-more { flex: 1 1 180px; min-width: 140px; height: 120px; border-radius: 10px; overflow: hidden; border:1px solid var(--border-strong); background: var(--card); position: relative; }
.image-card img { width: 100%; height: 100%; object-fit: cover; display:block; }
.image-card:hover { outline: 1px solid var(--border); }
.image-more { display:flex; align-items:center; justify-content:center; color: var(--muted-accent); font-weight: 600; text-decoration: none; }
.image-more:hover { filter: brightness(1.05); }
.images-page { border-radius: 10px; }

/* Chat page */
.chat-page { padding: 20px;   height: calc(100dvh - 114px); display:grid; grid-template-rows: 60px auto; }
.chat-container { display:flex; flex-direction: column; gap: 12px; height: 100%; overflow: hidden; grid-row: 2; }
.chat-messages { display:flex; flex-direction: column; gap: 10px; padding: 12px; border:1px solid var(--border-strong); border-radius: 10px; background: var(--card); flex: 1; min-height: 0; overflow-y: auto; }
.chat-message { display:flex; flex-direction: column; gap: 4px; align-items:flex-start; }
.message-title { font-size: 12px; color: var(--muted); font-weight: 600; }
.chat-message.user .message-title { align-self: flex-end; }
.chat-bubble { padding: 10px 12px; border-radius: 10px; background: var(--hover); color: var(--text); max-width: 80%; }
.chat-bubble.assistant { background: var(--bg-accent-muted); border: 1px solid var(--border-strong); }
.chat-bubble.user { background: var(--hover-strong); margin-left: auto; }
.chat-input { display:flex; gap: 8px; }
.chat-input textarea { flex: 1; min-height: 44px; padding: 10px 12px; border:1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); resize: vertical; }
.chat-input button { display:inline-flex; align-items:center; gap:8px; padding:12px 16px; background: var(--accent); color: var(--text-on-accent); font-weight: 600; cursor: pointer; border-radius: 8px; border: 2px solid var(--accent-border); }
.chat-input button:hover { filter: brightness(1.05); }
/* Markdown rendering inside assistant bubbles */
.chat-bubble.markdown { white-space: normal; }
.chat-bubble.markdown h1,
.chat-bubble.markdown h2,
.chat-bubble.markdown h3,
.chat-bubble.markdown h4,
.chat-bubble.markdown h5,
.chat-bubble.markdown h6 { margin: 8px 0 4px; font-weight: 600; }
.chat-bubble.markdown p { margin: 6px 0; }
.chat-bubble.markdown ul,
.chat-bubble.markdown ol { margin: 6px 0 6px 18px; }
.chat-bubble.markdown li { margin: 3px 0; }
.chat-bubble.markdown a { color: var(--accent); text-decoration: underline; }
.chat-bubble.markdown code {
  background: var(--hover-strong);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
.chat-bubble.markdown pre {
  background: var(--hover-strong);
  border: 1px solid var(--border-strong);
  padding: 10px;
  border-radius: 6px;
  overflow: auto;
}
.chat-bubble.markdown pre code { background: transparent; padding: 0; }
.image-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; position: relative; min-height: 240px; }
.image-grid .image-card { height: 180px; }
.image-grid .image-card img { width:100%; height:100%; object-fit:cover; display:block; }
.image-grid .image-card:hover { outline:1px solid var(--border); }
.image-loading { position: absolute; inset: 0; display:flex; align-items:center; justify-content:center; pointer-events:none; }
.image-loading.hidden { display: none; }
.image-modal.hidden { display: none; }
.image-modal { position: fixed; inset: 0; z-index: 1000; }
.image-modal-backdrop { position: absolute; inset: 0; background: var(--modal-backdrop); opacity: 0; transition: opacity 240ms ease; }
.image-modal:not(.hidden) .image-modal-backdrop { opacity: 1; }
.image-modal-dialog { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: auto; max-width: 90vw; max-height: 90vh; background: var(--card); border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; box-shadow: 0 20px 60px rgba(var(--shadow-rgb), 0.5); }
.image-modal-toolbar { display:flex; align-items:center; justify-content: space-between; gap: 8px; padding: 10px; border-bottom: 1px solid var(--border-strong); background: var(--card); }
.image-modal-actions { display:flex; align-items:center; gap:8px; }
.image-modal-actions .btn-icon { background: var(--card); color: var(--text); border: 1px solid var(--control-border); border-radius: 6px; width: 34px; height: 34px; padding: 0; display:flex; align-items:center; justify-content:center; cursor: pointer; text-decoration: none; }
.image-modal-actions .btn-icon svg { width: 18px; height: 18px; }
.btn-link-icon { display:inline-flex; align-items:center; gap:6px; background: var(--card); color: var(--text); border: 1px solid var(--control-border); border-radius: 6px; padding: 6px 10px; text-decoration: none; }
.btn-link-icon svg { width:16px; height:16px; }
.image-modal-actions .btn-icon:hover { background: var(--hover-strong); }
 .image-modal-body { display:flex; align-items:center; justify-content:center; background: var(--image-bg); }
#img-modal-img { max-width: 100%; object-fit: contain; }
body.modal-open { overflow: hidden; }
.result-item { 
  background: var(--card);
  background-image: none;
  background-repeat: no-repeat;
  border:1px solid var(--border-strong); border-radius: 10px; padding: 14px; position:relative; overflow: hidden;
}
.result-item.has-glow {
  background-image: radial-gradient(800px circle at 14% 14%, var(--item-glow, transparent) 0%, transparent 60%);
}
.result-meta { position:absolute; right: 14px; top: 14px; color: var(--muted); font-size: 12px; }
.result-title { margin: 0 0 4px; font-size: 20px; display:flex; align-items:center; gap:8px; }
.result-title a { min-width: 0; overflow-wrap: anywhere; }
.result-title a { color: var(--accent); text-decoration: none; }
.result-title a:hover { text-decoration: underline; }
.favicon { width:16px; border-radius:4px; background: var(--favicon-bg); flex:0 0 16px; object-fit: contain; }
.result-url { color: var(--muted); font-size: 13px; margin-bottom: 8px; overflow-wrap: anywhere; word-break: break-word; }
.result-url .favicon { display: none; }
.result-desc { margin:0; color: var(--text-soft); line-height: 1.5; font-size: 14px; max-width: max(500px, 80%);}
.result-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.result-desc.expanded { display: block; -webkit-line-clamp: initial; overflow: visible; }
.result-desc.hidden-by-locale { display: none; }
.result-desc.hidden-by-locale.expanded { display: block; }

/* Side panel Wikipedia summary clamp */
.wiki-summary { display: -webkit-box; -webkit-line-clamp: 10; -webkit-box-orient: vertical; overflow: hidden; }
.wiki-summary.expanded { display: block; -webkit-line-clamp: initial; overflow: visible; }
.show-more { margin-top: 6px; background: none; border: none; color: var(--muted-accent); cursor: pointer; font-weight: 600; padding: 0; }
.show-more.hidden { display: none; }

.calculator-page { border-radius: 10px; }
.calculator-layout { display: grid; grid-template-columns: 0.8fr 1.2fr; gap: 16px; max-width: 1000px;
  margin-left: auto;
  margin-right: auto; }
.calculator-card { height:fit-content; background: var(--card); border:1px solid var(--border-strong); border-radius:10px; }
.calc-display { border-bottom:1px solid var(--divider); padding: 14px; background: var(--card); color: var(--text); }
.calc-expression { font-size: 18px; color: var(--text-soft); min-height: 28px; }
.calc-result { font-size: 24px; font-weight: 700; margin-top: 6px; }
.calc-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 12px; background: var(--card); }
.calc-btn { aspect-ratio: 3; background: var(--card); color: var(--text); border:1px solid var(--control-border); border-radius:8px; padding: 12px; font-weight:600; font-size: 20px; cursor:pointer; transition: background 140ms ease, box-shadow 140ms ease, transform 80ms ease; }
.calc-btn:hover { background: var(--hover-strong); }
.calc-btn.eq { background: var(--accent); color: var(--text-on-accent); border-color: var(--accent-border); }
.calc-btn.active { box-shadow: 0 0 0 2px var(--accent) inset; background: var(--hover-strong); transform: translateY(1px); }
.calculator-history { background: var(--card); border:1px solid var(--border-strong); border-radius:10px; overflow:hidden; }
.history-header { padding: 12px 14px; border-bottom:1px solid var(--border-strong); font-weight:700; display:flex; align-items:center; justify-content: space-between; gap: 10px; }
.history-header .clear-history { margin-left: auto; }
.history-list { list-style:none; margin:0; padding:0; }
.history-item { display:flex; align-items:center; gap:8px; padding:10px 14px; border-bottom:1px solid var(--divider); cursor:pointer; }
.history-item:last-child { border-bottom:none; }
.history-item:hover { background: var(--hover); }
.history-item .h-expr { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.history-item .h-res { font-weight: 600; }
.history-item .h-eq { margin-left: auto; }

@media (max-width: 768px) {
  .calculator-layout { grid-template-columns: 1fr; }
}

.no-results, .error { color: var(--error); }

/* Hide date on smaller screens to give title more room */
@media (max-width: 768px) {
  .search-layout { grid-template-columns: 1fr; }
  .results-row { grid-template-columns: 1fr; }
  .side-panel { display: none; }
  .logo { margin-left: auto; margin-right: auto; margin-bottom: 8px; }
  .result-meta, .result-date { display: none; }
  .result-title { font-size: 18px; }
  .result-title .favicon { display: none; }
  .result-url { display:flex; align-items:center; gap:6px; }
  .result-url .favicon { display: inline-block; }
  /* Icon-only submit button on mobile */
  .search-form button { padding:12px; min-width:72px; justify-content:center; }
  .search-form button .btn-text { display:none; }
  /* Move tabs below search bar and make full-width on mobile */
  .site-header { flex-wrap: wrap; row-gap: 8px; }
  .search-form.inline { order: 2; }
  .tabs { order: 3; width: 100%; margin-left: 0; justify-content: flex-start; margin-top: 0px;}
  .site-header .logo{
    visibility: hidden;
    display: none;
  }

.site-header{
  padding-top: 26px;
}
}

/* Additional mobile safeguard: collapse grid on touch devices */
@media (pointer: coarse) {
  .results-row { grid-template-columns: 1fr; }
  .side-panel { display: none; }
}

/* Maps page */
.maps-page { padding: 0px; }
/* Desktop: default full-width map; when panel-open, place sidebar to the right */
.maps-layout { display: grid; grid-template-columns: 1fr; gap: 0; align-items: stretch; }
.maps-layout.panel-open { grid-template-columns: minmax(0, 1fr) max(360px, 32dvw); }
.map-container { position: relative; width: 100%; height: calc(100dvh - 114px); border: 1px solid var(--border); border-radius: 0px; background: #aad3df; }
/* Map routing loading overlay */
.map-loading-overlay { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,0.25); z-index: 1300; pointer-events: none; }
.map-loading-pill { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--card); color: var(--muted); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: 0 2px 8px rgba(var(--shadow-rgb), 0.25); }
/* Floating action button for navigation on map */
.nav-button.map-fab { position: absolute; bottom: 16px; right: 16px; z-index: 1000; box-shadow: 0 4px 12px rgba(var(--shadow-rgb), 0.35); }
@media (max-width: 768px) {
  .nav-button.map-fab { bottom: 12px; right: 12px; margin-bottom: 8px; padding: 12px; }
}
.leaflet-bottom.leaflet-left { padding: 8px; }
.map-sidebar { height: calc(100dvh - 114px); border: 1px solid var(--border-strong); border-left: none; background: var(--card); color: var(--text); overflow: auto; }
.map-sidebar-header { padding: 12px 14px; border-bottom:1px solid var(--border-strong); font-weight:700; display: flex; align-items: center; position: sticky;
  top: 0px;
  background: var(--bg);
  z-index: 5;
}
.location-details-header{
   top: 58px;
  z-index: 4;
}
.location-details { padding: 12px 14px; display: grid; gap: 8px; }
.location-details.empty { color: var(--muted); }
.location-details .detail-line { display:flex; gap:8px; align-items:flex-start; }
.detail-label { min-width: 72px; color: var(--muted); }
.detail-value { word-break: break-word; }

@media (max-width: 900px) {
  .maps-layout { grid-template-columns: 1fr; }
  .maps-layout.panel-open { grid-template-columns: 1fr; }
  .map-sidebar { height: auto; max-height: 40vh; }
}

/* Leaflet minimal defaults to prevent corrupt tile layout if CDN CSS fails */
.leaflet-container { position: relative; overflow: hidden; }
.leaflet-pane, .leaflet-tile, .leaflet-marker-icon, .leaflet-marker-shadow, .leaflet-tile-container, .leaflet-overlay-pane svg { position: absolute; left: 0; top: 0; }
.leaflet-container img { max-width: none !important; }

/* Leaflet controls fallback */
.leaflet-control-container .leaflet-top, .leaflet-control-container .leaflet-bottom { position: absolute; z-index: 1000; }
.leaflet-control-container .leaflet-top { top: 0; }
.leaflet-control-container .leaflet-bottom { bottom: 0; }
.leaflet-control-container .leaflet-left { left: 0; }
.leaflet-control-container .leaflet-right { right: 0; }
.leaflet-control { pointer-events: auto; }
.leaflet-marker-pane { z-index: 650; }
.leaflet-popup-pane { z-index: 700; }
.leaflet-bar { box-shadow: 0 1px 5px rgba(var(--shadow-rgb), 0.4); border-radius: 6px; overflow: hidden; }
.leaflet-bar a { display:block; width: 32px; height: 32px; line-height: 32px; text-align:center; text-decoration:none; background: var(--card); color: var(--text); border: 1px solid var(--control-border); }
.leaflet-bar a:hover { background: var(--hover-strong); }
.leaflet-touch .leaflet-bar a { width: 40px; height: 40px; line-height: 40px; }
.leaflet-control-zoom-in { font-weight: 700; }
.leaflet-control-zoom-out { font-weight: 700; }
.leaflet-control-attribution { background: var(--card); color: var(--muted); padding: 2px 6px; border: 1px solid var(--control-border); border-radius: 4px; }
/* Hide Ukraine flag from Leaflet attribution */
.leaflet-attribution-flag {   visibility: hidden; margin-right: -15px;}
.leaflet-control-attribution a { color: var(--text) !; }
.leaflet-control-scale { background: var(--card); color: var(--text); border: 1px solid var(--control-border); border-radius: 4px; padding: 2px 6px; }
.leaflet-control-scale-line { border-top: 2px solid var(--text-soft); padding-top: 2px; }
.leaflet-control-geocoder { min-height: 40px; background: var(--card); color: var(--text); border: 1px solid var(--control-border); border-radius: 6px; position: relative; z-index: 1100; }
.leaflet-control-geocoder .leaflet-control-geocoder-form { display:flex; align-items:center; gap:6px; padding:4px; }
.leaflet-control-geocoder input { background: var(--card); color: var(--text); border: 1px solid var(--control-border); border-radius: 6px; padding: 6px 8px; min-width: 220px; }
.leaflet-control-geocoder .leaflet-control-geocoder-icon { width: 32px; height: 32px; background: var(--card); border: 1px solid var(--control-border); border-radius: 6px; }
.leaflet-control-geocoder-alternatives { height: fit-content; overflow-y: hidden; width: 100% !important; background: var(--card); color: var(--text); border: 1px solid var(--control-border); border-radius: 6px; margin-top: 4px; box-shadow: 0 8px 18px rgba(var(--shadow-rgb), 0.35); max-height: 240px; overflow-y: auto; }
.leaflet-control-geocoder-alternatives li { padding: 6px 8px; }
.leaflet-control-geocoder-alternatives li:hover { background: var(--hover-strong); }
.leaflet-control-geocoder-alternatives a { border: none; display: block; color: var(--text); text-decoration: none; }
.leaflet-control-geocoder-alternatives strong { font-weight: 600; }
.leaflet-control-geocoder-alternatives .suggestion-secondary { color: var(--muted); font-size: 12px; }
/* Optional business/location name line below address */
.leaflet-control-geocoder-alternatives .suggestion-business { color: var(--muted); font-size: 12px; }
/* --- Geocoder UI tweaks: remove icon, horizontal layout with zoom, spacing --- */
/* Lay out top-left controls horizontally and add a small gap */
.leaflet-top.leaflet-left {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 6px; /* tiny spacing between zoom and search */
  padding: 8px; /* small offset from map edges */
}
/* Neutralize default margins so gap controls spacing */
.leaflet-top .leaflet-control { margin-top: 0 !important; }
.leaflet-left .leaflet-control { margin-left: 0 !important; }
/* Ensure ordering: zoom first, then geocoder to its right */
.leaflet-control-zoom { order: 1; }
.leaflet-control-geocoder { order: 2; }

.leaflet-control-container .leaflet-top.leaflet-left{
  width: 100%;
}

.leaflet-control-geocoder {
  width: 100%;
  max-width: max(450px, 50dvw);
}

/* Hide the geocoder icon; show only the input */
.leaflet-control-geocoder .leaflet-control-geocoder-icon { display: none !important; }
.leaflet-control-geocoder .leaflet-control-geocoder-form { padding: 0px; height: 38px; width: 100%;}
.leaflet-control-geocoder .leaflet-control-geocoder-form input {
  height: 100%;
  line-height: 28px;
  padding: 0 8px;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--card);
  color: var(--text);
  width: 100%;
}
.leaflet-control-geocoder .leaflet-control-geocoder-form input::placeholder { color: var(--muted); }

/* Dark mode readability overrides */
[data-theme="dark"] .leaflet-control-geocoder .leaflet-control-geocoder-form input {
  background: #1f1f1f; /* slightly lighter than page bg for contrast */
  color: #f2f2f2;
  border-color: #3a3a3a;
}
[data-theme="dark"] .leaflet-control-geocoder .leaflet-control-geocoder-form input::placeholder { color: #bfc3c9; }
[data-theme="dark"] .leaflet-control-geocoder-alternatives {
  background: #1f1f1f;
  color: #f2f2f2;
  border-color: #3a3a3a;
}
[data-theme="dark"] .leaflet-control-geocoder-alternatives li:hover { background: #2a2a2a; }

/* Style Leaflet popup close like image modal close */
.leaflet-popup-close-button {
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  text-decoration: none;
  cursor: pointer;
  top: 6px;
  right: 6px;
  line-height: 34px; /* ensure the × centers if text */
  font-size: 18px;
}
.leaflet-popup-close-button:hover { background: var(--hover-strong); }
[data-theme="dark"] .leaflet-popup-close-button {
  background: #1f1f1f;
  color: #f2f2f2;
  border-color: #3a3a3a;
}

.results:has(.maps-page) {
  padding: 0px;
}

/* Side panel map card: emphasize exact street address line */
.map-card .address-street {
  margin-top: 8px;
  color: var(--text);
  font-weight: 600;
}

/* Side panel YouTube card: vertical pills under the main video */
.video-card .pill-list {
  display: flex;
  gap: 8px;
  flex-direction: column;
}
.video-card .youtube-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--card);
  color: var(--text);
  text-decoration: none;
  white-space: normal;
}
.video-card .youtube-icon { width: 16px; height: 16px; flex: 0 0 16px; }
.video-card .youtube-title { line-height: 1.3; }

#domain-strip .youtube-pill {
  min-width: fit-content;
}

/* Translation panel */
.translate-panel { border: 1px solid var(--border-strong); background: var(--card); border-radius: 10px; 
  margin-top: 0px; }
.translate-title { font-weight: 700; margin-bottom: 8px; }
.translate-box { display: grid; gap: 10px; position: relative; }
.translate-controls { display: grid; align-items: center; margin-top: 8px; grid-template-columns: 1fr 1fr;
  gap: 10px;}
.select-group { display: grid; gap: 4px; }
.select-label { color: var(--muted); font-size: 12px; }
.select { appearance: none; -webkit-appearance: none; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--control-border); background: var(--card); color: var(--text); font-size: 14px; }
.select:focus { outline: none; box-shadow: 0 0 0 2px var(--accent) inset; }
.swap-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 6px; border: 1px solid var(--control-border); background: var(--card); color: var(--text); cursor: pointer; }
.swap-btn:hover { background: var(--hover-strong); }
.translate-btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--accent); color: var(--text-on-accent); font-weight: 600; border: 2px solid var(--accent-border); border-radius: 8px; cursor: pointer; }
.translate-btn[disabled] { opacity: 0.6; cursor: not-allowed; }
.translate-btn:hover { filter: brightness(1.05); }
.controls-spacer { flex: 1; }
.translate-panel .copy-btn{
  position: absolute;
  top: 8px;
  right: 8px;
}

.translate-controls select{
  max-width: 250px;  
  min-width: 90px;
  appearance: auto;
  -webkit-appearance: auto;
}

.translate-panel .select-group{
  display: block;
}
.translate-panel .select-label{
  padding-right: 4px;
  padding-left: 8px;
}

.translate-panel .panel-header{
  justify-content: flex-end;
  align-items: end;
}


.translate-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.translate-col { display: grid; gap: 6px; position: relative; }
.translate-input { padding: 12px 14px; border-radius: 8px; border: 2px solid var(--border-strong); background: var(--card); color: var(--text); font-size: 15px; min-height: 120px; resize: vertical; }
.translate-input::placeholder { color: var(--muted); }
.translate-output { padding: 12px 14px; border-radius: 8px; border: 1px solid var(--control-border); background: var(--bg-weak); color: var(--text); min-height: 120px; white-space: pre-wrap; }
.translate-output-toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.copy-btn { display: inline-flex; align-items: center; gap: 6px; background: var(--card); color: var(--text); border: 1px solid var(--control-border); border-radius: 6px; padding: 6px 10px; cursor: pointer; }
.copy-btn:hover { background: var(--hover-strong); }
.copy-btn.copied { border-color: var(--accent); color: var(--muted-accent); }
.translate-panel{ margin-bottom: 16px; }
/* translate controls sit below header in panel body */
.panel-actions { display: flex; align-items: center; gap: 8px; }

.translate-error { color: var(--error); font-size: 13px; }
.translate-error.hidden { display: none; }
.translate-loading { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; }
.translate-loading.hidden { display: none; }
.translate-loading:not(.hidden) { display: flex; backdrop-filter: blur(2px); }

@media (max-width: 768px) {
  .translate-columns { grid-template-columns: 1fr; }
}


#asset-chart{
  margin-bottom: 15px;
}
#fx-chart{
  margin-bottom: 16px;
}

/* FX chart: position container relatively to anchor absolute tooltip */
#fx-chart-container {
  position: relative;
}

/* FX chart hover tooltip: converted amount at hovered time */
.fx-hover-tooltip {
  position: absolute;
  display: none;
  padding: 6px 8px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(var(--shadow-rgb), 0.35);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}
