/* Mobile overrides load last. Shared sticky columns also fix desktop hscroll. */
body.gleaner-app .pos-overview-table :is(th, td):nth-child(2) {
  position: sticky;
  left: var(--pos-check-width, 34px);
  z-index: 2;
  box-shadow: 1px 0 0 var(--border), 5px 0 8px -7px var(--text);
}
body.gleaner-app .pos-overview-table thead th:nth-child(2) { z-index: 5; }
body.gleaner-app :is(.pos-sym-cell, .hodl-sym-cell):has(.sym-menu-panel.open) { z-index: 30; }
body.gleaner-app .pos-sym-main,
body.gleaner-app .pos-sym-text { display: contents; }
body.gleaner-app .pos-check-label { display: inline-flex; align-items: center; justify-content: center; }
body.gleaner-app .pos-sym-link { display: inline-block; max-width: 160px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
body.gleaner-app .hodl-long-table { --hodl-check-width: 44px; }
body.gleaner-app .hodl-long-table :is(th, td):first-child {
  width: var(--hodl-check-width); min-width: var(--hodl-check-width); max-width: var(--hodl-check-width); padding-left: 0; padding-right: 0;
}
body.gleaner-app .hodl-long-table :is(th, td):nth-child(2),
body.gleaner-app .hodl-short-table :is(th, td):first-child {
  position: sticky; left: var(--hodl-check-width, 0px); z-index: 2;
  box-shadow: 1px 0 0 var(--border), 5px 0 8px -7px var(--text);
}
body.gleaner-app .hodl-long-table th:nth-child(2),
body.gleaner-app .hodl-short-table th:first-child { z-index: 5; background: var(--table-head-bg); }
body.gleaner-app .hodl-sym-cell .sym-futures-link,
body.gleaner-app .hodl-sym-cell .hodl-sym-label { display: inline-block; max-width: 140px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
body.gleaner-app tr.hodl-short-no-config > td { background: color-mix(in srgb, var(--muted) 8%, var(--card)); }
/* Brand packs may provide translucent status colors. Composite sticky cells
   over the card so horizontally scrolling text never shows through them. */
body.gleaner-app :is(.pos-overview-table, .hodl-long-table, .hodl-short-table) tbody tr { --sticky-row-fill: var(--card); }
body.gleaner-app :is(.pos-overview-table, .hodl-long-table, .hodl-short-table) tbody tr:hover { --sticky-row-fill: var(--table-hover-bg); }
body.gleaner-app tbody tr.hodl-long-buy-below-max { --sticky-row-fill: var(--row-buy-bg); }
body.gleaner-app tbody tr.hodl-long-buy-below-max:hover { --sticky-row-fill: var(--row-buy-bg-hover); }
body.gleaner-app tbody tr.hodl-long-sell-above-max { --sticky-row-fill: var(--row-sell-bg); }
body.gleaner-app tbody tr.hodl-long-sell-above-max:hover { --sticky-row-fill: var(--row-sell-bg-hover); }
body.gleaner-app tbody tr.hodl-long-below-min { --sticky-row-fill: color-mix(in srgb, var(--warn) 10%, var(--card)); }
body.gleaner-app tbody tr.hodl-long-below-min:hover { --sticky-row-fill: color-mix(in srgb, var(--warn) 16%, var(--card)); }
body.gleaner-app tbody tr.hodl-short-no-config { --sticky-row-fill: color-mix(in srgb, var(--muted) 8%, var(--card)); }
body.gleaner-app tbody tr.gleaner-position-selected,
body.gleaner-app tbody tr.gleaner-position-selected:hover { --sticky-row-fill: var(--active-bg); }
body.gleaner-app :is(.pos-overview-table, .hodl-long-table) tbody td:nth-child(-n+2),
body.gleaner-app .hodl-short-table tbody td:first-child {
  background: linear-gradient(var(--sticky-row-fill), var(--sticky-row-fill)), var(--card);
}

/* Adding semantic nav classes must not activate the legacy desktop glyph rules. */
@media (min-width: 761px) {
  body.gleaner-app #workbar-rail .rail-glyph { display: block; width: 1.05rem; height: 1.05rem; flex: 0 0 auto; }
  body.gleaner-app #workbar-rail .rail-label { font: inherit; }
}

@media (max-width: 760px) {
  body.gleaner-app > .gleaner-topbar {
    padding-top: max(6px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  body.gleaner-app #detail.v2-workspace {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  /* The high specificity also covers controls inside dialogs and drawers. */
  body.gleaner-app :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    font-size: 16px !important;
  }
  body.gleaner-app :is(.modal-panel, .drawer-body, .drawer-panel) { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  body.gleaner-app :is(.pos-lifeline-pill .meta, .pos-lifeline-margin-title, .pos-lifeline-margin-note,
    .pos-lifeline-margin-table th, .pos-lifeline-margin-table .pm-bnb-tag, .pos-equity-title, .pos-equity-note,
    .pos-equity-pill, .pos-equity-legend, .pos-equity-empty, .pos-equity-svg text, .pos-detail-mark em, .pos-detail-kv, .funding-kpi .l,
    .pos-detail-label, .pos-mobile-account) { font-size: 12px; }
  body.gleaner-app .pos-overview-table :is(td, td .num, .pos-pile-chip, .pos-range-gap) { font-size: 13px; }
  body.gleaner-app .mh-quality { font-size: 12px; }
  body.gleaner-app #pre-order-drawer-path { font-size: 12px; }
  body.gleaner-app .pos-overview-table :is(th, td) { padding: 6px 8px; }
  body.gleaner-app .pos-overview-table :is(th, td):first-child { width: 44px; min-width: 44px; padding: 0; }
  body.gleaner-app .pos-check-label,
  body.gleaner-app .hodl-check-label { position: absolute; inset: 0; display: flex; width: 100%; height: 100%; min-height: 52px; align-items: center; justify-content: center; cursor: pointer; }
  /* Keep the familiar small checkbox drawing inside a real 40px hit target. */
  body.gleaner-app input:is(.pos-overview-check, .hodl-long-batch-check) {
    appearance: none; -webkit-appearance: none; position: relative;
    flex: 0 0 40px; width: 40px; height: 40px; margin: 0; padding: 0;
    border: 0; border-radius: 4px; background: transparent; cursor: pointer;
  }
  body.gleaner-app input:is(.pos-overview-check, .hodl-long-batch-check)::before {
    content: ""; position: absolute; inset: 12px; border: 1px solid var(--muted); border-radius: 3px; background: var(--card);
  }
  body.gleaner-app input:is(.pos-overview-check, .hodl-long-batch-check):checked::before { background: var(--accent); border-color: var(--accent); }
  body.gleaner-app input:is(.pos-overview-check, .hodl-long-batch-check):checked::after {
    content: ""; position: absolute; left: 17px; top: 14px; width: 5px; height: 9px; border: solid var(--btn-primary-fg, #fff); border-width: 0 2px 2px 0; transform: rotate(45deg);
  }
  body.gleaner-app input:is(.pos-overview-check, .hodl-long-batch-check):disabled { opacity: .45; cursor: default; }
  body.gleaner-app .pos-overview-table .pos-sym-main { display: flex; align-items: center; gap: 8px; }
  body.gleaner-app .pos-overview-table .pos-sym-text { display: flex; flex-direction: column; min-width: 0; }
  body.gleaner-app .pos-overview-table td.pos-sym-cell :is(.pos-serve-dot, .sym-menu) { flex-shrink: 0; margin: 0; }
  body.gleaner-app .pos-overview-table td.pos-sym-cell .pos-menu-btn { width: 40px; min-width: 40px; height: 40px; min-height: 40px; padding: 0; }
  body.gleaner-app .pos-overview-table .pos-sym-link { min-width: 40px; max-width: 112px; height: 40px; line-height: 40px; }
  body.gleaner-app .pos-mobile-account { max-width: 112px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); line-height: 1.3; }
  body.gleaner-app :is(.sym-refresh-btn, .gleaner-position-link) { min-width: 40px; min-height: 40px; }
}

/* Disclosures preserve the desktop text and spacing. */
body.gleaner-app .pos-mobile-explanation { display: contents; }
body.gleaner-app .pos-mobile-explanation > summary { display: none; }
body.gleaner-app .pos-mobile-batch-actions { display: contents; }
body.gleaner-app :is(.pos-mobile-batch-label, .btn-pos-overview-clear-selection) { display: none; }

@media (max-width: 760px) {
  body.gleaner-app #detail.v2-workspace { padding-bottom: calc(20px + var(--mobile-batch-height, 0px) + var(--mobile-nav-height, 0px)); }
  body.gleaner-app .pos-mobile-explanation { display: block; margin: 0 0 6px; width: 100%; }
  body.gleaner-app .pos-mobile-explanation > summary { display: list-item; width: fit-content; min-height: 32px; padding: 4px 0; font-size: 12px; color: var(--muted); cursor: pointer; }
  body.gleaner-app .pos-mobile-explanation > p { margin: 4px 0 8px; }
  body.gleaner-app .pos-overview > .detail-head {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start;
    gap: 8px; margin-bottom: 6px; padding-bottom: 0;
  }
  body.gleaner-app .pos-overview > .detail-head .detail-head-actions { width: auto; }
  body.gleaner-app .pos-overview .pos-overview-tabs { margin-bottom: 6px; }
  body.gleaner-app .pos-lifeline { margin-bottom: 10px; }
  body.gleaner-app .pos-lifeline-toggle { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 8px 10px; text-align: left; }
  body.gleaner-app .pos-lifeline-title { grid-column: 1; grid-row: 1; }
  body.gleaner-app .pos-lifeline-chevron { grid-column: 2; grid-row: 1; }
  body.gleaner-app .pos-lifeline-pills { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; width: 100%; margin: 0; }
  body.gleaner-app .pos-lifeline-pill { min-width: 0; padding: 5px 6px; }
  body.gleaner-app .pos-lifeline-pill strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
  body.gleaner-app .pos-lifeline-pill:is([data-pos-lifeline-metric="equity"], [data-pos-lifeline-metric="unimmr"]) strong { font-size: 16px; }
  body.gleaner-app .detail-head-actions:has(.mobile-primary-actions) { display: flex; align-items: center; flex-wrap: nowrap; gap: 8px; height: 44px; }
  body.gleaner-app .gleaner-page-heading:has(.mobile-primary-actions) { flex-wrap: nowrap; }
  body.gleaner-app .gleaner-page-heading > .detail-head-actions:has(.mobile-primary-actions) { width: auto; flex: 0 0 auto; }
  body.gleaner-app .gleaner-page-heading:has(.mobile-primary-actions) > div:first-child { min-width: 0; }
  body.gleaner-app .mobile-primary-actions { position: relative; order: 2; }
  body.gleaner-app .mobile-primary-toggle { width: 44px; height: 44px; padding: 0; font-size: 22px; }
  body.gleaner-app :is(.mobile-primary-menu, .mobile-batch-menu) {
    position: absolute; z-index: 100; right: 0; min-width: 170px; padding: 6px;
    display: flex; flex-direction: column; gap: 4px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg);
  }
  body.gleaner-app .mobile-primary-menu { top: calc(100% + 6px); }
  body.gleaner-app .mobile-primary-menu button { width: 100%; text-align: left; }
  body.gleaner-app .pos-overview-batch { min-height: 40px; flex-wrap: nowrap; margin-bottom: 6px; gap: 8px; }
  body.gleaner-app .mobile-batch-dock {
    position: fixed; z-index: 160; left: 0; right: 0; bottom: calc(var(--mobile-nav-height, 0px) + var(--mobile-batch-offset, 0px));
    display: flex; flex-direction: column; gap: 6px; padding: 8px max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    border-top: 1px solid var(--border-strong); background: var(--card); box-shadow: 0 -4px 16px color-mix(in srgb, var(--text) 10%, transparent);
  }
  body.gleaner-app .pos-mobile-batch-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
  body.gleaner-app .pos-mobile-batch-label { display: block; flex: 1 1 auto; font-size: 12px; }
  body.gleaner-app .btn-pos-overview-clear-selection { display: inline-flex; }
  body.gleaner-app .mobile-batch-dock button { min-height: 40px; padding: 7px 10px; font-size: 13px; }
  body.gleaner-app .mobile-batch-dock .pos-mobile-batch-actions:not([hidden]) + .pos-mobile-batch-actions:not([hidden]) { padding-top: 6px; border-top: 1px solid var(--border); }
  body.gleaner-app .hodl-mobile-batch-dock { flex-flow: row wrap; align-items: center; }
  body.gleaner-app .hodl-mobile-batch-dock #gleaner-hodl-batch-actions { display: flex; gap: 6px; padding: 0; flex-wrap: wrap; }
  body.gleaner-app .mobile-batch-more { position: relative; margin-left: auto; }
  body.gleaner-app .mobile-batch-menu { bottom: calc(100% + 6px); }
  body.gleaner-app .mobile-batch-scope-note { font-size: 12px; color: var(--muted); padding: 4px; }
  body.gleaner-app .pos-overview-table tfoot td { background: var(--table-head-bg); }
  body.gleaner-app .mobile-tabs-scroll { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; max-width: 100%; scrollbar-width: none; }
  body.gleaner-app .mobile-tabs-scroll > * { flex-shrink: 0; }
  body.gleaner-app .mobile-tabs-scroll.mobile-overflow-right { mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent); }
  body.gleaner-app .mobile-tabs-scroll.mobile-overflow-left { mask-image: linear-gradient(to right, transparent, #000 22px); }
  body.gleaner-app .mobile-tabs-scroll.mobile-overflow-left.mobile-overflow-right { mask-image: linear-gradient(to right, transparent, #000 22px, #000 calc(100% - 22px), transparent); }
}

@media (max-width: 760px) {
  body.gleaner-app {
    --mobile-nav-height: calc(56px + env(safe-area-inset-bottom));
    --v2-bottom-nav-height: var(--mobile-nav-height);
    display: block; height: auto; min-height: 100dvh; overflow: visible;
  }
  body.gleaner-app > .gleaner-topbar {
    position: sticky; top: 0; z-index: 70; flex-wrap: nowrap; gap: 8px;
    height: calc(52px + env(safe-area-inset-top)); min-height: calc(52px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }
  body.gleaner-app .gleaner-brand-symbol { width: 28px; height: 28px; }
  body.gleaner-app .gleaner-brand-name { font-size: 20px; }
  body.gleaner-app #gleaner-menu-toggle,
  body.gleaner-app .gleaner-topbar #btn-theme-cycle { display: none; }
  body.gleaner-app .gleaner-user-tools { flex-wrap: nowrap; }
  body.gleaner-app #workbar-rail.gleaner-nav,
  body.gleaner-app.gleaner-menu-open #workbar-rail.gleaner-nav {
    position: fixed; inset: auto 0 0; z-index: 120;
    display: flex; flex-flow: row nowrap; align-items: stretch; gap: 0;
    width: 100%; height: var(--mobile-nav-height); min-height: 0; margin: 0;
    padding: 0 max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
    border: 0; border-top: 1px solid var(--border); background: var(--chrome-mobile-nav); overflow: visible;
  }
  body.gleaner-app #workbar-rail .rail-item {
    flex: 1 1 0; flex-direction: column; justify-content: center; gap: 2px;
    width: 0; min-width: 0; height: 55px; min-height: 55px; padding: 4px 0; border-radius: 0;
  }
  body.gleaner-app #workbar-rail .rail-glyph { display: block; width: 20px; height: 20px; flex: 0 0 20px; }
  body.gleaner-app #workbar-rail .rail-label { display: block; font-size: 12px; line-height: 18px; white-space: nowrap; }
  body.gleaner-app .gleaner-shell { display: block; height: auto; min-height: 0; overflow: visible; }
  body.gleaner-app #detail.v2-workspace { height: auto; max-height: none; overflow: visible; padding-bottom: calc(20px + var(--mobile-nav-height) + var(--mobile-batch-height, 0px)); }
  body.gleaner-app .gleaner-workspace-context { min-height: 54px; padding-top: 5px; padding-bottom: 5px; }
  body.gleaner-app .table-wrap { max-height: none; overflow-x: auto; overflow-y: hidden; }
  body.gleaner-app :has(> .config-servers-table) { position: relative; min-width: 0; max-width: 100%; overflow-x: auto; }
  body.gleaner-app .config-subpanel .ops-field { min-width: 0 !important; max-width: 100%; }
  body.gleaner-app .config-subpanel .cfg-field-key { overflow-wrap: anywhere; }
  body.gleaner-app th { position: static; }
  body.gleaner-app #workbar-panel.v2-context-panel,
  body.gleaner-app.gleaner-menu-open #workbar-panel.v2-context-panel {
    position: fixed; z-index: 220; top: calc(58px + env(safe-area-inset-top)); bottom: auto;
    left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
    width: auto; max-width: none; max-height: calc(100dvh - 70px - env(safe-area-inset-top) - var(--mobile-nav-height));
  }
  body.gleaner-app .shell:not(.workbar-collapsed) > .workbar-scrim[aria-hidden="false"] {
    position: fixed; z-index: 210; inset: 0; background: var(--overlay); backdrop-filter: none;
  }
  body.gleaner-app .mobile-theme-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
  body.gleaner-app .mobile-theme-row .theme-switch:not([hidden]) { display: flex !important; justify-content: space-between; align-items: center; gap: 12px; }
  body.gleaner-app .mobile-theme-row .theme-select { display: block; width: auto; min-width: 110px; }
  body.gleaner-app :is(.modal-backdrop, .drawer-backdrop) { z-index: 500; }
  body.gleaner-app .modal-backdrop { padding-bottom: calc(14px + var(--mobile-nav-height)); padding-top: max(14px, env(safe-area-inset-top)); }
  body.gleaner-app .modal-panel { max-height: calc(100dvh - 28px - env(safe-area-inset-top) - var(--mobile-nav-height)); }
  body.gleaner-app button.action-confirm-mode-btn:not(.is-on):not([aria-pressed="true"]),
  body.gleaner-app button.action-confirm-mode-btn:not(.is-on):not([aria-pressed="true"]):hover:not(:disabled) { background: var(--card); }
  body.gleaner-app button.action-confirm-mode-btn:is(.is-on, [aria-pressed="true"]),
  body.gleaner-app button.action-confirm-mode-btn:is(.is-on, [aria-pressed="true"]):hover:not(:disabled) { color: var(--btn-primary-fg, #fff); }
  body.gleaner-app .drawer-panel { bottom: var(--mobile-nav-height); height: calc(100dvh - var(--mobile-nav-height)); max-height: calc(100dvh - var(--mobile-nav-height)); }
  body.gleaner-app .pos-overview-table .pos-col-settings > div { z-index: 240; max-height: calc(100dvh - var(--mobile-nav-height) - 80px); overflow: auto; background: var(--card); }
}
