/* ==========================================================================
   💾 CORE RESET, VARIABLE ARCHITECTURE & CUSTOM BRACKET BRAND COLORS
   ========================================================================== */
* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

:root {
    --bg-color: #fafaf9;
    --text-color: #44403c;
    --headline-color: #1c1917;
    --card-bg: #ffffff;
    --border-color: #e7e5e4;
    
    --primary: #dc2626; /* Pack O' Jacks Crimson */
    --primary-hover: #b91c1c;
    --primary-glow: rgba(220, 38, 38, 0.12);
    --accent-gold: #eab308;
    --secondary: #78716c;
    --success: #16a34a;
    --danger: #dc2626;
    
    --shadow-sm: 0 1px 3px rgba(28, 25, 23, 0.05);
    --shadow-md: 0 10px 25px -5px rgba(28, 25, 23, 0.08);
    --shadow-lg: 0 20px 40px -10px rgba(28, 25, 23, 0.15);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 24px;
    
    --paid-color: #16a34a;
    --paid-bg: rgba(22, 163, 74, 0.1);
    --unpaid-color: #d97706;
    --unpaid-bg: rgba(217, 119, 6, 0.1);
    
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-blur: blur(16px);
}

body.dark-theme {
    --bg-color: #1c1917;
    --text-color: #a8a29e;
    --headline-color: #f5f5f4;
    --card-bg: #262220;
    --border-color: #44403c;
    
    --primary: #ef4444;
    --primary-hover: #dc2626;
    --primary-glow: rgba(239, 68, 68, 0.2);
    --secondary: #87807b;
    --success: #4ade80;
    --danger: #f87171;
    
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 12px 30px -8px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 50px -12px rgba(0, 0, 0, 0.6);
    
    --paid-color: #4ade80;
    --paid-bg: rgba(74, 222, 128, 0.1);
    --unpaid-color: #fbbf24;
    --unpaid-bg: rgba(251, 191, 36, 0.1);
    
    --glass-bg: rgba(38, 34, 32, 0.85);
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: hidden; /* Prevent body horizontal overscroll handles */
}

.hidden { display: none !important; }

/* ==========================================================================
   🎛️ BUTTONS & CONTROLS INTERACTIVE MATRIX
   ========================================================================== */
.btn { 
    padding: 0.65rem 1.25rem; 
    border-radius: var(--radius-sm); 
    border: 1px solid transparent;
    font-weight: 600; 
    font-size: 0.9rem; 
    cursor: pointer; 
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); 
    display: inline-flex; 
    align-items: center; 
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); scale: 0.98; }

.primary-btn { 
    background-color: var(--primary); 
    color: #ffffff; 
    box-shadow: 0 4px 12px var(--primary-glow);
}
.primary-btn:hover { 
    background-color: var(--primary-hover);
    box-shadow: 0 6px 20px var(--primary-glow);
}

.secondary-btn { 
    background-color: var(--card-bg); 
    color: var(--text-color); 
    border-color: var(--border-color); 
    box-shadow: var(--shadow-sm);
}
.secondary-btn:hover { 
    background-color: var(--bg-color);
    color: var(--headline-color);
    border-color: var(--secondary);
}

.danger-btn { 
    background-color: rgba(220, 38, 38, 0.1); 
    color: var(--primary);
    border: 1px solid rgba(220, 38, 38, 0.2);
}
.danger-btn:hover { 
    background-color: var(--primary); 
    color: #ffffff;
}

.mini-btn { padding: 0.45rem 0.75rem; font-size: 0.8rem; border-radius: 6px; }

/* ==========================================================================
   🔐 GATEKEEPER SECURE LOGIN SHIELD
   ========================================================================== */
.auth-container { 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    min-height: 100vh; 
    padding: 1rem; 
    background: radial-gradient(circle at top right, var(--primary-glow), transparent 45%), var(--bg-color); 
}
.auth-card { 
    background: var(--card-bg); 
    border: 1px solid var(--border-color); 
    padding: 3rem 2rem; 
    border-radius: var(--radius-lg); 
    width: 100%; 
    max-width: 450px; 
    box-shadow: var(--shadow-lg); 
    text-align: center;
    backdrop-filter: var(--glass-blur);
}
.auth-brand-logo { width: 130px; height: auto; margin-bottom: 1.5rem; }
.auth-card h1 { font-size: 1.6rem; font-weight: 800; margin-bottom: 0.75rem; letter-spacing: -0.03em; color: var(--headline-color); line-height: 1.2; }
.auth-card p { color: var(--secondary); font-size: 0.95rem; margin-bottom: 2rem; line-height: 1.5; }
.auth-card input { width: 100%; padding: 0.9rem 1rem; border-radius: var(--radius-sm); border: 2px solid var(--border-color); background: var(--bg-color); color: var(--headline-color); font-size: 1.1rem; text-align: center; font-weight: 700; letter-spacing: 0.05em; outline: none; margin-bottom: 1.5rem; }
.auth-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-glow); }

/* ==========================================================================
   📊 NAVIGATION BAR BRAND LOGO INTEGRATION
   ========================================================================== */
.portal-nav { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 0.85rem 1.5rem; 
    border-bottom: 1px solid var(--border-color); 
    background: var(--glass-bg); 
    backdrop-filter: var(--glass-blur);
    position: sticky; 
    top: 0; 
    z-index: 100; 
    box-shadow: var(--shadow-sm); 
    gap: 1rem;
}
.nav-brand { 
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 800; 
    font-size: 1.15rem; 
    color: var(--headline-color);
    letter-spacing: -0.03em;
    min-width: 0; /* Enable flex child text truncation models */
}
.nav-brand span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-brand-logo { height: 36px; width: auto; pointer-events: none; flex-shrink: 0; }
.nav-actions { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }

.main-content { 
    max-width: 1000px; 
    margin: 2rem auto; 
    padding: 0 1rem; 
}

/* ==========================================================================
   🏠 PORTAL DIRECTORY VIEW (MULTI-INVOICE LIST)
   ========================================================================== */
.section-main-title { font-size: 1.4rem; font-weight: 800; color: var(--headline-color); margin-bottom: 1.5rem; letter-spacing: -0.03em; }
.invoice-directory-grid { display: flex; flex-direction: column; gap: 0.85rem; }
.invoice-directory-row { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    background: var(--card-bg); 
    border: 1px solid var(--border-color); 
    padding: 1.25rem; 
    border-radius: var(--radius-md); 
    cursor: pointer; 
    box-shadow: var(--shadow-sm); 
    transition: all 0.2s ease-in-out; 
    gap: 1rem;
}
.invoice-directory-row:hover { 
    transform: translateY(-2px); 
    box-shadow: var(--shadow-md); 
    border-color: var(--primary); 
}
.directory-meta-block { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.directory-title-text { font-size: 1.1rem; font-weight: 700; color: var(--headline-color); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.directory-date-text { font-size: 0.85rem; color: var(--secondary); font-weight: 500; }
.directory-financial-block { display: flex; align-items: center; gap: 1rem; flex-shrink: 0; }
.directory-amount-text { font-size: 1.2rem; font-weight: 800; color: var(--headline-color); }

.status-badge { padding: 0.35rem 0.65rem; border-radius: 6px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; flex-shrink: 0; text-align: center; }
.status-badge.paid { background-color: var(--paid-bg); color: var(--paid-color); }
.status-badge.unpaid { background-color: var(--unpaid-bg); color: var(--unpaid-color); }

/* ==========================================================================
   📄 DETAILED INVOICE UPPER WRAPPER
   ========================================================================== */
.invoice-summary-header { 
    display: flex; 
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2rem; 
    background: linear-gradient(135deg, var(--card-bg), var(--bg-color)); 
    padding: 1.5rem; 
    border-radius: var(--radius-md); 
    border: 1px solid var(--border-color); 
    box-shadow: var(--shadow-md);
    border-left: 5px solid var(--accent-gold); 
}
.invoice-summary-header h2 { 
    font-size: 1.6rem; 
    font-weight: 800; 
    letter-spacing: -0.04em;
    color: var(--headline-color);
}
.grand-total-box { 
    display: flex; 
    flex-wrap: wrap;
    gap: 1.5rem 2rem; 
    text-align: left; 
}
.total-label { 
    font-size: 0.72rem; 
    text-transform: uppercase; 
    letter-spacing: 0.06em; 
    color: var(--secondary); 
    font-weight: 700;
    display: block;
}
.total-amount { 
    font-size: 1.5rem; 
    font-weight: 800; 
    color: var(--headline-color); 
    letter-spacing: -0.03em; 
    line-height: 1.2;
    margin-top: 0.15rem;
}
.pretty-date { 
    font-size: 1.05rem; 
    font-weight: 800; 
    color: var(--headline-color); 
    margin-top: 0.3rem;
}

/* ==========================================================================
   ⚡ CHRONOLOGICAL TASK LEDGER ITEMS (NUMBERED ROWS)
   ========================================================================== */
.ledger-section h3 { font-size: 1.25rem; font-weight: 800; margin-bottom: 1.25rem; color: var(--secondary); letter-spacing: -0.02em; }
.tasks-display-container { display: flex; flex-direction: column; gap: 1.25rem; }
.viewer-task-card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 1.25rem; box-shadow: var(--shadow-sm); }

/* Flexible Stack grid structure to prevent overflow on mobile header blocks */
.task-card-header { 
    display: flex; 
    flex-direction: column;
    align-items: stretch; 
    gap: 1rem;
    width: 100%; 
}
.task-title { font-size: 1.2rem; font-weight: 800; color: var(--headline-color); line-height: 1.3; }
.task-locations-meta { font-size: 0.85rem; color: var(--primary); font-weight: 600; margin-top: 0.3rem; line-height: 1.4; }
.task-actions-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.85rem; }

/* ==========================================================================
   📂 EXPANDABLE CONTAINER BLOCKS ACCORDIONS
   ========================================================================== */
.collapsible-content { 
    margin-top: 1.25rem; 
    padding-top: 1.25rem; 
    border-top: 1px dashed var(--border-color); 
}
.task-description { 
    font-size: 0.95rem; 
    line-height: 1.5; 
    color: var(--text-color); 
    background: var(--bg-color); 
    padding: 1rem 1.25rem; 
    border-radius: var(--radius-sm); 
    border-left: 4px solid var(--accent-gold);
}

.task-total-trigger-wrapper { 
    display: flex; 
    flex-direction: row; 
    align-items: center; 
    justify-content: space-between;
    width: 100%;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--border-color);
}
.task-total-badge-btn { 
    background: var(--bg-color); 
    border: 1px solid var(--border-color); 
    padding: 0.5rem 1rem; 
    border-radius: var(--radius-sm); 
    font-size: 1.1rem; 
    font-weight: 800; 
    color: var(--headline-color); 
    cursor: pointer; 
    transition: all 0.15s ease;
    text-align: left;
}
.task-total-badge-btn:hover { background: var(--primary-glow); border-color: var(--primary); color: var(--primary); }
.click-expand-hint { font-size: 0.7rem; color: var(--secondary); margin-top: 0; font-weight: 600; text-transform: uppercase; }

.viewer-supplies-box { background: var(--bg-color); border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 1.25rem; width: 100%; }
.viewer-supplies-title { font-size: 0.75rem; font-weight: 700; color: var(--secondary); text-transform: uppercase; margin-bottom: 0.6rem; letter-spacing: 0.02em; }
.viewer-supply-row { display: flex; justify-content: space-between; padding: 0.4rem 0; border-bottom: 1px dashed var(--border-color); font-size: 0.9rem; gap: 1rem; }
.viewer-supply-row span { overflow: hidden; text-overflow: ellipsis; }
.viewer-supply-row:last-child { border-bottom: none; }

.financial-item-row { display: flex; justify-content: space-between; font-size: 0.95rem; padding: 0.5rem 0; font-weight: 500; }
.financial-item-row strong { color: var(--headline-color); }
.financial-total-row { border-top: 2px solid var(--border-color); margin-top: 0.6rem; padding-top: 0.6rem; font-weight: 800; }
.financial-total-row strong { color: var(--primary); font-size: 1.15rem; }

/* ==========================================================================
   📊 LOWER FOOTER INVOICE TOTAL ACCENT CARD
   ========================================================================== */
.invoice-summary-footer-card { 
    display: flex; 
    flex-direction: column;
    align-items: stretch; 
    background: linear-gradient(135deg, var(--card-bg), var(--bg-color)); 
    border: 1px solid var(--border-color); 
    padding: 1.5rem; 
    border-radius: var(--radius-md); 
    box-shadow: var(--shadow-md); 
    margin-top: 2rem; 
    border-right: none;
    border-left: 5px solid var(--primary); 
    gap: 1.25rem;
}

/* ==========================================================================
   💳 REUSABLE COMPONENT: BRANDED PAYMENT PORTAL BADGES
   ========================================================================== */
.payment-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 0.45rem 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--headline-color);
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, border-color 0.15s ease;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.payment-badge span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.payment-badge:hover {
    transform: translateY(-1px);
    border-color: var(--secondary);
}
.payment-highlight {
    font-weight: 800;
    color: var(--primary);
}

/* ==========================================================================
   🖼️ FLUID IMAGE MEDIA GALLERIES & LIGHTBOX POPUPS
   ========================================================================== */
.gallery-wrapper { margin-bottom: 1rem; }
.gallery-title { font-size: 0.75rem; font-weight: 700; color: var(--secondary); text-transform: uppercase; margin-bottom: 0.5rem; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.6rem; }
.gallery-item { border: 1px solid var(--border-color); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-color); aspect-ratio: 4/3; cursor: zoom-in; box-shadow: var(--shadow-sm); transition: all 0.2s ease; }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s ease; }
.gallery-item:hover { border-color: var(--primary); }
.gallery-item:hover img { transform: scale(1.06); }

.lightbox-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(28, 25, 23, 0.92); backdrop-filter: blur(8px); display: flex; justify-content: center; align-items: center; z-index: 2000; padding: 1rem; }
.lightbox-img { max-width: 100%; max-height: 80vh; object-fit: contain; border-radius: var(--radius-md); box-shadow: 0 25px 50px rgba(0,0,0,0.5); }
.lightbox-close { position: absolute; top: 1rem; right: 1.5rem; color: #ffffff; font-size: 2.5rem; font-weight: 300; cursor: pointer; transition: transform 0.2s ease; z-index: 2100; }
.lightbox-close:hover { color: var(--primary); transform: rotate(90deg); }

/* ==========================================================================
   🏢 BRAND FOOTNOTE GLOBAL STICKY COMPONENT
   ========================================================================== */
.portal-global-footer { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.75rem; margin-top: 4rem; padding: 2.5rem 1rem; border-top: 1px solid var(--border-color); background: var(--card-bg); text-align: center; }
.footer-brand-logo { height: 50px; width: auto; }
.footer-cta-link { font-size: 0.9rem; font-weight: 700; color: var(--primary); text-decoration: none; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.2rem 0; border-bottom: 2px solid transparent; transition: all 0.2s ease-in-out; }
.footer-cta-link:hover { color: var(--headline-color); border-color: var(--accent-gold); }

/* ==========================================================================
   📈 ANALYTICS METRIC MATRIX SYSTEM GRID
   ========================================================================== */
.analytics-dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.85rem;
    margin-top: 1.25rem;
}

.analytics-card-node {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.1rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.2s ease-in-out;
    min-width: 0; /* Safeguard flex grid items */
}

.analytics-card-node:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.analytics-node-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.3;
    margin-bottom: 0.4rem;
    word-wrap: break-word;
}

.analytics-node-value {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--headline-color);
    letter-spacing: -0.02em;
    line-height: 1.2;
    word-wrap: break-word;
}

.analytics-node-subtitle {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--primary);
    margin-top: 0.3rem;
    line-height: 1.3;
}

/* ==========================================================================
   📱 CORE MEDIA QUERY WORKBENCH BREAKPOINTS (TABLETS & SMARTPHONES)
   ========================================================================== */
@media (min-width: 601px) {
    /* Desktop & Tablet Optimization Row Transitions */
    .task-card-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    .task-total-trigger-wrapper {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        width: auto;
        padding-top: 0;
        border-top: none;
    }
    .task-total-badge-btn {
        text-align: right;
    }
    .invoice-summary-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
    .grand-total-box {
        justify-content: flex-end;
        text-align: right;
    }
    .invoice-summary-footer-card {
        flex-direction: column;
    }
    /* Keep desktop summary layout side-by-side */
    .footer-financial-row {
        display: flex;
        justify-content: flex-end;
        gap: 3rem;
        text-align: right;
        width: 100%;
        padding-bottom: 0.5rem;
    }
    .analytics-header-block {
        display: flex; 
        justify-content: space-between; 
        align-items: center; 
        margin-bottom: 1.5rem; 
        border-bottom: 2px solid var(--border-color); 
        padding-bottom: 0.5rem;
    }
    .analytics-header-actions {
        display: flex; 
        gap: 0.5rem;
    }
}

@media (max-width: 600px) {
    /* 🚨 Mobile Header Overhaul: Strict Centered Stacking */
    .portal-nav {
        padding: 1.25rem 1rem;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 1.25rem;
        text-align: center;
        width: 100%;
    }
    
    .nav-brand {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.65rem;
        width: 100%;
        text-align: center;
    }
    
    .nav-brand-logo {
        height: 48px;
        width: auto;
        margin: 0 auto;
    }
    
    .nav-brand span {
        font-size: 1.3rem;
        font-weight: 800;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        display: block;
        width: 100%;
        padding: 0 0.25rem;
        letter-spacing: -0.02em;
    }
    
    .nav-actions {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 0.6rem;
        width: 100%;
    }
    
    .nav-actions .btn {
        flex: 1;
        max-width: 140px;
        padding: 0.55rem 0.85rem;
        font-size: 0.85rem;
    }

    /* 📈 Analytics Header Responsive Fix: Force Stacking Actions */
    .portal-home-view div[style*="display: flex; justify-content: space-between;"] {
        flex-direction: column !important;
        align-items: center !important;
        gap: 1rem !important;
        text-align: center !important;
        border-bottom: 2px solid var(--border-color);
        padding-bottom: 1.25rem;
    }
    
    .portal-home-view div[style*="display: flex; gap: 0.5rem;"] {
        flex-direction: column !important;
        width: 100% !important;
        gap: 0.65rem !important;
    }
    
    .portal-home-view div[style*="display: flex; gap: 0.5rem;"] .btn {
        width: 100% !important;
        padding: 0.65rem 1rem !important;
    }

    /* 🔛 Bottom Invoice Summary Breakdown Overhaul: Clean Centered Stack */
    .invoice-summary-footer-card div[style*="justify-content: flex-end;"] {
        flex-direction: column !important;
        align-items: center !important;
        gap: 1.5rem !important;
        text-align: center !important;
        width: 100%;
        padding-bottom: 1rem !important;
    }
    
    .invoice-summary-footer-card div[style*="justify-content: flex-end;"] div {
        text-align: center !important;
        width: 100%;
    }

    /* Home View Directory Layout Overrides */
    .main-content {
        margin: 1.5rem auto;
    }
    .invoice-directory-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        text-align: center;
    }
    .directory-meta-block {
        align-items: center;
        text-align: center;
    }
    .directory-financial-block {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 0.5rem;
        border-top: 1px dashed var(--border-color);
        padding-top: 0.75rem;
    }
    
    /* Analytics Responsive Shrink Matrix */
    .analytics-dashboard-grid {
        grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
        gap: 0.65rem;
    }
    .analytics-card-node {
        padding: 0.85rem;
        align-items: center;
        text-align: center;
    }
    .analytics-node-title {
        text-align: center;
        padding-right: 0 !important;
    }
    .analytics-node-value {
        font-size: 1.1rem;
        text-align: center;
    }
    .analytics-node-subtitle {
        text-align: center;
    }

    /* Bottom Payment Methods Width Normalization */
    .payment-badge {
        font-size: 0.8rem;
        width: 100%; 
        justify-content: center;
    }
}