:root {
    --bg-color: #0f172a;
    --sidebar-bg: #1e293b;
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --accent: #38bdf8;
    --accent-glow: rgba(56, 189, 248, 0.2);
    --card-bg: #1e293b;
    --border: #334155;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
}

/* Utility Classes */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-baseline { align-items: baseline; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-16 { width: 4rem; }
.flex-shrink-0 { flex-shrink: 0; }
.overflow-hidden { overflow: hidden; }
.min-w-0 { min-width: 0; }
.pr-1 { padding-right: 4px; }
.pl-2 { padding-left: 8px; }
.uppercase { text-transform: uppercase; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: row-reverse;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 350px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-family: 'Outfit', sans-serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 8px;
}

.logo span {
    color: var(--accent);
}

.sidebar-header h1 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
}

.document-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.doc-item {
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.doc-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border);
}

.doc-item.active {
    background: var(--accent-glow);
    border-color: var(--accent);
}

.doc-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.doc-filename {
    font-weight: 600;
    font-size: 14px;
}

.doc-meta {
    font-size: 12px;
    color: var(--text-dim);
}

.status-badge {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-badge.CONFIRMED {
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
}

.status-badge.RETRY {
    background: var(--warning);
    box-shadow: 0 0 10px var(--warning);
}

.status-badge.ERROR {
    background: var(--error);
    box-shadow: 0 0 10px var(--error);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--text-dim);
}

.empty-state .icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.detail-view {
    flex: 1;
    overflow: hidden;
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 400px) 1fr;
    gap: 24px;
    height: 100%;
    width: 100%;
    overflow: hidden;
    min-height: 0;
}

.pdf-viewer-container {
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    min-height: 0;
}

.view-header {
    background: var(--sidebar-bg);
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.view-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
}

.pdf-viewer-overlay-container {
    flex: 1;
    position: relative;
    overflow: auto;
    background: #404448;
    /* Klassisches PDF-Grau */
    display: flex;
    justify-content: center;
    /* Zentrierung */
    padding: 20px;
}

.document-wrapper {
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    background: white;
    height: fit-content;
}

iframe,
#pdf-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 1000px;
    /* Begrenzung für bessere Lesbarkeit */
}

.highlight-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

.doc-box {
    position: absolute;
    border: 2px solid var(--accent);
    background: rgba(56, 189, 248, 0.2);
    box-shadow: 0 0 8px var(--accent);
    border-radius: 2px;
    z-index: 10;
    transition: all 0.3s ease;
}

.doc-box::after {
    content: attr(data-label);
    position: absolute;
    top: -20px;
    left: 0;
    background: var(--accent);
    color: #000;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.learned-box {
    border-color: var(--warning);
    background: rgba(245, 158, 11, 0.2);
    box-shadow: 0 0 8px var(--warning);
}

.learned-box::after {
    background: var(--warning);
    color: #000;
}

.metadata-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    min-width: 0;
}

.meta-section {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
}

.meta-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.meta-header-row h3 {
    margin-bottom: 0 !important;
}

.select-all-container {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
}

.select-all-container input {
    accent-color: var(--accent);
    cursor: pointer;
}

.fields-grid {
    display: grid;
    gap: 12px;
}

.field-row {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 12px;
    width: 100% !important;
    overflow: hidden !important;
    box-sizing: border-box;
}

.field-row.with-checkbox {
    gap: 12px;
}

.field-info {
    flex: 1;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 8px !important;
    min-width: 0 !important;
    overflow: hidden !important;
}

.field-info-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex-grow: 1;
    overflow: hidden;
}

.conf-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px !important;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 4px;
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #e2e8f0;
    white-space: nowrap;
    margin-left: auto;
    line-height: normal;
    flex-shrink: 0;
}

.highlight-toggle {
    margin-top: 18px;
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent);
}

.field-label {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    white-space: nowrap;
}

.field-value {
    font-size: 14px;
    background: rgba(0, 0, 0, 0.2);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    width: 100% !important;
    display: block !important;
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

th {
    background: rgba(0, 0, 0, 0.3);
    text-align: left;
    padding: 10px;
    color: var(--text-dim);
}

td {
    padding: 10px;
    border-top: 1px solid var(--border);
}

/* Word Cloud */
.word-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.word-tag {
    background: rgba(56, 189, 248, 0.1);
    color: var(--accent);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    border: 1px solid rgba(56, 189, 248, 0.2);
}

.hint {
    font-style: italic;
    color: var(--text-dim);
}

/* Selection Box for Learning Mode */
.selection-rect {
    position: absolute;
    border: 2px dashed var(--accent);
    background: rgba(56, 189, 248, 0.3);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
    pointer-events: none;
    z-index: 1000;
}

.document-wrapper {
    cursor: crosshair;
    user-select: none;
    -webkit-user-drag: none;
}

/* Lern Modus UI */
.lern-section {
    border-color: var(--warning);
}

.correction-row {
    background: rgba(245, 158, 11, 0.05);
    border: 1px solid rgba(245, 158, 11, 0.2);
    padding: 12px;
    border-radius: 8px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-select {
    background: var(--sidebar-bg);
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 6px;
    border-radius: 4px;
    font-size: 12px;
}

.custom-field-name {
    background: var(--bg-color);
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    outline: none;
}

.field-value-input {
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 8px;
    border-radius: 4px;
    font-size: 13px;
    width: 100%;
    resize: vertical;
}

.btn-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: var(--error);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-save {
    background: var(--success);
    color: #fff;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(34, 197, 94, 0.3);
}

.btn-save:hover {
    background: #16a34a;
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(34, 197, 94, 0.4);
}

.btn-save:disabled {
    background: #475569;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}