* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Barlow', system-ui, sans-serif;
    background: #f8fafc;
    padding: 20px;
    color: #0f172a;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
}

h1 {
    font-size: 28px;
    margin-bottom: 4px;
    color: #0f172a;
    font-weight: 600;
}

.header-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.header-row h1 {
    margin: 0;
    line-height: 1;
}

.logo {
    height: 48px;
    width: auto;
    flex-shrink: 0;
    display: block;
}

.subtitle {
    font-size: 16px;
    color: #64748b;
    margin-bottom: 12px;
    font-weight: 400;
}

.mode-selector {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
}

.mode-btn {
    background: #f1f5f9;
    border: 2px solid #cbd5e1;
    color: #475569;
    padding: 12px 16px;
    font-size: 14px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    flex: 1;
}

.mode-btn:first-child {
    border-radius: 8px;
    border-right: 1px solid #cbd5e1;
}

.mode-btn:last-child {
    border-radius: 8px;
    border-left: 1px solid #cbd5e1;
}

.mode-btn:not(:first-child):not(:last-child) {
    border-radius: 8px;
    border-left: 1px solid #cbd5e1;
    border-right: 1px solid #cbd5e1;
}

.mode-btn:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

.mode-btn.active {
    background: #0f172a;
    border-color: #0f172a;
    color: white;
}

.mode-btn.active:hover {
    background: #1e293b;
    border-color: #1e293b;
}

.mode-content {
    display: none;
}

.mode-content.active {
    display: block;
}

.inheritance-inputs {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
    background: #f1f5f9;
    border-radius: 12px;
    max-width: 500px;
}

.inheritance-inputs .input-group {
    display: flex;
    flex-direction: column;
}

.inheritance-inputs label {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: #475569;
}

.inheritance-inputs input[type="text"],
.inheritance-inputs select {
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
}

.inheritance-inputs input[type="text"]:focus,
.inheritance-inputs select:focus {
    outline: none;
    border-color: #64748b;
    box-shadow: 0 0 0 2px rgba(100,116,139,0.3);
}

.inheritance-inputs select {
    background: white;
    cursor: pointer;
}

.inheritance-outputs {
    margin-top: 30px;
    padding: 20px;
    background: #f0fdf4;
    border-radius: 8px;
    border-left: 4px solid #16a34a;
    max-width: 500px;
}

.inheritance-outputs h3 {
    font-size: 16px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 15px;
}

.output-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #e2e8f0;
}

.output-row:last-child {
    border-bottom: none;
}

.output-label {
    font-size: 14px;
    color: #475569;
}

.output-value {
    font-size: 14px;
    font-weight: 600;
    color: #0f172a;
}

.output-note {
    font-size: 11px;
    color: #64748b;
    font-weight: 400;
    margin-top: 2px;
}

.tax-chart-container {
    margin-top: 30px;
    padding: 20px;
    background: #f1f5f9;
    border-radius: 12px;
    max-width: 500px;
}

.tax-chart-container h3 {
    font-size: 16px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 15px;
}

.chart-wrapper {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.chart-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    flex-shrink: 0;
}

.legend-label {
    color: #0f172a;
}

.legend-value {
    color: #64748b;
    font-weight: 500;
}

.explainer-btn {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: #475569;
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 20px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.explainer-btn:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
}

.explainer-btn .arrow {
    transition: transform 0.2s;
    font-size: 10px;
}

.explainer-btn.expanded .arrow {
    transform: rotate(90deg);
}

.description {
    margin-bottom: 30px;
    color: #475569;
    line-height: 1.6;
    font-size: 14px;
    display: none;
}

.description.visible {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.description-section {
    padding: 15px;
    background: #f1f5f9;
    border-radius: 8px;
}

.description-section.green {
    border-left: 3px solid #16a34a;
}

.description-section.blue {
    border-left: 3px solid #3b82f6;
}

.description-section.red {
    border-left: 3px solid #dc2626;
}

details.description-section summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

details.description-section summary::-webkit-details-marker {
    display: none;
}

details.description-section summary::before {
    content: '▶';
    font-size: 10px;
    transition: transform 0.2s;
    display: inline-block;
}

details.description-section[open] summary::before {
    transform: rotate(90deg);
}

details.description-section.blue summary {
    color: #3b82f6;
}

details.description-section.red summary {
    color: #dc2626;
}

details.description-section summary ~ p {
    margin-top: 10px;
}

.description p {
    margin-bottom: 15px;
}

.description p:last-child {
    margin-bottom: 0;
}

.load-portfolio-btn {
    background: #0f172a;
    color: white;
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 8px;
    height: 28px;
}

.load-portfolio-btn:hover {
    background: #1e293b;
}

.clear-assets-btn {
    background: white;
    color: #0f172a;
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 8px;
    height: 28px;
    border: 1px solid #cbd5e1;
}

.clear-assets-btn:hover {
    background: #f8fafc;
}

.crypto-override-btn {
    background: white;
    color: #0f172a;
    padding: 4px 10px;
    font-size: 11px;
    border-radius: 6px;
    height: 24px;
    border: 1px solid #cbd5e1;
    cursor: pointer;
    margin-bottom: 6px;
}

.crypto-override-btn:hover {
    background: #f8fafc;
}

.crypto-override-btn.active {
    background: #0f172a;
    color: white;
    border-color: #0f172a;
}

.refresh-prices-btn {
    background: white;
    color: #0f172a;
    padding: 4px 10px;
    font-size: 11px;
    border-radius: 6px;
    height: 24px;
    border: 1px solid #cbd5e1;
    cursor: pointer;
    margin-bottom: 6px;
    margin-left: 4px;
}

.refresh-prices-btn:hover {
    background: #f8fafc;
}

.override-pill {
    display: inline-block;
    cursor: pointer;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    text-align: center;
    user-select: none;
    line-height: 1.4;
    letter-spacing: 0.02em;
    min-width: 40px;
}

.override-auto {
    background: #e2e8f0;
    color: #64748b;
}

.override-useq {
    background: #dbeafe;
    color: #2563eb;
}

.override-crypto {
    background: #fef3c7;
    color: #d97706;
}

.override-mode-column {
    display: flex;
    align-items: center;
    justify-content: center;
}

.checkbox-container {
    margin-bottom: 20px;
}

.checkbox-row {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    padding: 8px 12px;
    border-radius: 8px;
    border: 2px solid transparent;
    transition: border-color 0.2s, background-color 0.2s;
}

.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 8px;
    cursor: pointer;
    accent-color: #0f172a;
}

.checkbox-row label {
    font-size: 14px;
    font-weight: 500;
    color: #0f172a;
    cursor: pointer;
    margin: 0;
    height: auto;
    line-height: normal;
}

.checkbox-row.liquidity-checked {
    border-color: #3b82f6;
    background-color: rgba(59, 130, 246, 0.1);
}

.checkbox-row.tax-checked {
    border-color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
}

.checkbox-row.tax-checked input[type="checkbox"] {
    accent-color: #ef4444;
}

.checkbox-sub-row {
    display: flex;
    align-items: center;
    padding: 4px 12px 4px 36px;
    width: 100%;
}

.checkbox-sub-row input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin-right: 6px;
    cursor: pointer;
    accent-color: #ef4444;
}

.checkbox-sub-row label {
    font-size: 12px;
    font-weight: 400;
    color: #0f172a;
    cursor: pointer;
    margin: 0;
    height: auto;
    line-height: normal;
}

.tax-lots-section {
    text-align: center;
    margin-bottom: 16px;
}

.tax-lots-subtitle {
    font-size: 16px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 10px;
}

.global-inputs {
    display: grid;
    grid-template-columns: 60% 20% 20%;
    align-items: end;
    gap: 0;
    margin-bottom: 30px;
    padding: 20px;
    background: #f1f5f9;
    border-radius: 8px;
}

.input-group {
    display: flex;
    flex-direction: column;
}

.input-group input {
    height: 36px;
}

.stock-entry .input-group label,
.tbill-summary-row .input-group label {
    display: none;
}

label {
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 4px;
    color: #475569;
    min-height: 16px;
    line-height: 16px;
}

input[type="text"],
input[type="number"] {
    padding: 8px 6px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
}

.stock-entry input:not(.ticker),
.tbill-summary-row input:not(.ticker) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.global-inputs .input-group:not(:last-of-type) input[type="text"],
.global-inputs .input-group:not(:last-of-type) input[type="number"] {
    border-right: none;
}

.global-inputs .input-group:first-of-type input[type="text"],
.global-inputs .input-group:first-of-type input[type="number"] {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
}

.global-inputs .input-group:last-of-type input[type="text"],
.global-inputs .input-group:last-of-type input[type="number"] {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
}

/* When T-Bill is the only visible field (tax unchecked) */
.global-inputs.tbill-only #tbill-rate {
    border-right: 1px solid #cbd5e1;
    border-radius: 8px;
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: #64748b;
    box-shadow: 0 0 0 2px rgba(100,116,139,0.3);
}

.price-from-yfinance {
    background-color: #F0F0F0 !important;
    color: #1B5E20 !important;
}

.stock-entry input.current-price:not(.price-from-yfinance) {
    background-color: #fef2f2;
}

.stock-entry .field-defaulted {
    background-color: #fecaca !important;
}

.auto-label {
    color: #1B5E20;
}

.stock-entry .downside-probability,
.stock-entry .position-usd,
.tbill-summary-row .position-usd {
    background-color: #F0F0F0;
    color: #1B5E20;
    cursor: default;
}

.stock-entry-header .down-prob-header {
    color: #1B5E20;
}

.input-warning {
    border-color: #d97706 !important;
    background-color: #fffbeb !important;
}

.price-warnings {
    color: #dc2626;
    font-size: 18px;
    text-align: center;
    margin-top: 12px;
}

.price-warnings strong {
    font-weight: 700;
}

.stocks-section {
    margin-bottom: 30px;
}

.stocks-section h2 {
    font-size: 20px;
    margin-bottom: 20px;
    color: #0f172a;
}

.assets-container {
    background: transparent;
    border-radius: 0;
    overflow: hidden;
    border: none;
}

.stock-entry-header {
    display: grid;
    gap: 2px;
    padding: 0 20px 8px 0;
    background: transparent;
    border-bottom: none;
    font-weight: 600;
    font-size: 13px;
    color: #334155;
}

.stock-entry-header .header-cell {
    text-align: center;
    padding: 0 4px;
}

.stock-entry-header .ticker-header {
    text-align: center;
}

/* Frozen ticker column */
.stock-entry-header .ticker-header,
.stock-entry .ticker-column,
.tbill-summary-row .ticker-column {
    position: sticky;
    left: 0;
    z-index: 2;
}

.stock-entry-header .ticker-header {
    background: white;
}

.stock-entry .ticker-column,
.tbill-summary-row .ticker-column {
    background: white;
    padding-left: 10px;
}

.assets-container.is-scrolled .stock-entry-header .ticker-header,
.assets-container.is-scrolled .stock-entry .ticker-column,
.assets-container.is-scrolled .tbill-summary-row .ticker-column {
    box-shadow: 4px 0 6px -2px rgba(0, 0, 0, 0.1);
}

#stocks-container {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.stock-entry {
    display: grid;
    gap: 2px;
    padding: 0px 0px 0px 0px;
    border-bottom: none;
    position: relative;
    margin: 0 0 6px 0;
    background: transparent;
}

.stock-entry:last-child {
    border-bottom: none;
}

.tbill-summary-row {
    display: grid;
    gap: 2px;
    padding: 0;
    margin: 0;
}

.tbill-summary-row .tbill-negative {
    color: #dc2626 !important;
}

.remove-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    color: #94a3b8;
    border: 1px solid #e2e8f0;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    aspect-ratio: 1;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.remove-btn:hover {
    color: #dc2626;
    border-color: #dc2626;
}

.csv-button-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 16px;
}

.csv-btn {
    background: white;
    color: #0f172a;
    border: 1px solid #cbd5e1;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.csv-btn:hover {
    background: #f8fafc;
    border-color: #94a3b8;
}

.button-group {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    justify-content: center;
}

button {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.add-stock-row {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
}

.add-stock-btn {
    background: white;
    color: #0f172a;
    border: 2px solid #0f172a;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    border-radius: 50%;
    padding: 0;
    font-size: 18px;
    font-weight: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.add-stock-btn:hover {
    background: #f1f5f9;
}

.calculate-btn {
    background: #0f172a;
    color: white;
    padding: 16px 31px;
    font-size: 18px;
    transition: background-color 0.2s;
}

.calculate-btn:hover {
    background: #1e293b;
}

.calculate-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

.loading {
    text-align: center;
    padding: 20px;
    color: #64748b;
}

.assets-loading {
    text-align: center;
    padding: 15px;
    color: #64748b;
    background: transparent;
    border-radius: 0;
    display: none;
}

.assets-loading.visible {
    display: block;
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #e2e8f0;
    border-top: 3px solid #0f172a;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.results {
    margin-top: 30px;
}

.results h2 {
    font-size: 20px;
    margin-bottom: 20px;
    color: #0f172a;
}

#growth-chart-container {
    margin-top: 20px;
    margin-bottom: 20px;
}

.growth-chart-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 14px;
    color: #555;
}

.growth-chart-header input {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
}

#aa-growth-chart {
    width: 100%;
    height: 400px;
}

#portfolio-volatility {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 20px;
    font-size: 14px;
    color: #0f172a;
    line-height: 1.7;
}

#portfolio-volatility .pv-title {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 15px;
}

#portfolio-volatility .pv-line {
    display: flex;
    justify-content: space-between;
    max-width: 420px;
}

.tabs-container {
    margin-top: 30px;
}

.tabs-container h3 {
    font-size: 18px;
    margin-bottom: 15px;
    color: #0f172a;
    font-weight: 600;
}

.tabs {
    display: flex;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 20px;
}

.tab {
    padding: 12px 24px;
    background: #f1f5f9;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #475569;
    transition: all 0.2s;
    margin-right: 4px;
}

.tab:hover {
    background: #e2e8f0;
}

.tab.active {
    background: white;
    border-bottom-color: #16a34a;
    color: #0f172a;
    font-weight: 600;
}

.tab[data-tab="naive"].active {
    border-bottom-color: #16a34a;
}

.tab[data-tab="liquidity"].active {
    border-bottom-color: #3b82f6;
}

.tab[data-tab="tax"].active {
    border-bottom-color: #dc2626;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.tab-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

.tab-table {
    table-layout: fixed;
}

.tab-table th {
    padding: 12px;
    text-align: left;
    background: #f1f5f9;
    font-weight: 600;
    font-size: 13px;
    color: #334155;
    border-bottom: 2px solid #e2e8f0;
}

.tab-table th.ticker-col,
.tab-table th.weight-col {
    width: 8ch;
}

th.weight-naive {
    background-color: #f0fdf4;
}
th.weight-liquidity {
    background-color: #eff6ff;
}
th.weight-tax {
    background-color: #fef2f2;
}

th[colspan] {
    text-align: center;
}

.tab-table th:not(.ticker-col):not(.weight-col) {
    width: calc((100% - 16ch) / 4);
}

.tab-table td {
    padding: 12px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 16px;
}

.tab-table tr:last-child td {
    border-bottom: none;
}

td.delta-positive {
    background-color: rgba(22, 163, 74, 0.1);
}

td.delta-negative {
    background-color: rgba(220, 38, 38, 0.1);
}

.tax-annotation {
    font-size: 0.8em;
    color: #94a3b8;
    margin-top: 2px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

th {
    background: #f1f5f9;
    font-weight: 600;
    color: #334155;
    font-size: 16px;
}

td {
    font-size: 16px;
    color: #0f172a;
}

tr:hover {
    background: #f8fafc;
}

.error {
    padding: 15px;
    background: #fef2f2;
    color: #dc2626;
    border-radius: 8px;
    margin-top: 20px;
    border: 1px solid #fecaca;
}

.calc-warnings {
    padding: 10px 15px;
    background: #fef2f2;
    color: #dc2626;
    border-radius: 8px;
    margin-top: 16px;
    border: 1px solid #fecaca;
    font-size: 0.85rem;
    line-height: 1.6;
}

.calc-warnings strong {
    font-weight: 700;
}

td.vol-na {
    background: #fef2f2;
    color: #dc2626;
    font-weight: 600;
}

.hidden {
    display: none;
}

.hidden-column {
    display: none !important;
}

/* Future Growth Table */
.future-growth-table {
    width: 100%;
    max-width: 600px;
    border-collapse: collapse;
    background: white;
    margin-top: 10px;
}

.future-growth-table th {
    padding: 12px;
    text-align: left;
    background: #f1f5f9;
    font-weight: 600;
    font-size: 13px;
    color: #334155;
    border-bottom: 2px solid #e2e8f0;
}

.future-growth-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 14px;
    color: #0f172a;
}

.future-growth-table tr:last-child td {
    border-bottom: none;
}

.future-growth-table input[type="text"],
.future-growth-table input[type="number"] {
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.future-growth-table input[type="text"]:focus,
.future-growth-table input[type="number"]:focus {
    outline: none;
    border-color: #64748b;
    box-shadow: 0 0 0 2px rgba(100,116,139,0.3);
}

#future-growth-content.active {
    display: flex;
    flex-direction: column;
}

#future-growth-content .future-growth-table {
    flex-shrink: 0;
}

.fg-results-container {
    margin-top: 20px;
    padding: 16px 20px;
    background: #f1f5f9;
    border-radius: 12px;
    flex-shrink: 0;
}

.fg-results-container h3 {
    font-size: 16px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 12px;
}

.fg-results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.fg-results-table th,
.fg-results-table td {
    padding: 6px 12px;
    text-align: right;
    border-bottom: 1px solid #e2e8f0;
}

.fg-results-table th {
    font-weight: 600;
    color: #334155;
    background: #f1f5f9;
    font-size: 12px;
}

.fg-results-table th:first-child,
.fg-results-table td:first-child {
    text-align: left;
}

.fg-results-table tr:last-child td {
    border-bottom: none;
    font-weight: 600;
}

.fg-chart-years-row {
    margin-top: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.fg-chart-years-row label {
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    margin: 0;
    min-height: auto;
}

.fg-chart-years-row input {
    width: 80px;
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
}

.fg-chart-container {
    margin-top: 12px;
    padding: 20px;
    background: #f1f5f9;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

#fg-growth-chart {
    width: 100%;
    height: 400px;
}

.fg-chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 12px;
    flex-shrink: 0;
}

.fg-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #475569;
}

.fg-legend-swatch {
    width: 14px;
    height: 3px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* Runway calculate button */
.fg-calculate-row {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    flex-shrink: 0;
}

/* Runway / CoLA inputs */
.fg-runway-inputs {
    margin-top: 24px;
    padding: 20px;
    background: #f1f5f9;
    border-radius: 12px;
    flex-shrink: 0;
}

.fg-runway-inputs h3 {
    font-size: 16px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 14px;
}

.fg-runway-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
}

.fg-runway-grid .input-group label {
    font-size: 12px;
    font-weight: 500;
    color: #475569;
    margin-bottom: 4px;
}

.fg-runway-grid .input-group input {
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    width: 100%;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.fg-runway-grid .input-group input:focus {
    outline: none;
    border-color: #64748b;
    box-shadow: 0 0 0 2px rgba(100,116,139,0.3);
}

/* Runway results card */
.fg-runway-results {
    margin-top: 20px;
    padding: 16px 20px;
    background: #f1f5f9;
    border-radius: 12px;
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.fg-runway-headline {
    margin-bottom: 16px;
}

.fg-runway-headline .output-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
}

.fg-runway-headline .output-row:last-child {
    border-bottom: none;
}

.fg-runway-headline .output-label {
    font-size: 14px;
    color: #475569;
}

.fg-runway-headline .output-value {
    font-size: 14px;
    font-weight: 600;
    color: #0f172a;
}

.fg-runway-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.fg-runway-table th,
.fg-runway-table td {
    padding: 6px 12px;
    text-align: right;
    border-bottom: 1px solid #e2e8f0;
}

.fg-runway-table th {
    font-weight: 600;
    color: #334155;
    background: #f1f5f9;
    font-size: 12px;
    white-space: nowrap;
}

.fg-runway-table th:first-child,
.fg-runway-table td:first-child {
    text-align: left;
}

.fg-runway-table tr:last-child td {
    border-bottom: none;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 20px 15px;
    }
    
    h1 {
        font-size: 24px;
        margin-bottom: 15px;
    }

    .logo {
        height: 40px;
    }
    
    .description {
        font-size: 13px;
        margin-bottom: 20px;
    }
    
    .checkbox-container {
        margin-bottom: 20px;
    }
    
    .checkbox-row {
        margin-bottom: 10px;
    }
    
    .checkbox-row input[type="checkbox"] {
        width: 20px;
        height: 20px;
        margin-right: 10px;
    }
    
    .checkbox-row label {
        font-size: 15px;
    }
    
    .global-inputs {
        grid-template-columns: 60% 20% 20%;
        gap: 0;
        padding: 15px;
    }
    
    .stocks-section h2 {
        font-size: 18px;
    }
    
    .assets-container {
        margin: 0 -15px;
        border-radius: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border: none;
    }
    
    #stocks-container {
        overflow-x: visible;
        margin: 0;
        padding: 0;
    }
    
    .stock-entry-header {
        min-width: 900px;
        padding: 0 18px 8px 0;
        font-size: 12px;
    }
    
    .stock-entry-header .ticker-header {
        padding-left: 10px;
    }
    
    .stock-entry {
        min-width: 900px;
        padding: 0px 0px 0px 0px;
    }

    .tbill-summary-row {
        min-width: 900px;
    }
    
    .remove-btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
        aspect-ratio: 1;
        font-size: 16px;
        top: 8px;
        right: 8px;
    }
    
    .button-group {
        flex-direction: column;
        gap: 10px;
    }
    
    button {
        width: 100%;
        padding: 14px 24px;
        font-size: 16px;
        min-height: 44px;
    }
    
    
    .input-group input {
        height: 44px;
        font-size: 16px;
    }
    
    label {
        font-size: 13px;
    }
    
    .results h2 {
        font-size: 18px;
    }
    
    .results-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
        max-width: 100%;
    }
    
    .results-wrapper table {
        min-width: 0;
        width: 100%;
        max-width: 100%;
        table-layout: fixed;
    }
    
    .results-wrapper th {
        white-space: normal;
        word-wrap: break-word;
        word-break: break-word;
        overflow-wrap: break-word;
        line-height: 1.2;
        padding: 8px 4px;
        font-size: 11px;
    }
    
    .results-wrapper td {
        font-size: 13px;
        padding: 8px 4px;
    }
    
    .tabs-container .tab-content {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    
    .tab-table {
        min-width: 0;
        width: 100%;
        max-width: 100%;
        table-layout: fixed;
    }
    
    .tab-table th {
        white-space: normal;
        word-wrap: break-word;
        word-break: break-word;
        overflow-wrap: break-word;
        line-height: 1.2;
        padding: 8px 4px;
        font-size: 11px;
        width: auto;
        min-width: 0;
    }
    
    .tab-table th.ticker-col { width: 14%; }
    .tab-table th.weight-col { width: 12%; }
    .tab-table th:nth-child(3) { width: 12%; }
    .tab-table th:nth-child(4) { width: 12%; }
    .tab-table th:nth-child(5) { width: 25%; }
    .tab-table th:nth-child(6) { width: 25%; }
    
    .tab-table td {
        font-size: 13px;
        padding: 8px 4px;
    }
    
    th, td {
        padding: 10px 8px;
        font-size: 13px;
    }
    
    .results-wrapper td,
    .tab-table td {
        font-size: 14px;
    }
    
    .inheritance-inputs {
        max-width: 100%;
    }
    
    .inheritance-inputs input[type="text"],
    .inheritance-inputs select {
        font-size: 16px;
        padding: 12px 14px;
        min-height: 48px;
    }
    
    .inheritance-inputs label {
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 5px;
    }
    
    .container {
        padding: 15px 10px;
    }
    
    h1 {
        font-size: 22px;
        margin-bottom: 15px;
    }

    .logo {
        height: 36px;
    }
    
    .global-inputs {
        padding: 12px;
    }
    
    .assets-container {
        border-radius: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .results-wrapper {
        overflow: visible;
        margin: 0 0 12px 0;
        padding: 0;
    }
    
    .stock-entry-header {
        min-width: 850px;
        padding: 0 16px 8px 0;
        font-size: 11px;
    }
    
    .stock-entry-header .ticker-header {
        padding-left: 10px;
    }
    
    .stock-entry {
        min-width: 850px;
        padding: 0px 0px 0px 0px;
    }

    .tbill-summary-row {
        min-width: 850px;
    }
    
    .remove-btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
        aspect-ratio: 1;
        font-size: 16px;
    }
    
    button {
        font-size: 15px;
    }
    
    .results-wrapper th,
    .tab-table th {
        font-size: 10px;
        padding: 6px 3px;
    }
    
    .results-wrapper td,
    .tab-table td {
        font-size: 13px;
        padding: 6px 3px;
    }
    
    th, td {
        padding: 8px 6px;
        font-size: 12px;
    }
    
    .inheritance-inputs input[type="text"],
    .inheritance-inputs select {
        font-size: 18px;
        padding: 14px 16px;
        min-height: 52px;
    }
    
    .inheritance-inputs label {
        font-size: 16px;
    }
    
    .tax-chart-container {
        max-width: 100%;
    }
    
    .chart-wrapper {
        flex-direction: column;
        align-items: center;
    }
    
    #tax-pie-chart {
        max-width: 100%;
        height: auto;
    }
    
    .fg-chart-container {
        padding: 12px;
    }
    
    #fg-growth-chart {
        max-width: 100%;
    }
    
    .fg-runway-grid {
        grid-template-columns: 1fr;
    }
}

/* Tooltip styles for header cells and table headers */
.header-cell[data-tooltip],
th[data-tooltip] {
    position: relative;
    cursor: default;
    outline: none;
}

.header-cell[data-tooltip]::after,
th[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    padding: 5px 10px;
    background: #0f172a;
    color: #fff;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.4;
    border-radius: 8px;
    white-space: nowrap;
    max-width: 220px;
    white-space: normal;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.header-cell[data-tooltip]:hover::after,
.header-cell[data-tooltip]:focus::after,
.header-cell[data-tooltip]:active::after,
th[data-tooltip]:hover::after,
th[data-tooltip]:focus::after,
th[data-tooltip]:active::after {
    opacity: 1;
}

/* ---------------------------------------------------------------------------
   Auth controls
   --------------------------------------------------------------------------- */

.auth-controls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.auth-sign-in-btn {
    display: inline-block;
    padding: 7px 16px;
    background: #4285f4;
    color: #fff;
    border-radius: 6px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.15s;
}

.auth-sign-in-btn:hover {
    background: #3367d6;
}

.auth-user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.auth-email {
    color: #475569;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.auth-sign-out {
    color: #94a3b8;
    text-decoration: none;
    font-size: 12px;
}

.auth-sign-out:hover {
    color: #ef4444;
}

/* ---------------------------------------------------------------------------
   Cloud sync buttons
   --------------------------------------------------------------------------- */

.cloud-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.cloud-btn {
    padding: 6px 14px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #334155;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.cloud-btn:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

.cloud-btn-secondary {
    color: #64748b;
}

.cloud-btn-danger {
    color: #dc2626;
    border-color: #fecaca;
}

.cloud-btn-danger:hover {
    background: #fef2f2;
    border-color: #f87171;
}

.sync-status {
    font-size: 12px;
    color: #64748b;
    margin-left: 4px;
}

.sync-ok {
    color: #16a34a;
}

.sync-error {
    color: #dc2626;
}

.sync-busy {
    color: #2563eb;
}

/* ---------------------------------------------------------------------------
   PIN modal
   --------------------------------------------------------------------------- */

.pin-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.pin-modal {
    background: #fff;
    border-radius: 12px;
    padding: 32px;
    width: 340px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.pin-modal h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #0f172a;
}

.pin-modal-warning {
    font-size: 13px;
    color: #dc2626;
    margin-bottom: 16px;
    line-height: 1.5;
}

.pin-modal-field {
    margin-bottom: 12px;
}

.pin-modal-field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #475569;
    margin-bottom: 4px;
}

.pin-modal-field input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 20px;
    letter-spacing: 8px;
    text-align: center;
    font-family: monospace;
}

.pin-modal-field input:focus {
    outline: none;
    border-color: #4285f4;
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.15);
}

.pin-modal-error {
    font-size: 13px;
    color: #dc2626;
    margin-bottom: 12px;
}

.pin-modal-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
}

.pin-modal-btn {
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
}

.pin-modal-btn-primary {
    background: #4285f4;
    color: #fff;
}

.pin-modal-btn-primary:hover {
    background: #3367d6;
}

.pin-modal-btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pin-modal-btn-cancel {
    background: transparent;
    color: #64748b;
    border: 1px solid #e2e8f0;
}

.pin-modal-btn-cancel:hover {
    background: #f1f5f9;
}

.pin-spinner {
    width: 18px;
    height: 18px;
    border-width: 2px;
}

/* ---------------------------------------------------------------------------
   Responsive: auth controls
   --------------------------------------------------------------------------- */

@media (max-width: 768px) {
    .header-row {
        flex-wrap: wrap;
    }

    .auth-controls {
        margin-left: 0;
        width: 100%;
        justify-content: flex-start;
        margin-top: 8px;
    }

    .cloud-buttons {
        width: 100%;
    }

    .auth-email {
        max-width: 140px;
    }
}

/* ---------------------------------------------------------------------------
   Trust & Structure Simulator
   --------------------------------------------------------------------------- */

.ts-sections {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ts-section {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

.ts-section[open] {
    border-color: #cbd5e1;
}

.ts-section-title {
    font-size: 15px;
    font-weight: 600;
    padding: 14px 18px;
    cursor: pointer;
    color: #0f172a;
    background: #f8fafc;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}

.ts-section-title::-webkit-details-marker {
    display: none;
}

.ts-section-title::before {
    content: '▶';
    font-size: 10px;
    color: #94a3b8;
    transition: transform 0.15s;
    display: inline-block;
}

.ts-section[open] > .ts-section-title::before {
    transform: rotate(90deg);
}

.ts-section-title:hover {
    background: #f1f5f9;
}

.ts-section-body {
    padding: 18px;
    border-top: 1px solid #e2e8f0;
}

.ts-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.ts-inputs .input-group {
    display: flex;
    flex-direction: column;
}

.ts-inputs label {
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    margin-bottom: 4px;
}

.ts-inputs input[type="text"],
.ts-inputs input[type="number"] {
    padding: 9px 11px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    color: #0f172a;
    background: #fff;
}

.ts-inputs input:focus {
    outline: none;
    border-color: #64748b;
    box-shadow: 0 0 0 2px rgba(100, 116, 139, 0.15);
}

.ts-outputs {
    background: #f8fafc;
    border-radius: 8px;
    padding: 16px 18px;
    border: 1px solid #e2e8f0;
}

.ts-output-heading {
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 14px 0 6px;
}

.ts-output-heading:first-child {
    margin-top: 0;
}

.ts-output-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 6px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 14px;
    color: #334155;
}

.ts-output-row:last-child {
    border-bottom: none;
}

.ts-output-row span:first-child {
    font-weight: 400;
}

.ts-output-row span:last-child {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.ts-output-row.ts-highlight {
    background: #f0fdf4;
    margin: 4px -18px;
    padding: 8px 18px;
    border-radius: 6px;
    border-bottom: none;
    color: #166534;
}

.ts-output-row.ts-highlight span:last-child {
    font-weight: 700;
}

@media (max-width: 600px) {
    .ts-inputs {
        grid-template-columns: 1fr;
    }

    .ts-section-body {
        padding: 14px;
    }

    .ts-output-row.ts-highlight {
        margin: 4px -14px;
        padding: 8px 14px;
    }
}

/* ── Thesis Relativity ──────────────────────────────────────────── */

.tr-heading {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #0f172a;
}

.tr-hint {
    font-size: 14px;
    color: #64748b;
    margin-bottom: 16px;
    line-height: 1.45;
}

/* Advanced toggle */
.tr-advanced-toggle {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: #475569;
    padding: 6px 12px;
    font-size: 12px;
    font-family: 'Barlow', system-ui, sans-serif;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: auto;
    width: auto;
}

.tr-advanced-toggle:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
}

.tr-advanced-toggle .arrow {
    transition: transform 0.2s;
    font-size: 10px;
}

.tr-advanced-toggle.expanded .arrow {
    transform: rotate(90deg);
}

.tr-advanced {
    display: none;
    margin-bottom: 16px;
}

.tr-advanced.visible {
    display: block;
}

.tr-slider-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 400px;
}

.tr-slider-row label {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    margin-bottom: 0;
    min-height: auto;
}

.tr-concavity-value {
    font-weight: 600;
    color: #0f172a;
    font-variant-numeric: tabular-nums;
}

.tr-slider-row input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
    cursor: pointer;
}

.tr-slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #0f172a;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    cursor: pointer;
}

.tr-slider-row input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #0f172a;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    cursor: pointer;
}

.tr-advanced-row {
    display: flex;
    gap: 16px;
    margin-top: 10px;
}

.tr-advanced-field {
    flex: 1;
    max-width: 220px;
}

.tr-advanced-field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    margin-bottom: 4px;
}

.tr-advanced-field .tr-input {
    width: 100%;
}

.tr-weight-graph {
    margin-top: 14px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    padding: 12px;
}

.tr-weight-graph-hint {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 10px;
}

.tr-weight-canvas {
    width: 100%;
}

.tr-weight-svg {
    width: 100%;
    height: auto;
    display: block;
}

.tr-grid-line {
    stroke: #e2e8f0;
    stroke-width: 1;
}

.tr-axis-line {
    stroke: #94a3b8;
    stroke-width: 1.5;
}

.tr-axis-label {
    fill: #64748b;
    font-size: 11px;
    font-weight: 500;
}

.tr-rank-guide {
    stroke: #cbd5e1;
    stroke-width: 1;
    stroke-dasharray: 3 3;
}

.tr-feasible-line {
    stroke: #dc2626;
    stroke-width: 2;
    fill: none;
    opacity: 0.9;
}

.tr-weight-line {
    stroke: #0f172a;
    stroke-width: 2.5;
    fill: none;
}

.tr-weight-point {
    fill: #0f172a;
    stroke: #fff;
    stroke-width: 2;
}

.tr-vol-adj-line {
    stroke: #3b82f6;
    stroke-width: 2;
    fill: none;
    stroke-dasharray: 6 3;
}

.tr-vol-adj-point {
    fill: #3b82f6;
    stroke: #fff;
    stroke-width: 2;
}

.tr-point-label {
    fill: #0f172a;
    font-size: 11px;
    font-weight: 600;
}

.tr-ab-readout {
    margin-top: 10px;
    font-size: 12px;
    color: #334155;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 6px 10px;
    display: inline-block;
}

/* Entry phase */
.tr-entry-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.tr-input {
    flex: 1;
    padding: 10px 14px;
    font-size: 16px;
    font-family: 'Barlow', system-ui, sans-serif;
    border: 2px solid #cbd5e1;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s;
    color: #0f172a;
    min-height: 44px;
}

.tr-input:focus {
    border-color: #0f172a;
}

.tr-btn {
    font-family: 'Barlow', system-ui, sans-serif;
    font-weight: 600;
    font-size: 14px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    padding: 10px 20px;
    transition: background 0.2s, transform 0.1s;
    min-height: 44px;
}

.tr-btn:active {
    transform: scale(0.97);
}

.tr-btn-add {
    background: #0f172a;
    color: #fff;
}

.tr-btn-add:hover {
    background: #1e293b;
}

.tr-btn-done {
    background: #0f172a;
    color: #fff;
    width: 100%;
    margin-top: 8px;
}

.tr-btn-done:hover {
    background: #1e293b;
}

.tr-btn-back {
    background: #f1f5f9;
    color: #475569;
    border: 2px solid #cbd5e1;
}

.tr-btn-back:hover {
    background: #e2e8f0;
}

.tr-btn-calc {
    background: #0f172a;
    color: #fff;
    flex: 1;
}

.tr-btn-calc:hover {
    background: #1e293b;
}

.tr-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

/* Entry chips */
.tr-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}

.tr-entry-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 500;
    color: #0f172a;
}

.tr-chip-remove {
    background: none;
    border: none;
    font-size: 18px;
    line-height: 1;
    color: #94a3b8;
    cursor: pointer;
    padding: 0 2px;
    min-height: auto;
    min-width: auto;
    width: auto;
}

.tr-chip-remove:hover {
    color: #ef4444;
}

/* Ranking area */
.tr-ranking-area {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 60px;
    padding: 8px 0;
    touch-action: pan-y;
}

.tr-rank-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px 12px;
    min-height: 52px;
    transition: border-color 0.15s, background 0.15s;
}

.tr-rank-row.tr-merge-highlight {
    border-color: #0f172a;
    background: #f1f5f9;
}

.tr-rank-label {
    font-size: 14px;
    font-weight: 700;
    color: #94a3b8;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.tr-rank-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1;
}

.tr-asset-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #0f172a;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    padding: 8px 18px;
    border-radius: 10px;
    cursor: grab;
    user-select: none;
    touch-action: pan-y;
    min-height: 44px;
    transition: box-shadow 0.15s, transform 0.15s;
}

.tr-asset-chip:active {
    cursor: grabbing;
}

.tr-drag-placeholder {
    opacity: 0.25;
}

.tr-dragging {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    transform: scale(1.06);
    opacity: 0.92;
}

.tr-drop-indicator {
    position: absolute;
    left: 12px;
    right: 12px;
    height: 3px;
    background: #0f172a;
    border-radius: 2px;
    pointer-events: none;
    z-index: 10;
    transition: top 0.1s;
}

/* Results table */
.tr-results {
    margin-top: 24px;
    position: relative;
}

.tr-results.has-pf-cols::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.85));
    pointer-events: none;
    z-index: 1;
}

.tr-results-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tr-results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
}

.tr-results-table.has-pf-cols {
    min-width: 640px;
}

.tr-results-table th,
.tr-results-table td {
    white-space: nowrap;
}

.tr-results-table th {
    text-align: left;
    font-weight: 600;
    color: #475569;
    border-bottom: 2px solid #e2e8f0;
    padding: 10px 14px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tr-results-table td {
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    color: #0f172a;
}

.tr-results-table th:nth-child(n+3),
.tr-results-table td:nth-child(n+3) {
    text-align: right;
}

.tr-results-table tbody tr:last-child td {
    border-bottom: none;
}

.tr-total-row td {
    font-weight: 700;
    border-top: 2px solid #e2e8f0;
}

.tr-asset-chip .override-pill,
.tr-entry-chip .override-pill {
    margin-left: 4px;
    vertical-align: middle;
    min-width: 44px;
    min-height: 44px;
    padding: 4px 8px;
    font-size: 0.7rem;
    line-height: 36px;
}

.tr-results-table .vol-na {
    color: #dc2626;
    font-weight: 600;
}

/* =========================================================================
   Portfolio tab
   ========================================================================= */

.pf-section {
    max-width: 640px;
}

.pf-value-row {
    margin-bottom: 20px;
}

.pf-value-row label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: #334155;
    margin-bottom: 6px;
}

.pf-value-row input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-family: inherit;
    font-size: 16px;
    color: #0f172a;
    background: #fff;
    min-height: 44px;
}

.pf-value-row input:focus {
    outline: none;
    border-color: #0f172a;
    box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.1);
}

.pf-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.pf-table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
    font-size: 14px;
}

.pf-table thead th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: #64748b;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}

.pf-table thead th:last-child {
    width: 40px;
}

.pf-table tbody td {
    padding: 4px 6px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.pf-table tbody tr:last-child td {
    border-bottom: none;
}

.pf-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    color: #0f172a;
    background: transparent;
    min-height: 40px;
}

.pf-input:focus {
    outline: none;
    border-color: #0f172a;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.08);
}

.pf-ticker {
    text-transform: uppercase;
    font-weight: 500;
}

.pf-del-cell {
    text-align: center;
    width: 40px;
}

.pf-remove-btn {
    background: none;
    border: none;
    font-size: 18px;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}

.pf-remove-btn:hover {
    color: #dc2626;
    background: #fef2f2;
}

.pf-actions {
    margin-top: 12px;
}

.pf-add-btn {
    background: #f1f5f9;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    padding: 10px 20px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: #475569;
    cursor: pointer;
    width: 100%;
    min-height: 44px;
}

.pf-add-btn:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

.pf-price:not(.price-from-yfinance) {
    background-color: #fef2f2;
}

.pf-usd {
    background-color: #F0F0F0;
    color: #1B5E20;
    cursor: default;
}

.pf-usd:focus {
    cursor: text;
}

/* Mobile adjustments for mode selector */
@media (max-width: 768px) {
    .mode-selector {
        flex-wrap: wrap;
    }

    .mode-btn {
        font-size: 12px;
        padding: 10px 10px;
    }

    /* Prevent global button { width:100% } from clobbering TR buttons */
    .tr-btn-add {
        width: auto;
    }

    .tr-advanced-toggle {
        width: auto;
    }

    .crypto-override-btn {
        width: auto;
    }

    .tr-btn-back {
        width: auto;
    }

    .tr-btn-calc {
        width: auto;
        flex: 1;
    }

    .tr-btn-done {
        width: 100%;
    }

    .tr-heading {
        font-size: 18px;
    }

    .tr-entry-row {
        gap: 6px;
    }

    .tr-rank-row {
        padding: 6px 10px;
    }

    .tr-results-table {
        font-size: 13px;
    }

    .tr-results-table th {
        font-size: 11px;
        padding: 8px 10px;
    }

    .tr-results-table td {
        padding: 8px 10px;
    }

    .pf-input {
        min-height: 44px;
        font-size: 16px;
    }

    .pf-remove-btn {
        min-height: 44px;
        min-width: 44px;
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .mode-selector {
        flex-wrap: wrap;
        gap: 4px;
    }

    .mode-btn {
        font-size: 12px;
        padding: 8px 6px;
        flex: 0 0 auto;
        width: calc(50% - 2px);
    }

    .tr-asset-chip {
        font-size: 13px;
        padding: 8px 14px;
    }

    .tr-actions {
        flex-direction: column;
    }

    .tr-actions .tr-btn-back,
    .tr-actions .tr-btn-calc {
        width: 100%;
    }

    .tr-hint {
        font-size: 13px;
    }

    .tr-results-table th {
        font-size: 10px;
        padding: 6px 8px;
    }

    .tr-results-table td {
        font-size: 12px;
        padding: 6px 8px;
    }
}

/* =========================================================================
   My Data tab
   ========================================================================= */

.my-data-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid #e2e8f0;
}

.my-data-tab {
    padding: 8px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.my-data-tab:hover {
    color: #0f172a;
}

.my-data-tab.active {
    color: #0f172a;
    border-bottom-color: #0f172a;
}

.my-data-panel {
    min-height: 120px;
}

/* CTA / empty states */
.md-cta {
    text-align: center;
    padding: 40px 20px;
    color: #475569;
}

.md-cta p {
    margin: 0 0 16px;
    font-size: 15px;
}

/* Vault metadata */
.md-meta {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 16px;
}

.md-meta-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 14px;
    color: #334155;
}

.md-meta-label {
    font-weight: 500;
    color: #64748b;
}

/* Collapsible cards */
.md-card {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
}

.md-card summary {
    padding: 12px 16px;
    font-weight: 600;
    font-size: 14px;
    color: #0f172a;
    cursor: pointer;
    background: #f8fafc;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.md-card summary::-webkit-details-marker {
    display: none;
}

.md-card summary::before {
    content: '\25B6';
    font-size: 10px;
    transition: transform 0.15s;
    color: #94a3b8;
}

.md-card[open] summary::before {
    transform: rotate(90deg);
}

.md-card summary:hover {
    background: #f1f5f9;
}

.md-card-body {
    padding: 12px 16px;
    font-size: 14px;
}

.md-empty {
    color: #94a3b8;
    font-style: italic;
    margin: 0;
}

/* Key-value display */
.md-kv {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
}

.md-kv-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid #f1f5f9;
}

.md-kv-row:last-child {
    border-bottom: none;
}

.md-kv-label {
    color: #64748b;
    font-weight: 400;
}

.md-kv-value {
    color: #0f172a;
    font-weight: 500;
    text-align: right;
}

/* Stock table */
.md-stock-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.md-stock-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

.md-stock-table th {
    text-align: left;
    padding: 6px 10px;
    font-weight: 600;
    color: #64748b;
    border-bottom: 2px solid #e2e8f0;
    background: #f8fafc;
    position: sticky;
    top: 0;
}

.md-stock-table td {
    padding: 5px 10px;
    color: #334155;
    border-bottom: 1px solid #f1f5f9;
}

.md-stock-table tbody tr:hover {
    background: #f8fafc;
}

/* Action buttons row */
.md-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
}

/* Editable value tap affordance */
.md-kv-value.md-editable,
.md-stock-table td.md-editable {
    cursor: pointer;
    border-bottom: 1px dashed #cbd5e1;
    touch-action: manipulation;
}

.md-kv-value.md-editable:hover,
.md-stock-table td.md-editable:hover {
    background: #f1f5f9;
}

.md-kv-value.md-editable:active,
.md-stock-table td.md-editable:active {
    background: #e2e8f0;
}

/* :has() unsupported on Firefox <121 / older Samsung Internet; double border is cosmetic-only fallback */
.md-kv-row:has(> .md-kv-value.md-editable) {
    border-bottom: none;
}

.md-stock-table tbody tr:hover {
    background: transparent;
}

/* Boolean toggle */
.md-kv-value.md-bool {
    cursor: pointer;
    transition: background 0.3s;
}

.md-kv-value.md-bool:hover {
    color: #3b82f6;
}

.md-bool-flash {
    background: #dbeafe;
    border-radius: 4px;
}

.md-cloud-dirty {
    font-size: 13px;
    color: #92400e;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 6px;
    padding: 8px 12px;
    margin: 12px 0 0;
}

/* Inline edit input */
.md-inline-wrap {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.md-stock-table td {
    position: relative;
}

.md-stock-table td .md-inline-wrap {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    min-width: 120px;
    z-index: 5;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    border-radius: 6px;
    padding: 2px 4px;
}

.md-inline-input {
    font: inherit;
    font-size: 16px;
    padding: 2px 4px;
    border: 1px solid #64748b;
    border-radius: 4px;
    width: 100%;
    max-width: 150px;
    text-align: right;
    box-sizing: border-box;
}

.md-inline-cancel {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
    min-height: auto;
    width: auto;
    line-height: 1;
}

.md-inline-cancel:hover {
    color: #dc2626;
}

/* Stock delete button */
.md-stock-delete {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    min-height: auto;
    width: auto;
    line-height: 1;
}

.md-stock-delete:hover {
    color: #dc2626;
}

/* Mobile */
@media (max-width: 768px) {
    .my-data-tab {
        font-size: 13px;
        padding: 8px 14px;
    }

    .md-meta {
        padding: 12px 14px;
    }

    .md-card summary {
        font-size: 13px;
        padding: 10px 12px;
    }

    .md-card-body {
        padding: 10px 12px;
    }

    .md-actions {
        flex-direction: column;
    }

    .md-actions .cloud-btn {
        width: 100%;
        text-align: center;
    }

    .md-inline-input {
        max-width: none;
    }

    .md-inline-cancel {
        min-height: 44px;
        min-width: 44px;
        font-size: 18px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .md-stock-table .md-inline-cancel {
        min-height: 36px;
        min-width: 28px;
        font-size: 16px;
        padding: 0 2px;
    }

    .md-kv-value.md-editable,
    .md-kv-value.md-bool {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: flex-end;
        padding: 0 4px;
    }

    .md-stock-table td.md-editable {
        height: 44px;
        padding: 10px;
    }

    .md-stock-delete {
        min-height: 44px;
        min-width: 44px;
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .my-data-tabs {
        gap: 0;
    }

    .my-data-tab {
        flex: 1;
        text-align: center;
        font-size: 12px;
        padding: 8px 8px;
    }

    .md-inline-input {
        max-width: none;
    }
}
