/* =========================================================
   GLOBAL
========================================================= */

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100%;
    font-family: "Inter", Arial, sans-serif;
    color: #172033;
}

body {
    background:
        radial-gradient(
            circle at 0% 0%,
            rgba(219, 234, 254, 0.65),
            transparent 32%
        ),
        radial-gradient(
            circle at 100% 0%,
            rgba(237, 233, 254, 0.55),
            transparent 30%
        ),
        #f5f7fb;
}

/* =========================================================
   LOGIN OVERLAY
========================================================= */

.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(245, 247, 251, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.login-card {
    background: #ffffff;
    border: 1px solid #e4e8ef;
    border-radius: 12px;
    padding: 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.05);
    text-align: center;
}

.login-card h2 {
    margin: 0 0 8px 0;
    font-size: 22px;
    color: #172033;
}

.login-card p {
    margin: 0 0 24px 0;
    font-size: 13px;
    color: #64748b;
}

.login-input {
    width: 100%;
    height: 44px;
    padding: 0 16px;
    border: 1px solid #dce2eb;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    margin-bottom: 16px;
    outline: none;
    transition: all 0.2s;
}

.login-input:focus {
    border-color: #7c3aed;
    box-shadow: 0 0 0 3px rgba(124,58,237,0.08);
}

.login-btn {
    width: 100%;
    height: 44px;
    background: linear-gradient(90deg, #5b21f5, #7c3aed);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.login-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(109,40,217,0.22);
}

#login-error {
    color: #ef4444;
    font-size: 12px;
    margin-bottom: 12px;
    display: none;
}

.hidden-app {
    display: none !important;
}

/* =========================================================
   APP
========================================================= */

.app {
    width: 100%;
    min-height: 100vh;
    padding: 16px;
    display: flex;
    flex-direction: column;
}

/* Main dashboard */

.dashboard {
    width: 100%;
    margin: 0 auto;

    display: grid;
    grid-template-columns: 430px minmax(0, 1fr);
    gap: 24px;

    align-items: stretch;
    flex: 1;
}

/* =========================================================
   LEFT PANEL
========================================================= */

.left-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Header / upload control card */

.control-card {
    background: linear-gradient(145deg, #ffffff, #f8fafc);
    border: 1px solid rgba(226, 232, 240, 0.8);
    border-radius: 16px;
    padding: 28px 24px;
    box-shadow: 
        0 4px 20px -2px rgba(15, 23, 42, 0.05),
        inset 0 2px 4px rgba(255, 255, 255, 0.5);
    position: relative;
    overflow: hidden;
}

/* Subtle decorative glow for the card */
.control-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6, #ec4899);
}

.brand-logo-container {
    margin-bottom: 28px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
}

.brand-logo {
    max-width: 100%;
    height: auto;
    max-height: 64px;
    display: block;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.06));
}

.software-title {
    margin: 0;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* =========================================================
   CUSTOMER
========================================================= */

.field-label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.customer-select {
    width: 100%;
    height: 46px;
    padding: 0 16px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background-color: #f8fafc;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: #1e293b;
    outline: none;
    transition: all 0.25s ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.01);
}

.customer-select:hover {
    border-color: #cbd5e1;
    background-color: #ffffff;
}

.customer-select:focus {
    background-color: #ffffff;
    border-color: #8b5cf6;
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.15);
}

/* =========================================================
   UPLOAD CARD
========================================================= */

.upload-card {
    background: rgba(255,255,255,0.96);

    border: 1px solid #e4e8ef;
    border-radius: 12px;

    padding: 16px;

    box-shadow:
        0 3px 12px rgba(15,23,42,0.05);
    
    flex: 1;
    display: flex;
    flex-direction: column;
}

#upload-form {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.upload-zone {
    width: 100%;
    min-height: 78px;
    flex: 1;

    border: 1.5px dashed #8b5cf6;
    border-radius: 8px;

    background:
        linear-gradient(
            135deg,
            rgba(139,92,246,0.08),
            rgba(124,58,237,0.03)
        );

    display: flex;
    align-items: center;
    justify-content: center;

    cursor: pointer;

    transition: 0.2s;
}

.upload-zone:hover {
    background: rgba(124,58,237,0.09);
    border-color: #6d28d9;
}

.upload-content {
    text-align: center;
}

.upload-icon {
    width: 24px;
    height: 24px;

    color: #6d28d9;

    margin-bottom: 6px;
}

.file-name {
    display: block;

    font-size: 13px;
    font-weight: 500;

    color: #172033;
}

.file-type {
    display: block;

    margin-top: 4px;

    font-size: 12px;
    color: #64748b;
}

/* =========================================================
   ANALYZE BUTTON
========================================================= */

.analyze-button {
    width: 100%;
    height: 44px;

    margin-top: 16px;

    border: 0;
    border-radius: 6px;

    background:
        linear-gradient(
            90deg,
            #5b21f5,
            #7c3aed
        );

    color: white;

    font-family: inherit;
    font-size: 14px;
    font-weight: 600;

    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;

    transition: 0.2s;
}

.analyze-button:hover {
    transform: translateY(-1px);

    box-shadow:
        0 6px 15px rgba(109,40,217,0.22);
}

.analyze-button:active {
    transform: translateY(0);
}

.analyze-button svg {
    width: 13px;
    height: 13px;
}

/* =========================================================
   MAIN COLUMN
========================================================= */

.main-column {
    min-width: 0;

    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 20px;
}

/* =========================================================
   KPI GRID
========================================================= */

.kpi-grid {
    display: grid;

    grid-template-columns:
        repeat(6, minmax(0, 1fr));

    gap: 12px;
}

.kpi-card {
    min-height: 86px;

    padding: 16px 16px;

    background: #ffffff;

    border: 1px solid #e1e6ee;
    border-radius: 8px;

    display: flex;
    align-items: center;

    gap: 14px;

    box-shadow:
        0 3px 10px rgba(15,23,42,0.04);
}

.kpi-icon {
    width: 44px;
    height: 44px;

    flex-shrink: 0;

    border-radius: 8px;

    background: #f3efff;

    color: #6d28d9;

    display: flex;
    align-items: center;
    justify-content: center;
}

.kpi-icon svg {
    width: 20px;
    height: 20px;
}

.kpi-info {
    min-width: 0;
}

.kpi-label {
    margin-bottom: 4px;

    font-size: 11px;
    font-weight: 700;

    letter-spacing: 0.04em;

    color: #64748b;

    white-space: nowrap;
}

.kpi-value {
    font-size: 20px;
    line-height: 1;

    font-weight: 700;

    color: #172033;

    white-space: nowrap;
}

.kpi-value.profit,
.kpi-value.margin {
    color: #059669;
}
.kpi-value.negative {
    color: #ef4444 !important;
}

/* =========================================================
   INVOICE DETAILS
========================================================= */

.invoice-card {
    background: #ffffff;

    border: 1px solid #e0e5ed;
    border-radius: 10px;

    overflow: hidden;

    box-shadow:
        0 4px 14px rgba(15,23,42,0.05);
    
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Invoice title */

.invoice-header {
    height: 56px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #e5e9ef;
}

.invoice-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
}

.invoice-title svg {
    width: 20px;
    height: 20px;
    color: #64748b;
}

/* Search Bar */
.search-container {
    position: relative;
    width: 300px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: #94a3b8;
}

.search-input {
    width: 100%;
    height: 36px;
    padding: 0 16px 0 36px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    color: #172033;
    outline: none;
    transition: all 0.2s;
}

.search-input:focus {
    border-color: #6d28d9;
    box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.1);
}

/* Pagination */
.pagination-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-top: 1px solid #e5e9ef;
    background: #f8fafc;
}

.pagination-info {
    font-size: 13px;
    color: #64748b;
}

.pagination-controls {
    display: flex;
    gap: 6px;
}

.page-btn {
    height: 32px;
    min-width: 32px;
    padding: 0 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s;
}

.page-btn:hover:not(:disabled) {
    background: #f1f5f9;
    color: #172033;
}

.page-btn.active {
    background: #6d28d9;
    border-color: #6d28d9;
    color: #ffffff;
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* =========================================================
   TABLE
========================================================= */

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    max-height: calc(100vh - 380px); /* Adjust based on top elements */
    overflow-y: auto;
}

.invoice-table {
    width: 100%;
    min-width: 800px;

    border-collapse: collapse;

    table-layout: auto;
}

.invoice-table thead {
    background: #f8fafc;
}

.invoice-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f8fafc;
    height: 44px;
    padding: 0 8px;
    text-align: left;
    white-space: normal; /* Allow header wrapping */
    word-break: break-word;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #64748b;
    border-bottom: 1px solid #e3e8ef;
}

.invoice-table td {
    height: 50px;
    padding: 8px 8px;
    font-size: 11.5px;
    color: #334155;
    border-bottom: 1px solid #e8ecf1;
    white-space: nowrap;
}

.invoice-table tbody tr:last-child td {
    border-bottom: 0;
}

/* SKU */

.sku {
    font-weight: 700;
    color: #172033;
    max-width: 120px;
    white-space: normal;
    word-break: break-all;
}

/* Description */

.description {
    color: #334155;
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Group badge */

.group-badge {
    display: inline-flex;

    align-items: center;

    padding: 6px 12px;

    border-radius: 20px;

    background: #f1f5f9;

    color: #64748b;

    font-size: 11px;
    font-weight: 600;

    white-space: nowrap;
}

/* Profit */

.profit {
    font-weight: 700;
}
.profit-green { color: #059669 !important; }
.profit-red { color: #ef4444 !important; }
.profit-orange { color: #EA580C !important; }
.profit-yellow { color: #CA8A04 !important; }
.profit-grey { color: #94A3B8 !important; }

.actual-margin {
    font-weight: 700;
}
.margin-green { color: #059669 !important; }
.margin-red { color: #ef4444 !important; }
.margin-orange { color: #EA580C !important; }
.margin-yellow { color: #CA8A04 !important; }
.margin-grey { color: #94A3B8 !important; }

/* =========================================================
   CRITICAL ROW
========================================================= */

.critical-row {
    background: #fff9fa;
}

.critical-row td {
    color: #334155;
}

/* =========================================================
   STATUS
========================================================= */

.status {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    gap: 6px;

    height: 26px;

    padding: 0 12px;

    border-radius: 20px;

    font-size: 11px;
    font-weight: 600;
}

.status svg {
    width: 14px;
    height: 14px;
}

.status-green {
    color: #059669;
    background: #ecfdf5;
    border: 1px solid #a7e8cb;
}

.status-red {
    color: #ef4444;
    background: #fff1f2;
    border: 1px solid #fda4af;
}

.status-orange {
    color: #EA580C;
    background: #FFF7ED;
    border: 1px solid #FDBA74;
}

.status-yellow {
    color: #CA8A04;
    background: #FEFCE8;
    border: 1px solid #FDE047;
}

.status-grey {
    color: #64748B;
    background: #F8FAFC;
    border: 1px solid #E2E8F0;
}

/* =========================================================
   UPLOAD INPUT
========================================================= */

#invoiceFile {
    display: none;
}

/* =========================================================
   RESPONSIVE
========================================================= */

/* Large desktop */

@media (max-width: 1500px) {

    .dashboard {
        grid-template-columns: 300px minmax(0, 1fr);
    }

    .kpi-grid {
        grid-template-columns:
            repeat(3, minmax(0, 1fr));
    }
}

/* Tablet */

@media (max-width: 1000px) {

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

    .left-column {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .control-card {
        grid-column: span 1;
    }

    .upload-card {
        grid-column: span 1;
    }

    .kpi-grid {
        grid-template-columns:
            repeat(3, minmax(0, 1fr));
    }
}

/* Mobile */

@media (max-width: 650px) {

    .app {
        padding: 8px;
    }

    .dashboard {
        gap: 12px;
    }

    .left-column {
        display: flex;
    }

    .kpi-grid {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));

        gap: 8px;
    }

    .kpi-card {
        min-height: 62px;
    }

    .kpi-label {
        font-size: 7px;
    }

    .kpi-value {
        font-size: 14px;
    }

    .brand-title {
        font-size: 22px;
    }
}

/* =========================================
   ANIMATIONS & EFFECTS
========================================= */
.loader-spinner {
    display: inline-block;
    width: 44px;
    height: 44px;
    border: 4px solid rgba(99, 102, 241, 0.15);
    border-radius: 50%;
    border-top-color: #6366f1;
    animation: spin 1s ease-in-out infinite;
}

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

.loading-text {
    margin-top: 18px;
    font-weight: 600;
    font-size: 15px;
    color: #4f46e5;
    letter-spacing: 0.02em;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
