/* ---- Theme variables ---- */

:root {
    --bg: #f5f5f5;
    --card-bg: #fff;
    --text: #333;
    --text-secondary: #666;
    --text-label: #555;
    --text-muted: #888;
    --border: #ddd;
    --border-light: #f0f0f0;
    --border-subtle: #eee;
    --input-bg: #fff;

    --primary: #4a90d9;
    --primary-hover: #3a7bc8;
    --primary-disabled: #a0c4e8;

    --error-text: #c53030;
    --error-bg: #fde8e8;
    --error-border: #feb2b2;
    --success-text: #276749;
    --success-bg: #e6ffed;
    --success-border: #9ae6b4;
    --danger: #e74c3c;

    --table-header-bg: #f8f9fa;
    --row-hover: #f8f9fa;
    --amount-negative: #c53030;
    --amount-positive: #276749;

    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-light: rgba(0, 0, 0, 0.08);
    --focus-ring: rgba(74, 144, 217, 0.2);
}

[data-theme="dark"] {
    --bg: #1a1a2e;
    --card-bg: #16213e;
    --text: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-label: #b0b0b0;
    --text-muted: #808080;
    --border: #2a2a4a;
    --border-light: #222244;
    --border-subtle: #252545;
    --input-bg: #1a1a3e;

    --primary: #5a9ae9;
    --primary-hover: #4a8ad9;
    --primary-disabled: #3a5a7a;

    --error-text: #fc8181;
    --error-bg: #3b1a1a;
    --error-border: #5a2a2a;
    --success-text: #68d391;
    --success-bg: #1a3b2a;
    --success-border: #2a5a3a;
    --danger: #e74c3c;

    --table-header-bg: #1e1e3e;
    --row-hover: #1e1e3e;
    --amount-negative: #fc8181;
    --amount-positive: #68d391;

    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-light: rgba(0, 0, 0, 0.2);
    --focus-ring: rgba(90, 154, 233, 0.3);
}

/* ---- Base ---- */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.container {
    width: 100%;
    max-width: 400px;
    padding: 0 16px;
}

.card {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--shadow);
    padding: 32px;
}

.card h1 {
    font-size: 24px;
    margin-bottom: 8px;
    text-align: center;
}

.card p.subtitle {
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 24px;
    font-size: 14px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-label);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    background: var(--input-bg);
    color: var(--text);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

.btn {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary {
    background-color: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-primary:disabled {
    background-color: var(--primary-disabled);
    cursor: not-allowed;
}

.links {
    margin-top: 16px;
    text-align: center;
    font-size: 14px;
}

.links a {
    color: var(--primary);
    text-decoration: none;
}

.links a:hover {
    text-decoration: underline;
}

.message {
    padding: 10px 12px;
    border-radius: 4px;
    margin-bottom: 16px;
    font-size: 14px;
    display: none;
}

.message.error {
    background-color: var(--error-bg);
    color: var(--error-text);
    border: 1px solid var(--error-border);
}

.message.success {
    background-color: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success-border);
}

.message.visible {
    display: block;
}

/* ---- App layout (sidebar + main content) ---- */

body.app-layout {
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
}

.sidebar {
    width: 220px;
    min-height: 100vh;
    background: #2c3e50;
    color: #ecf0f1;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid #3d566e;
}

.sidebar-header h1 {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
}

.sidebar-header .user-name {
    font-size: 13px;
    color: #95a5a6;
    margin-top: 4px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow: hidden;
}

.sidebar-nav a {
    display: block;
    padding: 10px 20px;
    color: #bdc3c7;
    text-decoration: none;
    font-size: 14px;
    transition: background-color 0.15s, color 0.15s;
}

.sidebar-nav a:hover {
    background: #34495e;
    color: #fff;
}

.sidebar-nav a.active {
    background: #34495e;
    color: #fff;
    border-left: 3px solid #4a90d9;
    padding-left: 17px;
}

.sidebar-footer {
    padding: 12px 0;
    border-top: 1px solid #3d566e;
}

.sidebar-footer a {
    display: block;
    padding: 10px 20px;
    color: #e74c3c;
    text-decoration: none;
    font-size: 14px;
    transition: background-color 0.15s;
}

.sidebar-footer a:hover {
    background: #34495e;
}

.main-content {
    flex: 1;
    padding: 32px;
    min-height: 100vh;
    overflow-y: auto;
}

.main-content h2 {
    font-size: 22px;
    margin-bottom: 24px;
}

.main-content .card {
    max-width: 500px;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    margin-top: 32px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-subtle);
}

.section-title:first-of-type {
    margin-top: 0;
}

/* ---- Net worth dashboard ---- */

.net-worth-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.net-worth-value {
    font-size: 32px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-bottom: 24px;
}

.net-worth-value.negative {
    color: var(--amount-negative);
}

.net-worth-chart {
    display: flex;
    height: 32px;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 20px;
}

.bar-segment {
    display: block;
    height: 100%;
    transition: opacity 0.15s;
    min-width: 3px;
}

.bar-segment:hover {
    opacity: 0.8;
}

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

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    padding: 6px 8px;
    border-radius: 4px;
    transition: background-color 0.15s;
}

.legend-item:hover {
    background: var(--row-hover);
}

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

.legend-label {
    flex: 1;
    font-size: 14px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.legend-value {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---- Connected accounts list ---- */

.account-list {
    margin-bottom: 16px;
}

.account-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}

.account-item:last-child {
    border-bottom: none;
}

.account-info {
    flex: 1;
}

.account-info .account-name {
    font-size: 14px;
    font-weight: 500;
}

.account-info .account-detail {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.btn-remove {
    background: none;
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
    flex-shrink: 0;
    margin-left: 12px;
}

.btn-remove:hover {
    background: var(--danger);
    color: #fff;
}

.btn-refresh {
    background: none;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    margin-right: 6px;
    transition: background-color 0.15s, color 0.15s;
}

.btn-refresh:hover {
    background: var(--primary);
    color: #fff;
}

.btn-refresh:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.no-accounts {
    font-size: 14px;
    color: var(--text-muted);
    padding: 8px 0;
}

.subtype-select {
    font-size: 12px;
    padding: 1px 4px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--input-bg);
    color: var(--text);
    cursor: pointer;
}

.subtype-select:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-connect-provider {
    margin-right: 8px;
    margin-bottom: 8px;
    width: auto;
    display: inline-block;
}

/* ---- Sidebar accounts ---- */

.sidebar-section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #7f8c8d;
    padding: 16px 20px 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-section-link {
    color: #7f8c8d;
    text-decoration: none;
    transition: color 0.15s;
}

.sidebar-section-link:hover,
.sidebar-section-link.active {
    color: #fff;
}

.sidebar-sub-link {
    display: block;
    padding: 6px 20px 6px 28px;
    color: #bdc3c7;
    font-size: 13px;
    text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
}
.sidebar-sub-link:hover { color: #fff; background: #34495e; }
.sidebar-sub-link.active {
    background: #34495e;
    color: #fff;
    border-left: 3px solid #4a90d9;
    padding-left: 25px;
}

.sidebar-institution {
    font-size: 11px;
    color: #95a5a6;
    padding: 8px 20px 2px;
}

.sidebar-account {
    display: flex;
    align-items: center;
    padding: 6px 12px 6px 20px;
    font-size: 13px;
    transition: background-color 0.15s, color 0.15s;
}

.sidebar-account:hover {
    background: #34495e;
}

.sidebar-account.active {
    background: #34495e;
    border-left: 3px solid #4a90d9;
    padding-left: 17px;
}

.sidebar-account .account-label {
    overflow: hidden;
    flex: 1;
    min-width: 0;
    color: #bdc3c7;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.account-label-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-label-synced {
    font-size: 10px;
    color: #7f8c8d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-account:hover .account-label,
.sidebar-account.active .account-label {
    color: #fff;
}

.sidebar-account.syncing .account-label {
    opacity: 0.6;
}

.sidebar-account.syncing .btn-sync-account {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.btn-sync-all,
.btn-sync-account {
    background: none;
    border: none;
    color: #95a5a6;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 0 2px 4px;
    line-height: 1;
    flex-shrink: 0;
}

.btn-sync-all:hover,
.btn-sync-account:hover {
    color: #fff;
}

/* ---- CSV import ---- */

.account-header-right {
    text-align: right;
}

.account-header-right .last-synced {
    margin-bottom: 8px;
}

.import-card {
    max-width: none !important;
    margin-bottom: 24px;
}

.import-mappings {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.mapping-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mapping-row label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-label);
}

.mapping-select {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    background: var(--input-bg);
    color: var(--text);
    min-width: 160px;
}

.import-options {
    display: flex;
    gap: 20px;
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}

.import-options label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.import-actions {
    margin-top: 16px;
    display: flex;
    gap: 8px;
}

.btn-cancel {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-cancel:hover {
    background: var(--border-light);
}

/* ---- Transaction table ---- */

.main-content-wide {
    max-width: none;
}

.main-content-wide .card {
    max-width: none;
}

.account-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 24px;
}

.account-header h2 {
    margin-bottom: 0;
}

.account-balance {
    font-size: 20px;
    font-weight: 600;
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}

.last-synced {
    font-size: 13px;
    color: var(--text-muted);
}

.transaction-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px var(--shadow-light);
}

.transaction-table thead {
    background: var(--table-header-bg);
}

.transaction-table th {
    padding: 10px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid var(--border-subtle);
}

.transaction-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.transaction-table th.sortable:hover {
    color: var(--text);
}

.transaction-table th.sortable.active {
    color: var(--primary);
}

.sort-arrow {
    font-size: 10px;
    margin-left: 4px;
}

.transaction-table td {
    padding: 10px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border-light);
}

.transaction-table tbody tr:hover {
    background: var(--row-hover);
}

.transaction-table .amount-col {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.transaction-table th.amount-col {
    text-align: right;
}

.transaction-table .category-col {
    white-space: nowrap;
}

.category-select {
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 4px;
    font-size: 0.85rem;
    cursor: pointer;
    max-width: 180px;
}

.category-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

.transaction-table .action-col {
    width: 32px;
    text-align: center;
    padding: 4px;
}

.btn-delete-txn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0.4;
    transition: opacity 0.15s, color 0.15s;
}

.transaction-table tr:hover .btn-delete-txn {
    opacity: 1;
}

.btn-delete-txn:hover {
    opacity: 1;
    color: var(--amount-negative);
    background: var(--error-bg);
}

.transaction-table .negative {
    color: var(--amount-negative);
}

.transaction-table .positive {
    color: var(--amount-positive);
}

.transaction-table td a {
    color: var(--primary);
    text-decoration: none;
}

.transaction-table td a:hover {
    text-decoration: underline;
}

.transaction-table .txn-date {
    white-space: nowrap;
    color: var(--text-secondary);
}

.transaction-table .loading-msg {
    text-align: center;
    color: var(--text-muted);
    padding: 24px 16px;
}

/* ---- Filter Bar ---- */

.filter-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input[type="date"],
.filter-bar input[type="text"] {
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font-size: 0.85rem;
    color-scheme: light;
}

[data-theme="dark"] .filter-bar select,
[data-theme="dark"] .filter-bar input[type="date"],
[data-theme="dark"] .filter-bar input[type="text"] {
    color-scheme: dark;
}

.filter-toggle {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
}

.btn-clear-filters {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-clear-filters:hover {
    color: var(--text);
    border-color: var(--text-secondary);
}

/* ---- Pagination ---- */

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-page {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 13px;
    cursor: pointer;
    color: var(--primary);
    transition: background-color 0.15s;
}

.btn-page:hover {
    background: var(--border-light);
}

.page-num {
    padding: 0 8px;
}

/* ---- Merge UI ---- */

.merge-badge {
    font-size: 11px;
    color: var(--primary);
    margin-left: 6px;
    cursor: pointer;
}

.merge-badge:hover {
    text-decoration: underline;
}

.child-row {
    background: var(--border-light);
    font-size: 13px;
}

.child-row .child-indent {
    padding-left: 32px;
}

.btn-unmerge {
    background: none;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}

.btn-unmerge:hover {
    background: var(--primary);
    color: #fff;
}

/* ---- History Charts ---- */

.history-charts {
    margin-bottom: 24px;
}

.history-chart {
    width: 100%;
    max-width: 800px;
    height: auto;
    display: block;
    margin-bottom: 16px;
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 1px 4px var(--shadow-light);
    padding: 8px;
}

.chart-title {
    font-size: 13px;
    font-weight: 600;
    fill: var(--text);
}

.chart-grid {
    stroke: var(--border-light);
    stroke-width: 1;
}

.chart-zero {
    stroke: var(--text-muted);
    stroke-width: 1;
    stroke-dasharray: 4 2;
}

.chart-y-label {
    font-size: 10px;
    fill: var(--text-muted);
    text-anchor: end;
}

.chart-x-label {
    font-size: 10px;
    fill: var(--text-secondary);
    text-anchor: middle;
}

.bar-positive {
    fill: var(--amount-positive);
    opacity: 0.8;
}

.bar-negative {
    fill: var(--amount-negative);
    opacity: 0.8;
}

.chart-bar-link:hover .bar-positive,
.chart-bar-link:hover .bar-negative {
    opacity: 1;
}

.projected-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.projected-nav-months {
    display: flex;
    gap: 1rem;
}

.projected-summary {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 600;
}
