/* =====================================================================
 * Prime Koders v5 — new components (levels & wallet, deposit, roles,
 * investors, materials, insights, presence) and the native-app layer for
 * phones: bottom tab bar, menu sheet, compact header, cards instead of
 * tables, bottom-sheet filters and dialogs, safe areas and touch feedback.
 * Loaded last, after pro.css.
 * =================================================================== */

/* ---------- Spacing safety: long words and numbers never overlap ---------- */
h1, h2, h3, h4, p, li, td, th, label, .card-title, .stat-label, .pill, .badge, .tag, strong, small { overflow-wrap: break-word; }
h1, h2, h3, h4 { line-height: 1.25; word-break: normal; }
.flex, .flex-between, .btn-row, .card-meta, .dash-head, .card-head, .project-stats, .tags { row-gap: 8px; }
.dash-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.dash-head > div:first-child { min-width: 0; flex: 1 1 320px; }
.dash-head .flex { flex-wrap: wrap; }
.stat-card > div { min-width: 0; }
.stat-value { overflow-wrap: normal; white-space: nowrap; }
.btn { white-space: nowrap; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn-row form { margin: 0; }
.flex form { margin: 0; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.justify-center { justify-content: center; }
.pre-line { white-space: pre-line; }
.text-amber { color: var(--amber-text); }
hr.rule { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.pill-cyan { background: rgba(6, 182, 212, 0.12); color: var(--cyan-text); border-color: rgba(6, 182, 212, 0.3); }
.notice-warning { border-style: solid; }
.notice.small { font-size: 0.86rem; padding: 10px 14px; }
.tag-outline { background: transparent; border: 1px dashed var(--border-strong); }
.list.compact li { padding: 9px 0; }
.list.compact .list-main { min-width: 160px; }
.thumb-lg { width: 64px; height: 48px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.muted-row td { color: var(--muted); }
.side-count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--amber); color: #1a1300; font-size: 0.7rem; font-weight: 800; display: inline-grid; place-items: center; }
.otp-resend { margin: 0; }
.otp-resend button[disabled] { opacity: 0.75; cursor: default; }
.otp-resend small { margin-top: 6px; }

/* ---------- Stars & levels ---------- */
.rank-stars { display: inline-flex; gap: 2px; color: #f5a524; vertical-align: middle; }
.rank-stars .fa-regular { color: var(--border-strong); }
.rank-stars-sm { font-size: 0.72rem; }
.rank-stars-lg { font-size: 1.25rem; gap: 4px; margin: 6px 0; }
.rank-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 0.76rem; font-weight: 700; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-strong); white-space: nowrap; vertical-align: middle; }
.rank-badge .rank-stars { margin-left: 2px; }
.rank-grey { --rank: #7a847b; }
.rank-cyan { --rank: #0f9d8a; }
.rank-indigo { --rank: #2f6fd6; }
.rank-violet { --rank: #7c4ddb; }
.rank-amber { --rank: #c27c00; }
.rank-badge > i:first-child { color: var(--rank, var(--accent)); }
.rank-dot { position: absolute; right: -4px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; background: var(--rank, var(--accent)); color: #fff; font-size: 0.55rem; box-shadow: 0 0 0 2px var(--header-bg); }

.rank-card { display: grid; gap: 14px; margin-bottom: 20px; }
.rank-card-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.rank-card-head h3 { margin: 2px 0 0; font-size: 1.3rem; display: flex; gap: 8px; align-items: center; }
.rank-card-head h3 i { color: #f5a524; }
.wallet-chip { display: inline-flex; flex-direction: column; align-items: flex-end; padding: 8px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); border: 1px solid var(--accent-line); color: var(--text-strong); line-height: 1.2; }
.wallet-chip small { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; }
.wallet-chip strong { font-size: 1.1rem; }
.wallet-chip:hover { color: var(--text-strong); border-color: var(--accent); }
.rank-ladder { list-style: none; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin: 0; padding: 0; counter-reset: lvl; }
.rank-ladder li { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px 8px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); color: var(--subtle); font-size: 0.74rem; font-weight: 600; text-align: center; min-width: 0; }
.rank-ladder li i { font-size: 1rem; }
.rank-ladder li span { overflow-wrap: normal; word-break: keep-all; }
.rank-ladder li.done { background: var(--accent-soft); border-color: var(--accent-line); color: var(--green-text); }
.rank-ladder li.current { background: var(--surface); border-color: var(--accent); color: var(--text-strong); box-shadow: 0 0 0 3px var(--accent-soft); }
.rank-ladder li.current i { color: #f5a524; }

.sidebar-rank { display: grid; gap: 4px; }
.sidebar-rank > span:first-child { display: flex; align-items: center; gap: 8px; }
.sidebar-rank small { float: none; }
.sidebar-wallet { font-size: 0.78rem; color: var(--muted); font-weight: 600 !important; }

/* ---------- Wallet page ---------- */
.wallet-top { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; margin-bottom: 20px; }
.rank-hero { display: grid; gap: 14px; align-content: start; }
.rank-hero-head { display: flex; gap: 16px; align-items: center; }
.rank-hero-head h2 { margin: 2px 0 0; font-size: 1.5rem; }
.rank-hero-icon { width: 64px; height: 64px; flex-shrink: 0; border-radius: 18px; display: grid; place-items: center; font-size: 1.6rem; color: #fff; background: var(--rank, var(--accent)); box-shadow: 0 8px 24px color-mix(in srgb, var(--rank, var(--accent)) 35%, transparent); }
.wallet-card { display: grid; gap: 10px; align-content: start; }
.wallet-amount { font-size: 2.3rem; font-weight: 800; color: var(--text-strong); line-height: 1.1; letter-spacing: -0.02em; }
.wallet-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 6px 0; }
.wallet-stats div { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); min-width: 0; }
.wallet-stats dt { font-size: 0.74rem; color: var(--muted); margin: 0 0 2px; }
.wallet-stats dd { margin: 0; font-weight: 700; color: var(--text-strong); }
.wallet-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px; }
.earn-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; }
.earn-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.earn-list li:last-child { border-bottom: 0; }
.earn-list strong { color: #c27c00; white-space: nowrap; }
.form-stack { display: grid; gap: 4px; }
.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented label { position: relative; flex: 1 1 140px; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); font-weight: 600; font-size: 0.9rem; text-align: center; }
.segmented input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--text-strong); box-shadow: inset 0 0 0 1px var(--accent); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
fieldset.form-group { border: 0; padding: 0; margin: 0 0 16px; }
fieldset.form-group legend { font-weight: 600; font-size: 0.9rem; margin-bottom: 8px; color: var(--text-strong); padding: 0; }

.withdraw-list { display: grid; gap: 14px; }
.withdraw-item { display: grid; gap: 12px; }
.withdraw-main { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.withdraw-amount { text-align: right; display: grid; }
.withdraw-amount strong { font-size: 1.35rem; color: var(--text-strong); }
.withdraw-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0; }
.withdraw-meta dt { font-size: 0.74rem; color: var(--muted); }
.withdraw-meta dd { margin: 2px 0 0; font-weight: 600; min-width: 0; }
.withdraw-actions { display: grid; gap: 10px; border-top: 1px solid var(--border); padding-top: 12px; }

/* ---------- Registration deposit ---------- */
.deposit-page, .narrow-page { padding-top: 28px; padding-bottom: 40px; }
.narrow-page { max-width: 640px; }
.deposit-head { max-width: 720px; margin-bottom: 20px; }
.deposit-head h1 { margin: 6px 0 8px; }
.deposit-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.deposit-card { display: grid; gap: 12px; position: sticky; top: calc(var(--header-h) + 16px); }
.deposit-card h2 { margin: 0; font-size: 1.15rem; }
.deposit-icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 1.4rem; }
.deposit-icon.done { margin: 0 auto 6px; width: 72px; height: 72px; font-size: 1.8rem; background: var(--accent); color: #fff; }
.deposit-total { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.deposit-total strong { font-size: 1.3rem; color: var(--text-strong); }
.deposit-done { padding: 36px 28px; position: static; }
.deposit-card .check-list li i, .check-list li i.fa-check { color: var(--green-text); margin-right: 6px; }

/* ---------- Roles ---------- */
.sector-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.sector-card { display: grid; gap: 10px; align-content: start; }
.sector-card h2 { margin: 0; font-size: 1.2rem; }
.sector-card p { margin: 0; }
.sector-card.current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sector-card.highlight { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18); }
.sector-card-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 1.2rem; }
.sector-card-status { display: flex; gap: 6px; flex-wrap: wrap; }
.role-switch { padding: 10px 12px 12px; border-bottom: 1px solid var(--border); }
.role-switch-label { display: block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--subtle); font-weight: 700; margin-bottom: 8px; }
.role-switch-row { display: flex; flex-wrap: wrap; gap: 6px; }
.role-switch-row form { margin: 0; }
.dropdown-panel .role-switch-row button.role-chip, .role-chip { display: inline-flex !important; align-items: center; gap: 6px; width: auto !important; padding: 6px 12px !important; border-radius: 999px !important; border: 1px solid var(--border-strong) !important; background: var(--surface) !important; color: var(--text) !important; font-size: 0.8rem !important; font-weight: 600; cursor: pointer; white-space: nowrap; min-height: 32px; }
.role-chip.active, .dropdown-panel .role-switch-row button.role-chip.active { background: var(--accent) !important; border-color: var(--accent) !important; color: #fff !important; }
.role-chip.add { border-style: dashed !important; color: var(--muted) !important; }

/* ---------- Online status ---------- */
.presence-badge { display: inline-flex; align-items: center; gap: 7px; font-size: 0.82rem; color: var(--muted); font-weight: 500; white-space: nowrap; }
.pb-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--subtle); flex-shrink: 0; }
.presence-badge.on { color: var(--green-text); font-weight: 600; }
.presence-badge.on .pb-dot { background: #16a34a; box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2); animation: pb-pulse 2.4s ease-in-out infinite; }
.presence-text.on { color: var(--green-text); }
@keyframes pb-pulse { 50% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); } }

/* ---------- Developer: pending review + insights ---------- */
.pending-panel { margin-bottom: 20px; display: grid; gap: 14px; }
.pending-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.pending-grid h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 0.95rem; flex-wrap: wrap; }
.pending-item { display: grid; gap: 3px; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); margin-bottom: 8px; color: var(--text); background: var(--surface-2); }
.pending-item:hover { border-color: var(--accent-line); color: var(--text); }
.pending-item span { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.advice-list { display: grid; gap: 12px; }
.advice-card { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 16px; align-items: center; border-left: 4px solid var(--border-strong); }
.advice-card h3 { margin: 0 0 4px; font-size: 1rem; }
.advice-card.tone-up { border-left-color: #16a34a; }
.advice-card.tone-down { border-left-color: #d97706; }
.advice-card.tone-info { border-left-color: var(--accent-2, var(--accent)); }
.advice-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); font-size: 1.05rem; }
.tone-up .advice-icon { color: #16a34a; background: rgba(22, 163, 74, 0.1); }
.tone-down .advice-icon { color: #d97706; background: rgba(217, 119, 6, 0.1); }

/* ---------- Investors ---------- */
.investor-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi-card { display: flex; gap: 14px; align-items: flex-start; padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text); min-width: 0; }
.kpi-card > div { min-width: 0; }
.kpi-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex-shrink: 0; }
.kpi-icon.green { background: rgba(22, 163, 74, 0.12); color: #16a34a; }
.kpi-icon.cyan { background: rgba(6, 182, 212, 0.12); color: #0891b2; }
.kpi-value { font-size: 1.6rem; font-weight: 800; color: var(--text-strong); line-height: 1.15; white-space: nowrap; }
.kpi-label { font-weight: 600; color: var(--text-strong); font-size: 0.9rem; }
.credit-card:hover { color: var(--text); border-color: var(--accent-line); }
.credit-grade { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; color: #fff; background: var(--credit, var(--accent)); flex-shrink: 0; }
.credit-green { --credit: #16a34a; }
.credit-cyan { --credit: #0891b2; }
.credit-amber { --credit: #d97706; }
.credit-grey { --credit: #7a847b; }
.credit-badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.78rem; font-weight: 700; white-space: nowrap; }
.credit-badge strong { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 4px; border-radius: 999px; background: var(--credit, var(--accent)); color: #fff; font-size: 0.72rem; }
.credit-head { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.credit-head h3 { margin: 0 0 6px; }
.credit-head > div:last-child { flex: 1 1 280px; min-width: 0; }
.credit-dial { position: relative; width: 180px; flex-shrink: 0; }
.credit-dial svg { width: 100%; display: block; }
.credit-dial path { fill: none; stroke-width: 10; stroke-linecap: round; }
.credit-dial .dial-bg { stroke: var(--surface-3); }
.credit-dial .dial-fg { stroke: var(--credit, var(--accent)); }
.credit-dial-text { position: absolute; left: 0; right: 0; bottom: 4px; text-align: center; display: grid; line-height: 1.15; }
.credit-dial-text strong { font-size: 1.8rem; color: var(--text-strong); }
.credit-dial-text span { font-size: 0.76rem; color: var(--muted); font-weight: 600; }
.factor-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.factor-list li { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(80px, 1fr) 48px; gap: 12px; align-items: center; font-size: 0.88rem; }
.factor-list strong { text-align: right; color: var(--text-strong); }
.factor-bar { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.factor-fill { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--accent); transition: width 0.6s var(--ease); }
.factor-list li.negative .factor-fill { background: #d97706; }
.factor-list li.negative strong { color: var(--amber-text); }

.steps-bar { list-style: none; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; padding: 0; margin: 0 0 20px; }
.steps-bar li { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 0.82rem; font-weight: 600; color: var(--muted); min-width: 0; }
.steps-bar li span { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border-strong); font-size: 0.72rem; flex-shrink: 0; }
.steps-bar li.done { color: var(--green-text); border-color: var(--accent-line); background: var(--accent-soft); }
.steps-bar li.done span { background: var(--accent); border-color: var(--accent); color: #fff; }
.choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.choice-card, .chip-check { position: relative; }
.choice-card input, .chip-check input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.choice-card span { display: flex; align-items: center; min-height: 48px; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); font-weight: 600; font-size: 0.88rem; background: var(--surface); }
.choice-card input:checked + span, .chip-check input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--text-strong); box-shadow: inset 0 0 0 1px var(--accent); }
.choice-card input:focus-visible + span, .chip-check input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-select { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-check span { display: inline-flex; align-items: center; min-height: 36px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border-strong); font-size: 0.84rem; font-weight: 500; background: var(--surface); }
[data-company-box].is-optional { opacity: 0.8; }
.upload-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.upload-row select { flex: 1 1 220px; width: auto; min-width: 0; max-width: 100%; }
select { max-width: 100%; }
.upload-row input[type="file"] { flex: 2 1 240px; min-width: 0; }
.split-view { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 420px); gap: 20px; align-items: start; }
.review-panel { position: sticky; top: calc(var(--header-h) + 16px); max-height: calc(100vh - var(--header-h) - 32px); overflow-y: auto; display: grid; gap: 6px; }
.review-panel h3 { margin: 12px 0 4px; font-size: 0.95rem; }
.review-panel textarea { width: 100%; }
tr.selected td { background: var(--accent-soft); }
.invite-list { display: grid; gap: 14px; }
.invite-item { display: grid; grid-template-columns: 120px minmax(0, 1fr) auto; gap: 18px; align-items: center; }
.invite-item.pending { border-color: var(--accent-line); }
.invite-cover { width: 120px; height: 84px; object-fit: cover; border-radius: var(--radius-sm); }
.invite-body h3 { margin: 4px 0 6px; font-size: 1.05rem; }
.invite-body .person { gap: 8px; margin: 0 0 6px; }
.invite-message { margin: 0 0 6px; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; font-size: 0.88rem; }
.invite-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.invite-actions form { display: flex; gap: 8px; flex-wrap: wrap; margin: 0; }
.material-project { margin-bottom: 16px; display: grid; gap: 14px; }
.material-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.material-head h2 { font-size: 1.1rem; }
.material-head .person { gap: 6px; margin-top: 4px; }
.material-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.material-list li { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.material-list li form { margin: 0; }
.material-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex-shrink: 0; }
.investor-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; margin: 12px 0; }
.investor-option { position: relative; display: block; }
.investor-option input { position: absolute; top: 14px; right: 14px; width: 20px; height: 20px; accent-color: var(--accent); }
.investor-option-body { display: grid; gap: 6px; padding: 14px 44px 14px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); height: 100%; }
.investor-option:has(input:checked) .investor-option-body { border-color: var(--accent); background: var(--accent-soft); }
.tag-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 14px 0 2px; border-top: 1px solid var(--border); }
.filter-inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-inline input, .filter-inline select { width: auto; flex: 1 1 160px; }

/* ---------- Leaderboard ---------- */
.leader-main { flex: 1; min-width: 0; }
.leader-main .rank-badge { margin-top: 4px; }
.leader-filters { flex-wrap: wrap; gap: 10px; }

/* ---------- Tab bar + menu sheet + phone search button (hidden on desktop) ---------- */
.tabbar, .app-sheet, .nav-search-btn { display: none; }

/* =====================================================================
 * Tablet
 * =================================================================== */
@media (max-width: 1100px) {
    .investor-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .withdraw-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .split-view { grid-template-columns: minmax(0, 1fr); }
    .review-panel { position: static; max-height: none; }
    .choice-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
    .wallet-top, .wallet-grid, .deposit-layout { grid-template-columns: minmax(0, 1fr); }
    .deposit-card { position: static; }
    .sector-grid { grid-template-columns: minmax(0, 1fr); }
    .steps-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* =====================================================================
 * Phones and small tablets: native-app layout
 * =================================================================== */
@media (max-width: 860px) {
    :root { --header-h: 56px; --tabbar-h: 62px; }
    html { -webkit-text-size-adjust: 100%; }
    body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
    a, button, input, select, textarea, label { touch-action: manipulation; }
    /* 16px stops iOS from zooming into fields */
    input, select, textarea { font-size: 16px !important; }
    .container { padding-left: 16px; padding-right: 16px; }

    /* Compact app header that slides away while reading */
    .site-header { transition: transform 0.25s var(--ease), box-shadow 0.2s; padding-top: env(safe-area-inset-top); height: calc(var(--header-h) + env(safe-area-inset-top)); }
    .site-header.header-hidden { transform: translateY(-100%); }
    body.scrolled .site-header { box-shadow: 0 1px 8px rgba(15, 20, 16, 0.08); }
    .nav-wrap { gap: 8px; }
    .logo-mark { width: 32px; height: 32px; }
    .nav-actions { gap: 2px; }
    .nav-actions .icon-btn[href*="messages/inbox.php"], .nav-actions [data-notifications-toggle], .nav-actions .theme-toggle, .nav-actions .currency-menu { display: none; }
    .nav-actions [data-notifications-toggle] { display: none; }
    .nav-actions .dropdown:has([data-notifications-toggle]) { display: none; }
    .icon-btn { width: 44px; height: 44px; }
    /* The tab bar and Menu sheet replace the hamburger; the header keeps a search button */
    .nav-toggle { display: none !important; }
    .nav-search-btn { display: inline-grid; }
    .site-header .main-nav { display: none; }
    .site-header.nav-open .nav-center { padding: 12px 16px; }
    .nav-center { top: calc(var(--header-h) + env(safe-area-inset-top)); max-height: calc(100vh - var(--header-h) - var(--tabbar-h)); overflow-y: auto; }

    /* Bottom tab bar */
    .tabbar {
        display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 300;
        height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
        background: var(--header-bg); border-top: 1px solid var(--border); box-shadow: 0 -2px 14px rgba(15, 20, 16, 0.06);
    }
    .tabbar-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); background: none; border: 0; font: inherit; cursor: pointer; padding: 6px 2px; min-width: 0; position: relative; }
    .tabbar-icon { position: relative; display: grid; place-items: center; width: 44px; height: 28px; border-radius: 14px; font-size: 1.12rem; transition: background 0.2s, color 0.2s, transform 0.15s; }
    .tabbar-icon .count-badge { top: -4px; right: 2px; }
    .tabbar-label { font-size: 0.68rem; font-weight: 600; line-height: 1; white-space: nowrap; letter-spacing: 0.01em; }
    .tabbar-item.active { color: var(--accent); }
    .tabbar-item.active .tabbar-icon { background: var(--accent-soft); }
    .tabbar-item.pressed .tabbar-icon { transform: scale(0.9); }
    .tabbar-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border-strong); }
    body.sheet-open .tabbar [data-app-menu] { color: var(--accent); }

    /* Menu sheet */
    .app-sheet { display: block; position: fixed; inset: 0; z-index: 400; }
    .app-sheet[hidden] { display: none; }
    .app-sheet-backdrop { position: absolute; inset: 0; background: var(--overlay); opacity: 0; transition: opacity 0.25s; }
    .app-sheet-panel {
        position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
        background: var(--surface); border-radius: 22px 22px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
        transform: translateY(100%); transition: transform 0.28s var(--ease); box-shadow: var(--shadow-lg);
    }
    .app-sheet.open .app-sheet-backdrop { opacity: 1; }
    .app-sheet.open .app-sheet-panel { transform: none; }
    body.sheet-open { overflow: hidden; }
    .app-sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border-strong); margin: 4px auto 12px; }
    .app-sheet-user { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
    .app-sheet-user strong { color: var(--text-strong); display: block; }
    .app-sheet-user .flex-1 { min-width: 0; }
    .app-sheet-user small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .app-roles { padding: 12px 0; }
    .app-sheet-heading { display: block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--subtle); margin: 16px 0 8px; }
    .app-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
    .app-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 0.72rem; font-weight: 600; text-align: center; line-height: 1.2; min-height: 74px; justify-content: center; }
    .app-tile i { font-size: 1.15rem; color: var(--accent); }
    .app-tile span { overflow-wrap: break-word; }
    .app-tile.active { border-color: var(--accent); background: var(--accent-soft); }
    .app-tile.pressed { transform: scale(0.96); }
    .app-list { display: grid; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
    .app-list a { display: flex; align-items: center; gap: 12px; padding: 13px 14px; color: var(--text); border-bottom: 1px solid var(--border); font-weight: 500; min-height: 48px; }
    .app-list a:last-child { border-bottom: 0; }
    .app-list a i { width: 20px; text-align: center; color: var(--muted); }
    .app-sheet-actions { display: grid; gap: 10px; margin-top: 16px; }
    .app-sheet-actions .theme-segment { display: grid; grid-template-columns: repeat(3, 1fr); }

    /* Toasts and the compare tray sit above the tab bar */
    .toast-stack { left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); }
    .compare-tray { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px) !important; }

    /* Dashboard: the sidebar becomes the Menu sheet; content uses the full width */
    .dashboard { margin-top: 12px; }
    .sidebar { display: none; }
    .dash-head { margin-bottom: 14px; }
    .dash-head h1 { font-size: 1.4rem; }
    .dash-head .flex, .dash-head > .flex, .dash-head > div:last-child:not(:first-child) { width: 100%; }
    .dash-head .flex .btn { flex: 1 1 auto; }

    /* Tables become cards */
    .table-wrap:has(table.table-cards) { overflow: visible; border: 0; background: none; box-shadow: none; }
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table.table-cards, table.table-cards tbody, table.table-cards tr, table.table-cards td { display: block; width: 100%; }
    table.table-cards thead { display: none; }
    table.table-cards tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
    table.table-cards td { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 9px 0; border: 0; border-bottom: 1px solid var(--border); text-align: right !important; min-height: 40px; }
    table.table-cards td:last-child { border-bottom: 0; }
    table.table-cards td::before { content: attr(data-label); font-size: 0.76rem; font-weight: 600; color: var(--muted); text-align: left; flex-shrink: 0; max-width: 45%; }
    table.table-cards td.td-plain::before { content: none; }
    table.table-cards td.td-plain { justify-content: flex-start; text-align: left !important; }
    table.table-cards td:first-child { text-align: left !important; }
    table.table-cards td .table-person, table.table-cards td .person { text-align: left; }
    table.table-cards td progress { max-width: 140px; }
    table.table-cards td.check-col { position: absolute; width: auto; padding: 0; border: 0; min-height: 0; }
    table.table-cards tr { position: relative; }
    table.table-cards tr.selected { border-color: var(--accent); }

    /* Filters slide up as a bottom sheet */
    .filter-panel { inset: auto 0 0 0 !important; width: 100% !important; max-height: 85vh !important; border-radius: 22px 22px 0 0 !important; transform: translateY(105%) !important; top: auto !important; padding-bottom: calc(20px + env(safe-area-inset-bottom)) !important; z-index: 420 !important; }
    .filter-panel.open { transform: none !important; }

    /* Dialogs already open from the bottom; leave room for the home bar */
    .nx-modal-panel { padding-bottom: env(safe-area-inset-bottom); }

    /* Comfortable touch targets */
    .btn { min-height: 44px; }
    .btn-sm { min-height: 36px; }
    .tabs a, .tabs-ui a, .tabs-ui button { min-height: 40px; display: inline-flex; align-items: center; }
    .tabs, .tabs-ui { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .tabs::-webkit-scrollbar, .tabs-ui::-webkit-scrollbar { display: none; }
    .tabs a, .tabs-ui a, .tabs-ui button { flex-shrink: 0; white-space: nowrap; }
    .btn.pressed, .card a.pressed { transform: scale(0.98); }

    /* Content */
    .pending-grid { grid-template-columns: minmax(0, 1fr); }
    .advice-card { grid-template-columns: auto minmax(0, 1fr); }
    .advice-card .btn { grid-column: 1 / -1; }
    .invite-item { grid-template-columns: 84px minmax(0, 1fr); gap: 12px; }
    .invite-cover { width: 84px; height: 64px; }
    .invite-actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
    .rank-ladder { gap: 4px; }
    .rank-ladder li { font-size: 0.64rem; padding: 8px 2px 6px; }
    .withdraw-amount { text-align: left; }
    .chat-layout { height: calc(100vh - var(--header-h) - var(--tabbar-h) - 40px); height: calc(100dvh - var(--header-h) - var(--tabbar-h) - 40px); }
    .site-footer { padding-bottom: 12px; }
}

@media (max-width: 640px) {
    .investor-kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
    .kpi-card { padding: 14px; flex-direction: column; gap: 10px; }
    .kpi-value { font-size: 1.3rem; }
    .withdraw-meta { grid-template-columns: minmax(0, 1fr); }
    .wallet-amount { font-size: 2rem; }
    .choice-grid { grid-template-columns: minmax(0, 1fr); }
    .steps-bar { grid-template-columns: minmax(0, 1fr); gap: 6px; }
    .factor-list li { grid-template-columns: minmax(0, 1fr) 44px; }
    .factor-list .factor-bar { grid-column: 1 / -1; grid-row: 2; }
    .credit-dial { margin: 0 auto; }
    .app-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .rank-ladder li span { font-size: 0.6rem; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat-card { padding: 12px; gap: 10px; }
    .stat-value { font-size: 1.15rem; }
    .stat-label { font-size: 0.76rem; }
    .upload-row > * { flex: 1 1 100% !important; }
    .filter-inline > * { flex: 1 1 100%; }
    .deposit-total strong { font-size: 1.15rem; }
    h1 { font-size: 1.45rem; }
}
@media (max-width: 380px) {
    .tabbar-label { font-size: 0.62rem; }
    .app-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .investor-kpis, .stat-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Installed app (opened from the home screen) */
@media (display-mode: standalone) {
    [data-pwa-install] { display: none !important; }
    .site-header { -webkit-user-select: none; user-select: none; }
}
@media (prefers-reduced-motion: reduce) {
    .site-header, .app-sheet-panel, .app-sheet-backdrop, .factor-fill { transition: none !important; }
    .presence-badge.on .pb-dot { animation: none; }
}

/* ---------- Audit fixes ---------- */
.wave { display: inline-block; margin-left: 6px; }
@media (max-width: 860px) {
    table.table-cards td, table.table-cards td.nowrap, table.table-cards td * { white-space: normal; }
    table.table-cards td { overflow-wrap: break-word; }
    table.table-cards td > .td-val { flex: 1 1 auto; min-width: 0; text-align: right; overflow-wrap: anywhere; }
    table.table-cards td > .td-val > progress { display: inline-block; width: 110px; vertical-align: middle; margin-right: 6px; }
    table.table-cards td > .td-val .table-person, table.table-cards td > .td-val .person { justify-content: flex-end; text-align: left; }
    table.table-cards td > .td-val form { display: inline-flex; }
    table.table-cards td .table-person > div, table.table-cards td .person > span { min-width: 0; }
}
.sidebar-nav a { padding-top: 7px; padding-bottom: 7px; }
.sidebar-heading { padding-top: 10px; padding-bottom: 3px; }
.sidebar { overscroll-behavior: contain; }
/* Tables ignore width: 1px, so the screen-reader copy of each chart is boxed in */
table.sr-only { display: block; max-width: 1px; max-height: 1px; clip-path: inset(50%); }
.nx-chart { position: relative; }

/* Level ladder: labels shrink in narrow cards and become icons only in very narrow ones */
.rank-ladder { container-type: inline-size; }
@container (max-width: 460px) {
    .rank-ladder li { font-size: 0.6rem; padding-left: 1px; padding-right: 1px; letter-spacing: -0.01em; }
}
@container (max-width: 330px) {
    .rank-ladder li span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .rank-ladder li { padding: 9px 2px; }
}
.conv-info .badge { align-self: flex-start; }
.league-banner { flex-wrap: wrap; }
.league-banner > div { flex: 1 1 200px; min-width: 0; }
.league-banner .rank-stars .fa-regular { color: rgba(255, 255, 255, 0.45); }
.not-found .code, .container > .code { font-size: clamp(4rem, 18vw, 6rem); font-weight: 800; line-height: 1.1; margin-bottom: 12px; display: block; }
@media (max-width: 640px) { .league-banner .btn { width: 100%; } }
/* An open chat uses the whole screen on phones, like a messaging app */
@media (max-width: 860px) {
    .page-messages-chat .tabbar { display: none; }
    .page-messages-chat { padding-bottom: env(safe-area-inset-bottom); }
    .page-messages-chat .site-footer, .page-messages-chat .announce { display: none; }
    .page-messages-chat .chat-layout { height: calc(100vh - var(--header-h) - 28px); height: calc(100dvh - var(--header-h) - 28px); }
    .page-messages-chat .container.dashboard, .page-messages-chat .dashboard { margin-top: 8px; }
}

/* Developer profile head: the avatar overlaps the cover, the text always starts below it */
.profile-head { align-items: flex-start; }
.profile-head-info { padding-top: 72px; min-width: 0; }
.profile-actions { padding-top: 76px; }
.profile-head-info h1 { overflow-wrap: break-word; }
@media (max-width: 768px) {
    .profile-cover { height: 120px; }
    .profile-head { flex-direction: column; align-items: flex-start; gap: 10px; margin-top: -48px; }
    .profile-head-info { padding-top: 0; width: 100%; }
    .profile-actions { padding-top: 0; width: 100%; }
    .profile-actions .btn { flex: 1 1 auto; }
}
/* Phones: form buttons sit at the end of the form instead of floating over the fields */
@media (max-width: 860px) {
    .form-actions, .sticky-actions { position: static !important; margin: 16px 0 0 !important; backdrop-filter: none; border-radius: var(--radius-sm); }
    .form-actions .btn, .sticky-actions .btn { flex: 1 1 auto; }
}
