/* CA_THEDRAL — Toolbox styles. R-020 founding module.
   S38 aesthetic pass: dead-rule removal + capsule calculator + 7-col grid +
   strategy-color targeting + center-when-few-chips + mobile fullscreen-below-header. */

/* ═══ TOGGLE BAR (closed state) — sticky bottom of tab content ═══ */
.ct-toolbox-host {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: var(--surface-raised);
  border-top: 1px solid var(--border-default);
  margin-top: auto;
  flex-shrink: 0;
}

.ct-toolbox-toggle {
  width: 100%;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface-raised);
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  transition: background 0.15s, color 0.15s;
}

.ct-toolbox-toggle:hover {
  background: var(--surface-elevated);
  color: var(--text-primary);
}

.ct-toolbox-gear {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: color 0.15s;
}

.ct-toolbox-host.open .ct-toolbox-gear { color: var(--global-green); }

.ct-toolbox-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 5px;
  border-radius: 8px;
  background: var(--global-green);
  color: #000;
  font-size: 10px;
  font-weight: 700;
}

.ct-toolbox-badge[hidden] { display: none; }

/* ═══ DRAWER (open state) ═══ */
.ct-drawer {
  height: 0;
  overflow: hidden;
  transition: height 0.25s ease;
  background: var(--surface-raised);
  border-top: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
}

.ct-toolbox-host.open .ct-drawer {
  height: 230px;
}

/* ═══ TIER 2: TAB SCAFFOLDING ═══ */

.ct-tab-strip {
  display: flex;
  align-items: stretch;
  height: 36px;
  background: var(--surface-base);
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
}

/* Round 8: tab buttons match top-of-page .lp-btn styling for visual parity. */
.ct-tab-btn {
  padding: 7px 20px;
  background: var(--surface-elevated);
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: all 0.15s;
  border-radius: 0;
}

.ct-tab-btn + .ct-tab-btn { border-left: 1px solid var(--border-emphasis); }

.ct-tab-btn:hover { color: var(--text-secondary); background: var(--surface-overlay); }

.ct-tab-btn.active {
  background: var(--global-green);
  color: #000000;
}

/* Round 8: tab funnel button — sort-icon-btn parity, sits inline next to Calculator (matches top nav layout). */
.ct-tab-funnel-btn {
  background: var(--surface-elevated);
  color: var(--text-muted);
  border: none;
  border-left: 1px solid var(--border-emphasis);
  cursor: pointer;
  width: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.15s;
}

.ct-tab-funnel-btn:hover { background: var(--surface-overlay); color: var(--text-primary); }

.ct-tab-funnel-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* Tab body container — flex column with universal vertical centering */
.ct-tab-bodies {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.ct-tab-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 18px 22px;
}

.ct-tab-body[hidden] { display: none; }

.ct-tab-body:not([hidden]) {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* ═══ TIER 3: CALCULATOR INHABITANT (S38 aesthetic pass — capsule container + 7-col grid) ═══ */

/* Outer capsule — wraps entire calculator field; centered within tab body.
   5-col grid: input1 | connector | input2 | CALCULATE | result.
   Rows use display:contents so children flow into the parent grid for
   strict shared-column alignment across all 3 rows. */
.ct-calc-rows {
  display: grid;
  grid-template-columns: 90px 130px 90px 110px minmax(160px, 1fr);
  align-items: center;
  gap: 10px 12px;
  background: var(--surface-elevated);
  border: 1px solid var(--border-emphasis);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

/* Rows transparent — 7 children flow into parent grid for shared-col alignment.
   Markup flattened S38 (.ct-calc-row-body wrapper removed) so 7 children are
   direct descendants of .ct-calc-row. */
.ct-calc-row { display: contents; }

.ct-calc-row-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: right;
}

.ct-calc-input {
  width: 100%;
  padding: 7px 10px;
  background: var(--surface-raised);
  border: 1px solid var(--border-emphasis);
  color: var(--text-primary);
  font-family: var(--font-numeric);
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  appearance: textfield;
  -moz-appearance: textfield;
  box-sizing: border-box;
}
.ct-calc-input::-webkit-outer-spin-button,
.ct-calc-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ct-calc-input:focus { outline: none; border-color: var(--global-green); }

.ct-calc-connector {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
  text-align: center;
}

.ct-calc-button {
  padding: 7px 12px;
  background: var(--global-blue);
  color: #fff;
  border: 1px solid var(--global-blue);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  text-align: center;
}
/* Result capsule — same shape as button (background, border, radius, height) */
.ct-calc-result {
  background: var(--surface-raised);
  border: 1px solid var(--border-emphasis);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-family: var(--font-numeric);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-sizing: border-box;
}
.ct-calc-result.positive { color: var(--global-green); border-color: var(--global-green); }
.ct-calc-result.negative { color: var(--global-red); border-color: var(--global-red); }
.ct-calc-result.empty    { color: var(--text-muted); }

.ct-calc-copy {
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  text-align: center;
}
.ct-calc-copy:hover { color: var(--global-green); background: var(--surface-elevated); }
.ct-calc-copy.copied { color: var(--global-green); }

/* ═══ R-054 TIER 1 (revised): POSITIONS TAB BODY ═══ */

.ct-tab-body[data-tab-body="positions"] { padding: 0; }

/* Strip list wrapper — horizontal flex containing left arrow + list + right arrow.
   Native scrollbar is hidden; left/right arrows scroll programmatically when list overflows. */
.ct-strip-list-wrap {
  display: flex;
  align-items: center;
  flex: 1;
  min-height: 0;
  position: relative;
}

.ct-strip-list {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 8px;
  padding: 14px 16px;
  align-items: center;
  justify-content: safe center;
  flex: 1;
  min-width: 0;
  scroll-behavior: smooth;
  scrollbar-width: none;       /* Firefox */
  -ms-overflow-style: none;    /* IE/Edge */
}

/* Hide native horizontal scrollbar — replaced by ◀ ▶ arrow buttons */
.ct-strip-list::-webkit-scrollbar { display: none; }

/* Carousel arrow buttons (left/right of strip list) */
.ct-strip-arrow {
  background: var(--surface-raised);
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 28px;
  height: 28px;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 6px;
  padding: 0;
  line-height: 1;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  font-family: inherit;
}
.ct-strip-arrow:hover { background: var(--surface-elevated); color: var(--global-green); border-color: var(--border-emphasis); }
.ct-strip-arrow[hidden] { display: none; }

.ct-strip-empty {
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
  padding: 30px 16px;
  text-align: center;
  width: 100%;
}

.ct-strip-chip {
  flex: 0 0 auto;
  min-width: 140px;
  max-width: 200px;
  padding: 10px 12px;
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ct-strip-chip-line1 {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ct-strip-chip-symbol {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.ct-strip-chip-strat {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 2px;
  color: var(--text-secondary);
  border: 1px solid var(--border-emphasis);
  background: var(--surface-elevated);
}

/* Strategy-specific color tokens — match cathedral's stratStyle() helper at index.html:2806.
   Falls back to neutral var(--text-secondary)/var(--surface-elevated) when data-strat is absent. */
.ct-strip-chip-strat[data-strat="DCA"]    { color: var(--badge-strategy-1); border-color: rgba(45,201,138,0.45);  background: rgba(45,201,138,0.08); }
.ct-strip-chip-strat[data-strat="SNIPER"] { color: var(--badge-strategy-2); border-color: rgba(107,163,245,0.45); background: rgba(107,163,245,0.08); }
.ct-strip-chip-strat[data-strat="APE"]    { color: var(--badge-strategy-3); border-color: rgba(245,124,42,0.45);  background: rgba(245,124,42,0.08); }
.ct-strip-chip-strat[data-strat="R1P2"]   { color: var(--badge-strategy-4); border-color: rgba(240,98,146,0.45); background: rgba(240,98,146,0.08); }
.ct-strip-chip-strat[data-strat="RUNNER"] { color: var(--badge-strategy-5); border-color: rgba(255,210,63,0.45);  background: rgba(255,210,63,0.08); }

.ct-strip-chip-deployed {
  font-family: var(--font-numeric);
  font-size: 11px;
  color: var(--text-muted);
}

.ct-strip-chip-deployed b {
  color: var(--text-secondary);
  font-weight: 600;
}

/* P&L line — cathedral canonical render: "+0.0034 SOL/+5.43%"
   Separator span styled muted; SOL value + percent share the colored class on parent. */
.ct-strip-chip-pnl {
  font-family: var(--font-numeric);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 2px;
}

.ct-strip-chip-pnl.positive { color: var(--global-green); }
.ct-strip-chip-pnl.negative { color: var(--global-red); }

.ct-strip-chip-pnl .ct-strip-chip-pnl-sep { color: var(--text-secondary); }

/* ═══ R-020 ROUND 8: TOOLBOX SORT/FILTER DRAWER (collapsing, funnel-toggled) ═══ */

.ct-strip-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-numeric);
  white-space: nowrap;
  align-self: center;
}

.ct-toolbox-sort-drawer {
  max-height: 0;
  overflow: visible;
  transition: max-height 0.3s ease, opacity 0.2s ease;
  opacity: 0;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
}

.ct-toolbox-sort-drawer:not(.open) {
  pointer-events: none;
}

.ct-toolbox-sort-drawer.open {
  max-height: 220px;
  opacity: 1;
}

.ct-toolbox-sort-controls {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 12px 24px 14px;
  flex-wrap: wrap;
}

.ct-toolbox-sort-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 180px;
}

.ct-toolbox-sort-wallet-picker {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 180px;
}

/* .ct-toolbox-sort-wallet-panel inherits position:fixed from .sort-wallet-panel to escape .ct-drawer overflow:hidden clip.
   JS handler (ctToolboxWalletToggle) computes pixel coordinates from button.getBoundingClientRect at toggle time. */
.ct-toolbox-sort-wallet-panel {
  z-index: 1000;
}

/* ═══ R-054 TIER 4: ALERT BADGES ═══ */

.ct-strip-alert {
  position: relative;
  border-left: 3px solid var(--text-secondary);
}
.ct-strip-alert.positive { border-left-color: var(--global-green); }
.ct-strip-alert.negative { border-left-color: var(--global-red); }

.ct-strip-alert-reason {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-top: 2px;
}
.ct-strip-alert.positive .ct-strip-alert-reason { color: var(--global-green); }
.ct-strip-alert.negative .ct-strip-alert-reason { color: var(--global-red); }

.ct-strip-alert-pnl {
  font-family: var(--font-numeric);
  font-size: 12px;
  font-weight: 600;
  margin-top: 2px;
}
.ct-strip-alert.positive .ct-strip-alert-pnl { color: var(--global-green); }
.ct-strip-alert.negative .ct-strip-alert-pnl { color: var(--global-red); }

.ct-strip-alert-dismiss {
  position: absolute;
  top: 4px;
  right: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: inherit;
}
.ct-strip-alert-dismiss:hover { color: var(--text-primary); background: var(--surface-elevated); }

/* ═══ THEME OVERRIDES — relocated S66 Phase D iter3 to theme-retro-light.css
   (component CSS becomes theme-blind per Phase D principle). ═══ */

/* ═══ MOBILE / RESPONSIVE — fullscreen-below-header (cluster-scope per S38 D-T-A2-revised) ═══ */
/*
   Cathedral mobile chrome heights:
     topbar = 52px (index.html @media line 686)
     mobile-bottom-nav = 60px (#app padding-bottom)
   Open toolbox drawer = fullscreen between these two bars.
   44px HIG min-height on all interactive elements per S38 Q-T-A1.
*/
@media (max-width: 768px) {
  /* Drawer fullscreen between topbar and pinned toggle. Anchors use env() so
     content respects safe-area-inset on notched devices (iPhone X+) and the
     existing cathedral mobile chrome that already uses env() for topbar/bottom-nav. */
  .ct-toolbox-host.open .ct-drawer {
    position: fixed;
    top: calc(52px + env(safe-area-inset-top, 0px));
    left: env(safe-area-inset-left, 0px);
    right: env(safe-area-inset-right, 0px);
    bottom: calc(104px + env(safe-area-inset-bottom, 0px));
    height: auto;
    width: auto;
    z-index: 250;
    border-top: none;
    box-sizing: border-box;
  }
  /* Closed-state drawer: zero-height collapse (no fixed render) */
  .ct-toolbox-host:not(.open) .ct-drawer {
    height: 0;
  }

  /* Toggle bar — 44px HIG height; preserve mobile font size */
  .ct-toolbox-toggle {
    height: 44px;
    font-size: 10px;
    letter-spacing: 1px;
  }
  /* Open-state: toggle pinned at bottom (above mobile-bottom-nav) so it stays visible
     above the fullscreen drawer and tappable to close. z-index 251 > drawer's 250. */
  .ct-toolbox-host.open .ct-toolbox-toggle {
    position: fixed;
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    left: env(safe-area-inset-left, 0px);
    right: env(safe-area-inset-right, 0px);
    width: auto;
    z-index: 251;
    background: var(--surface-raised);
    border-top: 1px solid var(--border-default);
    border-bottom: 1px solid var(--border-default);
    margin: 0;
    box-sizing: border-box;
  }

  /* Tab strip — 44px HIG; explicit padding so tabs sit flush with drawer's left edge */
  .ct-tab-strip {
    height: 44px;
    padding: 0;
  }
  .ct-tab-btn {
    min-height: 44px;
    padding: 0 16px;
    flex-shrink: 0;
    min-width: 0;
    box-sizing: border-box;
  }

  /* Calculator — single-column stack on mobile */
  .ct-calc-rows {
    display: flex;
    flex-direction: column;
    grid-template-columns: unset;
    padding: 14px 14px;
    gap: 14px;
  }
  .ct-calc-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .ct-calc-row-label {
    text-align: left;
  }
  .ct-calc-input {
    min-height: 44px;
    font-size: 14px;
  }
  .ct-calc-button {
    min-height: 44px;
    padding: 12px 16px;
  }
  .ct-calc-result {
    min-height: 44px;
    padding: 12px;
  }
  .ct-calc-copy {
    min-height: 44px;
    min-width: 44px;
    padding: 12px;
    align-self: center;
  }

  /* Round 8: toolbox sort drawer — 44px HIG on mobile */
  .ct-toolbox-sort-drawer:not(.open) {
  pointer-events: none;
}

.ct-toolbox-sort-drawer.open { max-height: 320px; }
  .ct-toolbox-sort-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px 16px 14px;
  }
  .ct-toolbox-sort-group { min-width: 0; }
  .ct-toolbox-sort-wallet-picker { min-width: 0; width: 100%; }
  .ct-strip-count { width: 100%; text-align: right; }
  .ct-tab-funnel-btn { min-width: 44px; min-height: 44px; }

  /* Alert dismiss — 44px HIG (most mis-tap-prone control on the strip) */
  .ct-strip-alert-dismiss {
    min-width: 44px;
    min-height: 44px;
    top: 0;
    right: 0;
    padding: 8px;
    font-size: 18px;
  }

  /* Chip min-width tighter on mobile to allow more chips per row */
  .ct-strip-chip {
    min-width: 130px;
  }
}

/* End toolbox.css */
