/*
 * Application shell and responsive interaction layer.
 * The core data-view styling remains in index.html; this file groups navigation,
 * adds page hierarchy, and upgrades tablet/mobile behavior without touching data logic.
 */

:root {
  --sidebar-width: 236px;
  --shell-max: 1480px;
  --shell-focus: 0 0 0 3px rgba(15, 118, 110, .16);
}

body {
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
  box-shadow: var(--shell-focus);
}

/* ---------- Desktop sidebar ---------- */

body > header {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 45;
  width: var(--sidebar-width);
  height: 100dvh;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

body > header .wrap {
  width: 100%;
  max-width: none;
  height: 100%;
  margin: 0;
  padding: 20px 14px 16px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 0 6px 14px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--teal-hover);
  color: #fff;
  font-size: 16px;
  font-weight: 900;
  box-shadow: var(--sh-sm);
}

.brand-copy {
  min-width: 0;
}

.brand h1 {
  overflow: hidden;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-product {
  margin-top: 2px;
  overflow: hidden;
  color: var(--sub);
  font-size: 11.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#subline {
  margin: 0 6px 13px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--inset);
  color: var(--sub);
  font-size: 11px;
  line-height: 1.55;
}

#subline b {
  color: var(--ink) !important;
  font-variant-numeric: tabular-nums;
}

#subline .mut {
  display: block;
  margin-top: 3px;
}

.tabs {
  min-height: 0;
  margin: 0;
  padding: 0 2px 4px;
  display: flex;
  flex: 1;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 3px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
}

.nav-group-label {
  margin: 11px 9px 4px;
  color: var(--sub);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .08em;
}

.nav-group-label:first-child {
  margin-top: 2px;
}

.tab {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--sub);
  font-size: 13.5px;
  font-weight: 650;
  line-height: 1.35;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: color .16s ease, background .16s ease, border-color .16s ease;
}

.tab::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 2px;
  background: var(--line-strong);
  transition: background .16s ease, transform .16s ease;
}

.tab:hover {
  border-bottom-color: transparent;
  background: var(--inset);
  color: var(--ink);
}

.tab.on {
  border-color: var(--teal-line);
  border-bottom-color: var(--teal-line);
  background: var(--teal-bg);
  color: var(--teal-hover);
}

.tab.on::before {
  background: var(--teal);
  transform: scale(1.16);
}

.sidebar-feedback {
  width: calc(100% - 14px);
  min-height: 40px;
  margin: 14px 7px 0 !important;
  padding: 8px 12px !important;
  align-self: auto !important;
  flex: 0 0 auto;
  font-size: 13px !important;
}

main {
  width: calc(100% - var(--sidebar-width));
  max-width: none;
  min-height: 100vh;
  margin: 0 0 0 var(--sidebar-width);
  padding: 28px 32px 76px;
}

.content-frame {
  width: 100%;
  max-width: var(--shell-max);
  margin: 0 auto;
}

footer {
  margin-left: var(--sidebar-width);
  padding: 24px 36px 34px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.mobile-topbar,
.mobile-bottom-nav,
.nav-scrim {
  display: none;
}

/* ---------- Page context ---------- */

.page-intro {
  min-height: 74px;
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.page-eyebrow {
  margin: 0 0 2px;
  color: var(--teal);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .08em;
}

.page-intro h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(22px, 2vw, 27px);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -.015em;
}

.page-intro p {
  max-width: 760px;
  margin: 5px 0 15px;
  color: var(--sub);
  font-size: 13px;
}

.freshness-badge {
  min-height: 34px;
  margin-top: 4px;
  padding: 7px 10px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--sub);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--sh-sm);
}

.freshness-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--down);
  box-shadow: 0 0 0 3px var(--down-bg);
}

/* Keep the support module present but visually subordinate to the data task. */
.promo {
  min-height: 58px;
  padding: 10px 13px;
}

.promo-ava {
  width: 36px;
  height: 36px;
}

.promo-t {
  font-size: 13.5px;
}

.promo-s {
  color: var(--sub);
  font-size: 11.5px;
}

.promo-btn {
  padding: 7px 10px;
  border: 1px solid var(--teal-line);
  border-radius: 7px;
  background: var(--teal-bg);
  color: var(--teal-hover);
  font-size: 12px;
}

.promo:hover .promo-btn {
  background: var(--teal);
  color: #fff;
}

.promo-mq {
  display: none !important;
}

.fab {
  right: 20px;
  bottom: 20px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--teal);
  font-size: 12.5px;
  box-shadow: var(--sh-md);
}

.fab:hover {
  border-color: var(--teal-line);
  background: var(--teal-bg);
  box-shadow: var(--sh-md);
  transform: none;
}

.field-label {
  display: block;
  margin: 12px 0 5px;
  color: var(--sub);
  font-size: 12px;
  font-weight: 650;
}

.sharecard .x {
  padding: 0;
  border: 0;
  background: transparent;
}

/* Data sections scroll independently on mid-size screens instead of widening the page. */
#etfList,
#rankResult,
#instResult,
#stockResult,
#dtsResult,
#divResult,
#otherResult,
#perfResult,
#detSub,
#xResult,
#cmpResult {
  max-width: 100%;
}

/* ---------- Drawer navigation at tablet widths ---------- */

@media (max-width: 1079px) {
  body > header {
    width: min(300px, calc(100vw - 52px));
    transform: translateX(-102%);
    box-shadow: var(--sh-lg);
    transition: transform .19s ease;
  }

  body.nav-open > header {
    transform: translateX(0);
  }

  body.nav-open {
    overflow: hidden;
  }

  .nav-scrim {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: block;
    visibility: hidden;
    background: rgba(15, 23, 42, .42);
    opacity: 0;
    transition: opacity .19s ease, visibility .19s ease;
  }

  body.nav-open .nav-scrim {
    visibility: visible;
    opacity: 1;
  }

  .mobile-topbar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 35;
    min-height: 60px;
    padding: 8px 16px;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
  }

  .topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .topbar-actions .theme-toggle {
    width: 44px;
    height: 44px;
  }

  .mobile-icon-button {
    width: 44px;
    height: 44px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
    font-size: 18px;
    line-height: 1;
  }

  .mobile-brand {
    min-width: 0;
  }

  .mobile-brand strong,
  .mobile-brand span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-brand strong {
    font-size: 14px;
    line-height: 1.25;
  }

  .mobile-brand span {
    margin-top: 1px;
    color: var(--sub);
    font-size: 11.5px;
  }

  main {
    width: 100%;
    margin-left: 0;
    padding: 84px 24px 72px;
  }

  footer {
    margin-left: 0;
  }

  .page-intro {
    min-height: 68px;
  }

  #etfList,
  #rankResult,
  #instResult,
  #stockResult,
  #dtsResult,
  #divResult,
  #otherResult,
  #perfResult,
  #detSub,
  #xResult,
  #cmpResult {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }
}

@media (min-width: 561px) and (max-width: 1079px) {
  #etfList table,
  #rankResult table,
  #instResult table,
  #stockResult table,
  #dtsResult table,
  #divResult table,
  #otherResult table,
  #perfResult table,
  #detSub table,
  #xResult table {
    min-width: 720px;
  }
}

@media (max-width: 720px) {
  .mobile-topbar {
    padding-inline: 12px;
  }

  main {
    padding: 78px 14px 104px;
  }

  .page-intro {
    min-height: auto;
    margin-bottom: 16px;
    display: block;
  }

  .page-intro h2 {
    font-size: 21px;
  }

  .page-intro p {
    margin: 4px 0 12px;
    font-size: 12.5px;
  }

  .freshness-badge {
    margin: 0 0 14px;
  }

  .mobile-bottom-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 34;
    height: calc(68px + env(safe-area-inset-bottom));
    padding: 6px 6px env(safe-area-inset-bottom);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    border-top: 1px solid var(--line);
    background: var(--panel);
  }

  .mobile-nav-item {
    min-width: 0;
    min-height: 54px;
    padding: 5px 3px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--sub);
    font-size: 10.5px;
    font-weight: 650;
    line-height: 1.2;
  }

  .mobile-nav-item::before {
    content: "";
    width: 16px;
    height: 3px;
    border-radius: 2px;
    background: var(--line-strong);
  }

  .mobile-nav-item.on {
    background: var(--teal-bg);
    color: var(--teal-hover);
  }

  .mobile-nav-item.on::before {
    background: var(--teal);
  }

  footer {
    padding: 24px 16px calc(90px + env(safe-area-inset-bottom));
  }

  .fab {
    display: none;
  }

  .promo-btn {
    display: none;
  }

  .modal {
    padding: 20px 0 0;
    align-items: flex-end;
  }

  .sharecard {
    width: 100%;
    max-height: calc(100dvh - 20px);
    overflow-y: auto;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    border-radius: 12px 12px 0 0;
  }
}

@media (max-width: 390px) {
  .mobile-topbar {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 8px;
  }

  .mobile-icon-button {
    width: 44px;
    height: 44px;
  }

  .mobile-nav-item {
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  body > header,
  .mobile-topbar,
  .mobile-bottom-nav,
  .promo,
  .fab,
  .sidebar-feedback {
    display: none !important;
  }

  main,
  footer {
    width: 100%;
    margin: 0;
    padding-inline: 0;
  }
}
