:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #64748b;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #22c55e;
    --danger: #ef4444;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow-x: hidden;
}

/* Loader */
.loader-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid var(--primary);
    border-bottom-color: transparent;
    border-radius: 50%;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Sections */
.page-section {
    display: none;
    min-height: 100vh;
}

.page-section.active {
    display: flex;
}

/* Auth */
.auth-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
}

.auth-card {
    background: var(--bg-card);
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.logo {
    margin-bottom: 2rem;
}

.logo .icon {
    font-size: 3rem;
}

.logo h1 {
    font-size: 1.5rem;
    color: var(--primary);
    margin-top: 0.5rem;
}

h2 {
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.input-group {
    text-align: left;
    margin-bottom: 1.2rem;
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 0.4rem;
    font-weight: 500;
}

.input-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-primary {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    width: 100%;
    padding: 0.75rem;
    background: transparent;
    color: var(--secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #f1f5f9;
    color: var(--text-main);
    border-color: var(--secondary);
}

#logout-btn {
    margin-top: auto;
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

#logout-btn:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.auth-switch {
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

/* Main Layout */
#main-section {
    display: none;
}

#main-section.active {
    display: flex;
}

.sidebar {
    width: 260px;
    background: #1e293b;
    color: white;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
}

.sidebar-header .logo-small {
    font-weight: 700;
    font-size: 1.2rem;
    margin-bottom: 2rem;
    display: block;
}

.nav-links {
    list-style: none;
    flex-grow: 1;
}

.nav-links li {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
}

.nav-links li:hover {
    background: rgba(255, 255, 255, 0.1);
}

.nav-links li.active {
    background: var(--primary);
}

.nav-icon {
    margin-right: 10px;
}

.content-area {
    flex-grow: 1;
    padding: 2rem;
    overflow-y: auto;
    height: 100vh;
}

.app-page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.app-page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

header {
    margin-bottom: 2rem;
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat-card h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

/* Charts */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.chart-box {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.chart-box h3 {
    margin-bottom: 1.5rem;
    font-size: 1rem;
}

/* Tables */
.table-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: #f1f5f9;
    font-weight: 600;
    font-size: 0.875rem;
}

/* Upload */
.upload-container {
    max-width: 800px;
}

.upload-dropzone {
    border: 2px dashed var(--primary);
    border-radius: var(--radius);
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: background 0.2s;
    background: rgba(99, 102, 241, 0.05);
}

.upload-dropzone:hover {
    background: rgba(99, 102, 241, 0.1);
}

.upload-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 1rem;
}

/* OCR Edit */
.ocr-edit-card {
    margin-top: 2rem;
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.items-editor {
    border-top: 1px solid var(--border);
    padding-top: 1.5rem;
    margin-bottom: 2rem;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}

.product-item {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: center;
}

/* Filters */
.filters {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group input[type="date"] {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.filter-group label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    overflow: auto;
}

.modal-content {
    position: relative;
    margin: 5% auto;
    padding: 0;
    width: 90%;
    max-width: 1000px;
    background: #fff;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.modal-content img {
    width: 100%;
    height: auto;
    display: block;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 25px;
    color: #fff;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.5);
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close-modal:hover {
    color: #ccc;
}

.ocr-edit-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.image-preview-container {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: 500px;
}

.image-preview-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Responsive */
@media (max-width: 768px) {
    .ocr-edit-layout {
        grid-template-columns: 1fr;
    }
}

/* Responsive */
@media (max-width: 768px) {
    #main-section {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        padding: 1rem;
    }

    .content-area {
        height: auto;
    }

    .charts-container {
        grid-template-columns: 1fr;
    }
}