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

:root {
    --primary: #95b94f;
    --primary-dark: #7a9a3d;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --radius: 8px;
}

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

/* Login */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box {
    background: var(--bg-card);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    margin-bottom: 30px;
    color: var(--primary);
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

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

input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.btn:hover {
    transform: translateY(-1px);
}

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

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

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

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

.btn-secondary:hover:not(:disabled) {
    background: #475569;
}

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

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-small {
    padding: 6px 12px;
    font-size: 14px;
}

.btn-large {
    padding: 16px 32px;
    font-size: 18px;
}

/* App Layout */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: var(--bg-card);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 24px;
    color: var(--primary);
}

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

.user-info {
    color: var(--text-light);
}

/* Region Selector */
.region-selector {
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
    padding: 20px 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    border-bottom: 4px solid #e38815;
}

.region-label {
    font-weight: 700;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-right: 8px;
}

.region-btn {
    padding: 14px 28px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    color: rgba(255, 255, 255, 0.8);
    position: relative;
}

.region-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    transform: translateY(-2px);
}

.region-btn.active {
    background: #e38815;
    color: white;
    box-shadow: 0 4px 15px rgba(227, 136, 21, 0.4);
    transform: translateY(-2px);
}

.region-btn.active::after {
    content: '';
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #e38815;
}

/* Navigation */
.nav {
    background: var(--bg-card);
    padding: 0 24px;
    display: flex;
    justify-content: center;
    gap: 4px;
    border-bottom: 1px solid var(--border);
}

.nav-btn {
    padding: 16px 24px;
    background: none;
    border: none;
    font-size: 16px;
    color: var(--text-light);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.nav-btn:hover {
    color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

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

/* Content */
.content {
    flex: 1;
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.tab-content h2 {
    margin-bottom: 24px;
    color: var(--text);
}

/* Upload */
.upload-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.upload-card {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.upload-card h3 {
    margin-bottom: 16px;
    font-size: 18px;
}

.file-info {
    margin-bottom: 16px;
}

.file-info p {
    color: var(--text-light);
    font-size: 14px;
    margin: 4px 0;
}

.status {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
}

.status.success {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
}

.status.warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    transition: all 0.2s;
}

.upload-area:hover {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.02);
}

.upload-label {
    display: block;
    cursor: pointer;
    color: var(--text-light);
}

/* Mappings */
.add-mapping {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.add-mapping h3 {
    margin-bottom: 16px;
}

.mapping-form {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.mapping-form input {
    flex: 1;
    min-width: 200px;
}

.arrow {
    font-size: 20px;
    color: var(--primary);
}

.mappings-list {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.mappings-list h3 {
    margin-bottom: 16px;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    font-weight: 600;
    color: var(--text-light);
    font-size: 14px;
    text-transform: uppercase;
}

.table tr:hover {
    background: rgba(37, 99, 235, 0.02);
}

.table .arrow {
    text-align: center;
    width: 40px;
}

/* Status Grid */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.status-card {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    border-left: 4px solid var(--danger);
}

.status-card.ready {
    border-left-color: var(--success);
}

.status-icon {
    display: block;
    font-size: 32px;
    margin-bottom: 8px;
}

.status-card.ready .status-icon {
    color: var(--success);
}

.status-card:not(.ready) .status-icon {
    color: var(--danger);
}

/* Process */
.process-actions {
    text-align: center;
    margin-bottom: 32px;
}

.process-output {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.process-output h3 {
    margin-bottom: 16px;
}

.process-output pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.results-section {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.results-section h3 {
    margin-bottom: 16px;
}

.results-section.results-highlight {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    margin-bottom: 24px;
}

.results-section.results-highlight h3 {
    color: white;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.result-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius);
    padding: 20px;
    color: var(--text);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.result-type {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--primary);
}

.result-filename {
    font-weight: 600;
    font-size: 14px;
    word-break: break-all;
}

.result-meta {
    font-size: 13px;
    color: var(--text-light);
    display: flex;
    gap: 16px;
}

.result-card .btn {
    margin-top: auto;
    width: 100%;
}

.results-actions {
    margin-bottom: 16px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.results-section.results-highlight .results-actions .btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid white;
    color: white;
}

.results-section.results-highlight .results-actions .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.3);
}

.results-actions .btn {
    text-decoration: none;
}

/* Output Section - Ergebnisdateien */
.output-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-top: 24px;
    overflow: hidden;
}

.output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--primary);
    color: white;
}

.output-header h3 {
    margin: 0;
    font-size: 16px;
    color: white;
}

.output-actions {
    display: flex;
    gap: 8px;
}

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

.output-actions .btn-primary:hover {
    background: rgba(255, 255, 255, 0.9);
}

.output-actions .btn-secondary {
    background: transparent;
    border: 2px solid white;
    color: white;
}

.output-actions .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.output-files {
    padding: 0;
}

.output-file {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.output-file:last-child {
    border-bottom: none;
}

.output-file:hover {
    background: rgba(149, 185, 79, 0.05);
}

.output-icon {
    width: 44px;
    height: 44px;
    background: var(--primary);
    color: white;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.output-info {
    flex: 1;
    min-width: 0;
}

.output-name {
    font-weight: 500;
    color: var(--text);
    word-break: break-all;
    margin-bottom: 4px;
}

.output-meta {
    font-size: 13px;
    color: var(--text-light);
}

.output-section.output-empty {
    padding: 32px;
    text-align: center;
    background: var(--bg);
}

.output-section.output-empty p {
    color: var(--text-light);
    margin-bottom: 16px;
}

/* Matching Action Button */
.matching-action {
    margin-top: 24px;
    text-align: center;
    padding: 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* Process Results Section */
.process-results-section {
    margin-top: 24px;
}

.process-output-details {
    margin-bottom: 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.process-output-details summary {
    cursor: pointer;
    padding: 12px 20px;
    font-weight: 500;
    background: var(--bg);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.process-output-details summary::-webkit-details-marker {
    display: none;
}

.process-output-details summary::before {
    content: '+';
    font-size: 16px;
    font-weight: bold;
    color: var(--text-light);
}

.process-output-details[open] summary::before {
    content: '-';
}

.process-output-details pre {
    margin: 0;
    padding: 16px 20px;
    background: #1e293b;
    color: #e2e8f0;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 300px;
    overflow-y: auto;
}

/* Backups als Details/Summary */
details.backups-section {
    margin-top: 24px;
}

details.backups-section summary {
    cursor: pointer;
    font-weight: 600;
    padding: 16px 24px;
    background: var(--bg);
    border-radius: var(--radius);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

details.backups-section summary::-webkit-details-marker {
    display: none;
}

details.backups-section summary::before {
    content: '+';
    font-size: 18px;
    font-weight: bold;
    color: var(--primary);
}

details[open].backups-section summary::before {
    content: '-';
}

details.backups-section[open] summary {
    border-radius: var(--radius) var(--radius) 0 0;
}

details.backups-section .table {
    border-radius: 0 0 var(--radius) var(--radius);
}

.backups-actions {
    padding: 12px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

/* Settings */
.settings-section {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.settings-section h3 {
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.hint {
    display: block;
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
}

/* Notifications */
.notifications {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
}

.notification {
    padding: 16px 24px;
    border-radius: var(--radius);
    margin-top: 12px;
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
}

.notification.success {
    background: var(--success);
    color: white;
}

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

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

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Error */
.error {
    color: var(--danger);
    margin-top: 12px;
    text-align: center;
}

/* Backups */
.backups-section {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.backups-section h3 {
    margin-bottom: 16px;
}

/* History */
.download-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    padding: 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.download-actions .btn {
    text-decoration: none;
}

.history-controls {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.history-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.history-group-options {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.history-group-options label {
    font-weight: 500;
    color: var(--text-light);
    font-size: 14px;
}

.group-select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.group-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Gruppierte Historie */
.history-grouped {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.history-group {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.history-group-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--bg);
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid var(--border);
}

.history-group-header:hover {
    background: rgba(149, 185, 79, 0.1);
}

.group-toggle {
    font-size: 18px;
    font-weight: bold;
    color: var(--primary);
    width: 24px;
    text-align: center;
}

.group-title {
    font-weight: 600;
    color: var(--text);
    flex: 1;
}

.group-count {
    font-size: 13px;
    color: var(--text-light);
    background: var(--border);
    padding: 4px 10px;
    border-radius: 12px;
}

.history-group-content {
    padding: 0;
}

.history-group-content .history-entry {
    border-bottom: 1px solid var(--border);
    margin: 0;
}

.history-group-content .history-entry:last-child {
    border-bottom: none;
}

.history-list {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.history-entry {
    display: flex;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.history-entry:last-child {
    border-bottom: none;
}

.history-entry:hover {
    background: rgba(37, 99, 235, 0.02);
}

.history-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.history-actions .btn {
    text-decoration: none;
}

.history-icon {
    font-size: 24px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: var(--radius);
    flex-shrink: 0;
}

.history-content {
    flex: 1;
    min-width: 0;
}

.history-action {
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
}

.history-details {
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 4px;
}

.history-meta {
    font-size: 13px;
    color: var(--text-light);
    display: flex;
    gap: 16px;
}

.history-user {
    font-weight: 500;
}

.history-time {
    opacity: 0.8;
}

.history-region {
    color: var(--primary);
    font-weight: 500;
}

/* Responsive */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 12px;
    }

    .nav {
        overflow-x: auto;
    }

    .nav-btn {
        padding: 12px 16px;
        font-size: 14px;
    }

    .mapping-form {
        flex-direction: column;
    }

    .mapping-form input {
        width: 100%;
    }

    .table {
        font-size: 14px;
    }

    .table th,
    .table td {
        padding: 8px 12px;
    }
}
