/* CSS Variables */
:root {
    --primary-color: #4472C4;
    --primary-dark: #2E5090;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --background-color: #f5f7fa;
    --card-background: #ffffff;
    --text-color: #333333;
    --text-muted: #6c757d;
    --border-color: #dee2e6;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --nav-height: 70px;
    --header-height: 60px;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Pages */
.page {
    display: none;
}

.page.active {
    display: block;
}

/* Login Page */
.login-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 20px;
    max-width: 400px;
    margin: 0 auto;
}

.logo {
    text-align: center;
    margin-bottom: 40px;
    color: var(--primary-color);
}

.logo svg {
    margin-bottom: 16px;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Forms */
.form {
    background: var(--card-background);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-color);
    font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--card-background);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(68, 114, 196, 0.2);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.toggle-form {
    text-align: center;
    margin-top: 16px;
    color: var(--text-muted);
}

.toggle-form a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.error-message {
    background: #fef2f2;
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-top: 16px;
    text-align: center;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-full {
    width: 100%;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.875rem;
}

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

/* Header */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 1.2rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-actions span {
    font-size: 0.875rem;
    opacity: 0.9;
}

#logout-btn {
    background: rgba(255,255,255,0.2);
    color: white;
    padding: 6px 12px;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--card-background);
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

.nav-btn svg {
    fill: currentColor;
}

.nav-btn span {
    font-size: 0.75rem;
}

.nav-btn.active {
    color: var(--primary-color);
}

/* Main Content */
.main-content {
    padding: calc(var(--header-height) + 16px) 16px calc(var(--nav-height) + 16px);
    max-width: 800px;
    margin: 0 auto;
}

.page-content {
    display: none;
}

.page-content.active {
    display: block;
}

/* Dashboard Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-background);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-card h3 {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Charts */
.chart-section {
    background: var(--card-background);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.chart-section h2 {
    font-size: 1rem;
    margin-bottom: 16px;
    color: var(--text-color);
}

.chart-container {
    min-height: 200px;
}

.chart-bar {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
}

.chart-bar-label {
    width: 100px;
    font-size: 0.8rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.chart-bar-track {
    flex: 1;
    height: 24px;
    background: var(--background-color);
    border-radius: 4px;
    overflow: hidden;
    margin: 0 8px;
}

.chart-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.chart-bar-value {
    width: 80px;
    text-align: right;
    font-size: 0.85rem;
    font-weight: 500;
    flex-shrink: 0;
}

/* Category Colors */
.category-materiel { background: #E2EFDA; }
.category-artistes { background: #FCE4D6; }
.category-location { background: #DDEBF7; }
.category-communication { background: #FFF2CC; }
.category-administratif { background: #E4DFEC; }
.category-autres { background: #F2F2F2; }

/* Export Buttons */
.export-buttons {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.export-buttons .btn {
    flex: 1;
    font-size: 0.9rem;
}

.export-buttons .btn svg {
    fill: currentColor;
}

/* Upload Section */
.upload-section {
    background: var(--card-background);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.upload-section h2 {
    text-align: center;
    margin-bottom: 24px;
}

.upload-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.upload-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px 16px;
    background: var(--background-color);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
}

.upload-option:hover {
    border-color: var(--primary-color);
    background: rgba(68, 114, 196, 0.05);
}

.upload-option svg {
    fill: var(--primary-color);
}

.upload-option span {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
}

#upload-preview {
    margin-top: 24px;
    text-align: center;
}

#preview-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}

.pdf-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    background: var(--background-color);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}

.pdf-preview svg {
    fill: var(--danger-color);
}

.pdf-preview span {
    margin-top: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--background-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    border-radius: 4px;
    width: 0;
    animation: progress 2s ease-in-out infinite;
}

@keyframes progress {
    0% { width: 0; }
    50% { width: 70%; }
    100% { width: 100%; }
}

/* OCR Form Section */
#ocr-form-section {
    background: var(--card-background);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.ocr-confidence {
    text-align: center;
    margin-bottom: 16px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.ocr-raw {
    margin: 16px 0;
}

.ocr-raw summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.ocr-raw pre {
    margin-top: 8px;
    padding: 12px;
    background: var(--background-color);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.form-actions .btn {
    flex: 1;
}

/* Invoices List */
.filters-section {
    margin-bottom: 16px;
}

#filters-panel {
    background: var(--card-background);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-top: 12px;
}

.filter-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 12px;
}

.invoices-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.invoice-card {
    background: var(--card-background);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.invoice-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.invoice-card-main {
    flex: 1;
}

.invoice-card-supplier {
    font-weight: 600;
    margin-bottom: 4px;
}

.invoice-card-date {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.invoice-card-amount {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
}

.invoice-card-category {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-top: 8px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state svg {
    fill: var(--border-color);
    margin-bottom: 16px;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal-content {
    background: var(--card-background);
    border-radius: var(--radius);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    z-index: 1;
}

#modal-image-container {
    width: 100%;
    max-height: 300px;
    overflow: hidden;
    border-radius: var(--radius) var(--radius) 0 0;
}

#modal-image {
    width: 100%;
    height: auto;
    display: block;
}

#modal-details {
    padding: 20px;
}

#modal-details h3 {
    margin-bottom: 16px;
    color: var(--primary-color);
}

#modal-details p {
    margin-bottom: 8px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    padding: 0 20px 20px;
}

.modal-actions .btn {
    flex: 1;
}

/* Responsive Adjustments */
@media (min-width: 600px) {
    .main-content {
        padding: calc(var(--header-height) + 24px) 24px calc(var(--nav-height) + 24px);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .upload-options {
        max-width: 400px;
        margin: 0 auto;
    }
}

@media (min-width: 768px) {
    .bottom-nav {
        top: var(--header-height);
        bottom: auto;
        justify-content: flex-start;
        padding-left: 24px;
        gap: 8px;
        height: 50px;
    }

    .nav-btn {
        flex-direction: row;
        padding: 8px 16px;
    }

    .main-content {
        padding-top: calc(var(--header-height) + 50px + 24px);
        padding-bottom: 24px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #1a1a2e;
        --card-background: #16213e;
        --text-color: #eaeaea;
        --text-muted: #a0a0a0;
        --border-color: #2a2a4a;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        background: var(--background-color);
        color: var(--text-color);
    }
}
