/* CSS Custom Properties for Theming */
:root {
    /* Light theme colors */
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fa;
    --bg-accent: #e9ecef;
    --text-primary: #333333;
    --text-secondary: #6c757d;
    --text-muted: #9ca3af;
    --border-color: #e9ecef;
    --border-light: #f1f3f4;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-hover: rgba(0, 0, 0, 0.15);
    
    /* Brand colors (consistent across themes) */
    --primary: #0ea5e9;
    --primary-hover: #0284c7;
    --success: #22c55e;
    --success-hover: #16a34a;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #f59e0b;
    --info: #3b82f6;
}

/* Dark theme colors */
[data-theme="dark"] {
    --bg-primary: #0f172a;    /* slate-900 - dark blue background */
    --bg-secondary: #1e293b;  /* slate-800 - slightly lighter blue */
    --bg-tertiary: #334155;   /* slate-700 - medium blue */
    --bg-accent: #475569;     /* slate-600 - accent blue */
    --text-primary: #ffffff;
    --text-secondary: #cbd5e1; /* slate-300 - light blue text */
    --text-muted: #94a3b8;     /* slate-400 - muted blue text */
    --border-color: #475569;   /* slate-600 - blue borders */
    --border-light: #334155;   /* slate-700 - light blue borders */
    --shadow: rgba(0, 0, 0, 0.4);
    --shadow-hover: rgba(0, 0, 0, 0.6);
}


/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    margin-bottom: 0.5rem;
    font-weight: 600;
    line-height: 1.2;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.5rem; }

p {
    margin-bottom: 1rem;
}

/* Layout */
.header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
    color: white;
    padding: 0.75rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.header.scrolled {
    padding: 0.5rem 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

/* Mobile optimizations for sticky header */
@media (max-width: 768px) {
    .header {
        padding: 0.5rem 0;
    }
    
    /* Ensure touch targets are at least 44px */
    .btn, 
    .dropdown-selected,
    .theme-toggle-label,
    button {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Improve tap area for theme toggle */
    .theme-toggle-label {
        padding: 0.75rem;
    }
    
    /* Better mobile typography */
    .app-title {
        font-size: 1.25rem;
    }
    
    /* Improve mobile layout spacing */
    .container {
        padding: 0 1rem;
    }
    
    /* Stack header navigation on mobile */
    .header-nav {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }
    
    .portfolio-selector {
        width: 100%;
    }
    
    /* Better mobile form elements */
    input, select, textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.75rem;
    }
    
    .header.scrolled {
        padding: 0.375rem 0;
    }
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.app-title {
    text-align: center;
    font-size: 1.8rem;
    margin: 0;
}

.app-title-link {
    text-decoration: none;
    color: inherit;
    transition: opacity 0.2s ease;
}

.app-title-link:hover {
    opacity: 0.8;
    text-decoration: none;
}

.header-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: nowrap;
}

.portfolio-selector {
    position: relative;
    width: auto;
    min-width: 200px;
    flex: 0 0 auto;
}

/* Custom Dropdown */
.custom-dropdown {
    position: relative;
    width: 250px;
    cursor: pointer;
    user-select: none;
}

.dropdown-selected {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 500;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    min-height: 48px;
}

.dropdown-selected:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.custom-dropdown:focus .dropdown-selected {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.dropdown-arrow {
    display: flex;
    align-items: center;
    transition: transform 0.2s ease;
    color: var(--text-secondary);
}

.custom-dropdown[aria-expanded="true"] .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    z-index: 1000;
    max-height: 240px;
    overflow-y: auto;
}

.custom-dropdown[aria-expanded="true"] .dropdown-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-option {
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.15s ease;
    border-radius: 8px;
    margin: 4px;
}

.dropdown-option:hover,
.dropdown-option:focus {
    background: var(--bg-accent);
    outline: none;
}

.dropdown-option.selected {
    background: var(--primary);
    color: white;
}

.dropdown-option.selected:hover {
    background: var(--primary-hover);
}

/* Accessibility improvements */
.custom-dropdown:focus {
    outline: none;
}

.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

.sidebar {
    display: none;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    min-height: 44px;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

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

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

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
    min-height: 44px;
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

/* Specific styling for new portfolio form */
.new-portfolio-form input[type="text"],
#newPortfolioName {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border: 2px solid var(--border-color) !important;
}

.form-group input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Portfolio Sections */
.portfolio-section,
.new-portfolio-section,
.api-setup-section,
.welcome-section {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px var(--shadow);
    color: var(--text-primary);
}

/* Privacy Notice */
.privacy-notice {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: linear-gradient(135deg, #e8f5e8 0%, #f0f9ff 100%);
    border: 1px solid #d1fae5;
    border-radius: 8px;
    padding: 1rem;
    margin: 1.5rem 0 2rem 0;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.1);
}

.privacy-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.privacy-content {
    font-size: 0.9rem;
    line-height: 1.4;
    color: #065f46;
}

.privacy-content strong {
    color: #047857;
    font-weight: 600;
}

/* Disclaimer Notice */
.disclaimer-notice {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: linear-gradient(135deg, #fef3c7 0%, #fef7cd 100%);
    border: 1px solid #fde68a;
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0 2rem 0;
    box-shadow: 0 2px 4px rgba(217, 119, 6, 0.1);
}

.disclaimer-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.disclaimer-content {
    font-size: 0.9rem;
    line-height: 1.4;
    color: #92400e;
}

.disclaimer-content strong {
    color: #b45309;
    font-weight: 600;
}

/* Portfolio Management Content Spacing */
.portfolio-management-content {
    margin-top: 0;
}

.portfolio-management-content .section-header {
    margin-bottom: 2rem;
}

/* Two Column Portfolio Workspace */
.portfolio-workspace {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.portfolio-inputs-column {
    flex: 2;
    min-width: 0; /* Allow column to shrink */
}

.portfolio-recommendations-column {
    flex: 1;
    min-width: 300px;
    position: sticky;
    top: 2rem; /* Stick to top when scrolling */
}

/* Rebalancing Section Styling */
.portfolio-recommendations-column .rebalancing-section {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.portfolio-recommendations-column .rebalancing-section h3 {
    color: #374151;
    margin-bottom: 1rem;
    font-size: 1.25rem;
    border-bottom: 2px solid #3498db;
    padding-bottom: 0.5rem;
}

/* Compact Rebalancing Interface */
.rebalance-section-compact {
    text-align: center;
}

.sidebar-intro {
    font-size: 0.9rem;
    color: #6b7280;
    margin-bottom: 1rem;
}

.cash-input-compact {
    margin-bottom: 1rem;
}

.compact-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.5rem;
}

.compact-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.current-amount {
    display: block;
    font-size: 0.8rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
}

.btn-compact {
    width: 100%;
    padding: 0.75rem;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

/* Compact Results */
.results-compact {
    margin-top: 1rem;
}

.compact-summary {
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 1rem;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.summary-item:last-child {
    margin-bottom: 0;
}

.summary-item .label {
    font-size: 0.85rem;
    color: #6b7280;
}

.summary-item .value {
    font-size: 0.9rem;
    font-weight: 600;
    color: #374151;
}

/* Cash Change Compact */
.cash-change-compact {
    background: #dbeafe;
    border: 1px solid #93c5fd;
    border-radius: 6px;
    padding: 0.5rem;
    margin-bottom: 1rem;
    text-align: center;
}

.change-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #1d4ed8;
}

.new-amount {
    font-size: 0.8rem;
    color: #374151;
}

/* Recommendations List */
.recommendations-list {
    margin-top: 1rem;
}

/* Phase Headers for Order of Operations */
.phase-header {
    margin: 1.5rem 0 1rem 0;
    padding: 0.75rem;
    background: var(--bg-accent);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    border-left: 4px solid var(--primary);
}

.phase-header:first-child {
    margin-top: 0;
}

.phase-header h4 {
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
}

.phase-description {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.4;
}

/* Portfolio Preview Styles */
.portfolio-preview {
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 1px 3px var(--shadow);
}

.portfolio-preview h4 {
    margin: 0 0 1rem 0;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
}

.preview-table {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.preview-header {
    display: grid;
    grid-template-columns: 2fr 1fr 1.5fr 0.8fr;
    gap: 1rem;
    padding: 0.5rem 0.25rem;
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
    align-items: center;
}

.preview-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1.5fr 0.8fr;
    gap: 1rem;
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.875rem;
    align-items: center;
}

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

.preview-ticker {
    font-weight: 600;
    color: var(--text-primary);
}

.preview-shares {
    text-align: right;
    color: var(--text-secondary);
}

.preview-value {
    text-align: right;
    font-weight: 500;
    color: var(--text-primary);
}

.preview-percent {
    text-align: right;
    font-weight: 500;
    color: var(--primary);
}

.preview-total {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 2px solid var(--border-color);
    text-align: right;
    color: var(--text-primary);
    font-size: 0.95rem;
}

/* Responsive adjustments for preview table */
@media (max-width: 768px) {
    .preview-header,
    .preview-row {
        grid-template-columns: 1.5fr 0.8fr 1.2fr 0.8fr;
        gap: 0.5rem;
        font-size: 0.8rem;
    }
}

.rec-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.rec-item.buy {
    border-left: 3px solid #10b981;
}

.rec-item.sell {
    border-left: 3px solid #ef4444;
}

.rec-item.cash {
    border-left: 3px solid #f59e0b;
}

.rec-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.rec-icon {
    font-size: 1rem;
}

.rec-ticker {
    font-weight: 600;
    font-size: 0.9rem;
    color: #374151;
    flex-grow: 1;
    text-align: left;
    margin-left: 0.5rem;
}

.rec-amount {
    font-size: 0.85rem;
    font-weight: 600;
    color: #059669;
}

.rec-action {
    font-size: 0.8rem;
    color: #6b7280;
    text-align: left;
}

.rec-allocation {
    font-size: 0.75rem;
    color: #9ca3af;
    text-align: left;
    margin-top: 0.25rem;
}

/* ===== NEW MODERN PORTFOLIO DASHBOARD ===== */

/* Override section styles for new dashboard */
.portfolio-section {
    background: transparent !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    max-width: none !important;
}

/* Portfolio Dashboard Container */
.portfolio-dashboard {
    max-width: 1300px;
    margin: 0 auto;
    padding: 1rem 1rem 2rem;
}

/* Dashboard Header */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
}

.portfolio-title h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.portfolio-meta {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-icon {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    gap: 0.5rem;
}

/* Hide text labels by default, show only icons */
.btn-icon-text {
    display: none;
}

.btn-icon:hover {
    background: var(--bg-accent);
    transform: translateY(-1px);
    color: var(--text-primary);
}

.btn-danger-icon {
    color: var(--danger);
    border-color: var(--danger);
}

.btn-danger-icon:hover {
    background: var(--bg-accent);
    border-color: var(--danger-hover);
    color: var(--danger-hover);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.stat-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.stat-icon {
    font-size: 1.5rem;
    opacity: 0.7;
}

.stat-content {
    flex: 1;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 0.125rem;
}

/* Primary Action Card */
.primary-action-card {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    border-radius: 16px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.3);
}

.action-header h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.action-subtitle {
    opacity: 0.9;
    font-size: 1rem;
    margin-bottom: 1.5rem;
}

/* Modern Form */
.modern-form .form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
    align-items: end;
}

.modern-form .form-grid .form-field:last-child {
    grid-column: 1 / -1;
    margin-top: 1rem;
}

.form-field {
    display: flex;
    flex-direction: column;
}

.form-field label {
    font-size: 0.875rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 0.5rem;
}

.form-field input,
.form-field select {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0.75rem;
    color: white;
    font-size: 1rem;
    backdrop-filter: blur(10px);
}

.form-field input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.form-field input:focus,
.form-field select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

.btn-large {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.btn-large:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

/* Holdings Section */
.holdings-section {
    margin-bottom: 2rem;
}

/* Allocation total indicator */
.allocation-total-indicator {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 6px;
    border: 1px solid var(--border-light);
    margin-right: 0.75rem;
    font-size: 0.875rem;
}

.allocation-total-indicator .total-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.allocation-total-indicator .total-value {
    font-weight: 600;
    color: var(--text-primary);
    min-width: 45px;
}

.allocation-total-indicator.over-100 .total-value {
    color: var(--danger);
}

.allocation-total-indicator.complete .total-value {
    color: var(--success);
}

/* Preset templates dropdown */
.preset-templates-dropdown {
    position: relative;
    display: inline-block;
}

.preset-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    min-width: 450px;
    max-width: 500px;
    z-index: 1000;
    margin-top: 8px;
    overflow: hidden;
}

/* Prevent any ::after pseudo-elements from appearing on dropdown and its children */
.preset-dropdown-menu::after,
.preset-dropdown-menu *::after,
#presetDropdownMenu::after,
#presetDropdownMenu *::after {
    display: none !important;
    content: none !important;
}

/* Also prevent ::before elements just in case */
.preset-dropdown-menu::before,
.preset-dropdown-menu *::before,
#presetDropdownMenu::before,
#presetDropdownMenu *::before {
    display: none !important;
    content: none !important;
}

.preset-menu-content {
    max-height: 60vh;
    overflow-y: auto;
}

.preset-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    position: sticky;
    top: 0;
    z-index: 1;
}

.close-btn {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

/* Mobile-friendly close button in template dropdown */
@media (max-width: 768px) {
    /* Make mobile header larger and more touch-friendly */
    .preset-dropdown-menu .preset-menu-header {
        padding: 20px;
        min-height: 80px;
        background: var(--bg-secondary);
        font-size: 1.25rem;
        position: relative;
        flex-shrink: 0;
    }

    .preset-dropdown-menu .close-btn {
        position: absolute;
        top: 50%;
        right: 20px;
        transform: translateY(-50%);
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        padding: 0;
        border-radius: 8px;
        background: var(--bg-accent);
        border: 1px solid var(--border-color);
        z-index: 10;
    }

    .preset-dropdown-menu .close-btn:hover {
        background: var(--bg-tertiary);
        border-color: var(--text-secondary);
    }
}

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

.template-categories {
    padding: 12px 0;
}

.template-category {
    margin-bottom: 16px;
}

.template-category:last-child {
    margin-bottom: 8px;
}

.template-category h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 8px 0;
    padding: 0 20px;
}

.preset-template-option {
    display: block;
    width: 100%;
    padding: 12px 20px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-radius: 0;
}

.preset-template-option:hover {
    background: var(--bg-tertiary);
}

.preset-template-option:active {
    background: var(--hover);
}

.template-name {
    display: block;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 3px;
    font-size: 0.9rem;
}

.template-desc {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

/* Mobile-native dropdown styling */
@media (max-width: 768px) {
    .preset-dropdown-menu {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        max-width: none;
        min-width: auto;
        margin: 0;
        border-radius: 0;
        z-index: 9999;
        background: var(--bg-primary);
        border: none;
        box-shadow: none;
        overflow-y: auto;
        padding: 20px;
        display: flex;
        flex-direction: column;
    }

    /* Remove padding from main dropdown on mobile and let header handle spacing */
    .preset-dropdown-menu {
        padding: 0;
    }


    /* Make menu content take remaining space */
    .preset-dropdown-menu .preset-menu-content {
        flex: 1;
        max-height: none;
        height: 100%;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        padding: 20px;
    }

    /* Make template options more touch-friendly */
    .preset-dropdown-menu .preset-template-option {
        padding: 20px;
        margin: 8px 0;
        border-radius: 12px;
        min-height: 80px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .preset-dropdown-menu .template-name {
        font-size: 1.1rem;
        font-weight: 600;
        margin-bottom: 4px;
    }

    .preset-dropdown-menu .template-description {
        font-size: 0.9rem;
        line-height: 1.4;
    }

    /* Ensure dropdown doesn't get cut off by container boundaries */
    .preset-templates-dropdown {
        position: relative;
        overflow: visible;
    }
}

/* Template confirmation modal styles */
.template-confirm-modal {
    max-width: 500px;
    width: 90%;
}

.template-modal-message {
    margin-bottom: 20px;
    color: var(--text-primary);
    line-height: 1.5;
}

.template-holdings-list {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.template-holdings-list h4 {
    margin: 0 0 12px 0;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
}

.template-holding-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

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

.holding-ticker {
    font-weight: 600;
    color: var(--text-primary);
    min-width: 60px;
}

.holding-description {
    flex: 1;
    margin: 0 12px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.holding-allocation {
    font-weight: 500;
    color: var(--primary);
    min-width: 40px;
    text-align: right;
}

/* Template replace modal styles */
.template-replace-modal {
    max-width: 450px;
    width: 90%;
}

.replace-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 20px 0;
}

.option-card {
    position: relative;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    transition: all 0.2s ease;
    cursor: pointer;
}

.option-card:hover {
    border-color: var(--primary);
    background: var(--hover);
}

.option-card.selected {
    border-color: var(--primary);
    background: rgba(var(--primary-rgb), 0.1);
    box-shadow: 0 0 0 1px var(--primary);
}

.option-radio {
    display: none !important;
}

.option-label {
    display: block;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.option-label h4 {
    margin: 0 0 8px 0;
    color: var(--text-primary);
    font-size: 1rem;
    position: relative;
}

.option-label p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.3;
}


/* Modal footer base styles */
.modal-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: 0 0 12px 12px;
    gap: 12px;
}

/* Primary action should be on the right (standard UX practice) */
.modal-footer .btn {
    min-width: 100px;
    order: 1;
}

.modal-footer .btn-primary {
    order: 3; /* Rightmost position for primary action */
}

.modal-footer .btn-secondary {
    order: 0; /* Leftmost position for cancel */
}

.modal-footer .btn-outline {
    order: 2; /* Middle position for secondary actions */
}

/* Enhanced button styling for better hierarchy */
.modal-footer .btn {
    font-weight: 500;
    transition: all 0.2s ease;
    border-radius: 6px;
    font-size: 0.9rem;
    padding: 10px 20px;
}

.modal-footer .btn:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.modal-footer .btn-primary {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.modal-footer .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Template modal specific adjustments */
.template-replace-modal .modal-footer {
    justify-content: space-between;
}

.template-replace-modal .modal-footer .btn-secondary {
    order: 0;
}

.template-replace-modal .modal-footer .btn-outline,
.template-replace-modal .modal-footer .btn-primary {
    order: 1;
}

.template-replace-modal .modal-footer .btn-outline {
    margin-right: 8px;
}

/* Mobile-native buttons for Templates and Refresh Prices */
@media (max-width: 768px) {
    /* Templates button mobile styling */
    .preset-templates-dropdown #presetTemplatesBtn {
        background: var(--bg-accent);
        color: var(--text-primary);
        border: 1px solid var(--border-color);
        padding: 12px 16px;
        min-height: 44px;
        font-size: 1rem;
        font-weight: 600;
        border-radius: 8px;
        transition: all 0.2s ease;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .preset-templates-dropdown #presetTemplatesBtn:hover {
        background: var(--bg-tertiary);
        border-color: var(--text-secondary);
    }

    /* Refresh Prices button mobile styling */
    #refreshPricesBtn {
        background: var(--bg-accent) !important;
        color: var(--text-primary) !important;
        border: 1px solid var(--border-color) !important;
        padding: 12px 16px !important;
        min-height: 44px !important;
        font-size: 1rem !important;
        font-weight: 600 !important;
        border-radius: 8px !important;
        transition: all 0.2s ease !important;
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
    }

    #refreshPricesBtn:hover {
        background: var(--bg-tertiary) !important;
        border-color: var(--text-secondary) !important;
    }
}

/* Modal mobile adjustments */
@media (max-width: 600px) {
    .modal-footer {
        flex-direction: column-reverse;
        gap: 12px;
        padding: 1rem 1.5rem 1.5rem;
    }

    .modal-footer .btn {
        width: 100%;
        order: initial;
    }

    /* On mobile, stack with primary action on top */
    .template-replace-modal .modal-footer {
        flex-direction: column-reverse;
    }
}

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

    .template-confirm-modal,
    .template-replace-modal {
        width: 95%;
        max-width: none;
    }
}

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

.section-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.holdings-list {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: #6b7280;
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.5rem;
}

/* Cash Cards */
.cash-position-card,
.add-cash-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

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


.add-cash-prompt {
    text-align: center;
}

.add-cash-prompt h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.5rem;
}

.add-cash-prompt p {
    color: #6b7280;
    margin-bottom: 1rem;
}

.btn-outline {
    background: transparent;
    border: 2px solid #3b82f6;
    color: #3b82f6;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-outline:hover {
    background: #3b82f6;
    color: white;
    transform: translateY(-1px);
}

/* Cash Form */
.cash-form .form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.cash-form .form-field label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.cash-form .form-field input,
.cash-form .form-field select {
    background: #f9fafb;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 0.75rem;
    color: #111827;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* Rebalancing Card */
.rebalancing-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.rebalancing-header {
    margin-bottom: 1rem;
}

.rebalancing-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.rebalancing-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.rebalancing-prompt {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.prompt-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Responsive Design */
@media (max-width: 768px) {
    .dashboard-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .header-actions {
        justify-content: space-between;
    }

    /* Show text labels on mobile for portfolio action buttons */
    .btn-icon {
        padding: 0.75rem 1rem;
        min-height: 48px;
        font-size: 0.95rem;
        gap: 0.5rem;
    }

    .btn-icon-text {
        display: inline;
        font-size: 0.875rem;
        font-weight: 500;
    }

    .btn-icon-symbol {
        font-size: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .modern-form .form-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .cash-form .form-grid {
        grid-template-columns: 1fr;
    }
    
    .form-actions {
        justify-content: stretch;
    }
    
    .form-actions .btn {
        flex: 1;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .portfolio-dashboard {
        padding: 0.75rem 0.5rem 1rem;
    }
}

/* Holding Cards */
.holding-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.2s;
}

.holding-card:last-child {
    border-bottom: 1px solid #e5e7eb;
    border-radius: 0 0 12px 12px;
}

.holding-card:first-child {
    border-radius: 12px 12px 0 0;
}

.holding-card:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

.holding-header {
    flex: 0 0 200px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.holding-info {
    flex: 1;
}

.holding-ticker {
    font-size: 1.125rem;
    font-weight: 700;
    color: #111827;
    margin-bottom: 0.25rem;
}

.holding-company-name {
    font-size: 0.8rem;
    color: #6b7280;
    font-weight: 500;
    line-height: 1.2;
}

.holding-value {
    font-size: 0.875rem;
    color: #059669;
    font-weight: 600;
    flex-shrink: 0;
}

.holding-details {
    flex: 1;
    min-width: 0;
}

.holding-shares {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
}

.holding-allocation {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.allocation-bar {
    position: relative;
    height: 6px;
    background: #f3f4f6;
    border-radius: 3px;
    overflow: hidden;
}

.allocation-current {
    height: 100%;
    background: #3b82f6;
    border-radius: 3px;
    transition: width 0.3s;
}

.allocation-target {
    position: absolute;
    top: 0;
    width: 2px;
    height: 100%;
    background: #ef4444;
    transform: translateX(-1px);
}

.allocation-text {
    font-size: 0.75rem;
    color: #6b7280;
}

.holding-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.btn-sm {
    padding: 0.25rem;
    font-size: 0.875rem;
}

/* Cash Display Updates */
.cash-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: #f8fafc;
    border-radius: 8px;
    margin-top: 1rem;
}

.cash-amount-large {
    font-size: 1.25rem;
    font-weight: 700;
    color: #059669;
}

.cash-allocation-info {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Responsive Updates */
@media (max-width: 768px) {
    .holding-card {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .holding-header {
        flex: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .holding-actions {
        align-self: center;
    }
}

.portfolio-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.portfolio-actions {
    display: flex;
    gap: 0.5rem;
}

.input-section,
.cash-section,
.portfolio-display,
.rebalancing-section {
    margin-bottom: 2rem;
}

/* Tables */
.portfolio-table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #e1e8ed;
}

/* Editable table cells */
.editable-shares,
.editable-allocation {
    position: relative;
}

/* Legacy editable cell styles - kept for backward compatibility */

.price-override-indicator {
    color: var(--text-secondary);
    font-weight: bold;
    margin-left: 2px;
}

/* Holding detail rows for inline editing */
.holding-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding: 0.25rem 0;
}

.detail-label {
    font-weight: 500;
    color: #64748b;
    font-size: 0.875rem;
}

.holding-detail-row .editable-cell {
    margin-left: auto;
    min-width: 80px;
    text-align: right;
    padding: 0.25rem 0.5rem;
}

.holding-detail-row .edit-input {
    width: 80px;
    text-align: right;
}

/* Enhanced editable cell styling for table format */
.editable-cell {
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    padding: 0.25rem 0.5rem;
    margin: -0.25rem -0.5rem;
    min-height: 32px;
    display: flex;
    align-items: center;
    color: var(--text-primary) !important;
    position: relative;
}

/* Ensure italicized editable text also stays black */
.editable-cell .price-override-indicator,
.editable-cell .manual-price-indicator {
    color: var(--text-secondary) !important;
    font-style: italic;
}

.editable-cell::after {
    content: "";
    width: 1.25rem; /* Reserve space for pencil */
    flex-shrink: 0;
}

.editable-cell:hover {
    background-color: var(--bg-accent);
}

.editable-cell:hover::after {
    content: "✏️";
    font-size: 0.75rem;
    opacity: 0.6;
    width: 1.25rem; /* Same reserved space */
    flex-shrink: 0;
    text-align: center;
}

/* Hide pencil when checkmark is present */
.editable-cell.has-checkmark:hover::after {
    display: none;
}

.editable-cell.editing {
    background-color: var(--bg-tertiary);
}

.editable-cell.editing::after {
    display: none;
}

/* Success checkmark for updated cells */
.success-checkmark {
    color: #10b981;
    font-size: 0.875rem;
    opacity: 1;
    transition: opacity 0.3s ease;
    animation: checkmarkFadeIn 0.3s ease-in;
    width: 1.25rem; /* Same reserved space as pencil */
    flex-shrink: 0;
    text-align: center;
    position: absolute;
    right: 0.25rem;
}

.success-checkmark.fade-out {
    opacity: 0;
}

@keyframes checkmarkFadeIn {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Green highlight fade for newly added holdings */
.holdings-table .newly-added {
    animation: newHoldingHighlight 2.5s ease-out;
}

@keyframes newHoldingHighlight {
    0% {
        background-color: #d1fae5; /* Light green */
    }
    100% {
        background-color: transparent;
    }
}

.edit-input {
    border: none;
    background: transparent;
    font-weight: inherit;
    color: inherit;
    outline: none;
    width: 100%;
    font-size: inherit;
    padding: 0.25rem;
}

.edit-input:focus {
    outline: none;
    border-color: #2980b9;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.holding-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.edit-controls {
    display: flex;
    gap: 0.5rem;
}

/* Responsive table actions */
@media (max-width: 768px) {
    .holding-actions {
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .edit-controls {
        flex-direction: column;
        gap: 0.25rem;
    }
}

/* Allocation warning */
.allocation-warning {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 8px;
    padding: 1rem;
    color: #856404;
}

/* Dark mode allocation warning */
[data-theme="dark"] .allocation-warning {
    background: #3d2914;
    border: 1px solid #d97706;
    color: #fbbf24;
}

.warning-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.warning-icon {
    font-size: 1.2rem;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    min-height: auto;
}

.portfolio-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

.portfolio-table th,
.portfolio-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #e1e8ed;
}

.portfolio-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #2c3e50;
}

.portfolio-table tbody tr:hover {
    background: #f8f9fa;
}

/* Rebalancing Results */
.rebalancing-results {
    background: #f8f9fa;
    padding: 1.5rem;
    border-radius: 8px;
    border-left: 4px solid #3498db;
}

.rebalancing-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid #e1e8ed;
}

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

.rebalancing-action {
    font-weight: 600;
}

.buy { color: #27ae60; }
.sell { color: #e74c3c; }
.hold { color: #95a5a6; }

/* Google Ads */
.ad-banner,
.ad-sidebar,
.ad-footer {
    background: #f1f3f4;
    border: 2px dashed #dadce0;
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    color: #5f6368;
    font-size: 0.875rem;
    margin: 1rem 0;
}

.ad-placeholder {
    padding: 2rem;
    background: #f8f9fa;
    border-radius: 4px;
}

/* Loading and Modals */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: white;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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


.modal {
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: 2rem;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    border: 1px solid var(--border-color);
}

/* New Dashboard Layout */
.portfolio-overview {
    margin-bottom: 1rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
    margin-top: 1.25rem;
}

.portfolio-management, .rebalancing-dashboard {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Quick Actions Card */
.quick-actions-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px var(--shadow);
    border: 1px solid var(--border-color);
}

.actions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
}

.actions-header h3 {
    margin: 0;
    color: #1f2937;
    font-size: 1.1rem;
    font-weight: 600;
}

.quick-action {
    margin-bottom: 1rem;
}

.quick-action:last-child {
    margin-bottom: 0;
}

/* Compact Forms */
.compact-form {
    margin-top: 0.75rem;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    align-items: end;
}

.form-row input, .form-row select {
    padding: 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
}

.form-row button {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    white-space: nowrap;
}

/* Holdings Input Table Styles */
.holdings-input-table {
    margin-top: 0.75rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.table-header h4 {
    margin: 0;
    color: #374151;
    font-size: 1rem;
}

.table-actions {
    display: flex;
    gap: 0.5rem;
}

.input-table-container {
    margin-bottom: 1rem;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.holdings-input-table-element {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.holdings-input-table-element th {
    background: var(--bg-accent);
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

.holdings-input-table-element th:last-child {
    width: 60px;
    text-align: center;
}

.holdings-input-table-element td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}

.holdings-input-table-element tr:last-child td {
    border-bottom: none;
}

.holdings-input-table-element tr:hover {
    background: var(--bg-accent);
}

.table-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.875rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.table-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.table-input.error {
    border-color: #ef4444;
    background: #fef2f2;
}

.table-input.success {
    border-color: #10b981;
    background: #f0fdf4;
}

.remove-row-btn {
    padding: 0.25rem;
    border: none;
    border-radius: 4px;
    background: #f3f4f6;
    color: #6b7280;
    cursor: pointer;
    font-size: 0.875rem;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.remove-row-btn:hover {
    background: #ef4444;
    color: white;
}

.table-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.5rem;
    border-top: 1px solid #e5e7eb;
}

.help-text {
    font-size: 0.875rem;
    color: #6b7280;
    font-style: italic;
}

.validation-error {
    color: #ef4444;
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* Rate Limit Modal Styles */
.rate-limit-modal {
    max-width: 500px;
    width: 90%;
}

.rate-limit-content {
    text-align: center;
}

.rate-limit-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.rate-limit-details {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 6px;
    padding: 1rem;
    margin: 1rem 0;
    color: #92400e;
    font-size: 0.875rem;
}

/* Dark mode modal styles */
[data-theme="dark"] .rate-limit-details {
    background: #3d2914;
    border: 1px solid #d97706;
    color: #fbbf24;
}

.rate-limit-solutions {
    text-align: left;
    margin: 1.5rem 0;
    background: #f0f9ff;
    border-radius: 8px;
    padding: 1rem;
}

.rate-limit-solutions h4 {
    margin: 0 0 0.75rem 0;
    color: #1e40af;
    font-size: 1rem;
}

.rate-limit-solutions ul {
    margin: 0;
    padding-left: 1.5rem;
}

.rate-limit-solutions li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.rate-limit-tip {
    background: #ecfdf5;
    border: 1px solid #10b981;
    border-radius: 6px;
    padding: 1rem;
    margin-top: 1rem;
}

.rate-limit-tip p {
    margin: 0;
    color: #065f46;
    font-size: 0.875rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.modal-actions .btn {
    flex: 1;
    max-width: 160px;
}

/* Custom modal styling improvements */
.modal h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}


/* Holdings Summary Card */
.holdings-summary-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid #e5e7eb;
}

.summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
}

.summary-header h3 {
    margin: 0;
    color: #1f2937;
    font-size: 1.1rem;
    font-weight: 600;
}

.holdings-summary {
    /* Allow natural height expansion without scrolling */
}

.holdings-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0.5rem 0;
}

/* Add Holding Row Styles */
.add-holding-trigger, 
.add-holding-trigger-label {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    width: 100%;
    text-align: left;
}

.add-holding-trigger:focus,
.add-holding-trigger-label:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    background: var(--bg-accent);
}

.add-holding-trigger:hover,
.add-holding-trigger-label:hover {
    background: var(--bg-accent);
    transform: translateY(-1px);
}

.add-holding-trigger:active,
.add-holding-trigger-label:active {
    transform: translateY(0);
}

.add-holding-icon {
    font-size: 1.2rem;
    color: var(--primary);
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(14, 165, 233, 0.1);
}

.add-holding-label {
    color: var(--primary);
    font-weight: 500;
}

.add-holding-row {
    transition: background-color 0.2s ease;
}

.add-holding-row:hover {
    background-color: var(--bg-accent);
}

.add-holding-row.editing {
    background-color: var(--bg-tertiary);
}

.add-holding-row.editing .add-holding-trigger,
.add-holding-row.editing .add-holding-trigger-label,
.add-holding-row.editing .add-placeholder {
    display: none;
}

/* Form validation and error styles */
.field-error {
    font-size: 0.75rem;
    color: var(--danger);
    margin-top: 0.25rem;
    font-weight: 500;
}

.add-input.error {
    border-color: var(--danger);
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15);
}

.add-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.15);
}

.add-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.add-actions .btn {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    min-width: auto;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Allocations Card (Consolidated) */
.allocations-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px var(--shadow);
    border: 1px solid var(--border-color);
}

.allocations-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.allocations-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.allocation-actions {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.allocation-actions button {
    flex: 1;
    min-width: 140px;
}

/* Cash Form Styles */
.cash-form {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.form-header {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e5e7eb;
}

.form-header h4 {
    margin: 0;
    color: #374151;
    font-size: 1rem;
}

.form-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    color: #374151;
    font-size: 0.875rem;
}

.form-group input,
.form-group select {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.form-actions button {
    flex: 1;
    min-width: 120px;
}

.empty-holdings {
    text-align: center;
    color: #6b7280;
    padding: 2rem 0;
}

.holding-summary-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1.5rem;
    align-items: center;
    padding: 1.25rem 0;
    border-bottom: 1px solid #f1f5f9;
    transition: all 0.2s ease;
}

.holding-summary-item:hover {
    background-color: #f8fafc;
    border-radius: 8px;
    margin: 0 -1rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid #e2e8f0;
}

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

.holding-info {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.holding-main {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.holding-ticker {
    font-weight: 700;
    color: #0f172a;
    font-size: 1.125rem;
    letter-spacing: -0.025em;
}

.holding-name {
    font-size: 0.875rem;
    color: #64748b;
    font-weight: 500;
    margin: 0;
}

.holding-price-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.25rem 0;
}

.price-label {
    font-size: 0.875rem;
    color: #64748b;
    font-weight: 500;
    min-width: 45px;
}

.holding-details {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    margin-top: 0.125rem;
}

.shares-info, .value-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.price-display {
    font-weight: 600;
    color: #059669;
}

.manual-price-indicator {
    font-size: 0.75rem;
    margin-left: 0.25rem;
    opacity: 0.7;
}

.edit-price {
    opacity: 0.6;
    font-size: 0.75rem;
    padding: 0.2rem;
}

.edit-price:hover {
    opacity: 1;
}

.price-edit-form {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.5rem;
}

.price-input {
    width: 80px;
    padding: 0.25rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 0.8rem;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-weight: 500;
}

.btn-sm.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-sm.btn-secondary {
    background: #6b7280;
    color: white;
}

.price-label {
    color: #6b7280;
    font-size: 0.75rem;
    margin-right: 0.25rem;
}

.holding-price {
    font-weight: 600;
    color: #059669;
}

.holding-price.no-price {
    color: #9ca3af;
    font-weight: 400;
    font-style: italic;
    font-size: 0.75rem;
}

.holding-name {
    color: #6b7280;
    font-size: 0.8rem;
    font-weight: 500;
}

.holding-details {
    display: flex;
    gap: 1rem;
    font-size: 0.75rem;
}

.detail-label {
    color: #6b7280;
    font-weight: 500;
    margin-right: 0.25rem;
}

.current-value {
    color: #059669;
    font-weight: 600;
}

/* Holdings Table - Matching Portfolio List Styling */
.holdings-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px var(--shadow);
}

.holdings-table th,
.holdings-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.holdings-table th {
    background: var(--bg-accent);
    font-weight: 600;
    color: var(--text-primary);
    position: sticky;
    top: 0;
    z-index: 1;
}

.holdings-table tbody tr:hover {
    background: var(--bg-accent);
}

.holdings-table .ticker-cell {
    font-weight: 600;
    color: var(--text-primary);
}

.holdings-table .company-name {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-top: 2px;
    line-height: 1.2;
}

.holdings-table .actions-cell {
    text-align: center;
}

.holdings-table .btn-xs {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    min-width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Cash row styling */
.holdings-table .cash-row {
    background-color: var(--bg-accent);
    font-style: italic;
}

.holdings-table .cash-row:hover {
    background-color: var(--bg-tertiary);
}

.holdings-table .cash-row .ticker-cell {
    color: #28a745;
}

/* Selected row styling - matching portfolio table */
.holdings-table tbody tr.selected {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--primary);
}

.holdings-table tbody tr.selected:hover {
    background: var(--bg-accent);
}

/* Selection Controls for Holdings */
.selection-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-accent);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.selection-info {
    font-weight: 500;
    color: #495057;
    font-size: 0.875rem;
}

.selection-actions {
    display: flex;
    gap: 0.75rem;
}

/* Manual price indicator - uses italics for space efficiency */
.price-override-indicator {
    font-style: italic;
    color: #6b7280;
}

.manual-price-indicator {
    font-style: italic;
    color: var(--text-secondary);
}

/* Table-format Add Holding Row - matches regular rows */
.holdings-table .add-holding-row {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    /* Removed animation: fadeInSlide 0.3s ease; to prevent unwanted fading during cash toggle */
}

.holdings-table .add-holding-row:hover {
    background: var(--bg-accent);
}

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

.holdings-table .add-input {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    background: var(--bg-secondary);
    color: var(--text-primary);
    width: 100%;
    max-width: 150px;
}


.holdings-table .add-input:focus {
    outline: none;
    border-color: #0ea5e9;
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.15);
}

/* Hide spinner arrows for number inputs */
.holdings-table input[type="number"]::-webkit-outer-spin-button,
.holdings-table input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.holdings-table input[type="number"] {
    -moz-appearance: textfield;
}

/* Add dollar sign prefix to price input fields */
.price-input-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

.price-input-wrapper::before {
    content: "$";
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    pointer-events: none;
    z-index: 1;
    font-size: 0.875rem;
}

.price-input-wrapper input {
    padding-left: 1.25rem;
    width: 100%;
    text-indent: 0.5rem;
}

.holdings-table .ticker-input {
    text-transform: uppercase;
    font-weight: 600;
    max-width: 120px;
    min-width: 120px;
}

.holdings-table .allocation-input {
    text-align: right;
}

.holdings-table .price-placeholder, 
.holdings-table .value-placeholder, 
.holdings-table .current-placeholder {
    font-size: 0.8125rem;
    color: #9ca3af;
    font-style: italic;
}

/* Compact button group for table actions */
.holdings-table .add-holding-row .actions-cell {
    white-space: nowrap;
}

.holdings-table .add-holding-row .btn-xs {
    font-weight: 600;
    transition: all 0.15s ease;
    margin-right: 0.25rem;
}

.holdings-table .add-holding-row .btn-primary {
    background: #0ea5e9;
    border-color: #0ea5e9;
    color: white;
}

.holdings-table .add-holding-row .btn-primary:hover {
    background: #0284c7;
    border-color: #0284c7;
}

.holdings-table .add-holding-row .btn-secondary {
    background: #6b7280;
    border-color: #6b7280;
    color: white;
}

.holdings-table .add-holding-row .btn-secondary:hover {
    background: #4b5563;
    border-color: #4b5563;
}

/* Rebalancing Dashboard */
.rebalancing-dashboard {
    position: sticky;
    top: 2rem;
    height: fit-content;
}

.rebalancing-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px var(--shadow);
    border: 1px solid var(--border-color);
    min-height: 400px;
}

.rebalancing-header {
    text-align: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--primary);
}

.rebalancing-button-container {
    text-align: center;
    margin-bottom: 1.5rem;
}

.rebalancing-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.2rem;
    font-weight: 600;
}

.rebalancing-content {
    min-height: 300px;
}

.rebalancing-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.rebalancing-prompt .prompt-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.rebalancing-prompt h4 {
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
    font-size: 1.1rem;
}

/* Rebalancing Recommendations */
.rebalancing-summary {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.rebalancing-summary h4 {
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 600;
}

.rebalancing-total {
    font-size: 1rem;
    font-weight: 600;
    color: var(--success);
}

.recommendations-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.recommendation-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    border-left: 4px solid var(--primary);
}

.recommendation-action {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
    min-width: 80px;
}

.recommendation-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}

.recommendation-ticker {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.recommendation-amount {
    font-weight: 700;
    color: var(--success);
    font-size: 1rem;
}

.recommendation-shares {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* Holdings Details Section */
.holdings-details-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid #e5e7eb;
}

/* Breadcrumb Navigation */
.breadcrumb {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.breadcrumb-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.breadcrumb-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.breadcrumb-separator {
    margin: 0 0.5rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.breadcrumb-current {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.5rem;
    margin: 0;
}

/* Selection Header Styles */
.selection-header {
    background: #f0f9ff;
    border: 1px solid #0ea5e9;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.selection-info {
    font-weight: 600;
    color: #0369a1;
    display: flex;
    align-items: center;
}

.selection-info span {
    color: #0284c7;
    font-weight: 700;
}

/* Button Styles */
.btn-block {
    width: 100%;
    justify-content: center;
}

.btn-outline {
    background: transparent;
    border: 2px solid #3b82f6;
    color: #3b82f6;
}

.btn-outline:hover {
    background: #3b82f6;
    color: white;
}


/* Footer */
.footer {
    background: #2c3e50;
    color: white;
    padding: 2rem 0;
    margin-top: 3rem;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    text-align: center;
}

/* Responsive Design */
@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .form-row {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .rebalancing-dashboard {
        position: static;
    }
    
    .actions-header, .summary-header, .rebalancing-header, .allocations-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    
    .header-actions {
        justify-content: center;
    }
    
    .allocation-actions {
        flex-direction: column;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .compact-form {
        padding: 0.75rem;
    }
    
    /* Holdings Input Table Mobile */
    .holdings-input-table {
        padding: 0.75rem;
    }
    
    .table-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }
    
    .table-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .input-table-container {
        overflow-x: auto;
    }
    
    .holdings-input-table-element {
        min-width: 400px;
    }
    
    .table-footer {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
        text-align: center;
    }
    
    /* Mobile breadcrumb adjustments */
    .breadcrumb-current {
        font-size: 1.25rem;
    }
    
    .breadcrumb {
        flex-wrap: wrap;
    }
}

@media (min-width: 768px) {
    .header-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
    
    .app-title {
        text-align: left;
        margin: 0;
    }
    
    .header-nav {
        flex-wrap: wrap;
    }
    
    .portfolio-selector {
        width: 250px;
    }
    
    .main-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .sidebar {
        display: none;
    }
    
    .portfolio-header {
        flex-wrap: nowrap;
    }
}

@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .portfolio-table-container {
        overflow-x: visible;
    }
    
    .portfolio-table {
        min-width: auto;
    }
}

/* Portfolio Management Section */
.manage-portfolios-section {
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 4px 6px var(--shadow);
    padding: 2rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.section-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.portfolio-list-container {
    overflow-x: auto;
}

.portfolio-list-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px var(--shadow);
}

.portfolio-list-table th,
.portfolio-list-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.portfolio-list-table th {
    background: var(--bg-accent);
    font-weight: 600;
    color: var(--text-primary);
    position: sticky;
    top: 0;
    z-index: 1;
}

.portfolio-list-table tbody tr:hover {
    background: var(--bg-accent);
}

.checkbox-column {
    width: 50px;
    text-align: center;
}

.checkbox-column input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.portfolio-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.portfolio-actions .btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.no-portfolios {
    text-align: center;
    padding: 3rem;
    color: #6c757d;
}

.no-portfolios a {
    color: #3498db;
    text-decoration: none;
}

.no-portfolios a:hover {
    text-decoration: underline;
}

/* API Key Setup Section Link Styling */
#apiKeySetupSection a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

#apiKeySetupSection a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Error Modal Styling */
#errorModal .modal {
    max-width: 600px;
    min-width: 400px;
}

#errorModal #errorMessage {
    line-height: 1.6;
    white-space: pre-line;
    color: var(--text-primary);
    margin-bottom: 20px;
}

#errorModal h3 {
    color: var(--danger);
    margin-bottom: 16px;
}

#errorModal .btn {
    min-width: 80px;
}

/* Portfolio row selected state */
.portfolio-list-table tbody tr.selected {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--primary);
}

.portfolio-list-table tbody tr.selected:hover {
    background: var(--bg-accent);
}

/* Rebalancing Section */
.rebalance-section {
    text-align: center;
    padding: 2rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px dashed #dee2e6;
}

.rebalance-section p {
    margin-bottom: 1rem;
    color: #6c757d;
}

/* Alert Styles */
.alert {
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid transparent;
    margin: 1rem 0;
}

.alert-success {
    background-color: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

.alert-danger {
    background-color: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

/* Dark mode alert styles */
[data-theme="dark"] .alert-danger {
    background-color: #3d1a1a;
    border-color: #5a2828;
    color: #f8d7da;
}

[data-theme="dark"] .alert-success {
    background-color: #1a3d1a;
    border-color: #285a28;
    color: #d4edda;
}

/* Cash Holdings Section */
.cash-form {
    margin-bottom: 1rem;
}

.current-cash {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1rem;
}

.cash-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.cash-label {
    font-weight: 600;
    color: var(--text-primary);
}

.cash-amount {
    font-size: 1.125rem;
    font-weight: 600;
    color: #28a745;
}

.cash-allocation {
    color: #6c757d;
    font-style: italic;
}

.cash-info .btn {
    margin-left: auto;
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .btn:hover,
    .loading-spinner {
        animation: none;
        transform: none;
    }
}

/* Focus styles for keyboard navigation */
.btn:focus,
input:focus,
select:focus {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

/* Dark Mode Toggle Switch */
.theme-toggle {
    margin-left: 1rem;
}

.theme-toggle-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    gap: 0.5rem;
}

.theme-toggle-input {
    display: none;
}

.theme-toggle-slider {
    position: relative;
    width: 50px;
    height: 24px;
    background: var(--bg-accent);
    border-radius: 12px;
    transition: background-color 0.3s ease;
    border: 1px solid var(--border-color);
}

.theme-toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--bg-secondary);
    border-radius: 50%;
    transition: transform 0.3s ease, background-color 0.3s ease;
    box-shadow: 0 1px 3px var(--shadow);
}

.theme-toggle-input:checked + .theme-toggle-slider {
    background: var(--primary);
}

.theme-toggle-input:checked + .theme-toggle-slider::before {
    transform: translateX(26px);
}

.theme-icon {
    font-size: 1.1rem;
    transition: opacity 0.3s ease;
}

.theme-toggle-input:not(:checked) ~ .dark-icon {
    opacity: 0.4;
}

.theme-toggle-input:checked ~ .light-icon {
    opacity: 0.4;
}

.theme-toggle-label:hover .theme-toggle-slider {
    background: var(--primary);
}

.theme-toggle-label:hover .theme-toggle-slider::before {
    box-shadow: 0 2px 6px var(--shadow-hover);
}

/* Allocation bar rows - remove borders to connect visually with holding row above */
.holdings-table .allocation-bar-row td {
    border-top: none;
    padding-top: 0.5rem;
    padding-bottom: 1rem;
}

/* Remove bottom border from holding rows that have allocation bars below them */
.holdings-table tr:has(+ .allocation-bar-row) td {
    border-bottom: none;
}

/* Fallback for browsers that don't support :has() - target all holding rows except the last */
.holdings-table tbody tr:not(.allocation-bar-row):not(.add-holding-row):not(.cash-row) td {
    border-bottom: none;
}

/* Unified hover behavior - when hovering over holding row, highlight both rows */
.holdings-table tbody tr:not(.allocation-bar-row):not(.add-holding-row):not(.cash-row):hover {
    background: var(--bg-accent);
}
.holdings-table tbody tr:not(.allocation-bar-row):not(.add-holding-row):not(.cash-row):hover + .allocation-bar-row {
    background: var(--bg-accent);
}

/* When hovering over allocation bar row, highlight both rows */
.holdings-table .allocation-bar-row:hover {
    background: var(--bg-accent);
}
.holdings-table .allocation-bar-row:hover {
    background: var(--bg-accent);
}
/* Use :has() to highlight the holding row when hovering over its allocation bar */
.holdings-table tr:has(+ .allocation-bar-row:hover) {
    background: var(--bg-accent);
}

/* Selected state behavior - when holding row is selected, also select allocation bar row */
.holdings-table tbody tr.selected + .allocation-bar-row {
    background: var(--bg-tertiary);
}
.holdings-table tbody tr.selected + .allocation-bar-row:hover {
    background: var(--bg-accent);
}
/* Use :has() to select the holding row when its allocation bar is part of selection */
.holdings-table tr:has(+ .allocation-bar-row.selected) {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--primary);
}

.holdings-table .allocation-bar-row .empty-cell {
    border: none;
    padding: 0;
}

.holdings-table .allocation-bar-cell {
    text-align: center;
    padding-left: 1rem;
    padding-right: 1rem;
}

.holdings-table .holding-allocation-bar {
    width: 100%;
    margin: 0;
}

/* Cash Position Section */
.cash-position-section {
    margin-top: 2rem;
}

.cash-position-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.cash-position-section h4 {
    margin: 0;
    color: var(--text-primary);
    font-weight: 600;
}


.cash-position-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px var(--shadow);
    border: 1px solid var(--border-color);
}

.cash-details {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.cash-amount-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-light);
}

.cash-allocation-row,
.cash-target-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cash-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.cash-value {
    font-weight: 600;
    color: var(--success);
    font-size: 1.1rem;
}

.cash-amount-row .cash-value {
    font-size: 1.25rem;
    font-weight: 700;
}

.cash-bar-row {
    margin-top: 0.5rem;
}

.cash-allocation-bar {
    width: 100%;
}

.empty-cash {
    text-align: center;
    padding: 2rem;
    color: #6c757d;
    font-style: italic;
}

/* Cash editing styles */
.editable-cash-amount,
.editable-cash-allocation,
.editable-cash-target {
    position: relative;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    cursor: pointer;
    background: var(--bg-primary);
}

.editable-cash-amount:hover,
.editable-cash-allocation:hover,
.editable-cash-target:hover {
    background-color: var(--bg-accent);
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
}

.editable-cash-amount::after,
.editable-cash-allocation::after,
.editable-cash-target::after {
    content: "✏️";
    position: absolute;
    top: -8px;
    right: -8px;
    font-size: 0.7rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.editable-cash-amount:hover::after,
.editable-cash-allocation:hover::after,
.editable-cash-target:hover::after {
    opacity: 1;
}

/* Cash Target Section */
.cash-target-section {
    margin-top: 1.5rem;
}

.cash-target-header {
    margin-bottom: 1rem;
    text-align: center;
}

.cash-target-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}


.cash-control-group {
    transition: all 0.3s ease;
    border-radius: 12px;
    padding: 1rem;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-light);
    cursor: pointer;
}

.cash-control-group.active {
    background: var(--bg-primary);
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.15);
    transform: translateY(-2px);
}

.cash-control-group:not(.active) {
    opacity: 0.6;
}

.cash-control-group:not(.active):hover {
    opacity: 0.8;
    border-color: var(--border-color);
}

.control-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    text-align: center;
}

.control-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cash-control-group.active .control-label {
    color: var(--primary);
    font-weight: 700;
}

/* Enhanced cash value styling */
.cash-control-group .cash-value {
    font-size: 1.1rem;
    font-weight: 600;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    min-width: 80px;
    text-align: center;
    transition: all 0.2s ease;
}

.cash-control-group .cash-value:hover {
    border-color: #007AFF;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
}

.cash-control-group.active .cash-value {
    background: var(--bg-tertiary);
    border-color: #007AFF;
    color: var(--text-primary);
}

/* Responsive design */
@media (max-width: 768px) {
    .cash-details {
        gap: 1rem;
    }

    /* Mobile layout: stack controls vertically, hide toggle */
    .cash-target-section div[style*="grid-template-columns"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
        align-items: stretch !important;
    }

    /* Hide toggle switch on mobile */
    .cash-toggle-switch {
        display: none !important;
    }

    /* Mobile control groups styling */
    .cash-control-group {
        padding: 1rem;
        width: 100%;
        box-sizing: border-box;
    }

    /* Stack label above value on mobile */
    .cash-control-group .control-content {
        flex-direction: column !important;
        align-items: center !important;
        gap: 0.5rem !important;
        text-align: center !important;
    }

    /* Make text boxes more prominent on mobile */
    .cash-control-group .cash-value {
        width: 100% !important;
        max-width: 200px;
        text-align: center !important;
        font-size: 1.1rem !important;
        padding: 0.75rem !important;
    }

    /* Ensure both controls are always visible on mobile */
    .cash-control-group:not(.active) {
        opacity: 1 !important;
        background: var(--bg-tertiary) !important;
        border-color: var(--border-light) !important;
    }

    /* Stack Current Cash label above value on mobile */
    .cash-amount-row {
        padding: 1rem;
        flex-direction: column !important;
        align-items: center !important;
        gap: 0.5rem !important;
        text-align: center !important;
    }

    /* Make Current Cash value more prominent on mobile */
    .cash-amount-row .cash-value {
        width: 100% !important;
        max-width: 200px;
        text-align: center !important;
        font-size: 1.25rem !important;
        padding: 0.75rem !important;
    }
}
    
    .control-content {
        flex-direction: row;
        justify-content: space-between;
    }
}

/* Enhanced Toggle Switch */
.cash-toggle-switch {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1rem 0;
    padding: 0.5rem;
}

.cash-toggle-switch input[type="checkbox"] {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: relative;
    display: block;
    width: 60px;
    height: 32px;
    background-color: var(--bg-tertiary);
    border-radius: 16px;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    left: 2px;
    top: 2px;
    background-color: var(--text-primary);
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.cash-toggle-switch input:checked + .toggle-slider {
    background-color: var(--primary);
    border-color: var(--primary);
    box-shadow: inset 0 2px 4px rgba(0, 122, 255, 0.3);
}

.cash-toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(28px);
    background-color: white;
}

.cash-toggle-switch:hover .toggle-slider {
    transform: scale(1.05);
}

/* Legacy Cash Type Toggle (keeping for other views) */
.cash-type-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-light);
}

.cash-type-label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.toggle-group {
    display: inline-flex;
    background: var(--bg-tertiary);
    border-radius: 6px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.toggle-group input[type="radio"] {
    display: none;
}

.toggle-option {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.toggle-option:hover {
    color: #495057;
    background-color: #e9ecef;
}

.toggle-group input[type="radio"]:checked + .toggle-option {
    color: var(--primary);
    background: var(--bg-secondary);
    font-weight: 600;
    box-shadow: 0 1px 2px var(--shadow);
    border: 1px solid var(--primary);
}

/* Cash status display container for consistent positioning */
.cash-status-display {
    margin-top: 1rem;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-light);
}

/* Cash difference display for fixed amounts */
.cash-difference-display {
    text-align: center;
    width: 100%;
    padding: 1rem;
}

.cash-difference-display .difference-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.cash-difference-display .difference-amount {
    font-size: 1.1rem;
    font-weight: 600;
}

.cash-allocation-bar {
    width: 100%;
    padding: 0.75rem;
}

.cash-allocation-bar .allocation-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-accent);
    border-radius: 4px;
    position: relative;
    margin-bottom: 0.5rem;
}

.cash-allocation-bar .allocation-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.cash-allocation-bar .allocation-target-line {
    position: absolute;
    top: 0;
    width: 2px;
    height: 100%;
    background: var(--success);
    border-radius: 1px;
}

.cash-allocation-bar .allocation-text {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Additional cash row styling */
.cash-value-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Cash difference display for fixed amounts */
.cash-difference-row {
    margin-top: 0.5rem;
    text-align: center;
}

.cash-difference {
    font-size: 0.875rem;
    font-weight: 600;
}

.difference-positive {
    color: #22c55e;
}

.difference-negative {
    color: #ef4444;
}

.difference-balanced {
    color: #6b7280;
}

/* Target allocation line colors based on rebalancing needs */
.allocation-target.target-high {
    background: #22c55e; /* Green - need to buy more */
}

.allocation-target.target-low {
    background: #ef4444; /* Red - need to sell some */
}

.allocation-target.target-balanced {
    background: #6b7280; /* Gray - balanced */
}

/* Section Divider */
.section-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 1.5rem 0;
    opacity: 0.6;
}

/* Missing Price Data Highlighting */
.missing-price-data {
    background-color: rgba(239, 68, 68, 0.1) !important;
    border: 2px solid var(--danger) !important;
    border-radius: 4px;
    animation: pulseRed 2s infinite;
}

@keyframes pulseRed {
    0%, 100% { 
        background-color: rgba(239, 68, 68, 0.1);
        border-color: var(--danger);
    }
    50% { 
        background-color: rgba(239, 68, 68, 0.2);
        border-color: #dc2626;
    }
}

/* ===== MOBILE RESPONSIVE HOLDINGS INTERFACE ===== */
@media (max-width: 768px) {
    /* Holdings Input Table - Transform to Cards */
    .holdings-input-table {
        padding: 0.75rem;
    }
    
    .table-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .table-header h4 {
        text-align: center;
        font-size: 1.125rem;
    }
    
    .table-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .table-actions .btn {
        padding: 0.875rem;
        font-size: 1rem;
        min-height: 48px;
    }
    
    /* Replace table with card layout on mobile */
    .input-table-container {
        display: none;
    }
    
    /* Show mobile card layout instead */
    .holdings-input-mobile {
        display: block !important;
    }
    
    .holdings-input-card {
        background: var(--bg-primary);
        border: 2px solid var(--border-color);
        border-radius: 12px;
        padding: 1.25rem;
        margin-bottom: 1rem;
        position: relative;
    }
    
    .holdings-input-card h5 {
        margin: 0 0 1.25rem 0;
        color: var(--text-primary);
        font-size: 1rem;
        font-weight: 600;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 0.75rem;
    }
    
    .holdings-input-row {
        display: grid;
        gap: 1rem;
        grid-template-columns: 1fr;
    }
    
    .holdings-input-field {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .holdings-input-field label {
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 0.875rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }
    
    .holdings-input-field input,
    .holdings-input-field select {
        width: 100%;
        padding: 0.875rem;
        font-size: 16px;
        border: 2px solid var(--border-color);
        border-radius: 8px;
        background: var(--bg-secondary);
        color: var(--text-primary);
        min-height: 48px;
        transition: border-color 0.2s ease;
        box-sizing: border-box;
    }
    
    .holdings-input-field input:focus,
    .holdings-input-field select:focus {
        outline: none;
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }
    
    .remove-row-btn {
        position: absolute;
        top: 1rem;
        right: 1rem;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: var(--danger);
        color: white;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
        cursor: pointer;
        transition: background-color 0.2s ease;
    }
    
    .remove-row-btn:hover {
        background: #dc2626;
    }
    
    /* Mobile table footer */
    .table-footer {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .table-footer .btn {
        padding: 1rem;
        font-size: 1rem;
        min-height: 48px;
        border-radius: 12px;
    }
    
    .table-footer .help-text {
        text-align: center;
        font-size: 0.875rem;
        color: var(--text-secondary);
        padding: 0.5rem;
    }
    
    /* Replace holdings table with cards on mobile */
    .holdings-table {
        display: none;
    }
    
    
    .holdings-cards-mobile {
        display: block !important;
    }
    
    /* Mobile Add Holding Card */
    .add-holding-card-mobile {
        background: var(--bg-secondary);
        border: 2px solid var(--primary);
        border-radius: 12px;
        padding: 1.25rem;
        margin-bottom: 1rem;
        position: relative;
        box-shadow: 0 2px 8px rgba(14, 165, 233, 0.1);
    }
    
    .add-holding-card-mobile .holding-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 1.5rem;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid var(--border-color);
    }
    
    .add-holding-card-mobile .holding-card-header h3 {
        margin: 0;
        color: var(--primary);
        font-size: 1.1rem;
        font-weight: 600;
    }
    
    .mobile-cancel-add-btn {
        background: none;
        border: none;
        color: var(--text-secondary);
        font-size: 1.5rem;
        padding: 0.25rem;
        cursor: pointer;
        border-radius: 50%;
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
    }
    
    .mobile-cancel-add-btn:hover {
        background: var(--bg-accent);
        color: var(--text-primary);
    }
    
    .add-holding-form-mobile {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    .form-group-mobile {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .form-row-mobile {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    .form-label-mobile {
        font-size: 0.875rem;
        font-weight: 600;
        color: var(--text-primary);
        margin: 0;
    }
    
    .form-input-mobile {
        padding: 0.75rem;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        font-size: 1rem;
        background: var(--bg-primary);
        color: var(--text-primary);
        transition: border-color 0.2s ease;
    }
    
    .form-input-mobile:focus {
        outline: none;
        border-color: var(--primary);
        box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.15);
    }
    
    .ticker-input-mobile {
        text-transform: uppercase;
        font-weight: 600;
    }
    
    .form-actions-mobile {
        display: flex;
        gap: 0.75rem;
        margin-top: 0.5rem;
    }
    
    .btn-primary-mobile {
        flex: 1;
        padding: 0.875rem 1rem;
        background: var(--primary);
        color: white;
        border: none;
        border-radius: 8px;
        font-size: 1rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .btn-primary-mobile:hover {
        background: #0284c7;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
    }
    
    .btn-secondary-mobile {
        flex: 1;
        padding: 0.875rem 1rem;
        background: var(--bg-accent);
        color: var(--text-primary);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        font-size: 1rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .btn-secondary-mobile:hover {
        background: var(--bg-tertiary);
        border-color: var(--text-secondary);
    }
    
    .field-error {
        color: #ef4444;
        font-size: 0.75rem;
        margin-top: 0.25rem;
    }
    
    .holding-card-mobile {
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 1.25rem;
        margin-bottom: 1rem;
        position: relative;
    }
    
    .holding-card-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 1rem;
        padding-bottom: 1rem;
        border-bottom: 1px solid var(--border-color);
    }
    
    .holding-ticker {
        font-size: 1.25rem;
        font-weight: 700;
        color: var(--text-primary);
    }
    
    .holding-name {
        font-size: 0.875rem;
        color: var(--text-secondary);
        margin-top: 0.25rem;
    }
    
    .holding-actions {
        display: flex;
        gap: 0.5rem;
        flex-shrink: 0;
    }
    
    .holding-actions .btn {
        min-width: 44px;
        min-height: 44px;
        padding: 0.75rem;
        border-radius: 8px;
        font-size: 0.875rem;
    }

    /* Make delete button visible and touch-friendly on mobile */
    .holding-actions .remove-holding {
        min-width: 44px;
        min-height: 44px;
        padding: 0.75rem 1rem;
        background: var(--bg-secondary);
        border: 1px solid var(--danger);
        color: var(--danger);
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        font-size: 0.875rem;
        font-weight: 500;
    }

    .holding-actions .remove-holding .btn-icon-symbol {
        font-size: 1rem;
    }

    .holding-actions .remove-holding .btn-icon-text {
        display: inline;
        font-size: 0.875rem;
        font-weight: 500;
    }

    .holding-actions .remove-holding:hover {
        background: rgba(239, 68, 68, 0.1);
        border-color: var(--danger-hover);
        color: var(--danger-hover);
    }
    
    .holding-details {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem 1.5rem;
    }
    
    .holding-detail {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .holding-detail-label {
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }
    
    .holding-detail-value {
        font-size: 1rem;
        font-weight: 600;
        color: var(--text-primary);
    }
    
    .holding-detail-value.positive {
        color: var(--success);
    }
    
    .holding-detail-value.negative {
        color: var(--danger);
    }
    
    .holding-detail-value.neutral {
        color: var(--text-secondary);
    }
    
    /* Cash position mobile optimization */
    .cash-position-section .section-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }
    
    
    /* Portfolio selector mobile improvements */
    .portfolio-selector {
        width: 100%;
    }
    
    .custom-dropdown {
        width: 100%;
    }
    
    .dropdown-selected {
        padding: 0.875rem;
        min-height: 48px;
        font-size: 1rem;
    }
    
    .dropdown-options {
        font-size: 1rem;
    }
    
    .dropdown-option {
        padding: 0.875rem;
        min-height: 48px;
    }
    
    /* Portfolio creation form mobile optimization */
    .new-portfolio-section {
        padding: 1rem;
        margin: 1rem 0;
    }
    
    .new-portfolio-section h2 {
        font-size: 1.5rem;
        text-align: center;
        margin-bottom: 1.5rem;
    }
    
    .new-portfolio-form .form-group input {
        padding: 1rem;
        font-size: 1rem;
        min-height: 56px;
        border-radius: 12px;
        border: 2px solid var(--border-color);
    }
    
    .new-portfolio-form .form-actions {
        flex-direction: column;
        gap: 0.75rem;
        margin-top: 1.5rem;
    }
    
    .new-portfolio-form .form-actions .btn {
        padding: 1rem;
        font-size: 1rem;
        min-height: 56px;
        border-radius: 12px;
        font-weight: 600;
    }
    
    /* API Setup form mobile optimization */
    .api-setup-section {
        padding: 1rem;
        margin: 1rem 0;
    }
    
    .api-setup-section h2 {
        font-size: 1.5rem;
        text-align: center;
        margin-bottom: 1rem;
    }
    
    .api-setup-section p {
        font-size: 1rem;
        text-align: center;
        margin-bottom: 1.5rem;
        line-height: 1.6;
    }
    
    .api-setup-section ol {
        margin-bottom: 2rem;
        padding-left: 1.5rem;
    }
    
    .api-setup-section ol li {
        margin-bottom: 0.75rem;
        font-size: 1rem;
        line-height: 1.5;
    }
    
    .api-key-form .form-group {
        margin-bottom: 1.5rem;
    }
    
    .api-key-form .form-group label {
        font-size: 1rem;
        font-weight: 600;
        margin-bottom: 0.75rem;
    }
    
    .api-key-form .form-group input {
        padding: 1rem;
        font-size: 1rem;
        min-height: 56px;
        border-radius: 12px;
        border: 2px solid var(--border-color);
    }
    
    .api-key-form .btn {
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
        min-height: 56px;
        border-radius: 12px;
        font-weight: 600;
    }
    
    /* Welcome section mobile optimization */
    .welcome-section {
        padding: 1rem;
        text-align: center;
    }
    
    .welcome-section h2 {
        font-size: 1.75rem;
        margin-bottom: 1rem;
        line-height: 1.3;
    }
    
    .welcome-section p {
        font-size: 1rem;
        line-height: 1.6;
        margin-bottom: 2rem;
    }
    
    .privacy-notice {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
        padding: 1.5rem;
        border-radius: 16px;
    }
    
    .privacy-icon {
        font-size: 2rem;
    }
    
    .privacy-content {
        font-size: 0.9rem;
        line-height: 1.5;
    }
    
    /* Rebalancing workflow mobile optimization */
    .rebalancing-dashboard {
        margin-top: 2rem;
        position: static;
    }
    
    .rebalancing-card {
        padding: 1.25rem;
        margin: 0;
        min-height: auto;
        border-radius: 16px;
    }
    
    .rebalancing-header h3 {
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
    }
    
    .rebalancing-button-container {
        margin-bottom: 2rem;
    }
    
    .rebalancing-button-container .btn {
        width: 100%;
        padding: 1.25rem;
        font-size: 1.125rem;
        min-height: 56px;
        border-radius: 16px;
        font-weight: 700;
        letter-spacing: 0.025em;
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
    }
    
    .rebalancing-prompt {
        text-align: center;
        padding: 2rem 1rem;
    }
    
    .rebalancing-prompt .prompt-icon {
        font-size: 3rem;
        margin-bottom: 1rem;
    }
    
    .rebalancing-prompt h4 {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }
    
    .rebalancing-prompt p {
        font-size: 1rem;
        line-height: 1.6;
        color: var(--text-secondary);
    }
    
    /* Holdings details section mobile */
    .holdings-details-section {
        margin-top: 2rem;
    }
    
    .holdings-details-section .section-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
        margin-bottom: 1.5rem;
    }
    
    .holdings-details-section .section-header h3 {
        text-align: center;
        font-size: 1.375rem;
    }
    
    .holdings-details-section .section-header .btn {
        padding: 0.875rem;
        font-size: 1rem;
        min-height: 48px;
        border-radius: 12px;
    }
    
    /* Two-column layout becomes single column on mobile */
    .portfolio-layout {
        flex-direction: column;
        gap: 0;
    }
    
    .portfolio-management {
        margin-bottom: 2rem;
    }
    
    /* Summary cards mobile optimization */
    .summary-section {
        margin-bottom: 2rem;
    }
    
    .summary-stats {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .summary-card {
        padding: 1.25rem;
        text-align: center;
        border-radius: 16px;
    }
    
    .summary-card .stat-value {
        font-size: 1.75rem;
        font-weight: 800;
    }
    
    .summary-card .stat-label {
        font-size: 1rem;
        margin-top: 0.5rem;
    }
    
    /* Reorder stat cards on mobile - move Holdings card under Cash Position */
    .stats-grid {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    /* Order: Total Value (1), Cash Position (2), Holdings (3) */
    .stats-grid .stat-card:nth-child(1) { /* Total Value */
        order: 1;
    }
    
    .stats-grid .stat-card:nth-child(2) { /* Holdings - move to position 3 */
        order: 3;
    }
    
    .stats-grid .stat-card:nth-child(3) { /* Cash Position - move to position 2 */
        order: 2;
    }
    
    /* Make allocations card and rebalancing card as wide as stat cards by compensating for container padding */
    .allocations-card,
    .rebalancing-card {
        margin-left: -1rem;
        margin-right: -1rem;
        width: calc(100% + 2rem);
        max-width: calc(100% + 2rem);
    }
    
    /* Force holdings-section and its contents to be visible on mobile */
    .holdings-section {
        display: block !important;
        visibility: visible !important;
        margin: 1.5rem 0;
        padding: 1rem;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        box-shadow: 0 1px 3px var(--shadow);
        margin-left: -1rem;
        margin-right: -1rem;
        width: calc(100% + 2rem);
        max-width: calc(100% + 2rem);
    }
    
    .holdings-section .holdings-summary,
    .holdings-section .section-header {
        display: block !important;
        visibility: visible !important;
    }
    
    /* Hide table and show card layout on mobile */
    .holdings-section .holdings-summary table {
        display: none !important;
    }
    
    /* Mobile holdings cards - create card layout for each holding */
    .holdings-section .holdings-summary::after {
        content: "";
        display: block;
    }
    
    /* Create mobile cards using CSS generated content and JavaScript */
    .holdings-section .holdings-mobile-cards {
        display: block !important;
        gap: 0.75rem;
    }
    
    .holdings-mobile-card {
        background: var(--bg-primary);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 1rem;
        margin-bottom: 0.75rem;
    }
    
    .holdings-mobile-card .card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.75rem;
        padding-bottom: 0.5rem;
        border-bottom: 1px solid var(--border-light);
    }

    /* Delete button in mobile cards */
    .holdings-mobile-card .holding-actions .remove-holding {
        min-width: 44px;
        min-height: 44px;
        padding: 0.75rem 1rem;
        background: var(--bg-secondary);
        border: 1px solid var(--danger);
        color: var(--danger);
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        font-size: 0.875rem;
        font-weight: 500;
    }

    .holdings-mobile-card .holding-actions .remove-holding .btn-icon-symbol {
        font-size: 1rem;
    }

    .holdings-mobile-card .holding-actions .remove-holding .btn-icon-text {
        display: inline;
        font-size: 0.875rem;
        font-weight: 500;
    }

    .holdings-mobile-card .holding-actions .remove-holding:hover {
        background: rgba(239, 68, 68, 0.1);
        border-color: var(--danger-hover);
        color: var(--danger-hover);
    }
    
    .holdings-mobile-card .ticker {
        font-weight: 600;
        font-size: 1.1rem;
        color: var(--text-primary);
    }
    
    .holdings-mobile-card .company-name {
        font-size: 0.8rem;
        color: var(--text-secondary);
        margin-top: 0.25rem;
    }
    
    .holdings-mobile-card .card-body {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }
    
    .holdings-mobile-card .card-field {
        display: flex;
        flex-direction: column;
    }
    
    .holdings-mobile-card .field-label {
        font-size: 0.8rem;
        color: var(--text-secondary);
        margin-bottom: 0.25rem;
    }
    
    .holdings-mobile-card .field-value {
        font-weight: 500;
        color: var(--text-primary);
    }
    
    .holdings-mobile-card .current-allocation {
        color: var(--primary);
        font-weight: 600;
    }
    
    .holdings-mobile-card .price-override-indicator {
        color: var(--warning);
    }
    
    /* Mobile card editable styling */
    .holdings-mobile-card .editable-cell {
        cursor: pointer;
        padding: 0.25rem;
        border-radius: 4px;
        transition: background-color 0.2s;
    }
    
    .holdings-mobile-card .editable-cell:hover {
        background-color: var(--border-light);
    }
    
    .holdings-mobile-card .target-balanced {
        color: var(--success);
    }
    
    .holdings-mobile-card .target-high {
        color: var(--warning);
    }
    
    .holdings-mobile-card .target-low {
        color: var(--danger);
    }
    
    /* Mobile card editing inputs */
    .holdings-mobile-card .edit-input {
        width: 100%;
        padding: 0.25rem;
        border: 1px solid var(--border-color);
        border-radius: 4px;
        background: var(--bg-secondary);
        color: var(--text-primary);
        font-size: 0.9rem;
    }
    
    .holdings-mobile-card .edit-input:focus {
        outline: none;
        border-color: var(--primary);
        box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
    }
    
    .holdings-mobile-card .price-input-wrapper {
        width: 100%;
    }
    
    .holdings-mobile-card .editing {
        background-color: var(--bg-tertiary);
        border-color: var(--primary);
    }

    /* Mobile Add Holding Button */
    .mobile-add-holding-card {
        margin-top: 1rem;
        margin-bottom: 0.75rem;
    }

    .mobile-add-holding-btn {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        padding: 1rem;
        background: var(--bg-primary);
        border: 2px dashed var(--border-color);
        border-radius: 8px;
        color: var(--text-secondary);
        font-size: 1rem;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .mobile-add-holding-btn:hover {
        background: var(--bg-secondary);
        border-color: var(--primary);
        color: var(--primary);
    }

    .mobile-add-holding-btn:active {
        transform: translateY(1px);
    }

    .mobile-add-holding-btn .add-icon {
        font-size: 1.25rem;
        font-weight: bold;
    }

    .mobile-add-holding-btn .add-text {
        font-weight: 500;
    }
    
    /* Prevent horizontal scrolling - ensure all elements fit viewport */
    * {
        box-sizing: border-box;
        max-width: 100vw;
    }
    
    html, body {
        overflow-x: hidden;
        width: 100%;
    }
    
    .container,
    .main-content,
    .portfolio-section {
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    /* Ensure no child elements can cause horizontal scroll */
    .welcome-section,
    .api-setup-section,
    .new-portfolio-section,
    .portfolio-layout,
    .portfolio-management,
    .rebalancing-dashboard,
    .container,
    .main-content,
    .portfolio-section {
        max-width: 100vw !important;
        width: 100% !important;
        overflow-x: hidden;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    /* Header content needs to allow dropdown to be visible */
    .header-content {
        max-width: 100vw !important;
        width: 100% !important;
        overflow: visible; /* Allow dropdowns to be visible */
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box;
    }
    
    /* Ensure form elements don't exceed viewport */
    input,
    select,
    button,
    textarea {
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Hide default mobile card layouts on desktop */
    .holdings-input-mobile,
    .holdings-cards-mobile {
        display: none;
    }
    
    /* Override fixed widths that cause horizontal scrolling */
    .portfolio-recommendations-column,
    .custom-dropdown,
    .header-nav,
    .portfolio-selector {
        min-width: unset !important;
        width: 100% !important;
    }
    
    /* Ensure flex columns stack properly */
    .portfolio-column,
    .rebalancing-column {
        min-width: unset !important;
        flex: 1 1 100% !important;
    }
    
    /* Remove sticky positioning that can cause layout issues */
    .portfolio-recommendations-column {
        position: static !important;
    }
}

/* ===== HEADER ACTIONS & API SETTINGS ===== */
.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.settings-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
}

.settings-btn:hover {
    background: var(--bg-accent);
    color: var(--text-primary);
    border-color: var(--primary);
}

.settings-icon {
    font-size: 1rem;
}

.settings-label {
    font-weight: 500;
}

/* API Setup Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 1.5rem 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.api-setup-modal .modal-body p {
    margin-bottom: 1.5rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.api-setup-modal .modal-body ol {
    margin-bottom: 2rem;
    padding-left: 1.5rem;
}

.api-setup-modal .modal-body ol li {
    margin-bottom: 0.75rem;
    line-height: 1.5;
}

/* API Key Status Section */
.api-key-status {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.api-key-status h3 {
    margin: 0 0 1rem 0;
    color: var(--text-primary);
    font-size: 1.125rem;
}

.api-key-display {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 0.75rem;
    background: var(--bg-primary);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.api-key-preview {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.api-key-status-badge {
    font-size: 0.75rem;
    color: var(--success-color);
    font-weight: 600;
}

.api-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn-danger {
    background: #dc3545;
    color: white;
    border: 1px solid #dc3545;
}

.btn-danger:hover {
    background: #c82333;
    border-color: #bd2130;
}

.btn-danger:focus {
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.25);
}

/* Hidden class for when no portfolios exist */
.portfolio-list-table.hidden {
    display: none !important;
}

/* Desktop portfolio management - show table, hide mobile cards */
@media (min-width: 769px) {
    .portfolio-list-container .portfolio-list-table {
        display: table !important;
    }

    .portfolio-list-container .portfolio-list-table.hidden {
        display: none !important;
    }

    .portfolio-list-container .portfolio-cards-mobile {
        display: none !important;
    }
}

@media (max-width: 768px) {
    /* Mobile header actions - stack vertically */
    .header-actions {
        flex-direction: column;
        gap: 0.75rem;
        width: 100%;
        align-items: stretch;
    }
    
    .settings-btn {
        width: 100%;
        justify-content: center;
        padding: 0.875rem;
        min-height: 48px;
        font-size: 1rem;
    }

    .settings-label {
        font-size: 1rem;
    }

    /* Mobile allocation total indicator */
    .allocation-total-indicator {
        align-self: center;
        margin-bottom: 0.5rem;
        order: 1;
    }

    /* Mobile Templates and Refresh Prices buttons */
    .preset-templates-dropdown {
        width: 100%;
        order: 2;
    }

    #presetTemplatesBtn,
    #refreshPricesBtn {
        width: 100%;
        order: 3;
        margin-top: 0.5rem;
    }
    
    /* Mobile modal - only affect specific complex modals */
    #apiSetupModal.modal-overlay {
        padding: 0;
    }

    .modal-content {
        border-radius: 0;
        min-height: 100vh;
        max-height: 100vh;
    }
    
    .modal-header {
        padding: 1rem;
        position: sticky;
        top: 0;
        background: var(--bg-primary);
        z-index: 10;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    /* Mobile portfolio management - hide desktop table on mobile screens */
    .portfolio-list-container .portfolio-list-table {
        display: none !important;
    }

    /* Show mobile cards on mobile screens */
    .portfolio-cards-mobile {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .portfolio-card-mobile {
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 1.25rem;
        position: relative;
        box-shadow: 0 2px 4px var(--shadow);
    }

    .portfolio-card-mobile.selected {
        background: var(--bg-tertiary);
        border-left: 3px solid var(--primary);
    }

    .portfolio-card-mobile .portfolio-card-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 1rem;
    }

    .portfolio-card-mobile .portfolio-checkbox {
        margin-right: 0.75rem;
        transform: scale(1.1);
    }

    .portfolio-card-mobile .portfolio-name {
        font-weight: 600;
        font-size: 1.1rem;
        color: var(--text-primary);
        margin: 0;
    }

    .portfolio-card-mobile .portfolio-details {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .portfolio-card-mobile .detail-item {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }

    .portfolio-card-mobile .detail-label {
        font-size: 0.875rem;
        color: var(--text-secondary);
        font-weight: 500;
    }

    .portfolio-card-mobile .detail-value {
        font-size: 0.875rem;
        color: var(--text-primary);
    }

    .portfolio-card-mobile .portfolio-actions {
        display: flex;
        gap: 0.5rem;
        margin-top: 1rem;
    }

    .portfolio-card-mobile .portfolio-actions .btn {
        flex: 1;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        border-radius: 8px;
        min-height: 44px;
    }

    .api-key-status {
        padding: 1rem;
    }
    
    .api-actions {
        flex-direction: column;
    }

    .api-actions button {
        width: 100%;
    }

    /* Make selection and section actions mobile-friendly */
    .selection-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .selection-actions .btn {
        padding: 0.875rem;
        font-size: 1rem;
        min-height: 48px;
    }

    .section-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .section-actions .btn {
        padding: 0.875rem;
        font-size: 1rem;
        min-height: 48px;
    }
}

/* Rebalancing error and warning messages */
.error-message {
    background: var(--bg-secondary);
    border: 2px solid var(--danger);
    border-radius: 8px;
    padding: 1.5rem;
    margin: 1rem 0;
    color: var(--text-primary);
}

.error-message h3 {
    color: var(--danger);
    margin-bottom: 0.75rem;
    font-size: 1.125rem;
}

.error-message p {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.error-message small {
    color: var(--text-secondary);
    font-style: italic;
}

.cash-flow-warning {
    background: var(--bg-secondary);
    border: 2px solid var(--warning);
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
    color: var(--text-primary);
}

.cash-flow-warning h4 {
    color: var(--warning);
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.cash-flow-warning p {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.4;
}

.constraint-warning {
    background: var(--bg-secondary);
    border: 2px solid var(--info);
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
    color: var(--text-primary);
}

.constraint-warning h4 {
    color: var(--info);
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.constraint-warning p {
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    line-height: 1.4;
}

.constraint-warning small {
    color: var(--text-secondary);
    font-style: italic;
}
