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

:root {
    --blue-50: #eff6ff; --blue-100: #dbeafe; --blue-500: #3b82f6;
    --blue-600: #2563eb; --blue-700: #1d4ed8;
    --green-50: #f0fdf4; --green-500: #22c55e; --green-600: #16a34a;
    --red-50: #fef2f2; --red-500: #ef4444; --red-600: #dc2626;
    --yellow-50: #fefce8; --yellow-500: #eab308;
    --gray-50: #f8fafc; --gray-100: #f1f5f9; --gray-200: #e2e8f0;
    --gray-300: #cbd5e1; --gray-400: #94a3b8; --gray-500: #64748b;
    --gray-600: #475569; --gray-700: #334155; --gray-800: #1e293b;
    --gray-900: #0f172a;
    --sidebar-bg: #0f172a;
    --sidebar-width: 260px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
    --transition: 150ms ease;
}

html { font-size: 15px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App Layout ──────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-header { padding: 1.25rem 1rem; border-bottom: 1px solid rgba(255,255,255,.1); }
.logo { display: flex; align-items: center; gap: .75rem; }
.logo span { font-weight: 700; font-size: 1.05rem; line-height: 1.2; }
.logo small { font-weight: 400; font-size: .75rem; color: var(--blue-500); letter-spacing: .05em; text-transform: uppercase; }

.sidebar-nav { flex: 1; padding: .5rem 0; }
.nav-item {
    display: flex; align-items: center; gap: .75rem;
    padding: .625rem 1rem; margin: 2px .5rem;
    color: var(--gray-300); border-radius: 6px;
    transition: all var(--transition); font-size: .9rem;
    text-decoration: none;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--blue-600); color: #fff; }
.nav-divider { height: 1px; background: rgba(255,255,255,.1); margin: .5rem 1rem; }
.nav-section-label {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
    color: rgba(255,255,255,.4); padding: .35rem 1.25rem .15rem;
    font-weight: 600;
}
.nav-item-sub { font-size: .82rem !important; padding: .45rem 1rem .45rem 1.25rem !important; }
.nav-item-sub svg { opacity: .7; }

.sidebar-footer {
    padding: .75rem 1rem;
    border-top: 1px solid rgba(255,255,255,.1);
    display: flex; align-items: center; justify-content: space-between;
}
.user-info { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--gray-300); }
.btn-logout {
    color: var(--gray-400); padding: .25rem; border-radius: 4px;
    transition: all var(--transition);
}
.btn-logout:hover { color: var(--red-500); background: rgba(255,255,255,.08); }

/* ── Main Content ────────────────────────────────────────────────── */
.main-content {
    flex: 1; margin-left: var(--sidebar-width);
    padding: 1.5rem 2rem;
}

/* ── Page Header ─────────────────────────────────────────────────── */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.5rem; flex-wrap: wrap; gap: .75rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); }
.breadcrumb { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--gray-500); }
.breadcrumb a { color: var(--blue-600); }
.breadcrumb span:not(:first-child):not(:last-child) { color: var(--gray-300); }
.header-actions { display: flex; gap: .5rem; align-items: center; }
.header-actions form { display: flex; align-items: center; }
.header-actions .btn, .header-actions .folder-input-header,
.accounting-check-header, .file-action-inline, .badge {
    height: 32px; box-sizing: border-box;
}
.header-actions .btn { display: inline-flex; align-items: center; }
.accounting-check-header { display: inline-flex; align-items: center; }
.file-action-inline { display: inline-flex; align-items: center; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .5rem 1rem; border: none; border-radius: var(--radius);
    font-size: .875rem; font-weight: 500; cursor: pointer;
    transition: all var(--transition); text-decoration: none; line-height: 1.5;
    font-family: inherit;
}
.btn-primary { background: var(--blue-600); color: #fff; }
.btn-primary:hover { background: var(--blue-700); text-decoration: none; }
.btn-outline { background: #fff; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); text-decoration: none; }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-danger:hover { background: #b91c1c; text-decoration: none; }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── Stats Grid ──────────────────────────────────────────────────── */
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
    background: #fff; border-radius: var(--radius); padding: 1.25rem;
    box-shadow: var(--shadow); border: 1px solid var(--gray-200);
}
.stat-number { font-size: 2rem; font-weight: 700; color: var(--blue-600); line-height: 1; }
.stat-label { font-size: .8rem; color: var(--gray-500); margin-top: .35rem; text-transform: uppercase; letter-spacing: .05em; }

/* ── Filter Bar ──────────────────────────────────────────────────── */
.filter-bar {
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
    padding: .75rem 1rem; background: #fff; border-radius: var(--radius);
    border: 1px solid var(--gray-200); margin-bottom: 1rem;
}
.filter-group { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }
.filter-group label { color: var(--gray-500); font-weight: 500; white-space: nowrap; }
.filter-group select {
    padding: .3rem .5rem; border: 1px solid var(--gray-300); border-radius: 6px;
    font-size: .85rem; background: #fff; color: var(--gray-700); font-family: inherit;
}

/* ── Document Table ──────────────────────────────────────────────── */
.doc-table-wrap {
    background: #fff; border-radius: var(--radius);
    border: 1px solid var(--gray-200); overflow: hidden;
    box-shadow: var(--shadow);
}
.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th {
    text-align: left; padding: .75rem 1rem; font-size: .75rem;
    text-transform: uppercase; letter-spacing: .05em; color: var(--gray-500);
    background: var(--gray-50); border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
}
.doc-table td { padding: .75rem 1rem; border-bottom: 1px solid var(--gray-100); font-size: .9rem; }
.doc-table tbody tr:last-child td { border-bottom: none; }
.doc-table th.sortable { padding: 0; }
.doc-table th.sortable a {
    display: block; padding: .75rem 1rem; color: inherit;
    text-decoration: none; cursor: pointer;
    transition: background var(--transition);
}
.doc-table th.sortable a:hover { background: var(--gray-100); text-decoration: none; color: var(--blue-600); }
.doc-table th.sorted-asc a, .doc-table th.sorted-desc a { color: var(--blue-600); background: var(--blue-50); }
.sort-arrow { font-size: .7rem; margin-left: .25rem; color: var(--blue-500); }
.dup-list { display: flex; flex-direction: column; gap: 1.5rem; }
.dup-group {
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow);
}
.dup-group-header {
    padding: .75rem 1rem; background: var(--yellow-50);
    border-bottom: 1px solid #fde68a; font-size: .9rem; color: var(--gray-700);
}
.dup-group-header code { font-size: .85rem; }
.text-muted { color: var(--gray-500); }
.doc-row { cursor: pointer; transition: background var(--transition); }
.doc-row:hover { background: var(--blue-50); }

.doc-name-cell { display: flex; align-items: center; gap: .75rem; }
.doc-icon {
    width: 36px; height: 36px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.doc-icon-pdf { background: #fef2f2; color: var(--red-500); }
.doc-icon-jpg, .doc-icon-jpeg, .doc-icon-png { background: var(--green-50); color: var(--green-500); }
.doc-title { font-weight: 600; color: var(--gray-800); }
.doc-filename { font-size: .75rem; color: var(--gray-400); margin-top: 1px; }

.text-right { text-align: right; }
.actions-cell { display: flex; gap: .35rem; }

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
    display: inline-block; padding: .15rem .5rem; border-radius: 9999px;
    font-size: .75rem; font-weight: 500; white-space: nowrap;
}
.badge-blue { background: var(--blue-100); color: var(--blue-700); }
.badge-green { background: var(--green-50); color: var(--green-600); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-red { background: var(--red-50); color: var(--red-600); }

/* ── Status ──────────────────────────────────────────────────────── */
.status {
    display: inline-flex; align-items: center; gap: .35rem;
    font-size: .8rem; font-weight: 500;
}
.status::before {
    content: ''; width: 7px; height: 7px; border-radius: 50%;
}
.status-pending::before { background: var(--yellow-500); }
.status-processing::before { background: var(--blue-500); animation: pulse 1.5s infinite; }
.status-completed::before { background: var(--green-500); }
.status-error::before { background: var(--red-500); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
}

/* ── Pagination ──────────────────────────────────────────────────── */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 1rem; margin-top: 1.25rem;
}
.page-info { font-size: .85rem; color: var(--gray-500); }

/* ── Empty State ─────────────────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 3rem 1rem;
    background: #fff; border-radius: var(--radius);
    border: 2px dashed var(--gray-200);
}
.empty-state h3 { margin-top: 1rem; color: var(--gray-600); }
.empty-state p { color: var(--gray-400); margin: .5rem 0 1.25rem; }

/* ── Flash Messages ──────────────────────────────────────────────── */
.flash-messages { margin-bottom: 1rem; }
.flash {
    padding: .75rem 1rem; border-radius: var(--radius); font-size: .9rem;
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: .5rem; animation: slideDown .3s ease;
}
.flash-success { background: var(--green-50); color: var(--green-600); border: 1px solid #bbf7d0; }
.flash-error { background: var(--red-50); color: var(--red-600); border: 1px solid #fecaca; }
.flash-close {
    background: none; border: none; font-size: 1.25rem;
    cursor: pointer; color: inherit; opacity: .6; line-height: 1;
}
.flash-close:hover { opacity: 1; }

@keyframes slideDown {
    from { transform: translateY(-10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ── Login Page ──────────────────────────────────────────────────── */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--gray-900) 0%, #1e3a5f 100%);
    padding: 1rem;
}
.login-card {
    background: #fff; border-radius: 12px; padding: 2.5rem;
    width: 100%; max-width: 400px; box-shadow: 0 25px 50px rgba(0,0,0,.25);
}
.login-header { text-align: center; margin-bottom: 2rem; }
.login-header svg { margin-bottom: .75rem; }
.login-header h1 { font-size: 1.5rem; color: var(--gray-900); }
.login-header p { color: var(--gray-500); font-size: .9rem; margin-top: .25rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.remember-check {
    display: flex; align-items: center; gap: .5rem;
    font-size: .9rem; color: var(--gray-600); cursor: pointer; user-select: none;
}
.remember-check input { accent-color: var(--blue-600); width: 16px; height: 16px; cursor: pointer; }
.login-footer { text-align: center; margin-top: 1.5rem; color: var(--gray-400); }

/* ── Forms ────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label { font-size: .85rem; font-weight: 500; color: var(--gray-600); }
.form-group input, .form-select {
    padding: .6rem .75rem; border: 1px solid var(--gray-300); border-radius: var(--radius);
    font-size: .9rem; transition: border-color var(--transition);
    font-family: inherit; background: #fff; color: var(--gray-800);
}
.form-group input:focus, .form-select:focus {
    outline: none; border-color: var(--blue-500);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.form-input {
    padding: .6rem .75rem; border: 1px solid var(--gray-300); border-radius: var(--radius);
    font-size: .9rem; transition: border-color var(--transition);
    font-family: inherit; background: #fff; color: var(--gray-800); box-sizing: border-box;
}
.form-input:focus {
    outline: none; border-color: var(--blue-500);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

/* ── Upload Zone ─────────────────────────────────────────────────── */
.upload-container {
    max-width: 700px;
}
.upload-zone {
    border: 2px dashed var(--gray-300); border-radius: var(--radius);
    padding: 3rem 2rem; text-align: center; cursor: pointer;
    transition: all var(--transition); background: #fff;
    margin-top: 1rem;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--blue-500); background: var(--blue-50);
}
.upload-zone h3 { margin-top: 1rem; color: var(--gray-700); }
.upload-zone p { color: var(--gray-400); font-size: .9rem; }
.upload-hint { font-size: .8rem !important; color: var(--gray-400) !important; margin-top: .5rem; }

.file-list {
    margin-top: 1rem; background: #fff; border-radius: var(--radius);
    border: 1px solid var(--gray-200); overflow: hidden;
}
.file-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: .75rem 1rem; border-bottom: 1px solid var(--gray-100);
}
.file-item:last-child { border-bottom: none; }
.file-item-name { font-size: .9rem; font-weight: 500; }
.file-item-size { font-size: .8rem; color: var(--gray-400); }
.file-item-remove {
    background: none; border: none; color: var(--gray-400);
    cursor: pointer; font-size: 1.1rem; padding: .25rem;
}
.file-item-remove:hover { color: var(--red-500); }

/* ── Info Card ────────────────────────────────────────────────────── */
.info-card {
    margin-top: 2rem; padding: 1.25rem; background: var(--blue-50);
    border-radius: var(--radius); border: 1px solid var(--blue-100);
    max-width: 700px;
}
.info-card h3 {
    display: flex; align-items: center; gap: .5rem;
    color: var(--blue-700); font-size: 1rem; margin-bottom: .75rem;
}
.info-card p { font-size: .9rem; color: var(--gray-600); }
.info-text { margin-top: .75rem; font-size: .85rem !important; color: var(--gray-500) !important; }
.smb-shares { display: flex; flex-direction: column; gap: .5rem; margin: .75rem 0; }
.smb-share {
    display: flex; align-items: center; justify-content: space-between;
    background: #fff; padding: .5rem .75rem; border-radius: 6px;
    border: 1px solid var(--gray-200);
}
.smb-share code { font-size: .85rem; color: var(--gray-700); }

/* ── Document Detail ─────────────────────────────────────────────── */
.document-layout {
    display: grid;
    grid-template-columns: minmax(360px, 1fr) minmax(0, 1.6fr);
    gap: 1.5rem; align-items: start;
    height: calc(100vh - 6rem);
}
/* Info = column 1, Preview = column 2 (HTML order enforced by grid) */
.document-info { order: 1; }
.document-preview { order: 2; }

.document-preview {
    position: sticky; top: 1.5rem;
    height: calc(100vh - 7rem);
    display: flex; flex-direction: column; gap: .5rem;
}
.preview-container {
    background: #fff; border-radius: var(--radius); border: 1px solid var(--gray-200);
    overflow: hidden; flex: 1; min-height: 0;
}
.preview-container object, .preview-container iframe { width: 100%; height: 100%; border: none; }
.preview-image { width: 100%; height: 100%; object-fit: contain; }
.document-info {
    display: flex; flex-direction: column; gap: 1.25rem;
    overflow-y: auto; max-height: calc(100vh - 7rem);
    padding-right: .5rem; padding-bottom: 4rem;
    scrollbar-width: thin; scrollbar-color: var(--gray-300) transparent;
}

/* ── Summary & Search Index ──────────────────────────────────────── */
.summary-section, .index-section {
    background: #fff; padding: 1rem 1.25rem; border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}
.summary-section h3, .index-section h3 {
    display: flex; align-items: center; gap: .5rem;
    font-size: .9rem; color: var(--gray-600); margin-bottom: .5rem;
    text-transform: uppercase; letter-spacing: .03em; font-weight: 600;
}
.summary-section p {
    font-size: .9rem; line-height: 1.7; color: var(--gray-700);
}
.search-index-text {
    font-size: .8rem; line-height: 1.8; color: var(--gray-500);
    word-break: break-word;
}

/* ── Reprocess Feedback ──────────────────────────────────────────── */
.reprocess-banner {
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem 1rem; margin-bottom: 1rem;
    background: var(--blue-50); border: 1px solid var(--blue-100);
    border-radius: var(--radius); color: var(--blue-700);
    font-size: .9rem; animation: slideDown .3s ease;
}
.reprocess-spinner {
    width: 18px; height: 18px; border: 2px solid var(--blue-100);
    border-top-color: var(--blue-600); border-radius: 50%;
    animation: spin .8s linear infinite; flex-shrink: 0;
}
.reprocess-icon.spinning { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Page Viewer ─────────────────────────────────────────────────── */
.page-viewer {
    width: 100%; height: 100%;
    overflow-y: auto; display: flex; justify-content: center;
    background: var(--gray-100);
    position: relative;
}
.page-viewer .preview-image {
    width: 100%; height: auto; object-fit: contain;
}

/* ── Hover navigation arrows on document preview ─────────────────── */
.hover-nav {
    position: absolute;
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(15,23,42,.55); color: #fff;
    border: none; border-radius: 50%;
    cursor: pointer;
    text-decoration: none;
    opacity: 0;
    transition: opacity .18s ease, background .18s ease, transform .15s ease;
    z-index: 5;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.page-viewer:hover .hover-nav { opacity: .85; }
.hover-nav:hover { background: rgba(15,23,42,.85); opacity: 1 !important; transform: scale(1.08); }
.hover-nav.disabled { opacity: 0 !important; pointer-events: none; }
.hover-nav-left  { left: .75rem;   top: 50%; transform: translateY(-50%); }
.hover-nav-right { right: .75rem;  top: 50%; transform: translateY(-50%); }
.hover-nav-up    { top: .75rem;    left: 50%; transform: translateX(-50%); }
.hover-nav-down  { bottom: .75rem; left: 50%; transform: translateX(-50%); }
.hover-nav-left:hover  { transform: translateY(-50%) scale(1.08); }
.hover-nav-right:hover { transform: translateY(-50%) scale(1.08); }
.hover-nav-up:hover    { transform: translateX(-50%) scale(1.08); }
.hover-nav-down:hover  { transform: translateX(-50%) scale(1.08); }

.preview-placeholder {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; height: 100%; gap: 1rem;
    color: var(--gray-400); text-align: center; padding: 2rem;
}
.preview-placeholder p { font-size: .9rem; }
.page-nav {
    display: flex; align-items: center; gap: .5rem;
}
.nav-combined {
    display: flex; align-items: center; gap: .15rem;
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: var(--radius); padding: .2rem;
    width: 280px; justify-content: space-between;
    flex-shrink: 0;
}
.nav-btn {
    display: flex; align-items: center; justify-content: center;
    min-width: 32px; height: 28px; padding: 0 .4rem;
    background: none; border: none; font-size: 1rem; font-weight: 600;
    color: var(--gray-600); cursor: pointer; border-radius: 4px;
    text-decoration: none; transition: all var(--transition);
    font-family: inherit;
}
.nav-btn:hover:not(.nav-disabled):not(:disabled) {
    background: var(--blue-50); color: var(--blue-600); text-decoration: none;
}
.nav-btn:disabled, .nav-disabled { color: var(--gray-300); cursor: default; }
.page-indicator {
    font-size: .8rem; color: var(--gray-500); padding: 0 .5rem;
    min-width: 90px; text-align: center; flex: 1;
}
.preview-actions {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: .4rem;
}
.preview-actions > .nav-combined { align-self: center; }
.preview-actions-row {
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
    justify-content: space-between;
}
.preview-actions-left {
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
}
.preview-actions-buttons {
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
    justify-content: flex-end;
}
/* Icon-only button: square, kein Text */
.btn.btn-icon {
    padding: .35rem .5rem;
    min-width: 32px;
    justify-content: center;
}
@media (max-width: 768px) {
    .preview-actions-row { justify-content: center; }
}
.info-section h2 {
    font-size: 1.25rem; display: flex; align-items: center; gap: .75rem;
    flex-wrap: wrap;
}
.doc-description { color: var(--gray-600); margin-top: .5rem; font-size: .95rem; }

.meta-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: .75rem;
    background: #fff; padding: 1rem; border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}
.meta-item { display: flex; flex-direction: column; gap: .15rem; }
.meta-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-400); font-weight: 600; }
.meta-value { font-size: .9rem; color: var(--gray-800); }

.tags-section {
    background: #fff; padding: 1rem; border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}
.tag-list { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.tag {
    background: var(--gray-100); color: var(--gray-600); padding: .2rem .6rem;
    border-radius: 9999px; font-size: .8rem;
}

/* ── Linked Documents ────────────────────────────────────────────── */
.linked-section {
    background: var(--blue-50); padding: 1rem; border-radius: var(--radius);
    border: 1px solid var(--blue-200);
}
.linked-header {
    display: flex; align-items: center; gap: .5rem;
    font-weight: 600; color: var(--blue-700); margin-bottom: .5rem;
    font-size: .9rem;
}
.linked-list { display: flex; flex-direction: column; gap: .35rem; margin-top: .5rem; }
.linked-item {
    display: flex; align-items: center; gap: .5rem;
    padding: .4rem .6rem; border-radius: 6px; font-size: .85rem;
    color: var(--blue-600); background: var(--blue-50);
    border: 1px solid var(--blue-100); text-decoration: none;
    transition: all var(--transition);
}
.linked-item:hover { background: var(--blue-100); text-decoration: none; }

/* ── Invoice Section ─────────────────────────────────────────────── */
.invoice-section {
    background: #fff; padding: 1.25rem; border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}
.invoice-section h3 { font-size: 1.05rem; color: var(--gray-800); margin-bottom: 1rem; }
.invoice-header-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.invoice-number { font-weight: 700; color: var(--blue-600); }
.total-amount { font-weight: 700; font-size: 1.1rem; color: var(--gray-900); }

.positions-section { margin-top: 1rem; overflow-x: auto; }
.positions-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: .75rem; flex-wrap: wrap; gap: .5rem;
}
.positions-header h4 { font-size: .95rem; color: var(--gray-700); }
.positions-actions { display: flex; gap: .35rem; }

.positions-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.positions-table th {
    text-align: left; padding: .5rem .5rem; font-size: .7rem;
    text-transform: uppercase; letter-spacing: .04em; color: var(--gray-400);
    border-bottom: 2px solid var(--gray-200); font-weight: 600;
}
.positions-table td {
    padding: .6rem .5rem; border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
.position-row { transition: background var(--transition); }
.position-row:hover { background: var(--gray-50); }
.pos-editable {
    cursor: pointer; border-bottom: 1px dashed transparent; padding: 1px 2px;
    border-radius: 2px; transition: all var(--transition);
}
.pos-editable:hover { border-bottom-color: var(--blue-400); background: var(--blue-50); }
.pos-expand-btn {
    background: none; border: none; cursor: pointer; color: var(--gray-400);
    padding: 2px; border-radius: 4px; display: flex;
}
.pos-expand-btn:hover { color: var(--blue-600); background: var(--gray-100); }
.pos-expand-btn svg { transition: transform .2s ease; }
.position-detail td { padding: 0 !important; border-bottom: 1px solid var(--gray-100); }
.pos-detail-grid {
    display: flex; gap: 1rem; padding: .5rem .75rem .75rem; background: var(--gray-50);
    align-items: start;
}
.pos-detail-field { flex: 1; }
.pos-detail-field label { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-400); font-weight: 600; display: block; margin-bottom: .25rem; }
.pos-notes {
    width: 100%; padding: .4rem .5rem; border: 1px solid var(--gray-300);
    border-radius: 4px; font-size: .8rem; font-family: inherit;
    resize: vertical; min-height: 40px; line-height: 1.4;
}
.pos-notes:focus { border-color: var(--blue-500); outline: none; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.pos-detail-info { font-size: .8rem; color: var(--gray-500); white-space: nowrap; padding-top: 1.2rem; }
.pos-desc-cell { max-width: 250px; word-break: break-word; line-height: 1.3; }

.usage-select {
    padding: .3rem .4rem; border-radius: 6px; font-size: .8rem;
    border: 1px solid var(--gray-300); font-family: inherit;
    cursor: pointer; min-width: 130px; background: #fff;
}
.usage-weiterverkauf { background: var(--blue-50); border-color: var(--blue-500); color: var(--blue-700); }
.usage-buero { background: var(--green-50); border-color: var(--green-500); color: var(--green-600); }

.positions-summary {
    display: flex; gap: 1.5rem; margin-top: 1rem; padding-top: 1rem;
    border-top: 2px solid var(--gray-200); flex-wrap: wrap;
}
.summary-item { display: flex; align-items: center; gap: .5rem; }
.summary-label { font-size: .85rem; color: var(--gray-500); font-weight: 500; }
.summary-value { font-weight: 700; font-size: 1rem; }
.summary-weiterverkauf .summary-value { color: var(--blue-700); }
.summary-buero .summary-value { color: var(--green-600); }
.summary-undecided .summary-value { color: var(--gray-500); }

/* ── OCR Section ─────────────────────────────────────────────────── */
.ocr-section {
    background: #fff; border-radius: var(--radius);
    border: 1px solid var(--gray-200); overflow: hidden;
}
.ocr-section summary {
    display: flex; align-items: center; gap: .5rem;
    padding: .75rem 1rem; cursor: pointer; font-weight: 500;
    color: var(--gray-600); font-size: .9rem;
}
.ocr-section summary:hover { background: var(--gray-50); }
.ocr-text {
    padding: 1rem; background: var(--gray-50);
    font-size: .85rem; line-height: 1.6; white-space: pre-wrap;
    max-height: 70vh; min-height: 300px; overflow-y: auto; color: var(--gray-700);
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    border-top: 1px solid var(--gray-200);
    resize: vertical;
}

/* ── OCR Toggle Button ──────────────────────────────────────────── */
.ocr-toggle-btn {
    display: flex; align-items: center; gap: .5rem; width: 100%;
    padding: .75rem 1rem; font-size: .9rem; font-weight: 600;
    color: var(--blue-700); background: var(--blue-50);
    border: 1px solid var(--blue-500); border-radius: var(--radius);
    cursor: pointer; text-align: left; font-family: inherit;
    transition: background var(--transition);
}
.ocr-toggle-btn:hover { background: var(--blue-100); }
.ocr-toggle-arrow { margin-left: auto; transition: transform .2s ease; font-size: .7rem; }
.ocr-toggle-btn.open .ocr-toggle-arrow { transform: rotate(90deg); }
.ocr-details { display: flex; flex-direction: column; gap: .5rem; margin-top: .5rem; }

/* ── Copy Button ────────────────────────────────────────────────── */
.copy-btn {
    background: none; border: 1px solid var(--gray-300);
    cursor: pointer; padding: 2px 7px; margin-left: auto;
    border-radius: 4px; font-size: .85rem; line-height: 1;
    color: var(--gray-600); transition: all var(--transition);
}
.copy-btn:hover { background: var(--blue-50); border-color: var(--blue-500); color: var(--blue-700); }
.copy-btn.copied { background: var(--green-50); border-color: var(--green-500); color: var(--green-600); }
.summary-section h3, .index-section h3 { display: flex; align-items: center; gap: .5rem; }
.ocr-section summary { display: flex; align-items: center; gap: .5rem; }

/* Button saving/success states */
.btn-saving { opacity: .7; position: relative; padding-left: 2rem !important; }
.btn-saving::before {
    content: ''; position: absolute; left: .6rem; top: 50%; transform: translateY(-50%);
    width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite;
}
.btn-saved { background: var(--green-600) !important; border-color: var(--green-600) !important; }
.btn-error { background: var(--red-600) !important; border-color: var(--red-600) !important; }

/* ── Search ──────────────────────────────────────────────────────── */
.search-container { margin-bottom: 1.5rem; }
.search-form { max-width: 700px; }
.search-input-wrap {
    display: flex; align-items: center; gap: .5rem;
    background: #fff; border: 1px solid var(--gray-300);
    border-radius: var(--radius); padding: .25rem .25rem .25rem .75rem;
    transition: border-color var(--transition);
}
.search-input-wrap:focus-within { border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.search-input {
    flex: 1; border: none; outline: none; font-size: .95rem; padding: .5rem 0;
    font-family: inherit; background: transparent;
}
.results-count { font-size: .9rem; color: var(--gray-500); margin-bottom: 1rem; }

/* ── Modal ────────────────────────────────────────────────────────── */
.modal {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000; align-items: center; justify-content: center;
}
.modal.show { display: flex; }
.modal-backdrop {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.5); backdrop-filter: blur(2px);
}
.modal-content {
    position: relative; background: #fff; border-radius: 12px;
    width: 100%; max-width: 450px; box-shadow: 0 25px 50px rgba(0,0,0,.25);
    animation: modalIn .2s ease;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 1.05rem; }
.modal-close {
    background: none; border: none; font-size: 1.5rem;
    cursor: pointer; color: var(--gray-400); line-height: 1;
}
.modal-close:hover { color: var(--gray-600); }
.modal-body { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-footer {
    padding: 1rem 1.5rem; border-top: 1px solid var(--gray-200);
    display: flex; justify-content: flex-end; gap: .5rem;
}

@keyframes modalIn {
    from { transform: scale(.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ── Inbox / Tile Grid ───────────────────────────────────────────── */
.inbox-hint { font-size: .9rem; color: var(--gray-500); margin-bottom: 1.25rem; }
.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
}
.doc-tile {
    background: #fff; border-radius: var(--radius);
    border: 1px solid var(--gray-200); overflow: hidden;
    box-shadow: var(--shadow); transition: all .2s ease;
    display: flex; flex-direction: column;
}
.doc-tile:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.tile-preview {
    display: block; height: 280px; overflow: hidden;
    background: var(--gray-100); position: relative;
    text-decoration: none; cursor: zoom-in;
}
.tile-preview img {
    width: 100%; height: 100%; object-fit: cover;
    object-position: top center;
    transition: transform .4s ease;
    transform-origin: top center;
}
.tile-preview:hover img {
    transform: scale(2.5);
}
.tile-placeholder {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    background: var(--gray-50);
}
.tile-badge {
    position: absolute; top: .5rem; right: .5rem;
    padding: .15rem .5rem; border-radius: 4px;
    font-size: .7rem; font-weight: 600;
    backdrop-filter: blur(4px);
}
.tile-badge-invoice { background: rgba(34,197,94,.9); color: #fff; }
.tile-badge-privat { background: rgba(168,85,247,.9); color: #fff; }
.tile-badge-einzel { background: rgba(245,158,11,.9); color: #fff; }
.tile-badge-andere { background: rgba(100,116,139,.9); color: #fff; }

/* PWA Offline-Upload-Badge */
.dms-offline-badge {
    position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%);
    z-index: 12000; background: #1e293b; color: #fff; padding: .55rem 1rem;
    border-radius: 999px; font-size: .82rem; box-shadow: 0 4px 14px rgba(0,0,0,.25);
    cursor: pointer; max-width: 92vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Camera Page ────────────────────────────────────────────────── */
.camera-page { max-width: 800px; margin: 0 auto; }
.camera-step { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.camera-video {
    width: 100%; max-width: 600px; max-height: 70vh;
    background: #000; border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}
.camera-controls { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.camera-shoot-btn { padding: .75rem 1.5rem; font-size: 1rem; }
.camera-hint { color: var(--gray-500); font-size: .9rem; text-align: center; }

.multi-preview {
    display: flex; gap: .75rem; flex-wrap: wrap; justify-content: center;
    max-height: 50vh; overflow-y: auto;
    padding: 1rem; background: var(--gray-50); border-radius: var(--radius);
}
.multi-preview-thumb {
    width: 120px; height: 120px; object-fit: cover;
    border: 2px solid var(--gray-300); border-radius: 6px;
}

.crop-stage {
    position: relative; max-width: 100%; touch-action: none;
    border-radius: var(--radius); overflow: hidden;
    background: var(--gray-900); box-shadow: var(--shadow-md);
}
.crop-stage canvas { display: block; max-width: 100%; max-height: 70vh; height: auto; }
.crop-rect {
    position: absolute; border: 2px solid var(--blue-500);
    box-shadow: 0 0 0 9999px rgba(0,0,0,.5); cursor: move;
    box-sizing: border-box;
}
.crop-handle {
    position: absolute; width: 24px; height: 24px;
    background: #fff; border: 2px solid var(--blue-600);
    border-radius: 50%; touch-action: none;
}
.handle-tl { top: -12px; left: -12px; cursor: nwse-resize; }
.handle-tr { top: -12px; right: -12px; cursor: nesw-resize; }
.handle-bl { bottom: -12px; left: -12px; cursor: nesw-resize; }
.handle-br { bottom: -12px; right: -12px; cursor: nwse-resize; }
.handle-t { top: -12px; left: 50%; margin-left: -12px; cursor: ns-resize; }
.handle-b { bottom: -12px; left: 50%; margin-left: -12px; cursor: ns-resize; }
.handle-l { left: -12px; top: 50%; margin-top: -12px; cursor: ew-resize; }
.handle-r { right: -12px; top: 50%; margin-top: -12px; cursor: ew-resize; }

/* Processing tiles */
.doc-tile-processing { opacity: .85; border: 1px dashed var(--blue-300); }
.tile-preview-processing {
    height: 280px; background: linear-gradient(135deg, var(--blue-50), var(--gray-100));
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
}
.tile-processing-spinner {
    width: 36px; height: 36px; border: 3px solid var(--blue-100);
    border-top-color: var(--blue-600); border-radius: 50%;
    animation: spin 1s linear infinite;
}
.tile-processing-label { color: var(--blue-700); font-weight: 600; font-size: .9rem; }
.tile-badge-link { background: rgba(59,130,246,.9); color: #fff; top: 2.2rem !important; right: .5rem; }
.tile-info { padding: .75rem; flex: 1; }
.tile-title {
    font-weight: 600; font-size: .85rem; color: var(--gray-800);
    line-height: 1.3; margin-bottom: .25rem;
    display: -webkit-box; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden;
}
.tile-meta { font-size: .75rem; color: var(--gray-400); }
.tile-actions {
    padding: .5rem .75rem .75rem; display: flex; gap: .35rem;
    border-top: 1px solid var(--gray-100);
}
.tile-folder {
    width: 62px; padding: .3rem .35rem; border: 1px solid var(--gray-300);
    border-radius: 6px; font-size: .85rem; font-family: inherit;
    background: #fff; text-align: center; font-weight: 600;
}
.folder-input-wrap { position: relative; display: inline-flex; align-items: center; gap: .25rem; flex-wrap: nowrap; }
.folder-bubbles { display: inline-flex; gap: .25rem; flex-wrap: nowrap; }
.quick-search {
    padding: .4rem .75rem; border: 1px solid var(--gray-300);
    border-radius: var(--radius); font-size: .85rem; font-family: inherit;
    width: 240px; background: #fff;
}
.quick-search:focus {
    outline: none; border-color: var(--blue-500);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.tile-pagecount { font-weight: 600; color: var(--gray-500); }
.folder-bubble {
    background: var(--blue-600); color: #fff; border: none;
    font-size: .75rem; font-weight: 600; padding: .2rem .5rem;
    border-radius: 9999px; cursor: pointer; white-space: nowrap;
    transition: all var(--transition);
    box-shadow: 0 1px 3px rgba(59,130,246,.3);
    font-family: inherit;
}
.folder-bubble:hover { background: var(--blue-700); transform: scale(1.05); }
.folder-bubble::before { content: '✨ '; font-size: .65rem; }
.folder-bubble-next {
    background: #f97316 !important;
    box-shadow: 0 1px 3px rgba(249,115,22,.3) !important;
}
.folder-bubble-next:hover { background: #ea580c !important; }
.folder-bubble-next::before { content: '+ '; font-weight: 700; }
.tile-folder:focus { border-color: var(--blue-500); outline: none; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.tile-file-btn { white-space: nowrap; }
.tile-accounting {
    padding: .35rem .75rem; border-top: 1px solid var(--gray-100);
}
.accounting-check, .accounting-check-header {
    display: flex; align-items: center; gap: .4rem;
    font-size: .8rem; color: var(--gray-600); cursor: pointer;
}
.accounting-check input, .accounting-check-header input {
    accent-color: var(--blue-600); width: 15px; height: 15px; cursor: pointer;
}
.accounting-check-header {
    background: var(--gray-50); padding: .35rem .6rem;
    border: 1px solid var(--gray-200); border-radius: var(--radius);
    font-size: .8rem;
}
.acc-section { margin-bottom: 2rem; }
.acc-group-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: .75rem 0 .5rem; flex-wrap: wrap; gap: .5rem;
    border-bottom: 2px solid var(--gray-200); margin-bottom: 1rem;
}
.acc-group-header h3 { font-size: 1.05rem; color: var(--gray-800); }
.acc-totals { font-size: .9rem; color: var(--gray-600); }
.acc-totals strong { color: var(--gray-800); }
.acc-amounts {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: .4rem; padding-top: .4rem;
    border-top: 1px solid var(--gray-100);
    font-size: .8rem;
}
.acc-amount-net { color: var(--gray-500); }
.acc-amount-gross strong { color: var(--blue-700); font-size: .95rem; }

/* Tax breakdown table */
.tax-breakdown-table {
    width: 100%; border-collapse: collapse; margin-top: .35rem;
    font-size: .8rem;
}
.tax-breakdown-table th, .tax-breakdown-table td {
    padding: .35rem .5rem; border: 1px solid var(--gray-200);
    text-align: right;
}
.tax-breakdown-table th { background: var(--gray-50); font-weight: 600; color: var(--gray-600); }
.tax-breakdown-table td:first-child, .tax-breakdown-table th:first-child { text-align: left; }
.source-tag {
    display: inline-block; font-size: .65rem; font-weight: 600;
    padding: 1px 6px; border-radius: 9999px; margin-left: .25rem;
    letter-spacing: .03em;
}
.source-tag[class*='smb'] { background: var(--blue-50); color: var(--blue-700); }
.source-imap { background: #ede9fe; color: #6d28d9; }
.source-upload { background: var(--gray-100); color: var(--gray-600); }
.processing-stats-bar { margin-top: 1rem; }
.progress-bar {
    height: 8px; background: var(--gray-200); border-radius: 4px; overflow: hidden;
}
.progress-fill {
    height: 100%; background: var(--green-500); border-radius: 4px;
    transition: width .5s ease;
}
.progress-label { font-size: .85rem; color: var(--gray-500); margin-top: .35rem; display: block; }
.badge-red { background: var(--red-50); color: var(--red-600); }
.sum-row { background: var(--gray-50); font-weight: 600; }
.sum-row td { border-top: 2px solid var(--gray-300) !important; }
.tile-delete-btn {
    background: none; border: 1px solid var(--gray-200); color: var(--gray-400);
    border-radius: 6px; cursor: pointer; padding: .3rem; display: flex;
    align-items: center; justify-content: center; transition: all var(--transition);
}
.tile-delete-btn:hover { color: var(--red-500); border-color: var(--red-300); background: var(--red-50); }

/* Tile select checkbox */
.tile-select-label {
    position: absolute; top: .5rem; left: .5rem; z-index: 5;
    background: rgba(255,255,255,.85); border-radius: 4px; padding: 2px;
    cursor: pointer; backdrop-filter: blur(2px);
}
.tile-select { width: 18px; height: 18px; accent-color: var(--blue-600); cursor: pointer; }
.doc-tile { position: relative; }
.doc-tile:has(.tile-select:checked) { outline: 2px solid var(--blue-500); outline-offset: -2px; }

/* Bulk action bar */
.bulk-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: .6rem 1rem; margin-bottom: 1rem;
    background: var(--blue-50); border: 1px solid var(--blue-200);
    border-radius: var(--radius); gap: .5rem; flex-wrap: wrap;
    position: sticky; top: 0; z-index: 20; animation: slideDown .2s ease;
}
.bulk-bar-left, .bulk-bar-right { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.bulk-count { font-size: .85rem; font-weight: 600; color: var(--blue-700); margin-left: .25rem; }
.bulk-sep { width: 1px; height: 20px; background: var(--blue-200); margin: 0 .25rem; }

/* ── Settings ────────────────────────────────────────────────────── */
.settings-card {
    background: #fff; border-radius: var(--radius); padding: 1.5rem;
    border: 1px solid var(--gray-200); box-shadow: var(--shadow);
    margin-bottom: 1.25rem; max-width: 600px;
}
.settings-card h3 {
    display: flex; align-items: center; gap: .5rem;
    font-size: 1.05rem; margin-bottom: .5rem;
}
.settings-desc { font-size: .9rem; color: var(--gray-500); margin-bottom: 1rem; }
.model-list { display: flex; flex-direction: column; gap: .5rem; }
.model-option {
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem 1rem; border: 1px solid var(--gray-200);
    border-radius: var(--radius); cursor: pointer;
    transition: all var(--transition);
}
.model-option:hover { border-color: var(--blue-500); background: var(--blue-50); }
.model-option input { accent-color: var(--blue-600); }
.model-active { border-color: var(--blue-500); background: var(--blue-50); }
.model-info { display: flex; align-items: center; gap: .75rem; }
.model-name { font-weight: 600; font-size: .95rem; }
.imap-import-form { margin-top: .5rem; }
.imap-form-row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; }

/* Signature */
.signature-canvas {
    border: 2px dashed var(--gray-300); border-radius: var(--radius);
    background: #fff; cursor: crosshair; max-width: 100%;
    touch-action: none; display: block;
}
.signature-current {
    background: var(--gray-50); padding: 1rem; border-radius: var(--radius);
    margin-bottom: 1rem; border: 1px solid var(--gray-200);
}
.signature-preview {
    max-width: 300px; max-height: 100px; background: #fff;
    border: 1px solid var(--gray-200); border-radius: 4px; padding: .5rem;
    display: block; margin-top: .5rem;
}

/* ── Inline Editing ──────────────────────────────────────────────── */
.editable {
    cursor: pointer; border-bottom: 1px dashed transparent;
    transition: all var(--transition); border-radius: 2px;
    padding: 1px 3px; margin: -1px -3px;
}
.editable:hover {
    border-bottom-color: var(--blue-500); background: var(--blue-50);
}
.editable:empty::after {
    content: '(leer - klicken zum Bearbeiten)';
    color: var(--gray-400); font-style: italic; font-size: .8em;
}
.inline-edit-input {
    width: 100%; padding: .35rem .5rem; border: 1px solid var(--blue-500);
    border-radius: 4px; font-size: inherit; font-family: inherit;
    background: #fff; color: var(--gray-800);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
    outline: none; resize: vertical;
}
textarea.inline-edit-input { min-height: 60px; line-height: 1.5; }
.inline-select {
    padding: .2rem .4rem; border: 1px solid var(--gray-300);
    border-radius: 6px; font-size: .85rem; font-family: inherit;
    background: #fff; cursor: pointer;
}
.inline-select:focus {
    border-color: var(--blue-500);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
    outline: none;
}
.save-indicator {
    display: inline-block; font-size: .7rem; padding: .15rem .4rem;
    border-radius: 4px; margin-left: .5rem; vertical-align: middle;
    background: var(--blue-50); color: var(--blue-600);
    animation: slideDown .2s ease;
}
.save-indicator.save-ok { background: var(--green-50); color: var(--green-600); }
.save-indicator.save-err { background: var(--red-50); color: var(--red-600); }
.file-action-inline {
    display: flex; align-items: center; gap: .35rem;
    background: var(--yellow-50); border: 1px solid #fde68a;
    padding: .3rem .5rem; border-radius: var(--radius);
}
.folder-input-header {
    width: 70px; padding: .25rem .4rem; border: 1px solid var(--gray-300);
    border-radius: 4px; font-size: .85rem; text-align: center;
    font-weight: 600; font-family: inherit;
}
.folder-input-header:focus { border-color: var(--blue-500); outline: none; }

/* ── Edit Dropdown ───────────────────────────────────────────────── */
.edit-dropdown { position: relative; display: inline-block; }
.edit-menu {
    display: none; position: absolute; top: 100%; left: 0; z-index: 50;
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    box-shadow: var(--shadow-md); min-width: 180px; padding: .25rem 0;
    margin-top: .25rem;
}
.edit-dropdown.open .edit-menu { display: block; }
/* Bulk-action bars sit at the bottom — submenus must open upward to stay on-screen */
.edit-dropdown.bulk-dropdown .edit-menu,
.bulk-bar .edit-dropdown .edit-menu,
.preview-actions .edit-dropdown .edit-menu {
    top: auto; bottom: 100%;
    margin-top: 0; margin-bottom: .25rem;
    right: 0; left: auto;
}
.edit-menu-item {
    display: flex; align-items: center; gap: .5rem; width: 100%;
    padding: .5rem .75rem; border: none; background: none;
    font-size: .85rem; font-family: inherit; color: var(--gray-700);
    cursor: pointer; text-align: left;
}
.edit-menu-item:hover { background: var(--blue-50); color: var(--blue-700); }
.edit-menu-sep { height: 1px; background: var(--gray-200); margin: .25rem 0; }

/* ── Crop Overlay ────────────────────────────────────────────────── */
.crop-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,.3); cursor: crosshair; z-index: 10;
}
/* In page-viewer: overlay should cover the image exactly */
.page-viewer .crop-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
}
.crop-selection {
    position: absolute; display: none;
    border: 2px dashed var(--blue-500);
    background: rgba(59,130,246,.1);
}
.crop-actions {
    position: absolute; bottom: 1rem; left: 50%;
    transform: translateX(-50%);
    display: flex; gap: .5rem;
    background: #fff; padding: .5rem; border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

/* ── Fine Rotation Bar ────────────────────────────────────────────── */
.fine-rotate-bar {
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
    padding: .6rem 1rem; margin-top: .5rem;
    background: linear-gradient(135deg, #fefce8, #fff7ed);
    border: 1px solid #fde68a; border-radius: var(--radius);
    animation: slideDown .2s ease;
}
.fine-label { font-size: .85rem; font-weight: 500; color: var(--gray-600); }
.fine-angle {
    font-size: .9rem; font-weight: 700; color: var(--blue-600);
    min-width: 45px; text-align: center;
}
.fine-slider {
    flex: 1; min-width: 120px; accent-color: var(--blue-600);
    cursor: pointer; height: 6px;
}

/* ── Pages Manager Panel ────────────────────────────────────────── */
.pages-panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: 200px;
    background: #fff; border-left: 1px solid var(--gray-200);
    box-shadow: -4px 0 12px rgba(0,0,0,.08); z-index: 90;
    display: flex; flex-direction: column;
    animation: slideInRight .25s ease;
}
/* Reserve right space for the panel in normal layout */
.main-content:has(.pages-panel) { padding-right: 220px; }
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
.pages-panel-header {
    padding: .75rem 1rem; border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center; justify-content: space-between;
    font-size: .9rem; background: var(--gray-50);
}
.pages-panel-close {
    background: none; border: none; font-size: 1.5rem; cursor: pointer;
    color: var(--gray-400); line-height: 1; padding: 0 .25rem;
}
.pages-panel-close:hover { color: var(--red-500); }
.pages-panel-hint { padding: .35rem 1rem; font-size: .7rem; color: var(--gray-400); background: var(--blue-50); }
.pages-list { flex: 1; overflow-y: auto; padding: .5rem; display: flex; flex-direction: column; gap: .4rem; }
.page-thumb {
    position: relative; background: #fff; border: 1px solid var(--gray-200);
    border-radius: 6px; overflow: hidden; cursor: grab;
    transition: all var(--transition);
    user-select: none; -webkit-user-select: none;
    flex-shrink: 0;  /* in flex-column container nicht stauchen — Thumb behält A4-Höhenverhältnis */
}
.page-thumb:hover { border-color: var(--blue-500); box-shadow: var(--shadow); }
.page-thumb.dragging { opacity: .4; cursor: grabbing; }
.page-thumb img { width: 100%; display: block; pointer-events: none; -webkit-user-drag: none; user-drag: none; }
.page-thumb-num {
    position: absolute; top: 4px; left: 4px; background: rgba(37,99,235,.9);
    color: #fff; font-size: .7rem; font-weight: 700; padding: 2px 6px;
    border-radius: 4px;
}
.page-thumb-del {
    position: absolute; top: 4px; right: 4px;
    background: rgba(220,38,38,.85); color: #fff; border: none;
    width: 22px; height: 22px; border-radius: 50%; cursor: pointer;
    font-size: 1rem; line-height: 1; display: flex;
    align-items: center; justify-content: center;
}
.page-thumb-del:hover { background: rgba(185,28,28,1); }
.pages-panel-footer {
    padding: .75rem 1rem; border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

/* ── Fullscreen Viewer ────────────────────────────────────────────── */
.fullscreen-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10000; background: var(--gray-900);
    flex-direction: column;
    display: none;
}
.fullscreen-overlay.active {
    display: flex;
}
.fs-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: .5rem 1rem; background: rgba(0,0,0,.8);
    backdrop-filter: blur(8px); flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,.1);
}
.fs-title {
    color: #fff; font-size: .9rem; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 300px;
}
.fs-controls {
    display: flex; align-items: center; gap: .25rem;
}
.fs-btn {
    background: none; border: none; color: rgba(255,255,255,.7);
    cursor: pointer; padding: .4rem; border-radius: 6px;
    transition: all var(--transition); display: flex;
    align-items: center; justify-content: center;
}
.fs-btn:hover { background: rgba(255,255,255,.15); color: #fff; }
.fs-btn:disabled { opacity: .3; cursor: default; }
.fs-btn:disabled:hover { background: none; }
.fs-close-btn:hover { background: var(--red-600); color: #fff; }
.fs-page-info {
    color: rgba(255,255,255,.7); font-size: .85rem;
    min-width: 60px; text-align: center;
}
.fs-zoom-level {
    color: rgba(255,255,255,.5); font-size: .8rem;
    min-width: 45px; text-align: center;
}
.fs-separator {
    width: 1px; height: 20px; background: rgba(255,255,255,.15);
    margin: 0 .35rem;
}
.fs-viewport {
    flex: 1; overflow: auto; display: flex;
    justify-content: center; align-items: flex-start;
    padding: 1rem;
}
.fs-image {
    max-width: 100%; height: auto;
    box-shadow: 0 4px 24px rgba(0,0,0,.5);
    border-radius: 2px;
    transition: width .15s ease;
}

/* ── Reply / Letter Editor ────────────────────────────────────────── */
.instruction-card {
    max-width: 700px; background: #fff; padding: 2rem;
    border-radius: var(--radius); border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
}
.instruction-card h2 { font-size: 1.3rem; margin-bottom: .5rem; }
.instruction-desc { color: var(--gray-500); font-size: .9rem; margin-bottom: 1.25rem; }
.original-info {
    background: var(--gray-50); padding: .75rem 1rem; border-radius: 6px;
    margin-bottom: 1.25rem; border: 1px solid var(--gray-200);
}
.original-info .text-muted { color: var(--gray-400); }
.form-textarea {
    width: 100%; padding: .6rem .75rem; border: 1px solid var(--gray-300);
    border-radius: var(--radius); font-size: .9rem; font-family: inherit;
    resize: vertical; min-height: 80px; line-height: 1.5;
}
.form-textarea:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.generate-status {
    display: flex; align-items: center; gap: .75rem; margin-top: 1rem;
    color: var(--blue-600); font-size: .9rem;
}

.editor-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: .75rem 0; margin-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: .5rem; }
.toolbar-title { font-weight: 600; font-size: 1rem; margin-left: .5rem; }

/* Rewrite bar (Canvas-style) */
.rewrite-bar {
    display: flex; align-items: center; gap: .5rem;
    padding: .6rem 1rem; margin-bottom: 1rem;
    background: linear-gradient(135deg, #eff6ff, #f0fdf4);
    border: 1px solid var(--blue-200);
    border-radius: var(--radius); animation: slideDown .2s ease;
}
.rewrite-input {
    flex: 1; padding: .4rem .6rem; border: 1px solid var(--gray-300);
    border-radius: 6px; font-size: .85rem; font-family: inherit;
    background: #fff;
}
.rewrite-input:focus { outline: none; border-color: var(--blue-500); }

/* Letter page */
.letter-frame {
    display: flex; justify-content: center; padding: 1rem;
    background: var(--gray-100); border-radius: var(--radius);
    min-height: 80vh;
}
.letter-page {
    width: 210mm; min-height: 297mm; background: #fff;
    box-shadow: 0 4px 24px rgba(0,0,0,.12);
    padding: 20mm 25mm 25mm 25mm;
    font-size: 10.5pt; line-height: 1.55; color: var(--gray-800);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    position: relative;
    background-size: cover; background-position: top center;
}
/* Sender toggle */
.sender-toggle { display: flex; gap: .5rem; margin-top: .25rem; }
.sender-option {
    display: flex; align-items: center; gap: .5rem;
    padding: .5rem 1rem; border: 1px solid var(--gray-200);
    border-radius: var(--radius); cursor: pointer; font-size: .9rem;
    transition: all var(--transition);
}
.sender-option:hover { border-color: var(--blue-500); }
.sender-option.sender-active { border-color: var(--blue-500); background: var(--blue-50); }
.sender-option input { accent-color: var(--blue-600); }
.sender-hint { color: var(--gray-400); font-style: italic; margin-top: .25rem; display: block; }

/* Letter header */
.letter-header {
    text-align: right; padding-bottom: 4mm;
    border-bottom: 2px solid var(--blue-600);
    margin-bottom: 3mm;
}
.sender-name { font-weight: 700; font-size: 12pt; color: var(--blue-700); }
.sender-detail { font-size: 8pt; color: var(--gray-500); line-height: 1.5; }

.letter-returnline {
    font-size: 7pt; color: var(--gray-400);
    text-decoration: underline; margin-bottom: 3mm;
    letter-spacing: .02em;
}

.letter-recipient { margin-bottom: 8mm; font-size: 10pt; line-height: 1.4; }
.letter-meta-row { text-align: right; margin-bottom: 2mm; font-size: 10pt; }
.letter-reference { color: var(--gray-500); font-size: 8.5pt; margin-bottom: 6mm; }
.letter-subject { font-size: 10.5pt; margin-bottom: 6mm; }
.letter-salutation { margin-bottom: 4mm; }
.letter-body { margin-bottom: 6mm; }
.letter-paragraph {
    margin: 0 0 3mm 0; padding: 2px 4px; border-radius: 3px;
    transition: all .15s ease; cursor: text;
    border: 1px solid transparent;
}
.letter-paragraph:hover { background: rgba(59,130,246,.04); border-color: rgba(59,130,246,.15); }
.paragraph-selected {
    background: rgba(59,130,246,.08) !important;
    border-color: var(--blue-500) !important;
    box-shadow: 0 0 0 2px rgba(59,130,246,.15);
}
.paragraph-loading {
    opacity: .5; pointer-events: none;
    background: repeating-linear-gradient(-45deg, transparent, transparent 8px, rgba(59,130,246,.03) 8px, rgba(59,130,246,.03) 16px) !important;
    animation: barberpole .8s linear infinite;
}
@keyframes barberpole { to { background-position: 22.6px 0; } }
.paragraph-rewritten {
    animation: rewriteFlash .5s ease;
}
@keyframes rewriteFlash {
    0% { background: rgba(34,197,94,.15); }
    100% { background: transparent; }
}

.letter-closing { margin-top: 8mm; }
.signature-space { height: 15mm; }
.letter-field-role { color: var(--gray-500); font-size: 9pt; }

.letter-field {
    outline: none; border-radius: 2px; padding: 1px 2px;
    transition: background .15s;
}
.letter-field:hover { background: rgba(59,130,246,.04); }
.letter-field:focus { background: rgba(59,130,246,.06); }
.letter-field:empty::after {
    content: '...'; color: var(--gray-300); font-style: italic;
}

.letter-footer {
    position: absolute; bottom: 20mm; left: 25mm; right: 25mm;
    border-top: 1px solid var(--gray-200); padding-top: 2mm;
    font-size: 7pt; color: var(--gray-400); text-align: center;
    line-height: 1.6;
}

/* Print styles */
@media print {
    .sidebar, .editor-toolbar, .rewrite-bar, .page-header { display: none !important; }
    .main-content { margin-left: 0 !important; padding: 0 !important; }
    .letter-frame { padding: 0; background: none; min-height: auto; }
    .letter-page {
        box-shadow: none; width: 100%; min-height: auto;
        padding: 15mm 20mm 20mm 20mm;
    }
    .letter-paragraph { border: none !important; padding: 0 !important; }
    .letter-paragraph:hover { background: none !important; }
    .letter-field:hover { background: none !important; }
    .letter-footer { position: fixed; bottom: 10mm; left: 20mm; right: 20mm; }
    .sender-name { color: #1d4ed8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .letter-header { border-bottom-color: #1d4ed8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ── Responsive ──────────────────────────────────────────────────── */
/* ── Laptop ~15" (1024-1440px) ────────────────────────────────────── */
@media (max-width: 1440px) {
    .document-layout { grid-template-columns: minmax(300px, 1fr) minmax(0, 1.2fr); gap: 1rem; }
    .main-content { padding: 1rem 1.25rem; }
    /* Compact positions table */
    .positions-table { font-size: .78rem; }
    .positions-table th, .positions-table td { padding: .4rem .35rem; }
    .pos-desc-cell { max-width: 180px; word-break: break-word; }
    .usage-select { min-width: 100px; font-size: .75rem; padding: .2rem .3rem; }
    .positions-actions { flex-wrap: wrap; gap: .25rem; }
    .positions-actions .btn { font-size: .7rem; padding: .25rem .5rem; }
    .positions-summary { flex-wrap: wrap; gap: .75rem; font-size: .85rem; }
    .meta-grid { gap: .5rem; }
    .meta-value { font-size: .85rem; }
    .invoice-header-grid { grid-template-columns: repeat(2, 1fr); }
    .summary-section p, .search-index-text { font-size: .8rem; }
    .info-section h2 { font-size: 1.1rem; }
    .invoice-section { padding: .75rem 1rem; }
    .invoice-section h3 { font-size: .95rem; }
    .header-actions { gap: .35rem; }
    .header-actions .btn { font-size: .75rem; padding: .3rem .5rem; }
}

@media (max-width: 1024px) {
    .document-layout { grid-template-columns: 1fr; height: auto; }
    .document-info { order: 2; max-height: none; overflow-y: visible; }
    .document-preview { order: 1; position: static; height: 50vh; }
    .positions-table { font-size: .75rem; }
    .pos-desc-cell { max-width: none; }
}

/* Burger Menu (mobile only) */
.burger-menu {
    display: none; position: fixed; top: .75rem; left: .75rem; z-index: 150;
    width: 44px; height: 44px; padding: 0;
    background: var(--blue-600); color: #fff; border: none;
    border-radius: 8px; box-shadow: var(--shadow-md);
    align-items: center; justify-content: center; cursor: pointer;
}
.burger-menu:hover { background: var(--blue-700); }
.sidebar-backdrop {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.5); z-index: 99;
}
.sidebar-backdrop.show { display: block; }

@media (max-width: 768px) {
    .burger-menu { display: flex; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform .3s ease;
        z-index: 100;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; padding: .75rem; padding-top: 4rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .meta-grid { grid-template-columns: 1fr; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .positions-table { font-size: .7rem; }
    .positions-table th:nth-child(4), .positions-table td:nth-child(4) { display: none; } /* Hide Einzel */
    .positions-actions { flex-wrap: wrap; }
    .page-header { flex-direction: column; align-items: start; }
    .header-actions { flex-wrap: wrap; width: 100%; }
}

/* Abweichende Unterschrift Modal */
.alt-sig-modal {
    position: fixed; inset: 0; z-index: 10500;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
}
.alt-sig-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}
.alt-sig-dialog {
    position: relative; z-index: 1;
    background: var(--white, #fff);
    border-radius: 12px;
    padding: 1.25rem;
    max-width: 560px; width: 100%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    max-height: 90vh; overflow-y: auto;
}

/* Accounting: expandable export rows */
.export-toggle .chev { transition: transform 0.15s ease; }
.export-detail-cell {
    background: var(--gray-50);
    padding: 1rem !important;
}
.export-detail-header {
    margin-bottom: .75rem;
    font-size: .9rem;
    color: var(--gray-700);
}
.export-detail-header .muted {
    color: var(--gray-500);
    font-weight: normal;
    margin-left: .5rem;
}
.export-tile-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.export-tile-grid .doc-tile { font-size: 0.85rem; }
.export-tile-grid .tile-preview { aspect-ratio: 4/5; }
.tile-deleted { opacity: 0.55; filter: grayscale(0.4); }
.tile-deleted .tile-title::before { content: ""; }

/* Toast notifications */
.toast-container {
    position: fixed; top: 1rem; right: 1rem; z-index: 11000;
    display: flex; flex-direction: column; gap: .5rem;
    pointer-events: none;
}
.toast {
    background: var(--gray-800, #1e293b); color: #fff;
    padding: .75rem 1.25rem; border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0,0,0,.2);
    font-size: .9rem; max-width: 400px;
    transform: translateX(110%); transition: transform .25s ease;
    pointer-events: auto;
}
.toast-show { transform: translateX(0); }
.toast-success { background: var(--green-600, #059669); }
.toast-error   { background: var(--red-600, #dc2626); }
.toast-info    { background: var(--blue-600, #2563eb); }

/* Disk space indicator in sidebar footer */
.disk-indicator {
    display: flex; align-items: center; gap: .35rem;
    padding: .25rem .5rem;
    color: var(--gray-400, #94a3b8);
    cursor: help;
    flex-shrink: 0;
}
.disk-indicator svg { flex-shrink: 0; }
.disk-bar {
    display: inline-block;
    width: 32px; height: 6px;
    background: var(--gray-300, #cbd5e1);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}
.disk-fill {
    display: block; height: 100%;
    background: var(--green-500, #10b981);
    transition: width .3s;
}
.disk-warn .disk-fill     { background: var(--orange-500, #f59e0b); }
.disk-warn .disk-indicator { color: var(--orange-500, #f59e0b); }
.disk-warn { color: var(--orange-500, #f59e0b); }
.disk-critical .disk-fill { background: var(--red-500, #ef4444); }
.disk-critical { color: var(--red-500, #ef4444); }

/* ── View mode switcher ───────────────────────────────────────────── */
.view-modes {
    display: inline-flex; gap: 0;
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    padding: 2px;
}
.view-mode-btn {
    background: none; border: none;
    padding: .35rem .55rem;
    color: var(--gray-500); cursor: pointer;
    border-radius: 4px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background var(--transition), color var(--transition);
    font-family: inherit;
}
.view-mode-btn:hover { background: var(--gray-100); color: var(--gray-700); }
.view-mode-btn.active {
    background: var(--blue-50, #eff6ff);
    color: var(--blue-700, #1d4ed8);
}

/* ── Tile-grid size variants ──────────────────────────────────────── */
.tile-grid.size-small  { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem; }
.tile-grid.size-small .tile-preview { height: 180px; }
.tile-grid.size-small .tile-info { padding: .5rem; }
.tile-grid.size-small .tile-title { font-size: .75rem; }
.tile-grid.size-small .tile-meta { font-size: .7rem; }

.tile-grid.size-normal { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1.25rem; }
.tile-grid.size-normal .tile-preview { height: 280px; }

.tile-grid.size-large { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1.5rem; }
.tile-grid.size-large .tile-preview { height: 420px; }
.tile-grid.size-large .tile-info { padding: 1rem; }
.tile-grid.size-large .tile-title { font-size: 1rem; }

/* List view — single column compact rows */
.tile-grid.size-list {
    display: flex; flex-direction: column; gap: 0;
    border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden;
    background: #fff;
}
.tile-grid.size-list .doc-tile {
    flex-direction: row; align-items: center;
    border: none; border-radius: 0;
    border-bottom: 1px solid var(--gray-100);
    box-shadow: none; transform: none !important;
}
.tile-grid.size-list .doc-tile:last-child { border-bottom: none; }
.tile-grid.size-list .doc-tile:hover {
    background: var(--gray-50); transform: none;
}
.tile-grid.size-list .tile-select-label { top: 8px; left: 8px; }
.tile-grid.size-list .tile-preview {
    height: 60px; width: 60px; flex: 0 0 60px;
    cursor: pointer;
}
.tile-grid.size-list .tile-preview:hover img { transform: none; }
.tile-grid.size-list .tile-badge {
    position: static; transform: none; font-size: .65rem;
    padding: 1px 5px; margin-left: .5rem; flex-shrink: 0;
}
.tile-grid.size-list .tile-info {
    flex: 1; padding: .5rem .75rem;
    display: grid; grid-template-columns: minmax(200px, 2fr) 1fr auto;
    gap: 1rem; align-items: center;
}
.tile-grid.size-list .tile-title { margin-bottom: 0; }
.tile-grid.size-list .tile-meta { font-size: .75rem; }
.tile-grid.size-list .acc-amounts {
    flex-direction: column; align-items: flex-end;
    margin-top: 0;
}

/* ── Dateibaum / virtual folder tree ──────────────────────────────── */
.tree-layout { padding: 0; }
.tree-panel {
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    padding: 1rem;
}
.tree-empty {
    text-align: center; padding: 2rem 1rem; color: var(--gray-600);
}
.tree-root {
    background: linear-gradient(0deg, transparent, rgba(37, 99, 235, 0.04));
    border-radius: 6px;
    margin-bottom: .5rem;
}
.tree-folder { margin: 2px 0; }
.tree-folder-header {
    display: flex; align-items: center; gap: .5rem;
    padding: .35rem .5rem; border-radius: 4px;
    cursor: pointer; user-select: none;
    transition: background var(--transition);
}
.tree-folder-header:hover { background: var(--gray-100, #f1f5f9); }
.tree-folder-header.tree-folder-drop {
    background: var(--blue-50, #eff6ff) !important;
    outline: 2px dashed var(--blue-500, #3b82f6);
    outline-offset: -2px;
}
.tree-chev {
    font-size: .7rem; color: var(--gray-500);
    transition: transform .15s ease;
    width: 12px; text-align: center;
}
.tree-chev.open { transform: rotate(90deg); }
.tree-folder-name { font-weight: 500; color: var(--gray-800); }
.tree-count {
    background: var(--gray-200, #e2e8f0); color: var(--gray-700);
    font-size: .7rem; font-weight: 500; padding: 1px 8px;
    border-radius: 999px; margin-left: .35rem;
}
.tree-folder-actions {
    margin-left: auto;
    display: none; gap: 2px;
}
.tree-folder-header:hover .tree-folder-actions { display: flex; }
.tree-icon-btn {
    width: 22px; height: 22px;
    background: transparent; border: 1px solid transparent;
    border-radius: 4px; cursor: pointer;
    color: var(--gray-500); font-family: inherit;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .9rem;
}
.tree-icon-btn:hover { background: #fff; border-color: var(--gray-300); color: var(--gray-700); }
.tree-icon-danger:hover { color: var(--red-600); border-color: var(--red-300); }
.tree-folder-body {
    margin-left: 1.25rem;
    padding-left: .5rem;
    border-left: 1px dashed var(--gray-200);
}
.tree-folder-docs { margin: .25rem 0 .5rem; }
.tree-doc-link {
    display: block; padding: .2rem .5rem;
    color: var(--gray-700); text-decoration: none;
    border-radius: 4px;
    font-size: .85rem;
    transition: background var(--transition);
}
.tree-doc-link:hover { background: var(--blue-50, #eff6ff); color: var(--blue-700); text-decoration: none; }
.tree-doc-path { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }
.tree-doc-name { font-family: inherit; font-size: .85rem; }
.tree-empty-folder { color: var(--gray-400); font-style: italic; padding: .25rem .5rem; }
.tree-loading { color: var(--gray-400); padding: .25rem .5rem; font-size: .8rem; }
.tree-auto-section {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--gray-300);
}
.tree-auto-title {
    display: flex; align-items: center; gap: .5rem;
    margin-bottom: .5rem; color: var(--gray-700);
    font-size: 1.05rem;
}
.tree-auto-hint {
    color: var(--gray-500); font-size: .85rem;
    margin-bottom: 1rem;
}

/* Tree picker modal rows */
.tree-picker-list {
    max-height: 400px; overflow-y: auto;
    border: 1px solid var(--gray-200); border-radius: 6px;
    padding: .25rem 0;
}
.tree-picker-row {
    display: flex; align-items: center;
    padding: .15rem .5rem;
}
.tree-picker-btn {
    flex: 1; display: flex; align-items: center; gap: .5rem;
    padding: .35rem .5rem; border: 1px solid transparent;
    background: transparent; border-radius: 4px;
    text-align: left; cursor: pointer; font-family: inherit;
    color: var(--gray-800);
}
.tree-picker-btn:hover {
    background: var(--blue-50, #eff6ff);
    border-color: var(--blue-200, #bfdbfe);
    color: var(--blue-700);
}
.tree-picker-add {
    width: 24px; height: 24px;
    border: 1px solid var(--gray-300); background: #fff;
    border-radius: 4px; cursor: pointer;
    color: var(--gray-600); font-size: .9rem;
    margin-left: .35rem;
}
.tree-picker-add:hover { background: var(--gray-50); color: var(--blue-600); border-color: var(--blue-300); }

/* Groups settings */
.group-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: .65rem .75rem;
    border: 1px solid var(--gray-200); border-radius: 6px;
    margin-bottom: .5rem;
    gap: 1rem; flex-wrap: wrap;
}
.group-row-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.muted { color: var(--gray-500); }

/* Folder permissions modal entries */
.fp-row {
    display: flex; align-items: center; gap: .5rem;
    padding: .5rem .65rem;
    border: 1px solid var(--gray-200); border-radius: 6px;
    margin-bottom: .35rem;
}
.fp-row .fp-subject { flex: 1; }
.fp-row .fp-level {
    font-size: .8rem; padding: 2px 8px; border-radius: 4px;
    font-weight: 600;
}
.fp-level-read  { background: #dbeafe; color: #1e40af; }
.fp-level-write { background: #fef3c7; color: #92400e; }
.fp-level-admin { background: #fce7f3; color: #9d174d; }

.tree-perm {
    margin-left: .25rem;
    font-size: .75rem;
    padding: 1px 6px;
    border-radius: 4px;
    cursor: help;
}
.tree-perm-read { background: #dbeafe; color: #1e40af; }
.tree-perm-write { background: #fef3c7; color: #92400e; }
.tree-perm-admin { background: #fce7f3; color: #9d174d; }

/* ── Right-click context menu ───────────────────────────────────── */
.ctx-menu {
    position: fixed;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
    min-width: 240px;
    padding: .35rem 0;
    z-index: 11000;
    font-size: .9rem;
}
.ctx-menu-item {
    padding: .45rem .9rem;
    cursor: pointer;
    color: var(--gray-800);
    user-select: none;
    transition: background .1s;
}
.ctx-menu-item:hover:not(.disabled) { background: var(--blue-50, #eff6ff); color: var(--blue-700); }
.ctx-menu-item.disabled { opacity: 0.45; cursor: not-allowed; }
.ctx-menu-item.danger { color: var(--red-600, #dc2626); }
.ctx-menu-item.danger:hover:not(.disabled) { background: #fef2f2; color: var(--red-700, #b91c1c); }
.ctx-menu-sep {
    height: 1px;
    background: var(--gray-200);
    margin: .25rem 0;
}
.tree-alias-icon {
    margin-right: .25rem;
    font-size: .8rem;
    cursor: help;
    opacity: 0.7;
}

/* Hint that right-click works */
.tree-folder[data-folder-id] > .tree-folder-header,
.tree-doc-link[data-doc-id] {
    cursor: context-menu;
}
.tree-folder[data-folder-id] > .tree-folder-header:hover {
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.15);
}

/* Tree multi-select checkboxes */
.tree-select {
    margin-right: .35rem;
    margin-left: 0;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--blue-600, #2563eb);
}
.tree-doc-row {
    display: flex; align-items: center;
    padding: .15rem .25rem;
    transition: background .1s;
}
.tree-doc-row:hover { background: var(--gray-50); border-radius: 4px; }
.tree-doc-row .tree-doc-link { flex: 1; padding: .1rem .25rem; }
