/* Filter Section Styles - Matching Reference */
.filter-section {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.filter-group {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 15px;
}

.filter-group h6 {
    margin-top: 0;
    margin-bottom: 12px;
    color: #495057;
    font-weight: 600;
    font-size: 14px;
}

.filter-row {
    margin-bottom: 10px;
}

.filter-row:last-child {
    margin-bottom: 0;
}

.filter-label {
    font-weight: 500;
    color: #6c757d;
    font-size: 13px;
    display: block;
    margin-bottom: 5px;
}

.filter-input, .filter-input select {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s;
    width: 100%;
}

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

.filter-checkbox {
    margin-right: 8px;
}

.advanced-filters {
    display: none;
}

.toggle-advanced {
    cursor: pointer;
    color: #007bff;
    text-decoration: none;
    font-weight: 500;
    float: right;
}

.toggle-advanced:hover {
    text-decoration: underline;
}

.filter-actions {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e9ecef;
}

/* Date Preset Buttons */
.date-presets {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.date-preset {
    flex: 1;
    padding: 6px 10px;
    font-size: 12px;
    white-space: nowrap;
    background: #fff;
    border: 1px solid #ced4da;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.date-preset:hover {
    background-color: #e9ecef;
}

.date-preset.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

/* Period Statistics */
.summary-stats {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

@media (min-width: 1024px) {
    .stat-grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

.stat-group {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    border: 1px solid #e9ecef;
    text-align: center;
}

.stat-group-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: #6c757d;
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 28px;
    font-weight: bold;
    color: #1f2937;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 13px;
    color: #6b7280;
}

.stat-sublabel {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 5px;
}

/* Period Statistics Compact View */
.stats-compact-metric {
    text-align: center;
    border-right: 1px solid #e9ecef;
}

.stats-compact-metric:last-child {
    border-right: none;
}

.stats-compact-value {
    font-size: 18px;
    font-weight: bold;
    color: #212529;
}

.stats-compact-label {
    font-size: 10px;
    color: #6c757d;
    text-transform: uppercase;
}

.stats-date-range {
    font-size: 12px;
    font-weight: 400;
    color: #6c757d;
    margin-left: 8px;
}

/* Period Statistics Detailed View */
.stats-detail-card {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 10px;
}

.stats-detail-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: #6c757d;
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.stats-detail-value {
    font-size: 20px;
    font-weight: bold;
    color: #212529;
}

.stats-detail-label {
    font-size: 10px;
    color: #6c757d;
    margin-top: 4px;
}

.stats-divider {
    border-top: 1px solid #e9ecef;
}

/* Expandable Order Cards */
.order-item-card {
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    margin-bottom: 12px;
    overflow: hidden;
    transition: all 0.2s ease;
    background: #fff;
    border: 1px solid #e9ecef;
}

.order-item-card:hover {
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

.order-item-card.negative-profit {
    border-left: 4px solid #dc3545;
    background-color: #fff5f5;
}

.order-item-card.positive-profit {
    border-left: 4px solid #28a745;
}

.order-item-card.own-stock.positive-profit {
    background-color: #e8f5e9;
}

.order-item-card.own-stock.negative-profit {
    background-color: #ffebee !important;
}

.order-summary {
    padding: 8px 12px;
    cursor: pointer;
    position: relative;
    background: rgba(255,255,255,0.7);
}

.order-summary:hover {
    background: rgba(255,255,255,0.9);
}

.order-summary-grid {
    display: flex;
    align-items: center;
    gap: 10px;
}

.summary-item {
    flex: 1;
    min-width: 0;
}

.summary-item.order-info {
    flex: 1.5;
}

.summary-item.financial {
    text-align: center;
    position: relative;
}

.expand-chevron {
    transition: transform 0.3s ease;
}

.expand-chevron.rotated {
    transform: rotate(180deg);
}

.summary-item.profit {
    text-align: right;
    flex: 1.2;
}

.summary-label {
    font-size: 9px;
    color: #6c757d;
    text-transform: uppercase;
    margin-bottom: 1px;
}

.summary-value {
    font-size: 12px;
    font-weight: 600;
    color: #212529;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.summary-value.positive {
    color: #0d6e0d;
}

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

.summary-subvalue {
    font-size: 10px;
    color: #6c757d;
    margin-top: 1px;
}

.expand-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    transition: transform 0.2s ease;
    font-size: 12px;
}

.order-item-card.expanded .expand-icon {
    transform: translateY(-50%) rotate(180deg);
}

.order-details {
    display: none;
    border-top: 1px solid #e9ecef;
    background: white;
    padding: 15px;
}

.order-item-card.expanded .order-details {
    display: block;
}

.financial-summary {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
}

.financial-metric {
    text-align: center;
}

.financial-metric .label {
    font-size: 9px;
    color: #6c757d;
    text-transform: uppercase;
}

.financial-metric .value {
    font-size: 13px;
    font-weight: 600;
}

.price-breakdown {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
    font-size: 11px;
}

.source-info {
    font-size: 10px;
    color: #6c757d;
    margin-top: 4px;
}

.commission-box, .fee-box, .discount-box {
    background: #fff3cd;
    border: 1px solid #ffc107;
    padding: 6px;
    margin-bottom: 6px;
    border-radius: 3px;
    font-size: 11px;
}

.fee-box {
    background: #f8d7da;
    border-color: #dc3545;
}

.discount-box {
    background: #d1ecf1;
    border-color: #17a2b8;
}

.profit-breakdown-section {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 4px;
    border: 1px solid #e5e7eb;
}

.total-line {
    margin-top: 6px;
    font-size: 11px;
    padding-top: 6px;
    border-top: 1px solid #e5e7eb;
    margin-bottom: 3px;
}

.net-result-line {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 2px solid #e5e7eb;
    text-align: center;
}

.net-margin-banner {
    margin-top: 10px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
    text-align: center;
    border: 1px solid #e5e7eb;
}

/* Legend and Formula */
/* Reference Information Box (unified legend + formula) */
.reference-info-box {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 15px;
}

.reference-section-title {
    color: #495057;
}

.legend-box {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 15px;
}

.legend-item {
    display: inline-block;
    margin-right: 15px;
    margin-bottom: 8px;
    font-size: 11px;
}

.legend-color {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 6px;
}

.formula-box {
    background: #f0f8ff;
    border: 1px solid #d0e8ff;
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 15px;
}

.formula-box h6 {
    cursor: pointer;
    user-select: none;
    margin: 0;
}

.formula-content {
    display: none;
    margin-top: 15px;
    font-size: 11px;
    line-height: 1.6;
}

.formula-group {
    margin-bottom: 12px;
}

.formula-group strong {
    display: block;
    margin-bottom: 4px;
    color: #495057;
}

.formula-item {
    padding-left: 15px;
    color: #6c757d;
    margin-bottom: 2px;
}

.formula-summary {
    background: white;
    padding: 10px;
    border-radius: 4px;
    margin-top: 12px;
    border: 1px solid #e0e0e0;
}

/* Confidence Badges */
.confidence-indicator {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
    display: inline-block;
}

.confidence-high {
    background: #d4edda;
    color: #155724;
}

.confidence-medium {
    background: #fff3cd;
    color: #856404;
}

.confidence-low {
    background: #f8d7da;
    color: #721c24;
}

/* Utility Classes */
.text-success {
    color: #28a745 !important;
    font-weight: 600;
}

.text-danger {
    color: #dc3545 !important;
    font-weight: 600;
}

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.badge-secondary {
    background: #6c757d;
    color: white;
}

/* Responsive */
@media (max-width: 768px) {
    .orders-table {
        font-size: 10px;
    }

    .orders-table th, .orders-table td {
        padding: 6px;
    }
}

/* ===========================
   DARK MODE STYLES
   =========================== */
.dark .filter-section {
    background: #1f2937;
    color: #e5e7eb;
}

.dark .filter-group {
    background: #374151;
    border-color: #4b5563;
}

.dark .filter-group h6 {
    color: #f3f4f6;
}

.dark .filter-label {
    color: #d1d5db;
}

.dark .filter-input,
.dark .filter-input select {
    background: #1f2937;
    border-color: #4b5563;
    color: #e5e7eb;
}

.dark .filter-input:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
}

.dark .filter-input:disabled {
    background: #111827;
    color: #6b7280;
}

.dark .filter-actions {
    border-top-color: #4b5563;
}

.dark .date-preset {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
}

.dark .date-preset:hover {
    background: #4b5563;
}

.dark .date-preset.active {
    background: #2563eb;
    border-color: #2563eb;
    color: white;
}

.dark .summary-stats {
    background: #1f2937;
    color: #e5e7eb;
}

.dark .stat-group {
    background: #374151;
    border-color: #4b5563;
}

.dark .stat-group-title {
    color: #9ca3af;
}

.dark .stat-value {
    color: #f3f4f6;
}

.dark .stat-label {
    color: #d1d5db;
}

.dark .stat-sublabel {
    color: #9ca3af;
}

.dark .order-item-card {
    background: #1f2937;
    border-color: #4b5563;
}

.dark .order-item-card.negative-profit {
    background-color: #3a1a1a;
    border-left-color: #ef4444;
}

.dark .order-item-card.own-stock.positive-profit {
    background-color: #1a2e1a;
}

.dark .order-item-card.own-stock.negative-profit {
    background-color: #3a1a1a !important;
}

.dark .order-summary {
    background: rgba(31,41,55,0.7);
}

.dark .order-summary:hover {
    background: rgba(31,41,55,0.9);
}

.dark .summary-label {
    color: #9ca3af;
}

.dark .summary-value {
    color: #e5e7eb;
}

.dark .summary-value.positive {
    color: #4ade80;
}

.dark .summary-value.negative {
    color: #f87171;
}

.dark .summary-subvalue {
    color: #9ca3af;
}

.dark .expand-chevron {
    color: #9ca3af;
}

.dark .order-details {
    background: #1f2937;
    border-top-color: #4b5563;
    color: #e5e7eb;
}

.dark .order-details h6 {
    color: #f3f4f6 !important;
}

.dark .order-details p,
.dark .order-details strong {
    color: #e5e7eb !important;
}

.dark .price-breakdown {
    background: #374151;
    color: #e5e7eb;
    border: 1px solid #4b5563;
}

.dark .commission-box {
    background: #5c5328;
    border-color: #d97706;
    color: #fcd34d;
}

.dark .fee-box {
    background: #7f1d1d;
    border-color: #dc2626;
    color: #fca5a5;
}

.dark .discount-box {
    background: #164e63;
    border-color: #0891b2;
    color: #67e8f9;
}

.dark .source-info {
    color: #9ca3af !important;
}

.dark .text-success {
    color: #4ade80 !important;
}

.dark .text-danger {
    color: #f87171 !important;
}

.dark .text-primary {
    color: #60a5fa !important;
}

.dark .profit-breakdown-section {
    background: #374151 !important;
    border-color: #4b5563 !important;
}

.dark .total-line {
    border-top-color: #4b5563 !important;
}

.dark .net-result-line {
    border-top-color: #4b5563 !important;
}

.dark .net-margin-banner {
    background: #374151 !important;
    border-color: #4b5563 !important;
    color: #e5e7eb !important;
}

.dark .net-margin-banner strong {
    color: #f3f4f6 !important;
}

.dark .calculated-results-box {
    background: #374151 !important;
    border-color: #4b5563 !important;
}

.dark .calculated-results-box hr {
    border-top-color: #4b5563 !important;
}

/* Reference Information Box - Dark Mode */
.dark .reference-info-box {
    background: rgb(24, 24, 27);
    border-color: rgb(63, 63, 70);
}

.dark .reference-section-title {
    color: rgb(161, 161, 170);
}

/* Dark mode flag and indicator visibility */
.dark .summary-value svg[title] {
    color: #fbbf24 !important; /* Bright yellow for better visibility */
}

.dark .summary-value svg[style*="#dc3545"] {
    color: #f87171 !important; /* Bright red for better visibility */
}

.dark .summary-value svg[style*="#ffc107"] {
    color: #fbbf24 !important; /* Bright yellow for DATE_PART_MATCH */
}

.dark .summary-value span[title*="Estimated"],
.dark .summary-value span[title*="Fee Data: Estimated"] {
    color: #fb923c !important; /* Bright orange for approximation sign */
}

.dark .summary-value span[title*="Actual"],
.dark .summary-value span[title*="Fee Data: Actual"] {
    color: #4ade80 !important; /* Bright green for equals sign */
}

/* Dark mode for expanded row sections */
.dark .order-details {
    background: #1f2937;
    border-top-color: #4b5563;
}

.dark .order-details h6 {
    color: #f3f4f6 !important;
}

.dark .order-details p {
    color: #e5e7eb !important;
}

.dark .order-details hr {
    border-top-color: #4b5563 !important;
}

/* Dark mode for color-coded boxes */
.dark .order-details .col-md-4 div[style*="background: #fff3cd"] {
    background: #78350f !important; /* Dark yellow */
    border-color: #92400e !important;
}

.dark .order-details .col-md-4 div[style*="background: #f8d7da"] {
    background: #7f1d1d !important; /* Dark red */
    border-color: #991b1b !important;
}

.dark .order-details .col-md-4 div[style*="background: #d1ecf1"] {
    background: #164e63 !important; /* Dark cyan */
    border-color: #155e75 !important;
}

.dark .order-details .col-md-4 div[style*="background: #f8f9fa"] {
    background: #374151 !important; /* Dark gray */
    border-color: #4b5563 !important;
}

.dark .legend-box {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
}

.dark .formula-box {
    background: #1e3a4a;
    border-color: #2d5a7a;
}

.dark .formula-box h6 {
    color: #f3f4f6;
}

.dark .formula-group strong {
    color: #f3f4f6;
}

.dark .formula-item {
    color: #d1d5db;
}

.dark .formula-summary {
    background: rgb(39, 39, 42);
    border-color: rgb(63, 63, 70);
}

.dark .formula-content > div[style*="background: white"] {
    background: #374151 !important;
    border-color: #4b5563 !important;
}

.dark .confidence-high {
    background: #1b5e3f;
    color: #a8e6a3;
}

.dark .confidence-medium {
    background: #5c5328;
    color: #f0e68c;
}

.dark .confidence-low {
    background: #4a3333;
    color: #f8d7da;
}

.dark .badge-secondary {
    background: #4b5563;
    color: #e5e7eb;
}

.dark .text-success {
    color: #4ade80 !important;
}

.dark .text-danger {
    color: #f87171 !important;
}

/* Dark mode info box */
.dark div[style*="background: #e7f3ff"] {
    background: #1e3a4a !important;
    border-color: #2d5a7a !important;
    color: #e5e7eb !important;
}

.dark div[style*="background: #e7f3ff"] i {
    color: #60a5fa !important;
}

/* Dark mode for inline styles */
.dark h1, .dark h2, .dark h3, .dark h4, .dark h5, .dark h6 {
    color: #f3f4f6 !important;
}

.dark span[style*="color: #6c757d"] {
    color: #9ca3af !important;
}

/* Dark mode for structured boxes */
.dark div[style*="background: #f8f9fa"] {
    background: #374151 !important;
    border-color: #4b5563 !important;
}

.dark div[style*="background: #e8f5e9"] {
    background: #1b4332 !important;
    border-color: #2d6a4f !important;
}

.dark div[style*="background: #e8f5e9"] h6 {
    color: #74c69d !important;
    border-bottom-color: #2d6a4f !important;
}

.dark div[style*="background: #ffebee"] {
    background: #4a1c1c !important;
    border-color: #7f1d1d !important;
}

.dark div[style*="background: #ffebee"] h6 {
    color: #fca5a5 !important;
    border-bottom-color: #7f1d1d !important;
}

.dark div[style*="background: #fff8e1"] {
    background: #4a3f1c !important;
    border-color: #92741c !important;
}

.dark div[style*="background: #fff8e1"] h6 {
    color: #fde047 !important;
    border-bottom-color: #92741c !important;
}

.dark div[style*="background: #e3f2fd"] {
    background: #1e3a5f !important;
    border-color: #2563eb !important;
}

.dark div[style*="background: #e3f2fd"] h6 {
    color: #60a5fa !important;
    border-bottom-color: #2563eb !important;
}

.dark div[style*="background: #e3f2fd"] hr {
    border-top-color: #2563eb !important;
}

/* ========================================
   DARK MODE FIXES - Comprehensive
   ======================================== */

/* Period Statistics - CRITICAL FIX */
.dark .summary-stats {
    background: rgb(24, 24, 27);
    color: rgb(229, 231, 235);
    box-shadow: 0 1px 3px rgba(255,255,255,0.05);
}

/* Stat Groups */
.dark .stat-group {
    background: rgb(39, 39, 42);
    border: 1px solid rgb(63, 63, 70);
}

.dark .stat-group-title {
    color: rgb(161, 161, 170);
}

/* Order Item Cards - CRITICAL FIX */
.dark .order-item-card {
    background: rgb(39, 39, 42);
    box-shadow: rgba(0, 0, 0, 0.3) 0px 1px 2px 0px;
}

.dark .order-item-card.negative-profit {
    background: rgb(76, 29, 29);
    border: 1px solid rgb(127, 29, 29);
}

.dark .order-item-card.positive-profit {
    background: rgb(39, 39, 42);
}

/* Period Statistics Compact View - Dark Mode */
.dark .stats-compact-metric {
    border-right-color: rgb(63, 63, 70);
}

.dark .stats-compact-value {
    color: rgb(229, 231, 235);
}

.dark .stats-compact-label {
    color: rgb(161, 161, 170);
}

.dark .stats-date-range {
    color: rgb(161, 161, 170);
}

/* Period Statistics Detailed View - Dark Mode */
.dark .stats-detail-card {
    background: rgb(39, 39, 42);
    border-color: rgb(63, 63, 70);
}

.dark .stats-detail-title {
    color: rgb(161, 161, 170);
}

.dark .stats-detail-value {
    color: rgb(229, 231, 235);
}

.dark .stats-detail-label {
    color: rgb(161, 161, 170);
}

.dark .stats-divider {
    border-top-color: rgb(63, 63, 70);
}

/* Modal Headings - CRITICAL FIX */
.modal-title {
    font-weight: 600;  /* Increase from 400 */
}

.dark .modal-title {
    color: rgb(243, 244, 246);
}

/* Filter Section */
.dark .filter-section {
    background: rgb(24, 24, 27);
}

.dark .filter-group {
    background: rgb(39, 39, 42);
    border: 1px solid rgb(63, 63, 70);
}

.dark .filter-group h6 {
    color: rgb(229, 231, 235);
}

.dark .filter-label {
    color: rgb(161, 161, 170);
}

/* Filter Inputs */
.dark .filter-input,
.dark .filter-input select {
    background: rgb(39, 39, 42);
    border: 1px solid rgb(63, 63, 70);
    color: rgb(229, 231, 235);
}

.dark .filter-input:focus {
    border-color: rgb(59, 130, 246);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Date Presets */
.dark .date-preset {
    background: rgb(39, 39, 42);
    border: 1px solid rgb(63, 63, 70);
    color: rgb(229, 231, 235);
}

.dark .date-preset:hover {
    background-color: rgb(63, 63, 70);
}

.dark .date-preset.active {
    background-color: rgb(59, 130, 246);
    color: white;
    border-color: rgb(59, 130, 246);
}

/* Toggle Advanced */
.dark .toggle-advanced {
    color: rgb(96, 165, 250);
}

/* Filter Actions */
.dark .filter-actions {
    border-top: 1px solid rgb(63, 63, 70);
}
