:root {
    --brand-black: #111111;
    --brand-dark: #333333;
    --brand-gray-700: #495057;
    --brand-gray-600: #6c757d;
    --brand-gray-300: #ced4da;
    --brand-gray-200: #e5e5e5;
    --brand-gray-100: #f5f5f5;
    --brand-white: #ffffff;
}

/* Border-Box überall: width:100% schließt Padding/Border ein (sonst laufen
   z. B. die Tab-Buttons über die Kartenkante hinaus). */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 40px 20px;
    background-color: #fafafa;
    color: var(--brand-black);
}

.container {
    max-width: 960px;
    margin: 0 auto;
    background: var(--brand-white);
    padding: 40px;
    border-radius: 12px;
    border: 1px solid var(--brand-gray-200);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
}

.brand {
    text-align: center;
    margin-bottom: 24px;
}

/* Obere Leiste: Benutzerinfo + Abmelden */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--brand-gray-600);
}

.top-bar .user-info strong {
    color: var(--brand-black);
}

.logo {
    width: 140px;
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto 10px;
}

h1 {
    color: var(--brand-black);
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

h2 {
    color: var(--brand-black);
    margin-bottom: 20px;
    font-size: 19px;
    font-weight: 600;
    border-bottom: 2px solid var(--brand-black);
    padding-bottom: 10px;
}

.section { margin-bottom: 30px; }

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--brand-gray-700);
}

input[type="text"], input[type="password"], input[type="file"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--brand-gray-300);
    border-radius: 4px;
    font-size: 16px;
    color: var(--brand-black);
    background-color: var(--brand-white);
    box-sizing: border-box;
    transition: border-color 0.15s;
}

input:focus {
    outline: 0;
    border-color: var(--brand-black);
    box-shadow: 0 0 0 0.2rem rgba(17, 17, 17, 0.12);
}

button {
    background: var(--brand-black);
    color: var(--brand-white);
    padding: 12px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: background-color 0.15s;
}

button:hover {
    background: var(--brand-dark);
}

button:disabled {
    background: var(--brand-gray-600);
    cursor: not-allowed;
}

.hidden { display: none; }

.status {
    margin: 20px 0;
    padding: 12px 15px;
    border-radius: 4px;
    font-size: 15px;
}

.status.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.status.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.status.info {
    background: var(--brand-gray-100);
    color: var(--brand-gray-700);
    border: 1px solid var(--brand-gray-200);
}

/* Wegklickbares Status-Banner mit Schließen-Button */
.status:has(.status-close) {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

/* Per .hidden ausgeblendete Status-Banner (z. B. Upload-Fehler) müssen auch mit
   Schließen-Button versteckt bleiben. */
.status.hidden {
    display: none;
}

.status .status-close {
    background: none;
    border: none;
    padding: 0;
    font-size: 20px;
    line-height: 1;
    font-weight: 600;
    color: inherit;
    cursor: pointer;
    flex-shrink: 0;
}

.status .status-close:hover {
    background: none;
    opacity: 0.7;
}

.result {
    margin-top: 25px;
    padding: 20px;
    background: var(--brand-gray-100);
    border-radius: 4px;
    border: 1px solid var(--brand-gray-200);
    overflow-x: auto;
}

.result h3 {
    margin-top: 0;
    color: var(--brand-black);
    font-size: 18px;
}

.result pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    background: var(--brand-white);
    padding: 15px;
    border-radius: 4px;
    margin-top: 15px;
    font-size: 13px;
    overflow-x: auto;
}

.result a {
    color: var(--brand-black);
    text-decoration: none;
    font-weight: 600;
}

.result a:hover {
    text-decoration: underline;
}

.progress-container {
    margin: 20px 0;
}

.progress-bar {
    position: relative;
    height: 20px;
    background: var(--brand-gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    background-color: var(--brand-black);
    /* Laufende Streifen zeigen auch bei unverändertem Prozentwert an, dass im
       Hintergrund weitergearbeitet wird (z. B. während OCR/Modellaufrufen). */
    background-image: linear-gradient(45deg,
        rgba(255, 255, 255, 0.22) 25%, transparent 25%,
        transparent 50%, rgba(255, 255, 255, 0.22) 50%,
        rgba(255, 255, 255, 0.22) 75%, transparent 75%, transparent);
    background-size: 1rem 1rem;
    transition: width 0.3s ease;
    animation: progress-stripes 1s linear infinite;
}

/* Solange Gesamt/Fortschritt unbekannt sind, läuft ein Balken hin und her. */
.progress-bar.indeterminate .progress-fill {
    width: 35% !important;
    animation: progress-stripes 1s linear infinite, progress-indeterminate 1.3s ease-in-out infinite;
}

@keyframes progress-stripes {
    from { background-position: 0 0; }
    to { background-position: 1rem 0; }
}

@keyframes progress-indeterminate {
    0% { margin-left: -35%; }
    100% { margin-left: 100%; }
}

/* Rotierender Indikator neben dem Fortschrittstext – signalisiert Aktivität. */
.progress-spinner {
    display: inline-block;
    flex: none;
    width: 13px;
    height: 13px;
    margin-right: 7px;
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-top-color: var(--brand-black);
    border-radius: 50%;
    animation: progress-spin 0.7s linear infinite;
}

@keyframes progress-spin {
    to { transform: rotate(360deg); }
}

.progress-info {
    display: flex;
    align-items: center;
}

.upload-progress h3 {
    margin-bottom: 4px;
}

@media (prefers-reduced-motion: reduce) {
    .progress-fill,
    .progress-bar.indeterminate .progress-fill {
        animation: none;
    }

    .progress-spinner {
        animation-duration: 1.6s;
    }
}

/* E-Mail Section Styles */
.email-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.email-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    line-height: inherit;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-block;
}

.btn-icon {
    padding: 6px 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon svg {
    display: block;
}

.btn-icon-round {
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.btn-icon-round svg {
    display: block;
}

.btn-primary {
    background: var(--brand-black);
    color: var(--brand-white);
}

.btn-primary:hover {
    background: var(--brand-dark);
}

.btn-secondary {
    background: var(--brand-gray-200);
    color: var(--brand-black);
}

.btn-secondary:hover {
    background: var(--brand-gray-300);
}

.email-table-container {
    overflow-x: auto;
    margin-bottom: 20px;
}

.email-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.email-table th,
.email-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--brand-gray-200);
}

.email-table th {
    background: var(--brand-gray-100);
    font-weight: 600;
    color: var(--brand-gray-700);
    position: sticky;
    top: 0;
}

.email-table tr:hover {
    background: var(--brand-gray-100);
}

.email-table .checkbox-col {
    width: 40px;
    text-align: center;
}

.email-table .subject-col {
    width: 40%;
    min-width: 200px;
}

.email-table .from-col {
    width: 25%;
    min-width: 150px;
}

.email-table .date-col {
    width: 20%;
    min-width: 120px;
}

.email-table .attachments-col {
    width: 80px;
    text-align: center;
}

.email-row {
    cursor: pointer;
}

.email-row.selected {
    background: #d4edda !important;
}

.email-row input[type="checkbox"] {
    cursor: pointer;
}

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--brand-gray-200);
}

#pagination-info {
    color: var(--brand-gray-600);
    font-size: 14px;
}

#load-more-btn {
    margin-left: auto;
}

/* Navigation - Tab Control */
.navigation {
    margin: 24px 0 32px 0;
}

.tab-container {
    display: flex;
    gap: 2px;
    border-bottom: 2px solid var(--brand-gray-200);
}

.tab-btn {
    padding: 10px 24px;
    background: var(--brand-gray-100);
    color: var(--brand-gray-600);
    border: 1px solid var(--brand-gray-200);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: background 0.2s ease, color 0.2s ease;
    text-decoration: none;
    display: inline-block;
    margin-bottom: -2px;
}

.tab-btn:hover {
    background: var(--brand-gray-200);
    color: var(--brand-black);
}

.tab-btn.active,
.tab-btn.active:hover {
    background: var(--brand-white);
    color: var(--brand-black);
    font-weight: 600;
    border-color: var(--brand-gray-200);
    border-bottom: 2px solid var(--brand-white);
}

/* Attachment badge */
.attachment-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--brand-black);
    color: var(--brand-white);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
}

.attachment-badge .count {
    font-weight: 600;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 220px;
}

.attachment-link {
    color: var(--brand-accent);
    text-decoration: none;
    font-size: 13px;
    line-height: 1.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-link:hover {
    text-decoration: underline;
}

.attachment-download {
    color: var(--brand-gray-600);
    text-decoration: none;
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
}

.attachment-download:hover {
    color: var(--brand-black);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    body {
        padding: 16px 10px;
    }

    .container {
        padding: 20px 16px;
    }

    .brand {
        margin-bottom: 16px;
    }

    .logo {
        width: 96px;
        margin-bottom: 6px;
    }

    h1 {
        font-size: 21px;
    }

    .navigation {
        margin: 16px 0 20px;
    }

    /* Kompakte Segment-Tabs nebeneinander statt gestapelter Blöcke. */
    .tab-container {
        flex-direction: row;
        gap: 2px;
        border-bottom: 2px solid var(--brand-gray-200);
    }

    .tab-btn {
        flex: 1;
        text-align: center;
        padding: 10px 8px;
        font-size: 14px;
        border-radius: 6px 6px 0 0;
        margin-bottom: -2px;
    }

    .tab-btn.active {
        border-bottom: 2px solid var(--brand-white);
    }

    .drop-zone {
        padding: 20px 12px;
    }

    .form-group button {
        width: 100%;
    }

    .email-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .top-bar {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .review-actions {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .review-actions button {
        width: 100%;
    }

    .email-group-header {
        flex-wrap: wrap;
    }

    .email-actions {
        width: 100%;
    }

    /* Runder Icon-Button nicht mitstretching (sonst Oval statt Kreis). */
    .email-actions .btn:not(.btn-icon-round) {
        flex: 1;
    }

    .email-actions .inline-form {
        flex: 1;
    }

    .email-actions .inline-form .btn {
        width: 100%;
    }

    /* Tabellen auf schmalen Screens: schrumpfen statt seitlich rauslaufen. */
    .email-table th,
    .email-table td {
        padding: 8px 10px;
    }

    .email-table td {
        word-break: break-word;
    }

    .email-table .subject-col,
    .email-table .from-col,
    .email-table .date-col {
        min-width: 0;
    }

    .email-table .subject-col {
        width: 35%;
    }

    .email-table .from-col {
        width: 25%;
    }

    .upload-camera-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .upload-camera-divider {
        display: flex;
        align-items: center;
        justify-content: center;
        text-transform: uppercase;
        letter-spacing: 0.4px;
    }

    .upload-camera-row .btn {
        flex: none;
        width: 100%;
    }

    .camera-modal-content {
        padding: 14px;
    }

    .camera-actions .btn {
        flex: 1;
    }
}

@media (max-width: 480px) {
    /* Datum-Spalte weglassen, damit Betreff/Von/Anhänge auf das Phone passen. */
    .email-table .date-col {
        display: none;
    }

    .tab-btn {
        padding: 9px 4px;
        font-size: 13px;
    }
}

/* Formular-Validierung */
.text-danger {
    color: #721c24;
    font-size: 13px;
    font-weight: 600;
}

/* Abmelden-Button in der Tab-Leiste */
.logout-form {
    margin: 0;
}

/* Formular innerhalb der E-Mail-Aktionsleiste */
.inline-form {
    margin: 0;
    display: inline-block;
}

/* Detail-Listen der Verarbeitungs-Ergebnisse (übersprungen/Fehler) */
.processing-list {
    margin: 10px 0 20px;
    padding-left: 20px;
    font-size: 14px;
    color: var(--brand-gray-700);
    max-height: 200px;
    overflow-y: auto;
}

.processing-list li {
    margin-bottom: 6px;
}

/* Nicht erkannte Dateien: eigener, klar abgegrenzter Block mit Gründen */
.not-recognized {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--brand-gray-200);
}

.not-recognized h4 {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 600;
    color: var(--brand-black);
}

.section-hint {
    margin: 0 0 12px;
    font-size: 13px;
    color: var(--brand-gray-600);
}

.skip-source {
    color: var(--brand-gray-600);
    font-size: 12px;
}

.reason-list {
    margin: 0;
    padding-left: 18px;
    font-size: 13px;
    color: var(--brand-gray-700);
}

.reason-list li {
    margin-bottom: 4px;
}

/* Hinweis-Marker an erkannten Rechnungen (Tooltip mit Details) */
.warning-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    cursor: help;
}

/* Prüftabelle der erkannten Rechnungen */
.review-table .checkbox-col {
    width: 40px;
}

/* Gruppierung erkannter Rechnungen nach E-Mail */
.email-group {
    margin-bottom: 24px;
    border: 1px solid var(--brand-gray-200);
    border-radius: 8px;
    overflow: hidden;
}

.email-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--brand-gray-100);
    font-size: 14px;
}

.email-group-header .email-group-from {
    color: var(--brand-gray-600);
    font-size: 13px;
}

.email-group-header .email-group-hint {
    color: var(--brand-gray-600);
    font-size: 12px;
    font-style: italic;
}

.email-group .email-table-container {
    margin-bottom: 0;
}

.invoice-row {
    cursor: pointer;
}

.review-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
}

/* Upload: Drag&Drop-Zone + Dateiliste */
.drop-zone {
    position: relative;
    border: 2px dashed var(--brand-gray-300);
    border-radius: 8px;
    background: var(--brand-gray-100);
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
    margin-bottom: 16px;
    overflow: hidden;
}

.drop-zone:hover,
.drop-zone.drop-zone-active,
.drop-zone:focus-within {
    border-color: var(--brand-black);
    background: var(--brand-white);
}

.drop-zone-title {
    margin: 0 0 4px;
    font-size: 16px;
    color: var(--brand-gray-700);
    pointer-events: none;
}

.drop-zone-hint {
    margin: 0;
    font-size: 13px;
    color: var(--brand-gray-600);
    pointer-events: none;
}

.drop-zone input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    padding: 0;
}

.file-list {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
    border: 1px solid var(--brand-gray-200);
    border-radius: 8px;
    overflow: hidden;
}

.file-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    font-size: 14px;
    background: var(--brand-white);
    border-bottom: 1px solid var(--brand-gray-200);
}

.file-list-item:last-child {
    border-bottom: none;
}

.file-list-item .file-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-list-item .file-size {
    color: var(--brand-gray-600);
    font-size: 12px;
    flex-shrink: 0;
}

.file-remove {
    background: none;
    border: none;
    color: var(--brand-gray-600);
    font-size: 20px;
    line-height: 1;
    padding: 0 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.file-remove:hover {
    color: #721c24;
    background: none;
}

.file-list-empty {
    padding: 10px 14px;
    font-size: 13px;
    color: var(--brand-gray-600);
    background: var(--brand-white);
}

.file-limit-warning {
    margin: 0 0 16px;
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 14px;
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

/* Upload: Rechnung per Foto aufnehmen (Kamera) */
.upload-camera-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: -6px 0 2px;
}

.upload-camera-divider {
    font-size: 13px;
    color: var(--brand-gray-600);
    flex-shrink: 0;
}

.upload-camera-row .btn {
    flex-shrink: 0;
}

.upload-camera-hint {
    margin: 0 0 16px;
    font-size: 12px;
    color: var(--brand-gray-600);
}

input.camera-fallback-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.camera-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.5);
}

.camera-modal[hidden] {
    display: none;
}

.camera-modal-content {
    background: var(--brand-white);
    border-radius: 12px;
    padding: 20px;
    width: 100%;
    max-width: 560px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.camera-title {
    margin: 0 0 14px;
    font-size: 18px;
    font-weight: 600;
    color: var(--brand-black);
}

#camera-video {
    display: block;
    width: 100%;
    max-height: 70vh;
    background: var(--brand-black);
    border-radius: 8px;
    object-fit: contain;
}

#camera-canvas {
    display: none;
}

.camera-error {
    margin: 0 0 14px;
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 14px;
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.camera-error[hidden] {
    display: none;
}

.camera-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.camera-actions .btn[hidden] {
    display: none;
}

/* Feedback nach Foto-Übernahme */
.upload-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    z-index: 1100;
    max-width: min(92vw, 520px);
    background: #155e3a;
    color: var(--brand-white);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.upload-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@keyframes submit-attention {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 193, 7, 0);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(255, 193, 7, 0.75);
    }
}

#upload-submit-btn.btn-attention {
    animation: submit-attention 0.9s ease 3;
}
