/* ============================================================
   Lean Finance — ROBUST APP SHELL
   Two-tier fixed top bar + mega-menu dropdowns
   Contextual left sidebar (theme pages)
   Dense dashboard hub (landing)
   Builds on styles.css tokens (--accent, --accent-soft, themes…)
   ============================================================ */

:root {
  --tb-util-h: 54px;
  --tb-main-h: 50px;
  --topbar-h: 104px;
  --side-w: 264px;
  --hub-maxw: 1380px;
}

/* per-area theme scoping so each mega-menu / nav item carries its own colour
   regardless of the page it's on */
.t-blue   { --accent:#1f4fa3; --accent-dark:#143468; --accent-soft:#e8eff9; --accent-ink:#1a4490; --t-dot:#1f4fa3; }
.t-green  { --accent:#2f6b46; --accent-dark:#173a27; --accent-soft:#e7f0ea; --accent-ink:#265a3a; --t-dot:#2f6b46; }
.t-yellow { --accent:#9a7410; --accent-dark:#5f470a; --accent-soft:#f7efd6; --accent-ink:#7c5d0c; --t-dot:#e7b62f; }

/* ============================================================
   TWO-TIER TOP BAR
   ============================================================ */
.topbar { position: fixed; inset: 0 0 auto 0; z-index: 300; background: var(--surface); border-bottom: 1px solid var(--line); }

/* tier 1 — utility */
.tb-util { height: var(--tb-util-h); display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 26px; padding: 0 24px; border-bottom: 1px solid var(--line-soft); }
.tb-util .brand { font-size: 17px; }

.tb-search { position: relative; width: 100%; max-width: 480px; justify-self: center; }
.tb-search input { width: 100%; height: 36px; border: 1px solid var(--line); background: var(--bg); border-radius: 9px; padding: 0 14px 0 38px; font-family: var(--sans); font-size: 14px; color: var(--ink); transition: border-color .18s ease, background .18s ease, box-shadow .18s ease; }
.tb-search input::placeholder { color: var(--ink-faint); }
.tb-search input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
.tb-search .si { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-faint); pointer-events: none; }
.tb-search .kbd { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-family: var(--mono); font-size: 10px; color: var(--ink-faint); border: 1px solid var(--line); border-radius: 5px; padding: 2px 6px; background: var(--surface); }
/* live search results */
.search-pop { position: absolute; top: calc(100% + 8px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow-md); padding: 8px; display: none; max-height: 60vh; overflow-y: auto; z-index: 40; }
.search-pop.show { display: block; }
.search-pop .sp-empty { padding: 16px; color: var(--ink-faint); font-size: 14px; text-align: center; }
.sp-item { display: grid; grid-template-columns: 30px 1fr auto; gap: 11px; align-items: center; padding: 8px 10px; border-radius: 8px; }
.sp-item:hover, .sp-item.sel { background: var(--accent-soft); }
.sp-item .sp-ic { width: 30px; height: 30px; border-radius: 7px; background: var(--accent-soft); display: grid; place-items: center; color: var(--accent-ink); }
.sp-item:hover .sp-ic, .sp-item.sel .sp-ic { background: var(--surface); }
.sp-item .sp-ic svg { width: 16px; height: 16px; }
.sp-item .sp-name { font-size: 14px; font-weight: 600; }
.sp-item .sp-area { font-family: var(--mono); font-size: 9px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.sp-item .sp-dot { width: 7px; height: 7px; border-radius: 50%; }

.tb-actions { display: flex; align-items: center; gap: 14px; }
.tb-actions .signin { font-size: 14px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.tb-actions .signin:hover { color: #1f4fa3; }

/* tier 2 — primary nav */
.tb-main { height: var(--tb-main-h); display: flex; align-items: stretch; padding: 0 16px; gap: 2px; }
.tb-nav { display: flex; align-items: stretch; }
.tb-main-right { margin-left: auto; display: flex; align-items: center; gap: 2px; }

.navitem { position: relative; display: flex; align-items: stretch; }
.navlink { display: inline-flex; align-items: center; gap: 8px; height: var(--tb-main-h); padding: 0 15px; font-size: 14px; font-weight: 600; color: var(--ink-soft); background: none; border: 0; border-bottom: 2px solid transparent; white-space: nowrap; transition: color .15s ease, border-color .15s ease; }
.navlink .ndot { width: 8px; height: 8px; border-radius: 50%; background: var(--t-dot, var(--accent)); }
.navlink .caret { width: 14px; height: 14px; color: var(--ink-faint); transition: transform .2s ease; }
.navitem:hover .navlink, .navitem.open .navlink { color: var(--ink); }
.navitem:hover .caret, .navitem.open .caret { transform: rotate(180deg); color: var(--ink-soft); }
.navitem.current .navlink { color: var(--ink); border-bottom-color: var(--t-dot, var(--accent)); }
.tb-main-right .navlink { font-weight: 500; }

/* mega-menu */
.mega { position: absolute; top: 100%; left: 0; margin-top: -1px; min-width: 600px; background: var(--surface); border: 1px solid var(--line); border-radius: 0 0 14px 14px; box-shadow: var(--shadow-md); padding: 20px; opacity: 0; visibility: hidden; transform: translateY(7px); transition: opacity .18s ease, transform .18s ease; z-index: 60; pointer-events: none; }
.navitem:hover .mega, .navitem:focus-within .mega, .navitem.open .mega { opacity: 1; visibility: visible; transform: none; pointer-events: auto; }
.mega.right { left: auto; right: 0; }
.mega-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; }
.mega-wide { grid-template-columns: 1fr 1fr 1fr; min-width: 740px; }
.mega-col { min-width: 0; }
.mega-col h6 { font-family: var(--mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); margin: 6px 10px 8px; font-weight: 700; }
.mega-link { display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: center; padding: 9px 10px; border-radius: 9px; transition: background .15s ease; }
.mega-link:hover { background: var(--accent-soft); }
.mega-link .mi { width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; }
.mega-link:hover .mi { background: var(--surface); }
.mega-link .mi svg { width: 18px; height: 18px; }
.mega-link .mt b { display: block; font-size: 14px; font-weight: 600; color: var(--ink); letter-spacing: -.005em; }
.mega-link .mt span { display: block; font-size: 12px; color: var(--ink-faint); margin-top: 1px; }
.mega-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.mega-foot .mf-note { font-size: 12.5px; color: var(--ink-soft); }
.mega-foot .mf-note b { color: var(--ink); font-weight: 700; }
.mega-foot .mf-actions { display: flex; gap: 9px; }
.mega-pill { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 14px; border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid var(--line); color: var(--ink); white-space: nowrap; transition: border-color .15s ease, background .15s ease; }
.mega-pill:hover { border-color: var(--accent); background: var(--accent-soft); }
.mega-pill.solid { background: var(--accent); color: #fff; border-color: var(--accent); }
.mega-pill.solid:hover { filter: brightness(1.07); background: var(--accent); }

/* mobile hamburger (hidden on desktop) */
.tb-burger { display: none; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); align-items: center; justify-content: center; color: var(--ink); }
.tb-burger svg { width: 18px; height: 18px; }

/* ============================================================
   APP SHELL (theme pages)  — sidebar + content
   ============================================================ */
.appshell { display: grid; grid-template-columns: var(--side-w) minmax(0,1fr); align-items: start; padding-top: var(--topbar-h); }

.sidemenu { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; border-right: 1px solid var(--line); background: var(--surface); padding: 20px 14px 40px; }
.sm-area { display: flex; align-items: center; gap: 10px; padding: 8px 12px 16px; border-bottom: 1px solid var(--line-soft); margin-bottom: 10px; }
.sm-area .sm-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--t-dot, var(--accent)); flex: none; }
.sm-area .sm-title { font-family: var(--serif); font-size: 16px; font-weight: 500; letter-spacing: -.01em; white-space: nowrap; }
.sm-area .sm-switch { margin-left: auto; width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line); display: grid; place-items: center; color: var(--ink-faint); }
.sm-area .sm-switch:hover { color: var(--ink); border-color: var(--ink); }

.sm-group { margin-top: 14px; }
.sm-glabel { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; padding: 6px 12px; font-family: var(--mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); font-weight: 700; }
.sm-glabel .gcaret { margin-left: auto; width: 13px; height: 13px; transition: transform .2s ease; }
.sm-group.collapsed .gcaret { transform: rotate(-90deg); }
.sm-links { display: flex; flex-direction: column; gap: 1px; overflow: hidden; }
.sm-group.collapsed .sm-links { display: none; }
.sm-link { display: grid; grid-template-columns: 20px 1fr auto; gap: 11px; align-items: center; padding: 8px 12px; border-radius: 8px; font-size: 13.5px; font-weight: 500; color: var(--ink-soft); transition: background .15s ease, color .15s ease; }
.sm-link .ic { width: 18px; height: 18px; color: var(--ink-faint); }
.sm-link:hover { background: var(--accent-soft); color: var(--ink); }
.sm-link:hover .ic { color: var(--accent-ink); }
.sm-link.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent); }
.sm-link.active .ic { color: var(--accent-ink); }
.sm-link .sm-badge { font-family: var(--mono); font-size: 9.5px; color: var(--ink-faint); background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; }
.sm-link.active .sm-badge { color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 30%, transparent); background: var(--surface); }
.sm-cta { margin: 16px 8px 0; padding: 14px; border: 1px solid var(--line); border-radius: 11px; background: var(--accent-soft); }
.sm-cta b { display: block; font-size: 13.5px; color: var(--ink); }
.sm-cta p { margin: 4px 0 11px; font-size: 12px; color: var(--ink-soft); line-height: 1.45; }

/* main content column */
.appmain { min-width: 0; padding: 26px 36px 90px; }
.crumbs { display: flex; align-items: center; gap: 9px; font-family: var(--mono); font-size: 11px; letter-spacing: .04em; color: var(--ink-faint); margin-bottom: 20px; }
.crumbs a:hover { color: var(--ink); }
.crumbs .sep { opacity: .5; }

/* compact page hero inside app */
.apphero { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 30px; align-items: end; padding-bottom: 22px; border-bottom: 1px solid var(--line); margin-bottom: 28px; }
.apphero h1 { font-size: clamp(30px, 3.4vw, 44px); max-width: 18ch; }
.apphero .lede { margin-top: 12px; font-size: 16px; }
.apphero .ah-actions { display: flex; gap: 10px; }

/* section block inside app main */
.block-sec { scroll-margin-top: calc(var(--topbar-h) + 16px); margin-top: 40px; }
.block-sec:first-of-type { margin-top: 0; }
.bs-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.bs-head h2 { font-size: 25px; }
.bs-head .bs-sub { font-size: 13px; color: var(--ink-faint); font-family: var(--mono); letter-spacing: .04em; text-transform: uppercase; }

/* tabs (denser app feel) */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.tab { padding: 10px 16px; font-size: 14px; font-weight: 600; color: var(--ink-soft); border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; border-top: 0; border-left: 0; border-right: 0; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent-ink); border-bottom-color: var(--accent); }

/* ============================================================
   DENSE DASHBOARD HUB (landing)
   ============================================================ */
.hub { padding-top: var(--topbar-h); }
.hub-inner { max-width: var(--hub-maxw); margin: 0 auto; padding: 22px 28px 40px; }

.hub-top { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; padding: 4px 2px 20px; }
.hub-top .ht-greet .eyebrow { margin-bottom: 10px; }
.hub-top .ht-greet h1 { font-size: clamp(26px, 3vw, 40px); }
.hub-top .ht-greet p { margin: 8px 0 0; color: var(--ink-soft); font-size: 15px; }
.hub-ticker { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; max-width: 460px; }
.tk-chip { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 9px 13px; min-width: 96px; }
.tk-chip .k { font-family: var(--mono); font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.tk-chip .v { font-family: var(--mono); font-weight: 700; font-size: 15px; margin-top: 3px; }
.tk-chip .c { font-size: 11px; font-weight: 700; }
.tk-chip .c.up { color: var(--up); } .tk-chip .c.down { color: var(--down); }

.hub-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.hub-row2 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; margin-top: 18px; }

/* theme panel */
.tpanel { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); overflow: hidden; display: flex; flex-direction: column; transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease; }
.tpanel:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.tpanel .tp-top { padding: 18px 20px 16px; border-bottom: 1px solid var(--line); background: var(--accent-soft); }
.tpanel .tp-eyebrow { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-ink); font-weight: 700; }
.tpanel .tp-eyebrow .pd { width: 8px; height: 8px; border-radius: 50%; background: var(--t-dot, var(--accent)); }
.tpanel h3 { font-family: var(--serif); font-size: 23px; font-weight: 500; margin-top: 10px; }
.tpanel .tp-desc { font-size: 13px; color: var(--ink-soft); margin-top: 5px; line-height: 1.45; }
.tpanel .tp-list { padding: 10px; display: flex; flex-direction: column; gap: 1px; flex: 1; }
.tp-link { display: grid; grid-template-columns: 30px 1fr auto; gap: 11px; align-items: center; padding: 9px 11px; border-radius: 9px; transition: background .15s ease; }
.tp-link:hover { background: var(--accent-soft); }
.tp-link .tl-ic { width: 30px; height: 30px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; }
.tp-link:hover .tl-ic { background: var(--surface); }
.tp-link .tl-ic svg { width: 16px; height: 16px; }
.tp-link .tl-name { font-size: 13.5px; font-weight: 600; letter-spacing: -.005em; }
.tp-link .tl-tag { font-family: var(--mono); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }
.tp-link .tl-go { color: var(--ink-faint); opacity: 0; transform: translateX(-3px); transition: opacity .15s ease, transform .15s ease; }
.tp-link:hover .tl-go { opacity: 1; transform: none; color: var(--accent-ink); }
.tpanel .tp-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.tpanel .tp-foot .tf-enter { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 700; color: var(--accent-ink); white-space: nowrap; }
.appmain .meta-row .v { white-space: nowrap; }
.tpanel .tp-foot .tf-enter:hover .arrow { transform: translateX(4px); }
.tpanel .tp-foot .tf-count { font-family: var(--mono); font-size: 10px; color: var(--ink-faint); }

/* journal panel */
.jpanel, .spanel { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.panel-head h3 { font-family: var(--serif); font-size: 20px; font-weight: 500; }
.panel-head .ph-link { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; color: var(--ink-soft); }
.panel-head .ph-link:hover { color: var(--ink); }
.jfeed { display: flex; flex-direction: column; }
.jrow { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 13px 18px; border-bottom: 1px solid var(--line-soft); transition: background .15s ease; }
.jrow:last-child { border-bottom: 0; }
.jrow:hover { background: var(--bg); }
.jrow .jr-date { font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint); white-space: nowrap; }
.jrow .jr-cat { display: inline-flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 9px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 4px; }
.jrow .jr-cat .cd { width: 6px; height: 6px; border-radius: 50%; }
.jrow .jr-title { font-size: 14.5px; font-weight: 600; letter-spacing: -.01em; line-height: 1.25; }
.jrow .jr-read { font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint); white-space: nowrap; }

/* spotlight / promo panel */
.spanel .sp-body { padding: 18px; }
.spanel.promo { background: #14130d; color: #f3f1e7; border-color: #14130d; }
.spanel.promo .panel-head { border-bottom-color: rgba(255,255,255,.12); }
.spanel.promo .panel-head h3 { color: #fff; }
.spanel.promo .sp-body p { color: #c7c4b6; font-size: 13.5px; line-height: 1.5; margin: 0 0 14px; }
.spanel.promo .sp-stat { display: flex; gap: 22px; margin-bottom: 16px; }
.spanel.promo .sp-stat .n { font-family: var(--serif); font-size: 26px; color: #fff; }
.spanel.promo .sp-stat .l { font-size: 11px; color: #9b9789; margin-top: 2px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  .hub-grid { grid-template-columns: 1fr; }
  .hub-row2 { grid-template-columns: 1fr; }
  .mega-wide { min-width: 0; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 940px) {
  :root { --topbar-h: 56px; }
  .tb-util { display: none; }
  .topbar { background: var(--surface); }
  .tb-main { height: 56px; padding: 0 14px; }
  .tb-nav { display: none; }
  .tb-burger { display: inline-flex; }
  .tb-mobile-brand { display: inline-flex; }
  .appshell { grid-template-columns: 1fr; }
  .sidemenu { position: fixed; top: 56px; left: 0; bottom: 0; width: 280px; z-index: 250; transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow-md); }
  .sidemenu.open { transform: none; }
  .appmain { padding: 22px 22px 70px; }
  .apphero { grid-template-columns: 1fr; gap: 16px; }
}
@media (min-width: 941px) { .tb-mobile-brand { display: none; } }
@media (max-width: 560px) {
  .hub-top { grid-template-columns: 1fr; }
  .hub-ticker { justify-content: flex-start; }
}
