/* ── Reset & base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Shell (navy) */
  --color-shell:       #152240;
  --color-shell-deep:  #0e1a30;
  --color-shell-hover: rgba(255,255,255,0.07);
  --color-shell-border:#1e3260;
  --color-shell-text:  #e8edf8;
  --color-shell-muted: #7b92bc;

  /* Content (light) */
  --color-bg:          #f0f3f8;
  --color-surface:     #ffffff;
  --color-border:      #dde2ed;
  --color-text:        #111827;
  --color-muted:       #6b7280;

  /* Accent */
  --color-accent:      #3b7eff;
  --color-accent-dim:  rgba(59,126,255,0.12);
  --color-accent-nav:  #7eb3ff;

  /* Badges */
  --color-badge-new:   #0ea96a;
  --color-badge-upd:   #d97706;

  /* Layout */
  --rail-width:        240px;
  --header-height:     56px;
  --font:              'Inter', system-ui, -apple-system, sans-serif;
  --radius:            8px;
  --transition:        180ms ease;
}

html, body {
  height: 100%;
  background: var(--color-shell);
  color: var(--color-text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout shell ──────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-columns: var(--rail-width) 1fr;
  grid-template-areas:
    "header header"
    "rail   main";
  height: 100dvh;
  overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────────── */
#header {
  grid-area: header;
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: var(--color-shell-deep);
  border-bottom: 1px solid var(--color-shell-border);
  gap: 12px;
  z-index: 10;
}

#header .brand {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

#header .brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--color-shell-text);
}

#header .brand-sub {
  font-size: 11px;
  color: var(--color-shell-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

#header .header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

#header .header-right a {
  font-size: 13px;
  color: var(--color-shell-muted);
  text-decoration: none;
  transition: color var(--transition);
}

#header .header-right a:hover { color: var(--color-shell-text); }

#header .header-right .btn-primary {
  background: var(--color-accent);
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

#header .header-right .btn-primary:hover {
  background: #2568e8;
  color: #fff;
}

/* ── Left rail ─────────────────────────────────────────────────── */
#rail {
  grid-area: rail;
  background: var(--color-shell);
  border-right: 1px solid var(--color-shell-border);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 0 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--color-shell-border) transparent;
}

#rail::-webkit-scrollbar { width: 4px; }
#rail::-webkit-scrollbar-thumb { background: var(--color-shell-border); border-radius: 2px; }

/* ── Accordion section ─────────────────────────────────────────── */
.nav-section { margin-bottom: 2px; }

.nav-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
  position: relative;
}

.nav-section-header:hover { background: var(--color-shell-hover); }
.nav-section-header.open  { background: var(--color-shell-hover); }

.nav-section-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--color-accent-nav);
  opacity: 0.9;
}

.nav-section-label {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-shell-text);
  letter-spacing: 0.01em;
}

.nav-chevron {
  width: 14px;
  height: 14px;
  color: var(--color-shell-muted);
  transition: transform var(--transition);
  flex-shrink: 0;
}

.nav-section-header.open .nav-chevron { transform: rotate(90deg); }

/* ── Badge ─────────────────────────────────────────────────────── */
.badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
  flex-shrink: 0;
}

.badge-new     { background: var(--color-badge-new); color: #fff; }
.badge-updated { background: var(--color-badge-upd); color: #fff; }

/* ── Nav items (inside accordion) ─────────────────────────────── */
.nav-items {
  display: none;
  padding: 2px 0 6px;
}

.nav-items.open { display: block; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 16px 7px 38px;
  cursor: pointer;
  color: var(--color-shell-muted);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  position: relative;
}

.nav-item-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--color-accent-nav);
  opacity: 0.85;
}

.nav-item:hover {
  background: var(--color-shell-hover);
  color: var(--color-shell-text);
}

.nav-item.active {
  color: var(--color-accent-nav);
  background: rgba(59,126,255,0.15);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--color-accent-nav);
  border-radius: 0 2px 2px 0;
}

.nav-item-link-icon {
  width: 11px;
  height: 11px;
  color: var(--color-shell-muted);
  flex-shrink: 0;
  margin-left: auto;
}

/* ── Section-level link (Newsletter, Podcast) ──────────────────── */
.nav-section-link {
  text-decoration: none;
}

/* ── Rail divider ──────────────────────────────────────────────── */
.rail-divider {
  height: 1px;
  background: var(--color-shell-border);
  margin: 10px 16px;
}

/* ── Main content panel ────────────────────────────────────────── */
#main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-bg);
}

/* ── Panel breadcrumb bar ──────────────────────────────────────── */
#panel-bar {
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 40px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  gap: 8px;
  flex-shrink: 0;
  box-shadow: 0 1px 0 var(--color-border);
}

#panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}

#panel-section-label {
  font-size: 12px;
  color: var(--color-muted);
}

.panel-sep {
  color: var(--color-border);
  font-size: 14px;
}

/* ── Content area ──────────────────────────────────────────────── */
#panel-content {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Chart state: iframe sits flush */
#panel-content iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #fff;
}

/* ── Welcome / hub panel ───────────────────────────────────────── */
/* Absolute fill so height is always resolved — centering works    */
#welcome {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 40px 40px 120px; /* pull content up to true optical center */
  gap: 40px;
  background: var(--color-bg);
}

.welcome-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#welcome .welcome-title {
  font-size: 30px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

#welcome .welcome-sub {
  font-size: 15px;
  color: var(--color-muted);
  line-height: 1.6;
}

/* ── Tile grid ─────────────────────────────────────────────────── */
/* 6 narrow columns — each tile spans 2, giving a 3-up top row.
   The 4th and 5th tiles are explicitly placed to center them:
   cols 2-3 and 4-5, leaving one empty col on each side.        */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 20px;
  width: 100%;
  max-width: 1000px;
}

.tile                { grid-column: span 2; }
.tile:nth-child(4)   { grid-column: 2 / span 2; }
.tile:nth-child(5)   { grid-column: 4 / span 2; }

.tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 32px 28px 24px;
  min-height: 200px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  transition: border-color var(--transition), background var(--transition),
              transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
  color: inherit;
  position: relative;
}

.tile:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-dim);
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(59,126,255,0.12);
}

.tile-icon {
  width: 34px;
  height: 34px;
  color: var(--color-accent);
  flex-shrink: 0;
}

.tile-label {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
  letter-spacing: 0.01em;
}

.tile-desc {
  font-size: 13px;
  color: var(--color-muted);
  line-height: 1.65;
  flex: 1;
}

.tile-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.tile-action {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-accent);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tile-ext-icon {
  width: 13px;
  height: 13px;
  color: var(--color-muted);
}

/* ── Loading state ─────────────────────────────────────────────── */
#panel-loading {
  display: none;
  position: absolute;
  inset: 0;
  background: var(--color-bg);
  align-items: center;
  justify-content: center;
  z-index: 5;
}

#panel-loading.visible { display: flex; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Hamburger button (hidden on desktop) ───────────────────────── */
#hamburger {
  display: none;
}

/* ── Nav backdrop (mobile drawer overlay) ───────────────────────── */
#nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 190;
  opacity: 0;
  transition: opacity 220ms ease;
}

#nav-backdrop.visible {
  display: block;
  opacity: 1;
}

/* ── Mobile top nav (portrait only, built by app.js) ────────────── */
#mobile-nav {
  display: none; /* shown only in portrait media query */
  flex-direction: column;
  background: var(--color-shell);
  border-bottom: 1px solid var(--color-shell-border);
  flex-shrink: 0;
}
#mobile-nav-sections,
#mobile-nav-items {
  display: flex;
  overflow-x: auto;
  padding: 5px 10px;
  gap: 6px;
  scrollbar-width: none;
}
#mobile-nav-sections::-webkit-scrollbar,
#mobile-nav-items::-webkit-scrollbar { display: none; }
#mobile-nav-items {
  border-top: 1px solid var(--color-shell-border);
  padding-top: 5px;
  padding-bottom: 6px;
}
#mobile-nav-items[hidden] { display: none !important; }
.mobile-nav-pill,
.mobile-nav-sub {
  flex-shrink: 0;
  border: 1px solid var(--color-shell-border);
  background: transparent;
  color: var(--color-shell-muted);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 11px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
}
.mobile-nav-pill:hover:not(.active),
.mobile-nav-sub:hover:not(.active) {
  background: var(--color-shell-hover);
  color: var(--color-shell-text);
}
.mobile-nav-pill.active,
.mobile-nav-sub.active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

/* ── Mobile modal overlay ────────────────────────────────────────── */
#mobile-modal-backdrop {
  position: fixed; inset: 0; z-index: 999998;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
#mobile-modal {
  background: #152240; color: #e8edf8;
  font-family: system-ui, sans-serif; font-size: 14px; line-height: 1.55;
  border-radius: 12px; padding: 24px 20px 20px;
  max-width: 340px; width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
  display: flex; flex-direction: column; gap: 14px;
}
#mobile-modal p { margin: 0; }
#mobile-modal button {
  align-self: flex-end;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.3);
  color: #e8edf8; border-radius: 6px; padding: 6px 20px;
  cursor: pointer; font-size: 13px; font-weight: 600;
}
#mobile-modal button:hover { background: rgba(255,255,255,0.22); }

/* ── Phone layout (portrait ≤768px OR landscape height ≤500px) ──── *
 * Completely replaces the desktop fixed-height app-shell with a     *
 * normal scrollable document flow. !important used throughout to    *
 * break out of the desktop architecture cleanly.                    *
 * ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px), (orientation: landscape) and (max-height: 500px) {

  /* ── Document root: normal flow, no fixed height ── */
  html, body {
    height: auto !important;
    min-height: 100dvh;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    max-width: 100% !important;
  }

  /* ── App shell: flex column, grows with content ── */
  #app {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    min-height: 100dvh;
    overflow: visible !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ── Header: shrink to fit narrow screens ── */
  #header {
    flex-shrink: 0;
    overflow: visible;
    padding: 0 12px;
  }
  #header .brand-name { font-size: 13px; }
  #header .brand-sub  { font-size: 10px; }
  #header .header-right .btn-primary {
    padding: 5px 10px;
    font-size: 11px;
    letter-spacing: 0.02em;
  }

  /* ── Show mobile pill nav, hide desktop nav ── */
  #mobile-nav   { display: flex; flex-shrink: 0; }
  #rail         { display: none !important; }
  #hamburger    { display: none !important; }
  #nav-backdrop { display: none !important; }
  #panel-bar    { display: none !important; }

  /* ── Main: flex child, grows naturally ── */
  #main {
    flex: 1;
    display: flex !important;
    flex-direction: column !important;
    overflow: visible !important;
    width: 100% !important;
  }

  /* ── Panel content: tall enough for charts to render fully ── */
  #panel-content {
    overflow: visible !important;
    position: static !important;
    width: 100% !important;
    min-height: 800px;
  }

  /* ── iframe: static block, tall fixed height — outer page scrolls ── */
  #panel-content iframe {
    position: static !important;
    display: block;
    width: 100% !important;
    height: 800px;
    border: none;
  }

  /* ── Welcome screen: normal flow, scrollable ── */
  #welcome {
    position: static !important;
    overflow: visible !important;
    width: 100% !important;
    padding: 16px 14px 60px;
    gap: 10px;
    justify-content: flex-start;
    align-items: stretch;
  }

  .welcome-header { gap: 4px; align-items: center; }
  #welcome .welcome-title { font-size: 20px; }
  #welcome .welcome-sub   { font-size: 12px; }

  /* ── Tile grid: single column, full width ── */
  .tile-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px;
    width: 100% !important;
    max-width: 100% !important;
  }

  .tile,
  .tile:nth-child(4),
  .tile:nth-child(5) {
    width: 100% !important;
    min-height: 0;
    padding: 12px 14px 10px;
    gap: 4px;
    border-radius: 9px;
    box-shadow: none;
  }

  .tile .tile-icon   { width: 18px; height: 18px; }
  .tile .tile-label  { font-size: 14px; }
  .tile .tile-desc   { font-size: 12px; line-height: 1.45; }
  .tile .tile-footer { margin-top: 4px; }
  .tile .tile-action { font-size: 10px; }
}
