/* /public/css/receipts.css */

/* Specialized Thumbnail styling for the Ledger */
.receipt-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: #0f172a;
    transition: transform 0.2s;
    cursor: zoom-in;
}

.receipt-thumb:hover {
    transform: scale(1.1);
    border-color: #3b82f6;
}

.receipt-thumbnail-wrapper {
    display: inline-block;
    vertical-align: middle;
}

/* Spending Summary Tiles */
.spending-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.stat-tile {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #94a3b8;
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
    position: relative;
}

.tile-toggle-icon {
    display: none;
}

.stat-breakdown {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: fit-content;
    margin: 0 auto;
    align-items: stretch;
    transition: all 0.3s ease;
}

.breakdown-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
    gap: 60px;
}

.breakdown-store {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 8px;
}

.breakdown-total {
    font-weight: 600;
    color: #69f0ae;
    text-align: right;
}

/* Store Icons */
.store-icon-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.store-logo {
    width: 24px;
    height: 24px;
    object-fit: contain;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
}

.stat-breakdown .store-logo {
    width: 18px;
    height: 18px;
    margin: 0;
}

/* Filtering Bar */
.ledger-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    background: rgba(30, 41, 59, 0.5);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 25px;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    justify-content: flex-start;
}

.filter-group {
    flex: 0 0 auto; /* Don't grow by default */
    min-width: 140px;
}

/* Make search input soak up all remaining dead space */
.filter-group:first-child {
    flex: 1;
}

#filterMinAmount {
    max-width: 120px;
}

.btn-icon-reset {
    background: #0ea5e9;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    flex: 0 0 auto;
}

.btn-icon-reset:hover {
    background: #0284c7;
    transform: rotate(-45deg);
}

.filter-input, .filter-select {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #f1f5f9;
    padding: 8px 12px;
    font-size: 0.9rem;
    transition: all 0.2s;
    outline: none;
}

.filter-input:focus, .filter-select:focus {
    border-color: #3b82f6;
    background: rgba(15, 23, 42, 0.8);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.filter-select option {
    background: #1e293b;
    color: white;
}

/* Image Viewer Modal Specifics */
.image-modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: inline-block;
}

/* Upload Progress Overlay */
/* Covers the full viewport while the server runs ImageMagick + Tesseract.    */
/* z-index 99998 sits below the toast container (99999) so toasts still show. */

.upload-progress-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(5, 12, 29, 0.92);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99998;
}

.upload-progress-inner {
    text-align: center;
    max-width: 420px;
    padding: 2rem;
}

.upload-spinner {
    width: 64px;
    height: 64px;
    border: 4px solid rgba(59, 130, 246, 0.2);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: upload-spin 0.9s linear infinite;
    margin: 0 auto 1.75rem;
}

@keyframes upload-spin {
    to { transform: rotate(360deg); }
}

.upload-progress-label {
    font-size: 1.25rem;
    font-weight: 300;
    color: #ffffff;
    margin: 0 0 0.75rem;
    transition: opacity 0.3s ease;
}

.upload-progress-sub {
    font-size: 0.875rem;
    color: #94a3b8;
    margin: 0;
}

/* Electronic Receipt (AI) Styles */
.ereceipt-modal-content {
    max-width: 500px;
    background: #1e293b;
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.ereceipt-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ereceipt-body {
    font-family: 'Courier New', Courier, monospace;
    color: #e2e8f0;
    line-height: 1.4;
}

.ereceipt-actions {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    justify-content: center;
}

.btn-ereceipt-rescan {
    width: auto;
    padding: 0 15px;
    height: 38px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ereceipt-summary {
    text-align: center;
    margin-bottom: 20px;
}

.ereceipt-store-name {
    margin: 0;
    font-size: 1.4rem;
    text-transform: uppercase;
}

.ereceipt-store-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
    margin-bottom: 10px;
    filter: drop-shadow(0 0 5px rgba(255,255,255,0.1));
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
}

.ereceipt-location {
    margin: 5px 0;
    font-size: 0.8rem;
    opacity: 0.7;
}

.ereceipt-datetime {
    margin: 5px 0;
    font-size: 0.85rem;
}

.ereceipt-items-list {
    margin-bottom: 20px;
}

.ereceipt-item {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
    padding: 8px 0;
    font-size: 0.9rem;
}

.ereceipt-item-desc {
    font-weight: 600;
}

.ereceipt-item-qty {
    opacity: 0.6;
}

.ereceipt-item-price {
    font-family: monospace;
}

.ereceipt-empty-items {
    text-align: center;
    opacity: 0.5;
}

.ereceipt-total-container {
    border-top: 2px solid rgba(255, 255, 255, 0.2);
    padding-top: 10px;
    margin-top: 10px;
}

.ereceipt-total-row {
    display: flex;
    justify-content: space-between;
    font-size: 1.2rem;
    font-weight: bold;
}

.ereceipt-payment {
    text-align: right;
    margin-top: 10px;
    font-size: 0.8rem;
    opacity: 0.7;
}

/* UI Utility Classes for Receipts */
.receipt-col-preview { text-align: center; }
.ai-badge { font-size: 0.8rem; margin-left: 5px; }
.receipt-description { color: rgba(255, 255, 255, 0.4); }
.receipt-total-value { color: #69f0ae; font-weight: bold; }
.receipt-empty-ledger { text-align: center; padding: 40px; color: rgba(255, 255, 255, 0.4); }

.receipt-edit-grid {
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 15px;
}

.crop-preview-container {
    text-align: center;
}

.crop-img-wrapper {
    max-height: 60vh; 
    overflow: hidden; 
    background: #000; 
    border-radius: 8px;
}

.crop-img-el {
    max-width: 100%; 
    display: block;
}

.crop-help-text {
    margin-top: 15px; 
    color: #94a3b8; 
    font-size: 0.85rem;
}

.crop-modal-actions, .edit-modal-actions {
    justify-content: center !important;
    gap: 15px;
}

.btn-ai-apply {
    background: #4338ca;
    color: white !important;
    border: none;
    border-radius: 8px;
    height: 38px;
    padding: 0 15px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-ai-apply:hover {
    background: #3730a3;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(67, 56, 202, 0.3);
}

.receipt-modal-img {
    max-width: 100%; 
    border-radius: 8px;
}

.ereceipt-item-content {
    flex: 1;
}

/* Mobile Responsiveness for Receipts Table (Gold Standard from files.css) */
@media (max-width: 768px) {
    .spending-stats {
        grid-template-columns: 1fr;
        gap: 15px;
        margin-bottom: 20px;
    }
    
    /* Collapsible Logic for Mobile */
    .stat-tile {
        cursor: pointer;
        padding: 15px;
    }
    .stat-value {
        font-size: 1.5rem;
        margin-bottom: 0;
        border-bottom: none;
        padding-bottom: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 10px;
    }
    .stat-breakdown {
        display: none;
        margin-top: 15px;
        padding-top: 15px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    .stat-tile.expanded .stat-breakdown {
        display: flex;
    }
    .stat-tile.expanded .stat-value {
        margin-bottom: 0;
        border-bottom: none;
        padding-bottom: 0;
    }
    .stat-tile.expanded .tile-toggle-icon {
        transform: rotate(180deg);
    }
    .tile-toggle-icon {
        display: inline-block;
        font-size: 0.8rem;
        transition: transform 0.3s ease;
        opacity: 0.5;
    }

    .ledger-filters {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        padding: 12px;
    }

    .filter-group {
        min-width: 0;
        width: 100%;
    }

    /* Row 1: Search (Full Width) */
    .filter-group:first-child {
        grid-column: span 3;
    }

    /* Row 3: Ensure Reset button is not too wide */
    .btn-icon-reset {
        width: 38px !important;
        height: 38px !important;
        margin-left: 0;
        justify-self: center;
    }

    .files-table thead { display: none; }
    .files-table, .files-table tbody { display: block; background: transparent; box-shadow: none; border: none; }
    .files-table tr {
        display: block; background: #1e293b; border-radius: 0.75rem; padding: 1rem; margin-bottom: 0.75rem; border: 1px solid #334155; position: relative; padding-left: 4.5rem;
    }
    .files-table td { display: block; padding: 0.25rem 0; border: none; width: 100% !important; text-align: left !important; }
    .files-table td::before {
        content: attr(data-label); font-weight: 600; color: #94a3b8; text-transform: uppercase; font-size: 0.7rem; margin-right: 0.5rem; min-width: 80px; display: inline-block;
    }
    .col-icon { position: absolute; left: 0.75rem; top: 1.5rem; width: 3rem !important; display: flex; justify-content: center; font-size: 2rem; padding: 0 !important; }
    .col-icon::before { content: none !important; }
    
    /* Action Button Container Aligned with Files standard */
    .action-buttons { 
        display: flex; 
        justify-content: center; 
        gap: 0.5rem; 
        margin-top: 0.5rem; 
        padding-top: 0.75rem; 
        border-top: 1px solid #334155;
        margin-left: -3.5rem; /* Counteract parent padding to center globally */
    }
    .col-actions::before { content: none !important; }

    /* Fix column wrapping in upload form */
    .admin-container .edit-form > div[style*="grid"] {
        grid-template-columns: 1fr !important;
        gap: 0 !important;
    }
}

/* Receipt Upload Modal specific styles */
.receipt-upload-modal .modal-content {
    max-width: 500px;
    width: 95%;
    border: none;
}

.file-drop-area {
    cursor: pointer;
    height: 250px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 2px dashed rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    transition: all 0.3s ease;
}

.file-drop-area:hover, .file-drop-area.dragover {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
}

.drop-hint {
    text-align: center;
    color: var(--text-secondary);
    line-height: 1.6;
}

.upload-file-name {
    margin-top: 10px;
    font-weight: 600;
    color: #fff;
    font-size: 0.9rem;
}

.upload-actions {
    justify-content: center !important;
    margin-top: 20px;
}
