header.compact-header {
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 6px;
  padding: 6px 10px;
  flex-wrap: nowrap;
  min-width: 0;
}
.compact-header > * { flex-shrink: 0; }
.compact-header #app-brand { font-size: 14px; }
.compact-header > button,
.compact-header #header-settings-btn,
.compact-header #header-tools-toggle,
.compact-header #telegram-channel-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 17px;
}
.compact-header #lang-toggle-btn { font-size: 13px; }
.compact-header #view-menu-btn {
  max-width: 180px;
  height: 34px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.compact-header #symbol-combobox { min-width: 0; }
.compact-header #symbol-search { width: 145px; height: 34px; }
.compact-header #interval-select { height: 34px; }
.compact-header #theme-toggle-btn { margin-left: auto; }
#header-settings-panel {
  position: absolute;
  top: calc(100% + 5px);
  left: 8px;
  width: min(320px, calc(100vw - 16px));
  max-height: min(640px, calc(100dvh - 105px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0,0,0,.28);
  z-index: 40;
}
#header-settings-panel:not([hidden]) { display: flex; flex-direction: column; gap: 8px; }
.header-settings-title { font-size: 14px; font-weight: 650; padding: 2px 2px 8px; border-bottom: 1px solid var(--border); }
#header-settings-panel > button { width: 100%; min-height: 38px; text-align: left; padding: 8px 10px; border-radius: 7px; }
#header-settings-panel #demo-mode-toggle { justify-content: flex-start; }
.header-setting-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; }
.header-setting-field:has(> [style*="display: none"]) { display: none; }
.header-setting-field > select, .header-setting-field > input { min-width: 0; width: 58%; min-height: 36px; }
#header-settings-panel #status { display: block; max-width: 100%; white-space: normal; font-size: 11px; color: var(--text-muted); }
#header-settings-panel #auto-refresh-wrap { padding: 8px 2px; }
.compact-header #header-tools-extra > button { min-height: 36px; }
@media (max-width: 900px) {
  header.compact-header {
    display: grid;
    grid-template-columns: 32px 32px minmax(60px, 1fr) repeat(4, 32px);
    grid-template-rows: 34px 34px;
    gap: 4px;
    padding: 5px 6px;
  }
  .compact-header #app-brand { grid-area: 1 / 1; font-size: 12px; }
  .compact-header #header-settings { grid-area: 1 / 2; }
  .compact-header #view-menu { grid-area: 1 / 3; min-width: 0; }
  .compact-header #view-menu-btn { width: 100%; max-width: 100%; padding: 4px; font-size: 12px; }
  .compact-header #theme-toggle-btn { grid-area: 1 / 4; margin: 0; }
  .compact-header #lang-toggle-btn { grid-area: 1 / 5; }
  .compact-header #telegram-channel-link { grid-area: 1 / 6; }
  .compact-header #profile-menu { grid-area: 1 / 7; }
  .compact-header #symbol-combobox { grid-area: 2 / 1 / 3 / 6; }
  .compact-header #symbol-search { width: 100%; font-size: 16px; padding: 5px 8px; }
  .compact-header .interval-toggle { grid-area: 2 / 6; justify-self: end; }
  .compact-header #interval-select { width: 56px; padding: 3px; font-size: 12px; }
  .compact-header #symbol-combobox { margin-right: 24px; }
  .compact-header #tools-menu { grid-area: 2 / 7; }
  .compact-header > button,
  .compact-header #header-settings-btn,
  .compact-header #header-tools-toggle,
  .compact-header #telegram-channel-link,
  .compact-header #profile-btn { width: 32px; height: 32px; padding: 0; }
  .compact-header .symbol-dropdown { width: min(270px, calc(100vw - 12px)); max-height: 50dvh; }
  .compact-header #header-tools-extra { max-height: calc(100dvh - 100px); overflow-y: auto; }
  #header-settings-panel { left: 6px; }
}


/* BTT header layout fix */
header.compact-header > #favorite-star-btn,
header.compact-header > #alerts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  flex-shrink: 0;
}

header.compact-header #lang-toggle-btn {
  width: auto;
  min-width: 76px;
  height: 34px;
  padding: 0 9px;
  font-size: 13px;
  white-space: nowrap;
}

header.compact-header #theme-toggle-btn {
  margin-left: auto;
}

header.compact-header #profile-menu {
  flex-shrink: 0;
}

@media (max-width: 900px) {
  header.compact-header {
    grid-template-columns:
      32px 32px minmax(60px, 1fr)
      56px 80px 32px 32px;
    grid-template-rows: 34px 34px;
  }

  .compact-header #app-brand { grid-area: 1 / 1; }
  .compact-header #header-settings { grid-area: 1 / 2; }
  .compact-header #view-menu { grid-area: 1 / 3; }
  .compact-header #theme-toggle-btn {
    grid-area: 1 / 4;
    margin: 0;
  }
  .compact-header #lang-toggle-btn {
    grid-area: 1 / 5;
    min-width: 0;
    width: 80px;
  }
  .compact-header #telegram-channel-link { grid-area: 1 / 6; }
  .compact-header #profile-menu { grid-area: 1 / 7; }

  .compact-header #symbol-combobox {
    grid-area: 2 / 1 / 3 / 4;
    margin-right: 0;
  }
  .compact-header .interval-toggle {
    grid-area: 2 / 4;
    justify-self: center;
  }
  .compact-header #favorite-star-btn {
    grid-area: 2 / 5;
    justify-self: start;
  }
  .compact-header #alerts-btn {
    grid-area: 2 / 6;
  }
  .compact-header #tools-menu {
    grid-area: 2 / 7;
  }
}

/* Keep chart controls reachable at narrow widths. */
header.compact-header #heatmap-shortcut-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  align-items: center;
  justify-content: center;
}
@media (max-width: 900px) {
  header.compact-header {
    grid-template-columns: 32px 32px minmax(35px, 1fr) 48px 38px 32px 32px 32px;
  }
  .compact-header #theme-toggle-btn { grid-area: 1 / 4; }
  .compact-header #lang-toggle-btn { grid-area: 1 / 5 / 2 / 7; width: 100%; }
  .compact-header #telegram-channel-link { grid-area: 1 / 7; }
  .compact-header #profile-menu { grid-area: 1 / 8; }
  .compact-header #symbol-combobox { grid-area: 2 / 1 / 3 / 4; }
  .compact-header .interval-toggle { grid-area: 2 / 4; }
  .compact-header #interval-select { width: 48px; min-width: 0; }
  .compact-header #favorite-star-btn { grid-area: 2 / 5; justify-self: center; }
  .compact-header #alerts-btn { grid-area: 2 / 6; }
  .compact-header #heatmap-shortcut-btn { grid-area: 2 / 7; width: 32px; height: 32px; }
  .compact-header #tools-menu { grid-area: 2 / 8; }
}

@media (max-width: 900px) {
  .compact-header #symbol-combobox {
    width: min(100%, 132px);
    justify-self: start;
  }
  .compact-header #symbol-combobox::after {
    content: '▾';
    position: absolute;
    right: 9px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 11px;
    pointer-events: none;
  }
  .compact-header #symbol-search {
    box-sizing: border-box;
    width: 100%;
    padding: 5px 23px 5px 8px;
    font-size: 16px;
  }
}

#view-guide .guide-inner { max-width: 920px; margin: 0 auto; }
#view-guide .guide-toc { display: flex; flex-wrap: wrap; gap: 7px; margin: 18px 0; }
#view-guide .guide-toc a { display: inline-block; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary); background: var(--surface-1); font-size: 13px; text-decoration: none; }
#view-guide .guide-toc a:hover, #view-guide .guide-toc a:focus-visible { border-color: var(--series-1); }
#view-guide .guide-source-note { color: var(--text-muted); font-size: 12px; line-height: 1.5; }
#view-guide .guide-article { color: var(--text-secondary); font-size: 14px; line-height: 1.7; overflow-wrap: anywhere; }
#view-guide .guide-article h2 { color: var(--text-primary); font-size: 20px; margin: 28px 0 10px; scroll-margin-top: 110px; }
#view-guide .guide-article p { margin: 0 0 16px; white-space: normal; }
#view-guide .guide-article strong { color: var(--text-primary); }
#view-guide .guide-article figure { margin: 20px 0; }
#view-guide .guide-article img { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: 7px; }
#view-guide .guide-article a { color: var(--series-1); }
@media (max-width: 600px) {
  #view-guide .guide-article { font-size: 14px; line-height: 1.6; }
  #view-guide .guide-article h2 { font-size: 18px; }
  #view-guide .guide-toc a { font-size: 12px; padding: 6px 8px; }
}
#view-guide .guide-topic-anchor { display: block; scroll-margin-top: 115px; }

/* Mobile browsers change the visible viewport as their toolbars appear. */
@supports (height: 100dvh) {
  .app { height: 100dvh; }
}
#mc-col { min-height: 0; }
@media (max-width: 640px) {
  #view-chart > .feed-panel { max-height: 40%; min-height: 0; }
}
.spring-chart-toggle { border: 1px solid var(--border); color: var(--text-primary); padding: 3px 6px; }
.spring-chart-toggle svg { width: 25px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
#chart-spring-panel { flex: 0 0 clamp(85px, 19%, 150px); min-height: 0; position: relative; border-top: 1px solid var(--border); background: var(--surface-1); }
#chart-spring-panel[hidden] { display: none; }
.chart-spring-canvas { position: absolute; inset: 0; }
.chart-spring-label { position: absolute; top: 3px; left: 8px; z-index: 2; pointer-events: none; color: var(--text-secondary); font-size: 11px; }
.mc-spring { opacity: .5; display: inline-flex; align-items: center; justify-content: center; }
.mc-spring.active { opacity: 1; border-color: var(--text-muted); }
.mc-spring svg { width: 20px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.mc-spring-panel { position: relative; flex: 0 0 clamp(65px, 28%, 120px); min-height: 0; border-top: 1px solid var(--border); }
.mc-spring-panel[hidden] { display: none; }
.mc-spring-canvas { position: absolute; inset: 0; }
.mc-spring-label { position: absolute; top: 2px; left: 6px; z-index: 2; pointer-events: none; color: var(--text-secondary); font-size: 10px; }

#youtube-channel-link {
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; width: 34px; height: 34px; color: #ff4444;
  background: var(--page-plane); border: 1px solid var(--border); border-radius: 4px;
  text-decoration: none;
}
#youtube-channel-link svg { width: 21px; height: 21px; fill: currentColor; }
#youtube-channel-link:hover { background: var(--hover); border-color: currentColor; }
#youtube-channel-link:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
@media (max-width: 900px) {
  header.compact-header {
    grid-template-columns: 30px 30px minmax(25px, 1fr) 40px 30px 30px 30px 30px 30px;
    gap: 3px;
  }
  .compact-header #theme-toggle-btn { grid-area: 1 / 4; }
  header.compact-header #lang-toggle-btn { grid-area: 1 / 5 / 2 / 7; width: 100%; min-width: 0; padding: 0 3px; }
  .compact-header #telegram-channel-link { grid-area: 1 / 7; }
  .compact-header #youtube-channel-link { grid-area: 1 / 8; width: 30px; height: 32px; }
  .compact-header #profile-menu { grid-area: 1 / 9; }
  .compact-header #symbol-combobox { grid-area: 2 / 1 / 3 / 4; }
  .compact-header .interval-toggle { grid-area: 2 / 4; }
  .compact-header #interval-select { width: 40px; }
  .compact-header #favorite-star-btn { grid-area: 2 / 5; }
  .compact-header #alerts-btn { grid-area: 2 / 6; }
  .compact-header #heatmap-shortcut-btn { grid-area: 2 / 7; }
  .compact-header #tools-menu { grid-area: 2 / 8; }
  header.compact-header > #favorite-star-btn, header.compact-header > #alerts-btn,
  header.compact-header > #heatmap-shortcut-btn, .compact-header #header-settings-btn,
  .compact-header #header-tools-toggle, .compact-header #telegram-channel-link,
  .compact-header #profile-btn { width: 30px; }
}
header.compact-header > .spring-chart-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
}
@media (max-width: 900px) {
  header.compact-header > .spring-chart-toggle { grid-area: 2 / 8; width: 30px; height: 32px; }
  .compact-header #tools-menu { grid-area: 2 / 9; }
}
#view-guide .guide-table-wrap { max-width: 100%; overflow-x: auto; margin: 18px 0; }
#view-guide .guide-table { width: 100%; border-collapse: collapse; font-size: 13px; line-height: 1.5; }
#view-guide .guide-table th, #view-guide .guide-table td { text-align: left; vertical-align: top; padding: 9px 11px; border: 1px solid var(--border); }
#view-guide .guide-table th { background: var(--surface-2); color: var(--text-primary); }
#view-guide .guide-table td:first-child { min-width: 115px; color: var(--text-primary); }
