/* CSS Variables for theming */
:root {
    --primary-color: #489c58;
    --primary-hover: #3d8549;
    --background-color: #ffffff;
    --text-color: #333333;
    --card-background: #ffffff;
    --border-color: #e0e0e0;
    --error-background: #fee;
    --error-border: #fcc;
    --error-text: #c33;
    --success-background: #efe;
    --success-border: #cfc;
    --success-text: #363;
    --info-background: #eef;
    --info-border: #ccf;
    --info-text: #336;
}

/* Dark mode variables */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #1a1a1a;
        --text-color: #ffffff;
        --card-background: #2a2a2a;
        --border-color: #404040;
        --error-background: #3a1a1a;
        --error-border: #5a2a2a;
        --error-text: #ff6666;
        --success-background: #1a3a1a;
        --success-border: #2a5a2a;
        --success-text: #66ff66;
        --info-background: #1a1a3a;
        --info-border: #2a2a5a;
        --info-text: #6666ff;
    }
}

/* Force dark mode class for manual control */
body.dark-mode {
    --background-color: #1a1a1a;
    --text-color: #ffffff;
    --card-background: #2a2a2a;
    --border-color: #404040;
    --error-background: #3a1a1a;
    --error-border: #5a2a2a;
    --error-text: #ff6666;
    --success-background: #1a3a1a;
    --success-border: #2a5a2a;
    --success-text: #66ff66;
    --info-background: #1a1a3a;
    --info-border: #2a2a5a;
    --info-text: #6666ff;
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Login page styles */
.login-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    max-width: 400px;
    margin: 0 auto;
}

.login-container h1 {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 2rem;
    text-align: center;
}

.description {
    text-align: center;
    margin-bottom: 2rem;
    opacity: 0.8;
}

.microsoft-button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
    width: 100%;
    text-align: center;
    transition: background-color 0.2s ease;
    cursor: pointer;
}

.microsoft-button:hover {
    background: var(--primary-hover);
}

/* Main application container */
.container {
    min-height: 100vh;
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

/* User info */
.user-info {
    position: absolute;
    top: 2rem;
    right: 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
}

.logout-link {
    color: var(--primary-color);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border: 1px solid var(--primary-color);
    transition: all 0.2s ease;
}

.logout-link:hover {
    background: var(--primary-color);
    color: white;
}

/* Page headers */
h1 {
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: 3rem;
    text-align: center;
}

/* Home page specific h1 styling */
.container h1 {
    margin-top: 4rem;
}

/* Button container and nav buttons */
.button-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 400px;
    margin: 0 auto;
}

@media (min-width: 768px) {
    .button-container {
        flex-direction: row;
        max-width: none;
        justify-content: center;
        gap: 2rem;
    }
}

.nav-button {
    background: var(--card-background);
    border: 2px solid var(--primary-color);
    color: var(--text-color);
    padding: 2rem 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    min-width: 180px;
    font-size: 1rem;
    font-weight: 500;
}

.nav-button:hover {
    background: var(--primary-color);
    color: white;
}

.button-text {
    font-size: 1.1rem;
    font-weight: 500;
}

/* Page-specific styles */
.page-container {
    background: var(--background-color);
    min-height: 100vh;
    padding: 0.5rem 2rem 2rem 2rem;
}

.page-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1rem;
}

.page-header .back-button {
    justify-self: start;
}

.page-header h1 {
    justify-self: center;
    margin: 0;
}

.page-header .header-controls {
    justify-self: end;
}

.back-button {
    background: var(--card-background);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.back-button:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.choose-fields-button,
.filter-date-button,
.clear-filter-button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    white-space: nowrap;
}

.choose-fields-button:hover,
.filter-date-button:hover,
.clear-filter-button:hover {
    background: var(--primary-hover);
}

.date-filter-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.date-filter-input {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    background: var(--background-color);
    color: var(--text-color);
    font-size: 0.9rem;
}

.date-filter-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.clear-filter-button {
    background: var(--border-color);
    color: var(--text-color);
}

.clear-filter-button:hover {
    background: var(--primary-color);
    color: white;
}

/* Form styles */
.form-container {
    background: var(--card-background);
    padding: 2rem;
    border: 1px solid var(--border-color);
    max-width: 500px;
    margin: 2rem auto;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="date"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    background: var(--background-color);
    color: var(--text-color);
    font-size: 1rem;
}

.form-group input[type="text"]:focus,
.form-group input[type="date"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.radio-group {
    display: flex;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.submit-button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s ease;
    font-weight: 500;
}

.submit-button:hover {
    background: var(--primary-hover);
}

.submit-button:disabled {
    background: var(--border-color);
    cursor: not-allowed;
}

/* Progress bars */
.progress-container {
    width: 100%;
    background: var(--border-color);
    margin-top: 1.5rem;
    height: 30px;
    overflow: hidden;
    display: none;
}

.progress-bar {
    height: 100%;
    width: 0;
    background: var(--primary-color);
    text-align: center;
    color: white;
    line-height: 30px;
    transition: width 0.3s ease;
    font-weight: 500;
}

.progress-bar.error {
    background: var(--error-text);
}

.batch-progress-container {
    width: 100%;
    background: var(--border-color);
    margin-top: 0.75rem;
    height: 30px;
    overflow: hidden;
    display: none;
}

.batch-progress-bar {
    height: 100%;
    width: 0;
    background: var(--primary-color);
    text-align: center;
    color: white;
    line-height: 30px;
    transition: width 0.3s ease;
    font-weight: 500;
}

.batch-progress-bar.error {
    background: var(--error-text);
}

.month-indicator {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    text-align: center;
    font-weight: 500;
}

.batch-details {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    text-align: center;
    opacity: 0.8;
}

.progress-label {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    text-align: center;
    opacity: 0.8;
}

/* Table styles */
.table-container {
    overflow: auto;
    border: 1px solid var(--border-color);
    max-height: 70vh;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: var(--card-background);
}

.data-table th,
.data-table td {
    border: 1px solid var(--border-color);
    padding: 0.75rem 0.5rem;
    text-align: left;
    word-wrap: break-word;
    position: relative;
}

.data-table th {
    background: var(--primary-color);
    color: white;
    font-weight: 500;
    position: sticky;
    top: 0;
    z-index: 10;
    cursor: col-resize;
}

.data-table tbody tr:nth-child(even) {
    background: var(--background-color);
}

.data-table tbody tr:hover {
    background: var(--border-color);
}

/* Column resizer */
.column-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    background: transparent;
    border-right: 2px solid transparent;
}

.column-resizer:hover,
.column-resizer.resizing {
    border-right-color: white;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: var(--card-background);
    margin: 5% auto;
    padding: 2rem;
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    margin: 0;
    font-weight: 600;
}

.close {
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    border: none;
    background: none;
    color: var(--text-color);
}

.close:hover {
    opacity: 0.7;
}

.field-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    transition: background-color 0.2s ease;
}

.field-checkbox:hover {
    background-color: var(--background-color);
}

.field-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

.field-checkbox label {
    cursor: pointer;
    flex: 1;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
    font-weight: 500;
}

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

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

.btn-secondary {
    background: var(--card-background);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

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

/* Alert styles */
.error-message,
.alert-error {
    background: var(--error-background);
    color: var(--error-text);
    border: 1px solid var(--error-border);
    padding: 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.alert-success {
    background: var(--success-background);
    color: var(--success-text);
    border: 1px solid var(--success-border);
    padding: 1rem;
    margin-bottom: 1rem;
}

.alert-info {
    background: var(--info-background);
    color: var(--info-text);
    border: 1px solid var(--info-border);
    padding: 1rem;
    margin-bottom: 1rem;
}

/* Pagination styles */
.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin: 1rem 0;
}

.pagination-info {
    font-size: 0.9rem;
    opacity: 0.8;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pagination-btn {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

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

.pagination-btn:disabled {
    background: var(--border-color);
    color: var(--text-color);
    cursor: not-allowed;
    opacity: 0.5;
}

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

.page-size-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-size-selector select {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color);
    background: var(--card-background);
    color: var(--text-color);
    font-size: 0.9rem;
}

/* Loading spinner */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive design */
@media (max-width: 768px) {
    .container,
    .page-container {
        padding: 1rem;
    }

    h1 {
        font-size: 2rem;
        margin-top: 2rem;
    }

    .user-info {
        position: static;
        justify-content: center;
        margin-bottom: 2rem;
    }

    .button-container {
        gap: 1rem;
    }

    .nav-button {
        min-width: 100%;
    }

    .page-header {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: 1rem;
        text-align: center;
    }

    .page-header .back-button {
        justify-self: start;
        grid-row: 1;
    }

    .page-header h1 {
        justify-self: center;
        grid-row: 2;
        margin: 0;
    }

    .page-header .header-controls {
        justify-self: center;
        grid-row: 3;
    }

    .date-filter-container {
        flex-wrap: wrap;
        justify-content: center;
    }
}