/* Net Worth Tracker Styles */
/*
 * Uses CSS calc() with viewport height to ensure content fits without scrolling.
 * The --nw-header-offset accounts for site headers (v2-header ~60px, main tabs ~50px)
 */
.networth-tracker-container {
    --nw-header-offset: 125px; /* Site header + main tabs */
    padding: 20px 20px 2px 20px; /* Minimal bottom padding */
    background: var(--color-gray-50);
    height: calc(100vh - var(--nw-header-offset));
    max-height: calc(100vh - var(--nw-header-offset));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
}

/* Header Section */
.nw-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    flex-shrink: 0; /* Don't shrink header */
}

.nw-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.nw-title-pill {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    background: var(--ui-main-contentHeaderBg, var(--color-ui-content-header));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-white-1);
    font-size: 16px;
    flex-shrink: 0;
    animation: nwPillPulse 2s ease-in-out infinite;
}

@keyframes nwPillPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(var(--ui-main-contentHeaderBg-rgb, var(--color-ui-content-header-rgb)), 0.4);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 8px rgba(var(--ui-main-contentHeaderBg-rgb, var(--color-ui-content-header-rgb)), 0);
    }
}

.nw-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nw-header h2.nw-title {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.03em;
    color: var(--ui-text-primaryText);
    visibility: hidden;
}

.nw-header h2.nw-title.animation-ready {
    visibility: visible;
}

.nw-header h2.nw-title .word {
    display: inline-block;
}

.nw-subtitle {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--ui-text-secondaryText);
    visibility: hidden;
}

.nw-subtitle.animation-ready {
    visibility: visible;
}

.nw-help-icon {
    cursor: pointer;
    flex-shrink: 0;
}

/* Summary Bar */
.nw-summary-bar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
    flex-shrink: 0; /* Don't shrink summary bar */
}

@media (max-width: 768px) {
    .nw-summary-bar {
        grid-template-columns: 1fr;
    }
}

.nw-summary-card {
    background: var(--color-white-1);
    border-radius: 14px;
    border: 1px solid var(--color-gray-200);
    padding: 14px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
}

.nw-summary-icon {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    background: var(--ui-main-contentHeaderBg, var(--color-ui-content-header));
    color: var(--color-white-1);
    flex-shrink: 0;
}

.nw-summary-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    text-align: left;
}

.nw-summary-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ui-text-secondaryText);
    font-weight: 500;
    margin: 0;
}

.nw-summary-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-gray-900);
    margin: 0;
}

.nw-summary-sub {
    font-size: 11px;
    color: var(--ui-text-secondaryText);
    margin: 0;
}

/* Description Section */
.networth-description {
    background: linear-gradient(135deg, var(--color-brand-light) 0%, var(--color-brand-light) 100%);
    border-left: 4px solid var(--color-cyan-1);
    padding: 20px 24px;
    margin-bottom: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(var(--color-ui-overlay-rgb), 0.08);
}

.networth-description p {
    margin: 0;
    font-size: 15px;
    line-height: 1.6;
    color: var(--color-brand-dark);
}

.networth-description strong {
    color: var(--color-brand-dark);
    font-weight: 600;
}

/* Graph Controls */
.networth-graph-controls {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 12px;
    flex-shrink: 0; /* Don't shrink the controls */
}

/* Graph type selector - tab style */
.graph-type-selector {
    display: flex;
    gap: clamp(2px, 0.32vw, 5px);
    align-items: center;
    flex-wrap: nowrap;
    border-bottom: 2px solid var(--color-gray-200);
    padding-bottom: 0;
}

/* Individual graph tabs */
.nw-graph-tab {
    padding: clamp(5px, 0.53vw, 10px) clamp(5px, 0.74vw, 14px);
    font-size: clamp(10px, 0.74vw, 14px);
    font-weight: 500;
    color: var(--color-gray-500);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: clamp(3px, 0.32vw, 6px);
    white-space: nowrap;
    outline: none;
    font-family: inherit;
}

.nw-graph-tab i {
    font-size: clamp(10px, 0.74vw, 14px);
}

.nw-graph-tab:hover {
    color: var(--color-blue-6);
    background: rgba(var(--color-blue-6-rgb), 0.05);
    border-radius: 6px 6px 0 0;
}

.nw-graph-tab.active {
    color: var(--color-blue-6);
    border-bottom-color: var(--color-blue-6);
    font-weight: 600;
}

.nw-graph-tab.active:hover {
    background: transparent;
}

.graph-actions {
    display: flex;
    gap: 10px;
}

/* Graph Container */
.networth-graph-container {
    background: var(--color-white-1);
    padding: 12px 15px 5px 15px; /* Minimal padding for tighter fit */
    border-radius: 8px;
    margin-bottom: 0;
    box-shadow: 0 1px 3px rgba(var(--color-ui-overlay-rgb), 0.1);
    overflow: hidden;
    flex: 1;
    min-height: 0; /* Critical for flex shrinking */
    position: relative;
}

/* Chart canvas - fills container, Chart.js handles sizing */
#networthChart {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* Snapshots Section */
.networth-snapshots-section {
    background: var(--color-white-1);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(var(--color-ui-overlay-rgb), 0.1);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Critical for flex shrinking */
    overflow: hidden;
}

.networth-snapshots-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--color-gray-300);
    flex-shrink: 0; /* Keep header fixed while content scrolls */
}

.networth-snapshots-section h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--color-gray-900);
}

/* Snapshots Table */
.networth-snapshots-table-container {
    overflow-x: auto;
    overflow-y: auto;
    flex: 1;
    min-height: 0; /* Critical for flex shrinking - allows container to shrink below content size */
}

.networth-snapshots-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-family: "Roboto", sans-serif;
    font-size: 0.875rem;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(var(--color-ui-overlay-rgb), 0.07), 0 2px 4px rgba(var(--color-ui-overlay-rgb), 0.04);
    background: var(--color-white-1);
    border: 1px solid rgba(var(--color-gray-200-rgb), 0.5);
}

.networth-snapshots-table thead {
    background-color: var(--color-gray-600) !important;
    background: linear-gradient(135deg, var(--color-gray-600) 0%, var(--color-gray-800) 100%) !important;
    border-bottom: none;
    position: sticky;
    top: 0;
    z-index: 10;
}

.networth-snapshots-table thead::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(var(--color-white-1-rgb), 0.3), transparent);
}

.networth-snapshots-table thead tr:first-child th:first-child {
    border-top-left-radius: 12px;
}

.networth-snapshots-table thead tr:first-child th:last-child {
    border-top-right-radius: 12px;
}

.networth-snapshots-table th {
    padding: 0.625rem 1.25rem;
    text-align: left;
    font-weight: 600;
    color: var(--color-white-1);
    white-space: nowrap;
    letter-spacing: 0.025em;
    font-size: 0.8125rem;
    text-transform: uppercase;
    border: none !important;
    border-bottom: 2px solid rgba(var(--color-white-1-rgb), 0.1);
    background-color: var(--color-gray-600);
}

.networth-snapshots-table th.text-right {
    text-align: right;
}

.networth-snapshots-table tbody tr {
    border-bottom: 1px solid rgba(var(--color-gray-200-rgb), 0.5);
}

.networth-snapshots-table tbody tr:nth-child(even) {
    background-color: var(--ui-table-header-rowEvenBg, var(--color-gray-100));
}

.networth-snapshots-table tbody tr:last-child {
    border-bottom: none;
}

.networth-snapshots-table tbody tr:last-child td:first-child {
    border-bottom-left-radius: 12px;
}

.networth-snapshots-table tbody tr:last-child td:last-child {
    border-bottom-right-radius: 12px;
}

.networth-snapshots-table td {
    padding: 0.5rem 1.25rem;
    color: var(--color-gray-900);
    font-size: 0.9375rem;
    border-left: none !important;
    border-right: none !important;
    border-top: none !important;
}

.networth-snapshots-table td.text-right {
    text-align: right;
    font-weight: 600;
    font-family: "Roboto", sans-serif;
    background: linear-gradient(90deg, transparent 0%, rgba(var(--color-gray-50-rgb), 0.5) 100%);
}

.snapshot-date-cell {
    font-weight: 500;
    white-space: nowrap;
}

.snapshot-date-cell > div {
    display: inline;
}

.snapshot-time {
    font-size: 11px;
    color: var(--color-gray-600);
    margin-left: 6px;
}

.positive-change {
    color: var(--color-semantic-success);
    font-weight: 500;
}

.negative-change {
    color: var(--color-semantic-danger);
    font-weight: 500;
}

.snapshot-actions-cell {
    text-align: center;
    white-space: nowrap;
}

.snapshot-actions-cell .btn-icon {
    padding: 4px 8px;
    margin: 0 2px;
    border: 1px solid var(--color-gray-300);
    background: var(--color-white-1);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
}

.snapshot-actions-cell .btn-icon:hover {
    background: var(--color-gray-100);
}

.snapshot-actions-cell .btn-icon.btn-danger {
    color: var(--color-semantic-danger);
}

.snapshot-actions-cell .btn-icon.btn-danger:hover {
    background: var(--color-semantic-danger);
    color: var(--color-white-1);
}

/* No Snapshots Message */
.no-snapshots-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--color-gray-600);
}

.no-snapshots-message i {
    font-size: 48px;
    color: var(--color-gray-300);
    margin-bottom: 10px;
    display: block;
}

.no-snapshots-message p {
    margin: 10px 0 0 0;
    font-size: 14px;
}

/* Button Styles */
.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.info-color {
    color: var(--color-cyan-1);
}

/* Account History Section (Spreadsheet View) */
.networth-account-history-section {
    background: var(--color-white-1);
    border-radius: 8px;
    padding: 10px 15px 5px 15px; /* Minimal top padding */
    box-shadow: 0 1px 3px rgba(var(--color-ui-overlay-rgb), 0.1);
    margin: 0; /* No margins */
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Critical for flex shrinking */
    overflow: hidden;
}

.networth-account-history-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 0 10px 0; /* Explicit zero top margin */
    padding-bottom: 8px;
    border-bottom: 2px solid var(--color-gray-300);
    flex-shrink: 0; /* Keep header fixed while content scrolls */
}

.networth-account-history-section h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--color-gray-900);
}

/* Account History Table - wrapper handles scrolling */
.networth-account-history-table-container {
    flex: 1;
    min-height: 0; /* Critical for flex shrinking */
    overflow: hidden;
}

/* Inner wrapper for scrolling - height determined by table content */
.networth-account-history-table-wrapper {
    overflow-x: auto; /* Horizontal scrollbar immediately below table */
    overflow-y: auto; /* Vertical scroll if table is taller than container */
    max-height: 100%; /* Don't exceed container */
    -webkit-overflow-scrolling: touch;
}

.networth-account-history-table {
    border-collapse: separate;
    border-spacing: 0;
    font-family: "Roboto", sans-serif;
    font-size: 0.8125rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(var(--color-ui-overlay-rgb), 0.07), 0 2px 4px rgba(var(--color-ui-overlay-rgb), 0.04);
    background: var(--color-white-1);
    border: 1px solid rgba(var(--color-gray-200-rgb), 0.5);
}

.networth-account-history-table thead {
    background-color: var(--color-brand-dark) !important;
    background: linear-gradient(135deg, var(--color-brand-dark) 0%, var(--color-brand-dark) 100%) !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
}

.networth-account-history-table th {
    padding: 0.625rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--color-white-1);
    white-space: nowrap;
    letter-spacing: 0.025em;
    font-size: 0.75rem;
    text-transform: uppercase;
    border: none !important;
    border-bottom: 2px solid rgba(var(--color-white-1-rgb), 0.15);
}

.networth-account-history-table th.sticky-col {
    position: sticky !important;
    background: var(--color-brand-dark) !important;
    z-index: 11 !important;
    box-shadow: 2px 0 0 0 var(--color-brand-dark); /* Cover gaps between sticky columns */
}

.networth-account-history-table th.sticky-col:nth-child(1) {
    left: 0 !important;
}

.networth-account-history-table th.sticky-col:nth-child(2) {
    left: 100px !important;
}

.networth-account-history-table th.sticky-col:nth-child(3) {
    left: 180px !important;
}

.networth-account-history-table th.date-col {
    text-align: right;
    padding-right: 1.25rem;
}

.networth-account-history-table tbody tr {
    border-bottom: 1px solid rgba(var(--color-gray-200-rgb), 0.5);
}

.networth-account-history-table tbody tr:nth-child(even) {
    background-color: var(--ui-table-header-rowEvenBg, var(--color-gray-100));
}

.networth-account-history-table tbody tr:hover {
    background-color: rgba(var(--color-blue-6-rgb), 0.05);
}

.networth-account-history-table td {
    padding: 0.5rem 1rem;
    color: var(--color-gray-900);
    font-size: 0.8125rem;
    border-left: none !important;
    border-right: none !important;
    border-top: none !important;
}

.networth-account-history-table td.sticky-col {
    position: sticky !important;
    background: var(--color-white-1); /* Solid white - no transparency */
    z-index: 5 !important;
    /* Cover any sub-pixel gaps between sticky columns */
    box-shadow: 2px 0 0 0 var(--color-white-1);
}

.networth-account-history-table tbody tr:nth-child(even) td.sticky-col {
    background: var(--ui-table-header-rowEvenBg, var(--color-gray-100)); /* Solid color for sticky overlap */
    box-shadow: 2px 0 0 0 var(--ui-table-header-rowEvenBg, var(--color-gray-100)); /* Match background to cover gaps */
}

.networth-account-history-table tbody tr:hover td.sticky-col {
    background: var(--color-brand-light); /* Solid light blue instead of rgba */
    box-shadow: 2px 0 0 0 var(--color-brand-light); /* Match background to cover gaps */
}

.networth-account-history-table td.sticky-col:nth-child(1) {
    left: 0 !important;
}

.networth-account-history-table td.sticky-col:nth-child(2) {
    left: 100px !important;
}

.networth-account-history-table td.sticky-col:nth-child(3) {
    left: 180px !important;
}

.networth-account-history-table .category-cell {
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    padding: 0.75rem 1rem;
    vertical-align: middle;
    border-right: 2px solid rgba(var(--color-gray-200-rgb), 0.8);
}

.networth-account-history-table .category-investment {
    background: linear-gradient(90deg, rgba(var(--color-blue-6-rgb), 0.1) 0%, transparent 100%);
    color: var(--color-brand-dark);
}

.networth-account-history-table .category-asset {
    background: linear-gradient(90deg, rgba(var(--color-teal-3-rgb), 0.1) 0%, transparent 100%);
    color: var(--color-teal-2);
}

.networth-account-history-table .category-liability {
    background: linear-gradient(90deg, rgba(var(--color-red-2-rgb), 0.1) 0%, transparent 100%);
    color: var(--color-semantic-danger);
}

.networth-account-history-table .category-cash {
    background: linear-gradient(90deg, rgba(var(--color-amber-2-rgb), 0.1) 0%, transparent 100%);
    color: var(--color-amber-1);
}

.networth-account-history-table .category-realestate {
    background: linear-gradient(90deg, rgba(var(--color-blue-5-rgb), 0.1) 0%, transparent 100%);
    color: var(--color-indigo-1);
}

.networth-account-history-table .owner-cell {
    font-weight: 500;
    color: var(--color-gray-600);
    font-size: 0.75rem;
}

.networth-account-history-table .account-cell {
    font-weight: 500;
    min-width: 150px;
    border-right: 1px solid rgba(var(--color-gray-200-rgb), 0.5);
}

.networth-account-history-table .value-cell {
    text-align: right;
    font-family: "Roboto", sans-serif;
    font-weight: 600;
    font-size: 0.8125rem;
    padding-right: 1.25rem;
    white-space: nowrap;
}

.networth-account-history-table .value-cell.empty-cell {
    color: var(--color-gray-600);
    font-weight: 400;
}

.networth-account-history-table .value-cell.value-increase {
    color: var(--color-teal-2);
}

.networth-account-history-table .value-cell.value-decrease {
    color: var(--color-semantic-danger);
}

/* Total Row */
.networth-account-history-table .total-row {
    border-top: 3px solid var(--color-gray-400);
    background: var(--color-gray-100) !important;
}

.networth-account-history-table .total-row .total-label {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--color-gray-900);
    position: sticky !important;
    left: 0 !important;
    background: var(--color-gray-100);
    z-index: 5 !important;
    box-shadow: 2px 0 0 0 var(--color-gray-100);
}

.networth-account-history-table .total-row .total-value {
    font-weight: 700;
    font-size: 0.875rem;
}

/* Tab Navigation */
.networth-tabs-container {
    margin: 0 0 16px 0; /* Reduced bottom margin */
    display: flex;
    gap: clamp(2px, 0.32vw, 5px);
    align-items: center;
    flex-wrap: nowrap;
    border-bottom: 2px solid var(--color-gray-200);
    padding-bottom: 0;
    flex-shrink: 0; /* Don't shrink tab navigation */
}

.networth-tabs {
    display: flex;
    gap: clamp(2px, 0.32vw, 5px);
    align-items: center;
    flex-wrap: nowrap;
}

.networth-tab-button {
    padding: clamp(6px, 0.6vw, 12px) clamp(6px, 0.84vw, 16px);
    font-size: clamp(12px, 0.84vw, 16px);
    font-weight: 500;
    color: var(--color-gray-500);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: clamp(4px, 0.4vw, 8px);
    white-space: nowrap;
    outline: none;
    font-family: inherit;
}

.networth-tab-button i {
    font-size: clamp(12px, 0.84vw, 16px);
}

.networth-tab-button:hover {
    color: var(--color-blue-6);
    background: rgba(var(--color-blue-6-rgb), 0.05);
    border-radius: 6px 6px 0 0;
}

.networth-tab-button.active {
    color: var(--color-blue-6);
    border-bottom-color: var(--color-blue-6);
    font-weight: 600;
}

.networth-tab-button.active:hover {
    background: transparent;
}

/* Tab Content */
.networth-tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
    flex: 1;
    min-height: 0; /* Critical for flex shrinking */
    overflow: hidden;
    padding: 0;
    margin: 0;
}

.networth-tab-content.active {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    margin: 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Design */

/* Adjust header offset for different screen sizes where headers may vary */
@media (max-height: 800px) {
    .networth-tracker-container {
        --nw-header-offset: 145px; /* Slightly less offset for shorter screens */
    }
}

@media (max-height: 600px) {
    .networth-tracker-container {
        --nw-header-offset: 130px; /* Even less for very short screens */
    }
}

@media (max-width: 768px) {
    .networth-tracker-container {
        --nw-header-offset: 140px; /* Mobile screens may have different header heights */
    }

    .networth-summary-bar {
        grid-template-columns: 1fr;
    }

    .networth-tabs-container {
        flex-wrap: wrap;
    }

    .networth-tabs {
        flex-wrap: wrap;
    }

    .networth-tab-button {
        padding: 10px 12px;
        font-size: 14px;
    }

    .networth-graph-controls {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .graph-type-selector {
        flex-wrap: wrap;
    }

    .nw-graph-tab {
        padding: 8px 10px;
        font-size: 11px;
    }

    .networth-snapshots-section .section-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .networth-account-history-section .section-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .networth-account-history-table {
        font-size: 0.75rem;
    }

    .networth-account-history-table th,
    .networth-account-history-table td {
        padding: 0.4rem 0.6rem;
    }
}