/* TradePilot app styles. Mobile first; desktop sidebar from 1024px. */

/* ---------- Base (scoped so themes are not affected) ---------- */
.tp-app, .tp-auth, .tp-widget { font-family: var(--tp-font); color: var(--tp-text); font-size: var(--tp-fs-body); line-height: 1.5; -webkit-font-smoothing: antialiased; }
.tp-app *, .tp-app *::before, .tp-app *::after,
.tp-auth *, .tp-auth *::before, .tp-auth *::after,
.tp-widget, .tp-widget * { box-sizing: border-box; }
.tp-app a, .tp-auth a { color: var(--tp-primary); }
.tp-app h1, .tp-app h2, .tp-app h3, .tp-auth h2 { font-family: var(--tp-font); color: var(--tp-text); margin: 0; letter-spacing: -0.01em; }
.tp-app p { margin: 0; }
.tp-icon { flex-shrink: 0; display: block; }
.tp-sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.tp-muted { color: var(--tp-text-muted); font-size: var(--tp-fs-small); }
.tp-app :focus-visible, .tp-auth :focus-visible { outline: 3px solid var(--tp-primary); outline-offset: 2px; border-radius: 4px; }

body.tp-standalone { margin: 0; background: var(--tp-bg); }
.tp-skip-link { position: absolute; left: -9999px; top: 8px; z-index: 1000; background: var(--tp-surface); padding: 12px 16px; border-radius: 8px; font-family: var(--tp-font); }
.tp-skip-link:focus { left: 8px; }

/* ---------- Shell ---------- */
.tp-app { background: var(--tp-bg); min-height: 100vh; min-height: 100dvh; width: 100%; overflow-x: hidden; }
.tp-app.has-nav { padding-bottom: calc(var(--tp-bottomnav-h) + env(safe-area-inset-bottom, 0px)); }
.tp-sidebar { display: none; }
.tp-main { min-width: 0; }

.tp-topbar { position: sticky; top: 0; z-index: 20; background: var(--tp-primary-dark); color: #fff; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
.tp-topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tp-topbar-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-app .tp-page-title { color: #C9D8F0; font-size: 14px; font-weight: 500; white-space: nowrap; }
.tp-brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--tp-primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.tp-brand-logo { height: 36px; width: auto; max-width: 120px; object-fit: contain; border-radius: 8px; background: #fff; padding: 2px; }

.tp-content { padding: 16px; display: flex; flex-direction: column; gap: 16px; max-width: 1200px; margin: 0 auto; width: 100%; }
.tp-content:focus { outline: none; }

.tp-bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--tp-surface); border-top: 1px solid var(--tp-border); display: flex; justify-content: space-around; padding-bottom: env(safe-area-inset-bottom, 0px); height: calc(var(--tp-bottomnav-h) + env(safe-area-inset-bottom, 0px)); }
.tp-bottomnav-link { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: var(--tp-touch); text-decoration: none; color: var(--tp-text-muted) !important; font-size: 12px; font-weight: 500; }
.tp-bottomnav-link.is-active { color: var(--tp-primary) !important; font-weight: 600; }

.tp-banner { display: flex; gap: 10px; align-items: flex-start; margin: 12px 16px 0; padding: 12px 14px; border-radius: var(--tp-radius-button); font-size: var(--tp-fs-small); }
.tp-banner-warning { background: var(--tp-warning-soft); color: #6B3D00; }
.tp-toast { display: flex; gap: 10px; align-items: center; margin: 12px 16px 0; padding: 12px 14px; border-radius: var(--tp-radius-button); background: var(--tp-success-soft); color: var(--tp-success-text); font-size: var(--tp-fs-small); font-weight: 500; transition: opacity .2s; }
.tp-toast.is-hidden { opacity: 0; }

/* ---------- Cards & dashboard ---------- */
.tp-card { background: var(--tp-surface); border-radius: var(--tp-radius-card); box-shadow: var(--tp-shadow-card); padding: 16px; }
.tp-card-title { font-size: 16px !important; font-weight: 600; }
.tp-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.tp-card-meta { font-size: 13px; color: var(--tp-text-muted); }

.tp-hero { background: var(--tp-primary-dark); color: #fff; margin: -16px -16px 0; padding: 4px 20px 64px; }
.tp-hero-greet { color: #C9D8F0; font-size: 14px; }
.tp-app .tp-hero-label { color: #C9D8F0; font-size: 13px; font-weight: 500; margin-top: 12px; }
.tp-hero-value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tp-hero-sub { color: #C9D8F0; font-size: 13px; }
.tp-hero-sub strong { color: #fff; font-weight: 600; }

.tp-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: -52px; }
.tp-kpi { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tp-kpi-wide { grid-column: 1 / -1; }
.tp-kpi-label { font-size: 13px; color: var(--tp-text-muted); }
.tp-kpi-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tp-kpi-value.is-positive { color: var(--tp-success-text); }
.tp-kpi-value.is-negative { color: var(--tp-danger); }
.tp-kpi-note { font-size: 12px; color: var(--tp-text-muted); }
.tp-badge { display: inline-flex; align-self: flex-start; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.tp-badge-danger { color: var(--tp-danger); background: var(--tp-danger-soft); }

.tp-empty p { color: var(--tp-text-muted); margin-top: 6px; font-size: var(--tp-fs-small); }
.tp-grid-2 { display: grid; gap: 16px; }
.tp-stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.tp-chart { width: 100%; height: auto; display: block; }
.tp-chart-grid { stroke: var(--tp-border); stroke-width: 1; }
.tp-chart-baseline { stroke: #C4CEDC; stroke-width: 1; }
.tp-chart-axis { fill: var(--tp-text-muted); font-size: 19px; font-family: var(--tp-font); } /* SVG units: about 11px on a phone */
.tp-chart-revenue { fill: var(--tp-primary); }
.tp-chart-expenses { fill: var(--tp-chart-expenses); }
.tp-chart-empty { fill: var(--tp-text-muted); font-size: 14px; font-family: var(--tp-font); }
.tp-legend { display: flex; gap: 16px; font-size: 12px; color: var(--tp-text-muted); margin-top: 8px; }
.tp-legend span { display: inline-flex; align-items: center; gap: 6px; }
.tp-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tp-swatch-revenue { background: var(--tp-primary); }
.tp-swatch-expenses { background: var(--tp-chart-expenses); }

.tp-list-card .tp-card-title { margin-bottom: 4px; }
.tp-list { list-style: none; margin: 0; padding: 0; }
.tp-list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--tp-border); min-height: var(--tp-touch); }
.tp-list-row:first-child { border-top: 0; }
.tp-list-main { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tp-list-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-list-meta { font-size: 13px; color: var(--tp-text-muted); }
.tp-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tp-amount.is-positive { color: var(--tp-success-text); }
.tp-date-chip { width: 48px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; background: var(--tp-primary-soft); border-radius: 12px; padding: 6px 0; }
.tp-date-chip span { font-size: 11px; font-weight: 600; color: var(--tp-primary); }
.tp-date-chip strong { font-size: 18px; font-weight: 700; color: var(--tp-primary-dark); line-height: 1.1; }

/* ---------- Buttons ---------- */
.tp-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 20px; border-radius: var(--tp-radius-button); border: 1px solid transparent; font: 600 16px/1 var(--tp-font); text-decoration: none !important; cursor: pointer; transition: background .15s, border-color .15s; }
.tp-btn-primary { background: var(--tp-primary); color: #fff !important; }
.tp-btn-primary:hover { background: var(--tp-primary-dark); }
.tp-btn-secondary { background: var(--tp-surface); color: var(--tp-text) !important; border-color: var(--tp-border); }
.tp-btn-secondary:hover { border-color: #B9C4D4; }
.tp-btn-block { width: 100%; }

/* ---------- Forms ---------- */
.tp-form { display: flex; flex-direction: column; gap: 18px; }
.tp-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; }
.tp-label { font-size: 14px; font-weight: 600; color: var(--tp-text); padding: 0; }
.tp-optional { font-weight: 400; color: var(--tp-text-muted); }
.tp-input { width: 100%; min-height: var(--tp-touch); padding: 10px 12px; border: 1px solid #C9D3E1; border-radius: var(--tp-radius-input); background: var(--tp-surface); color: var(--tp-text); font: 400 16px/1.4 var(--tp-font); appearance: none; -webkit-appearance: none; margin: 0; box-shadow: none; }
.tp-input:focus { border-color: var(--tp-primary); outline: 3px solid rgba(23, 105, 224, .2); outline-offset: 0; }
.tp-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%235E6C84' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px; }
.tp-textarea { min-height: 96px; resize: vertical; }
.tp-help { font-size: 13px; color: var(--tp-text-muted); margin: 0; }
.tp-error { font-size: 13px; color: var(--tp-danger); font-weight: 500; margin: 0; }
.has-error .tp-input { border-color: var(--tp-danger); }
.tp-password { position: relative; display: block; }
.tp-password .tp-input { padding-right: 52px; }
.tp-password-toggle { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 46px; height: 44px; border: 0; background: transparent; color: var(--tp-text-muted); display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 8px; padding: 0; }
.tp-password-toggle[aria-pressed="true"] { color: var(--tp-primary); }

.tp-fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.tp-segmented-field { border: 0; padding: 0; margin: 0; }
.tp-segmented { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; background: var(--tp-bg); border: 1px solid var(--tp-border); border-radius: var(--tp-radius-button); padding: 4px; }
.tp-segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tp-segmented label { min-width: 0; min-height: 44px; display: flex; align-items: center; justify-content: center; padding: 4px 6px; line-height: 1.2; border-radius: 9px; font-size: 15px; font-weight: 500; color: var(--tp-text-muted); cursor: pointer; text-align: center; }
.tp-segmented input:checked + label { background: var(--tp-surface); color: var(--tp-text); font-weight: 600; box-shadow: 0 1px 3px rgba(18, 58, 112, .18); }
.tp-segmented input:focus-visible + label { outline: 3px solid var(--tp-primary); outline-offset: 1px; }
.has-error .tp-segmented { border-color: var(--tp-danger); }

.tp-check { flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: 10px; }
.tp-check input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--tp-primary); flex-shrink: 0; }
.tp-check label { flex: 1; font-size: 15px; min-width: 0; }
.tp-check .tp-error, .tp-check .tp-help { flex-basis: 100%; }

.tp-row-2, .tp-row-3 { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }
.tp-upload { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 10px 14px; border: 1.5px dashed #9DBBEB; border-radius: var(--tp-radius-button); background: var(--tp-bg); color: var(--tp-primary); font-weight: 600; font-size: 15px; cursor: pointer; position: relative; }
.tp-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.tp-upload:focus-within { outline: 3px solid var(--tp-primary); outline-offset: 2px; }
.tp-logo-preview img { max-height: 64px; max-width: 200px; border: 1px solid var(--tp-border); border-radius: 8px; padding: 4px; background: #fff; }
.tp-note { background: var(--tp-primary-soft); border-radius: var(--tp-radius-button); padding: 12px 14px; font-size: 14px; color: var(--tp-primary-dark); }
.tp-note p { margin: 4px 0 0; }
.tp-note strong { font-weight: 600; }
.tp-preview-line { font-size: 14px; color: var(--tp-text-muted); margin-top: -8px; }
.tp-preview-line strong { color: var(--tp-text); }
.tp-form-actions { display: flex; gap: 12px; margin-top: 4px; }
.tp-form-actions .tp-btn { flex: 1; }

.tp-alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--tp-radius-button); font-size: 14px; font-weight: 500; margin-bottom: 16px; }
.tp-alert:focus { outline: none; }
.tp-alert-error { background: var(--tp-danger-soft); color: #8F2219; }
.tp-alert-success { background: var(--tp-success-soft); color: var(--tp-success-text); }

/* ---------- Wizard ---------- */
.tp-wizard { background: var(--tp-surface); border-radius: var(--tp-radius-card); box-shadow: var(--tp-shadow-card); padding: 20px; width: 100%; max-width: 640px; margin: 0 auto; }
.tp-step-count { font-size: 13px; font-weight: 600; color: var(--tp-text-muted); }
.tp-steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; list-style: none; margin: 8px 0 20px; padding: 0; }
.tp-steps li { height: 6px; border-radius: 999px; background: var(--tp-border); }
.tp-steps li.is-done, .tp-steps li.is-current { background: var(--tp-primary); }
.tp-app .tp-wizard-title { font-size: 24px; font-weight: 700; }
.tp-wizard-intro { color: var(--tp-text-muted); margin: 6px 0 20px !important; }

/* ---------- Settings ---------- */
.tp-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.tp-tabs::-webkit-scrollbar { display: none; }
.tp-tab { flex-shrink: 0; min-height: 40px; padding: 0 14px; display: inline-flex; align-items: center; border-radius: 999px; text-decoration: none !important; font-size: 14px; font-weight: 500; color: var(--tp-text-muted) !important; background: var(--tp-surface); border: 1px solid var(--tp-border); }
.tp-tab.is-active { background: var(--tp-primary-dark); color: #fff !important; border-color: var(--tp-primary-dark); font-weight: 600; }
.tp-settings-card .tp-card-title { margin-bottom: 16px; }
.tp-settings-card { max-width: 720px; width: 100%; }
.tp-dl { display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px; margin: 0 0 16px; font-size: 15px; }
.tp-dl dt { color: var(--tp-text-muted); }
.tp-dl dd { margin: 0; font-weight: 500; }
.tp-logout-line { margin-top: 20px !important; }
.tp-logout-line a { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; text-decoration: none; min-height: var(--tp-touch); }

/* ---------- Messages ---------- */
.tp-app-message { display: flex; align-items: flex-start; justify-content: center; padding: 32px 16px; min-height: 0; }
.tp-message { max-width: 520px; width: 100%; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }

/* ---------- Auth pages (render inside the theme) ---------- */
.tp-auth { display: flex; justify-content: center; padding: 24px 0; width: 100%; }
.tp-auth-card { width: 100%; max-width: 440px; background: var(--tp-surface); border-radius: var(--tp-radius-card); box-shadow: var(--tp-shadow-card); padding: 24px 20px; border: 1px solid var(--tp-border); }
.tp-auth .tp-auth-title { font-size: 24px; font-weight: 700; margin: 0 0 6px; }
.tp-auth-sub { color: var(--tp-text-muted); margin: 0 0 20px; font-size: 15px; }
.tp-auth-title + .tp-form, .tp-auth-title + .tp-alert { margin-top: 16px; }
.tp-auth-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 15px; }
.tp-auth-row a { min-height: var(--tp-touch); display: inline-flex; align-items: center; }
.tp-auth-alt { text-align: center; margin: 20px 0 0; font-size: 15px; color: var(--tp-text-muted); }
.tp-hp { position: absolute !important; left: -10000px !important; width: 1px; height: 1px; overflow: hidden; }

/* ---------- Standalone widgets ---------- */
.tp-status-badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--tp-primary-soft); font-size: 13px; }
.tp-status-plan { font-weight: 600; color: var(--tp-primary-dark); }
.tp-status-level { color: var(--tp-success-text); font-weight: 600; }
.tp-status-grace .tp-status-level, .tp-status-read_only .tp-status-level { color: var(--tp-warning); }
.tp-status-locked .tp-status-level { color: var(--tp-danger); }
.tp-editor-preview { display: flex; flex-direction: column; gap: 8px; border: 1.5px dashed #9DBBEB; }
.tp-editor-preview-tag { align-self: flex-start; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--tp-primary); background: var(--tp-primary-soft); padding: 3px 8px; border-radius: 999px; }
.tp-editor-bars { display: flex; align-items: flex-end; gap: 8px; height: 90px; }
.tp-editor-bars i { flex: 1; background: var(--tp-primary); border-radius: 4px 4px 0 0; opacity: .8; }
.tp-editor-lines { display: flex; flex-direction: column; gap: 10px; }
.tp-editor-lines i { height: 14px; background: var(--tp-border); border-radius: 6px; }
.tp-editor-lines i:nth-child(2n) { width: 70%; }

/* ---------- Tablet ---------- */
@media (min-width: 640px) {
	.tp-row-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
	.tp-row-3 { grid-template-columns: 2fr 1.4fr 1fr; }
	.tp-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
	.tp-kpi-wide { grid-column: auto; }
	.tp-content { padding: 24px; }
	.tp-hero { margin: -24px -24px 0; padding: 8px 28px 64px; }
	.tp-tabs { margin: 0; padding: 0; }
	.tp-chart-axis { font-size: 14px; }
	.tp-wizard { padding: 32px; }
	.tp-auth-card { padding: 32px; }
	.tp-form-actions .tp-btn { flex: 0 1 auto; min-width: 160px; }
	.tp-form-actions { justify-content: flex-end; }
}

/* ---------- Desktop: sidebar replaces bottom nav ---------- */
@media (min-width: 1024px) {
	.tp-app.has-nav { display: flex; padding-bottom: 0; }
	.tp-bottomnav { display: none; }
	.tp-sidebar { display: flex; flex-direction: column; gap: 24px; width: var(--tp-sidebar-w); flex-shrink: 0; background: var(--tp-primary-dark); color: #fff; padding: 24px 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
	.tp-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
	.tp-brand-name { font-weight: 700; font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
	.tp-sidenav { display: flex; flex-direction: column; gap: 4px; }
	.tp-sidenav-link { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 10px; color: #C9D8F0 !important; text-decoration: none !important; font-size: 15px; font-weight: 500; }
	.tp-sidenav-link:hover { background: rgba(255, 255, 255, .08); color: #fff !important; }
	.tp-sidenav-link.is-active { background: var(--tp-primary); color: #fff !important; font-weight: 600; }
	.tp-sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .14); padding-top: 16px; display: flex; flex-direction: column; gap: 4px; }
	.tp-sidebar-user { padding: 0 12px 8px; font-size: 13px; color: #C9D8F0; }
	.tp-main { flex: 1; }
	.tp-app.has-nav .tp-topbar { background: var(--tp-surface); color: var(--tp-text); border-bottom: 1px solid var(--tp-border); padding: 18px 32px; }
	.tp-app.has-nav .tp-topbar-brand { display: none; }
	.tp-app.has-nav .tp-page-title { color: var(--tp-text); font-size: 24px; font-weight: 700; }
	.tp-content { padding: 24px 32px 40px; }
	.tp-hero { margin: 0; border-radius: var(--tp-radius-card); padding: 24px 28px 72px; }
	.tp-kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); margin: -60px 16px 0; }
	.tp-grid-2 { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; }
	.tp-chart-axis { font-size: 13px; }
	.tp-banner, .tp-toast { margin: 16px 32px 0; }
}

@media (prefers-reduced-motion: reduce) {
	.tp-app *, .tp-auth * { transition: none !important; animation: none !important; }
}
