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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background: #f5f5f5;
}

header {
    margin-bottom: 30px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    color: #333;
}

/* User info in header */
.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: #666;
}

.btn-logout {
    padding: 6px 12px;
    background: #f0f0f0;
    color: #333;
    border: 1px solid #ddd;
    font-size: 13px;
}

.btn-logout:hover {
    background: #e5e5e5;
}

.btn-icon {
    padding: 6px 10px;
    background: #f0f0f0;
    color: #333;
    border: 1px solid #ddd;
    font-size: 18px;
    line-height: 1;
    border-radius: 4px;
    cursor: pointer;
}

.btn-icon:hover {
    background: #e5e5e5;
}

.btn-icon:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Login overlay */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.login-content {
    background: white;
    padding: 40px 50px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.login-content h2 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 28px;
}

.login-subtitle {
    color: #666;
    margin-bottom: 30px;
    font-size: 14px;
}

#google-signin-btn {
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
}

.login-error {
    color: #cc3333;
    font-size: 14px;
    margin-top: 15px;
    padding: 10px;
    background: #fff0f0;
    border-radius: 4px;
}

#actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#connect-btn {
    background: #0066cc;
    color: white;
}

#connect-btn:hover:not(:disabled) {
    background: #0055aa;
}

#refresh-btn {
    background: #666;
    color: white;
}

#refresh-btn:hover:not(:disabled) {
    background: #555;
}

#back-btn {
    background: #f0f0f0;
    color: #333;
    margin-bottom: 15px;
}

#back-btn:hover {
    background: #e0e0e0;
}

/* Summary Section */
#summary-section {
    margin-bottom: 20px;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.summary-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    text-align: center;
}

.summary-card.assets {
    border-top: 4px solid #228b22;
}

.summary-card.debt {
    border-top: 4px solid #cc3333;
}

.summary-card.net-worth {
    border-top: 4px solid #0066cc;
}

.summary-label {
    display: block;
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

.summary-value {
    display: block;
    font-size: 24px;
    font-weight: 600;
    color: #333;
}

.summary-value.positive {
    color: #228b22;
}

.summary-value.income {
    color: #2196f3;
}

.summary-value.negative {
    color: #cc3333;
}

/* Property styles */
.property-card {
    border-left-color: #228b22 !important;
}

.property-card .account-balance {
    color: #228b22;
}

/* Accounts Section */
#accounts-section, #detail-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

#accounts-section h2, #detail-section h2 {
    margin-bottom: 15px;
    color: #333;
    font-size: 18px;
}

.empty-message {
    color: #666;
    font-style: italic;
}

/* Account Groups */
.account-group {
    margin-bottom: 20px;
}

.account-type {
    font-size: 14px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
}

.category-total {
    font-weight: 600;
    color: #333;
    text-transform: none;
    letter-spacing: normal;
    margin-left: 10px;
}

/* Account Cards */
.account-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    margin-bottom: 8px;
    background: #f9f9f9;
    border-radius: 6px;
    border-left: 4px solid #0066cc;
    cursor: pointer;
    transition: background 0.2s;
}

.account-card:hover {
    background: #f0f0f0;
}

.account-info {
    display: flex;
    flex-direction: column;
}

.account-name {
    font-weight: 500;
    color: #333;
}

.account-institution {
    font-size: 12px;
    color: #888;
}

.account-balance {
    font-weight: 600;
    font-size: 16px;
    color: #333;
}

.account-balance.negative {
    color: #cc3333;
}

/* Detail View */
#detail-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

#detail-title {
    margin-bottom: 0;
}

.detail-summary {
    display: flex;
    gap: 30px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 6px;
    margin-bottom: 20px;
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-item .label {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
}

.detail-item .value {
    font-size: 16px;
    font-weight: 500;
    color: #333;
}

.nickname-value,
.balance-value {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    padding: 4px 8px;
    font-size: 14px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    margin: 0;
}

.icon-btn:hover {
    background: #e5e5e5;
}

/* Tables */
.transactions-table, .holdings-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.transactions-table th, .holdings-table th {
    text-align: left;
    padding: 10px;
    background: #f5f5f5;
    font-weight: 500;
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    border-bottom: 2px solid #ddd;
}

.transactions-table td, .holdings-table td {
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.transactions-table tr:hover, .holdings-table tr:hover {
    background: #fafafa;
}

.transactions-table tr.pending td {
    opacity: 0.6;
    font-style: italic;
}

.amount-col {
    text-align: right;
}

.positive {
    color: #228b22;
}

.negative {
    color: #cc3333;
}

h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: #333;
    font-size: 16px;
}

.load-more {
    display: block;
    width: 100%;
    margin-top: 15px;
    padding: 12px;
    background: #f0f0f0;
    color: #333;
    border: 1px solid #ddd;
    font-size: 14px;
}

.load-more:hover:not(:disabled) {
    background: #e5e5e5;
}

.load-more-container {
    min-height: 52px;
    margin-top: 15px;
}

/* Transaction Tags */
.tag-col {
    text-align: center;
    width: 80px;
}

.txn-tag {
    display: inline-block;
    min-width: 60px;
    padding: 2px 8px;
    font-size: 11px;
    border-radius: 10px;
    cursor: pointer;
    background: #f0f0f0;
    border: 1px dashed #ccc;
    color: #999;
}

.txn-tag:hover {
    background: #e5e5e5;
    border-color: #999;
}

.txn-tag:empty::before {
    content: "+ tag";
}

.txn-tag.tag-transfer {
    background: #e8f4fd;
    border: 1px solid #4a90d9;
    color: #2563eb;
    border-style: solid;
}

.txn-tag.tag-transfer:hover {
    background: #d1e8fc;
}

/* Category dropdown */
.category-col {
    width: 140px;
}

.category-select {
    width: 130px;
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
    border: 1px solid #ddd;
    background: #f9f9f9;
    cursor: pointer;
    transition: background 0.3s, border-color 0.3s;
}

.category-select:hover {
    border-color: #999;
}

.category-select:focus {
    outline: none;
    border-color: #0066cc;
}

.category-select.saved {
    background: #e8f5e9;
    border-color: #4caf50;
}

/* Analytics month selector */
.analytics-header {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;
    gap: 10px;
}

.analytics-month-select {
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    min-width: 150px;
}

.analytics-month-select:hover {
    border-color: #999;
}

.analytics-month-select:focus {
    outline: none;
    border-color: #0066cc;
}

/* Transfer Patterns Section */
#patterns-section {
    margin-top: 20px;
}

#patterns-section details {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

#patterns-section summary {
    padding: 15px 20px;
    cursor: pointer;
    font-weight: 500;
    color: #333;
}

#patterns-section summary:hover {
    background: #f9f9f9;
}

.patterns-content {
    padding: 0 20px 20px;
}

.patterns-help {
    font-size: 13px;
    color: #666;
    margin-bottom: 15px;
}

.patterns-form {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.patterns-form input {
    flex: 1;
    min-width: 150px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.patterns-form select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
}

.patterns-ul {
    list-style: none;
    padding: 0;
}

.patterns-ul li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #f5f5f5;
    border-radius: 4px;
    margin-bottom: 5px;
}

.pattern-text {
    font-family: monospace;
    font-size: 13px;
}

.delete-pattern-btn {
    padding: 2px 8px;
    font-size: 16px;
    background: transparent;
    border: none;
    color: #999;
    cursor: pointer;
    margin: 0;
}

.delete-pattern-btn:hover {
    color: #cc3333;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 25px;
    border-radius: 8px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 10px;
}

.modal-help {
    font-size: 13px;
    color: #666;
    margin-bottom: 20px;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 5px;
    color: #333;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-danger {
    background: #cc3333;
    color: white;
}

.btn-danger:hover {
    background: #aa2222;
}

/* Manual account badge */
.manual-badge {
    display: inline-block;
    padding: 2px 6px;
    font-size: 10px;
    background: #e8f4fd;
    color: #2563eb;
    border-radius: 3px;
    text-transform: uppercase;
    margin-left: 5px;
}

/* CSV Import Section */
.csv-import-section {
    margin-top: 20px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 6px;
    border: 1px dashed #ddd;
}

.csv-import-section h3 {
    margin-top: 0;
    margin-bottom: 10px;
}

.csv-import-form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.csv-import-form select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.csv-import-form input[type="file"] {
    flex: 1;
    min-width: 200px;
}

.csv-help {
    font-size: 12px;
    color: #666;
    margin-top: 10px;
    margin-bottom: 0;
}

.manual-account-actions {
    margin-top: 20px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.manual-account-actions .csv-help {
    margin: 0;
}

#add-manual-btn {
    background: #228b22;
    color: white;
}

#add-manual-btn:hover {
    background: #1a6b1a;
}

/* Automation status */
#automation-section {
    margin-top: 20px;
}

#automation-section details {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

#automation-section summary {
    padding: 15px 20px;
    cursor: pointer;
    font-weight: 500;
    color: #333;
}

#automation-section summary:hover {
    background: #f9f9f9;
    border-radius: 8px 8px 0 0;
}

#automation-status-content {
    padding: 0 20px 15px;
}

.automation-runs {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 0;
}

.automation-run {
    display: grid;
    grid-template-columns: 20px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    background: #f8f8f8;
}

.automation-run.status-ok {
    border-left: 3px solid #228b22;
}

.automation-run.status-error {
    border-left: 3px solid #dc3545;
}

.run-status {
    font-weight: bold;
    font-size: 14px;
}

.status-ok .run-status { color: #228b22; }
.status-error .run-status { color: #dc3545; }

.run-name {
    font-weight: 500;
}

.run-date {
    color: #666;
    font-size: 0.85em;
}

.run-error, .run-resolution {
    grid-column: 2 / -1;
    font-size: 0.85em;
}

.run-error {
    color: #dc3545;
}

.run-resolution {
    color: #555;
    font-style: italic;
}

/* Analytics Section */
.analytics-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.chart-column {
    min-width: 0;
}

.chart-container {
    position: relative;
    height: 280px;
}

@media (max-width: 900px) {
    .analytics-grid {
        grid-template-columns: 1fr;
    }
}

/* Analytics Modal */
.modal-large {
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    line-height: 1;
}

.close-btn:hover {
    color: #333;
}

#modal-chart-container {
    height: 250px;
    margin-bottom: 20px;
}

#modal-transactions {
    max-height: 300px;
    overflow-y: auto;
}

#modal-transactions h4 {
    margin: 15px 0 10px;
    font-size: 14px;
    color: #666;
}

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

.modal-transactions-table th {
    text-align: left;
    padding: 8px;
    background: #f5f5f5;
    font-weight: 500;
    font-size: 11px;
    color: #666;
    text-transform: uppercase;
    border-bottom: 2px solid #ddd;
}

.modal-transactions-table td {
    padding: 8px;
    border-bottom: 1px solid #eee;
}

.modal-transactions-table tr:hover {
    background: #fafafa;
}

/* Category breakdown in modal */
.category-breakdown {
    margin-bottom: 20px;
}

.category-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #f9f9f9;
    border-radius: 4px;
    margin-bottom: 5px;
    cursor: pointer;
    transition: background 0.2s;
}

.category-item:hover {
    background: #f0f0f0;
}

.category-name {
    font-weight: 500;
}

.category-amount {
    font-weight: 600;
    color: #cc3333;
}

/* Chart Summary */
.chart-summary {
    display: flex;
    justify-content: center;
    gap: 15px;
    padding: 8px 0;
    font-size: 12px;
    flex-wrap: wrap;
}

.chart-summary .summary-item {
    text-align: center;
}

.chart-summary .summary-label {
    font-size: 10px;
    color: #666;
    text-transform: uppercase;
    display: block;
}

.chart-summary .summary-value {
    font-weight: 600;
    font-size: 14px;
}

.chart-summary .positive { color: #228b22; }
.chart-summary .negative { color: #cc3333; }

/* Table scroll wrapper for mobile */
.table-scroll-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Add Account Section */
#add-account-section {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    justify-content: center;
}

#add-account-section button {
    min-height: 44px;
}

/* Mobile Breakpoints */

/* Tablet - 768px */
@media (max-width: 768px) {
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .summary-card.net-worth {
        grid-column: 1 / -1;
    }

    .detail-summary {
        flex-wrap: wrap;
        gap: 15px;
    }

    .analytics-grid {
        grid-template-columns: 1fr;
    }
}

/* Mobile - 600px */
@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .user-info {
        width: 100%;
        justify-content: space-between;
    }

    .summary-cards {
        grid-template-columns: 1fr;
    }

    .summary-card.net-worth {
        grid-column: auto;
    }

    #add-account-section {
        flex-direction: column;
    }

    #add-account-section button {
        width: 100%;
        min-height: 48px;
    }

    .detail-summary {
        flex-direction: column;
        gap: 12px;
    }

    .detail-item {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .transactions-table, .holdings-table {
        font-size: 13px;
    }

    .transactions-table th, .holdings-table th,
    .transactions-table td, .holdings-table td {
        padding: 8px 6px;
    }

    .patterns-form {
        flex-direction: column;
    }

    .patterns-form input,
    .patterns-form select,
    .patterns-form button {
        width: 100%;
    }

    .csv-import-form {
        flex-direction: column;
    }

    .csv-import-form select,
    .csv-import-form input,
    .csv-import-form button {
        width: 100%;
    }

    .manual-account-actions {
        flex-direction: column;
        gap: 10px;
    }

    .modal-content {
        width: 95%;
        padding: 20px 15px;
    }

    /* Close button touch target */
    .close-btn {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Icon button touch targets */
    .icon-btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Small Mobile - 480px */
@media (max-width: 480px) {
    header h1 {
        font-size: 22px;
    }

    .summary-card {
        padding: 15px;
    }

    .summary-value {
        font-size: 20px;
    }

    .chart-container {
        height: 240px;
    }

    #accounts-section, #detail-section {
        padding: 15px;
    }

    .account-card {
        padding: 10px 12px;
    }
}

/* Navigation Bar */
.main-nav {
    display: flex;
    gap: 24px;
    padding: 12px 0;
    border-bottom: 1px solid #ddd;
    margin-bottom: 20px;
}

.nav-link {
    text-decoration: none;
    color: #666;
    font-weight: 500;
    padding: 8px 0;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.nav-link:hover {
    color: #333;
}

.nav-link.active {
    color: #0066cc;
    border-bottom-color: #0066cc;
}

/* Page sections */
.page-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Transactions Page */
.transactions-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.transactions-page-header h2 {
    margin: 0;
}

.txn-page-count {
    font-size: 13px;
    color: #666;
    margin-bottom: 10px;
    min-height: 20px;
}

#transactions-table-container {
    min-height: 400px;
}

#txn-page-body {
    min-height: 300px;
}

.txn-page-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}

/* Fixed column widths to prevent shifting */
.txn-page-table th:nth-child(1),
.txn-page-table td:nth-child(1) { width: 240px; } /* Date */
.txn-page-table th:nth-child(2),
.txn-page-table td:nth-child(2) { width: 140px; } /* Account */
.txn-page-table th:nth-child(4),
.txn-page-table td:nth-child(4) { width: 140px; } /* Amount */
.txn-page-table th:nth-child(5),
.txn-page-table td:nth-child(5) { width: 150px; } /* Category */

.txn-page-table th {
    text-align: left;
    padding: 10px 8px;
    background: #f5f5f5;
    font-weight: 500;
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    border-bottom: 2px solid #ddd;
}

.txn-page-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.txn-page-table th.sortable:hover {
    background: #e8e8e8;
}

.txn-page-table th.sorted {
    background: #e0e8f0;
    color: #0066cc;
}

.txn-page-table td {
    padding: 10px 8px;
    border-bottom: 1px solid #eee;
}

.txn-page-table tr:hover {
    background: #fafafa;
}

.txn-page-table tr.empty-row:hover {
    background: none;
}

.txn-page-table .empty-cell {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-style: italic;
}

/* Filter row */
.filter-row th {
    background: #fafafa;
    padding: 8px;
    border-bottom: 1px solid #ddd;
}

.filter-row input,
.filter-row select {
    width: 100%;
    padding: 6px 8px;
    font-size: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

.filter-row input[type="date"] {
    width: calc(50% - 2px);
}

.filter-row input[type="number"] {
    width: calc(50% - 2px);
}

.filter-row input:focus,
.filter-row select:focus {
    outline: none;
    border-color: #0066cc;
}

/* Transaction cells */
.account-cell {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.desc-cell {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Chat page */
.chat-page {
    padding: 0 !important;
    height: calc(100vh - 140px);
    overflow: hidden;
}

.chat-layout {
    display: flex;
    height: 100%;
    width: 100%;
    position: relative;
}

.chat-sidebar {
    width: 250px;
    border-right: 1px solid #eee;
    padding: 16px;
    overflow-y: auto;
    background: white;
    flex-shrink: 0;
}

.chat-sidebar .btn-primary {
    width: 100%;
    padding: 12px;
    background: #0066cc;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 16px;
}

.chat-sidebar .btn-primary:hover {
    background: #0055aa;
}

#chat-sessions-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-session-item {
    padding: 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-session-item:hover {
    background: #f5f5f5;
}

.chat-session-item.active {
    background: #e8f4fd;
    color: #0066cc;
}

.chat-session-item .session-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-session-item .delete-session-btn {
    opacity: 0;
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 16px;
    margin: 0;
    line-height: 1;
}

.chat-session-item:hover .delete-session-btn {
    opacity: 1;
}

.chat-session-item .delete-session-btn:hover {
    color: #cc3333;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #f5f5f5;
}

.chat-header-mobile {
    display: none;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid #eee;
    align-items: center;
    gap: 12px;
}

.hamburger-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    color: #333;
}

#chat-session-title {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
}

.chat-message {
    max-width: 85%;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
    margin-left: auto;
    background: #0066cc;
    color: white;
    border-radius: 16px 16px 4px 16px;
    padding: 12px 16px;
}

.chat-message.assistant {
    background: white;
    border-radius: 16px 16px 16px 4px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.chat-message.assistant .message-content {
    word-wrap: break-word;
    line-height: 1.6;
}

/* Markdown styling in chat */
.message-content .md-h1 {
    font-size: 1.4em;
    font-weight: 600;
    margin: 16px 0 8px 0;
    color: #222;
}

.message-content .md-h2 {
    font-size: 1.2em;
    font-weight: 600;
    margin: 14px 0 6px 0;
    color: #333;
}

.message-content .md-h3 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 12px 0 4px 0;
    color: #444;
}

.message-content .md-list {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content .md-list li {
    margin: 4px 0;
}

.message-content .md-code-block {
    background: #f5f5f5;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 13px;
    margin: 8px 0;
}

.message-content .md-inline-code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

.message-content .md-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
}

.message-content .md-table th {
    text-align: left;
    padding: 10px 12px;
    background: #f5f5f5;
    border-bottom: 2px solid #ddd;
    font-weight: 600;
    color: #333;
}

.message-content .md-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #eee;
    color: #444;
}

.message-content .md-table tbody tr:nth-child(even) {
    background: #fafafa;
}

.message-content .md-table tbody tr:hover {
    background: #f0f7ff;
}

/* Tool blocks in chat */
.tool-block {
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: 8px;
    margin: 12px 0;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 13px;
    overflow: hidden;
}

.tool-header {
    padding: 8px 12px;
    background: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #aaa;
}

.tool-header .tool-name {
    font-weight: 500;
    color: #9cdcfe;
}

.tool-header .tool-toggle {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 6px;
}

.tool-header .tool-toggle:hover {
    color: white;
}

.tool-content {
    padding: 12px;
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
}

.tool-content.collapsed {
    display: none;
}

.tool-content pre {
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.tool-content .sql-query {
    color: #ce9178;
}

.tool-content .python-code {
    color: #dcdcaa;
}

/* Tool result styling */
.tool-result {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #444;
}

.tool-result-label {
    font-size: 11px;
    color: #6a9955;
    margin-bottom: 4px;
}

.tool-result-content {
    color: #b5cea8;
}

.tool-result-error {
    color: #f48771;
}

/* SQL result table */
.sql-result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 8px;
}

.sql-result-table th {
    text-align: left;
    padding: 6px 8px;
    background: #2d2d2d;
    color: #9cdcfe;
    border-bottom: 1px solid #444;
}

.sql-result-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #333;
    color: #d4d4d4;
}

.sql-result-table tbody tr:nth-child(even) {
    background: #252525;
}

.sql-result-table tbody tr:nth-child(odd) {
    background: #1e1e1e;
}

.sql-result-table tr:hover {
    background: #2d3748 !important;
}

/* Chart image in chat */
.chat-chart-image {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 8px;
}

/* Chat input area */
.chat-input-area {
    border-top: 1px solid #eee;
    padding: 16px;
    display: flex;
    gap: 12px;
    background: white;
}

#chat-input {
    flex: 1;
    resize: none;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    max-height: 150px;
    overflow-y: auto;
}

#chat-input:focus {
    outline: none;
    border-color: #0066cc;
}

#chat-send-btn {
    padding: 12px 24px;
    background: #0066cc;
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

#chat-send-btn:hover:not(:disabled) {
    background: #0055aa;
}

#chat-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Chat loading indicator */
.chat-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #666;
    font-size: 14px;
    padding: 12px 16px;
}

.chat-loading .dots {
    display: flex;
    gap: 4px;
}

.chat-loading .dot {
    width: 8px;
    height: 8px;
    background: #0066cc;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.chat-loading .dot:nth-child(1) { animation-delay: -0.32s; }
.chat-loading .dot:nth-child(2) { animation-delay: -0.16s; }
.chat-loading .dot:nth-child(3) { animation-delay: 0; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Mobile sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.sidebar-overlay.open {
    display: block;
}

/* Empty chat state */
.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #666;
    text-align: center;
    padding: 40px;
    margin: auto;
}

.chat-empty-state h3 {
    margin: 0 0 8px 0;
    color: #333;
    font-size: 18px;
}

.chat-empty-state p {
    margin: 0;
    font-size: 14px;
}

/* Mobile chat styles */
@media (max-width: 768px) {
    .chat-page {
        height: calc(100vh - 120px);
    }

    .chat-sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        width: 280px;
    }

    .chat-sidebar.open {
        left: 0;
    }

    .chat-header-mobile {
        display: flex;
    }

    .chat-message {
        max-width: 90%;
    }

    #chat-input {
        padding: 10px 14px;
    }

    #chat-send-btn {
        padding: 10px 18px;
    }
}

@media (max-width: 480px) {
    .chat-input-area {
        padding: 12px;
        gap: 8px;
    }

    #chat-messages {
        padding: 12px;
    }

    .chat-message.assistant {
        padding: 12px;
    }

    .tool-content {
        font-size: 11px;
    }
}

.loading-message {
    color: #666;
    font-style: italic;
    padding: 20px;
}

/* Multi-select dropdown */
.multi-select-container {
    position: relative;
    width: 100%;
}

.multi-select-btn {
    width: 100%;
    padding: 6px 8px;
    font-size: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.multi-select-btn:hover {
    border-color: #999;
}

.multi-select-btn:focus {
    outline: none;
    border-color: #0066cc;
}

.multi-select-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
    max-height: 250px;
    overflow-y: auto;
    margin-top: 2px;
}

.multi-select-dropdown.open {
    display: block;
}

.multi-select-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}

.multi-select-option:hover {
    background: #f5f5f5;
}

.multi-select-option input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

/* Mobile nav */
@media (max-width: 768px) {
    .main-nav {
        justify-content: center;
        gap: 16px;
    }
}

@media (max-width: 600px) {
    .main-nav {
        gap: 12px;
        padding: 10px 0;
    }

    .nav-link {
        font-size: 14px;
    }

    .transactions-page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .txn-page-table {
        font-size: 12px;
    }

    .txn-page-table th,
    .txn-page-table td {
        padding: 8px 4px;
    }

    .filter-row input,
    .filter-row select {
        font-size: 11px;
        padding: 4px 6px;
    }

    .account-cell {
        max-width: 80px;
    }

    .desc-cell {
        max-width: 120px;
    }

    .category-col {
        width: 110px;
    }

    .category-select {
        width: 100px;
        font-size: 11px;
    }

    /* Adjust fixed column widths for mobile */
    .txn-page-table th:nth-child(1),
    .txn-page-table td:nth-child(1) { width: 160px; }
    .txn-page-table th:nth-child(2),
    .txn-page-table td:nth-child(2) { width: 80px; }
    .txn-page-table th:nth-child(4),
    .txn-page-table td:nth-child(4) { width: 100px; }
    .txn-page-table th:nth-child(5),
    .txn-page-table td:nth-child(5) { width: 110px; }

    #transactions-table-container {
        min-height: 300px;
    }
}
