/* SmartBooks — Dark Theme (Indigo Accent) */
/* Phase A: Design-System-Foundation — Token-System via tokens.css */
@import url('tokens.css');

:root {
    /* Layout-spezifische Variablen (nicht im Token-System) */
    --sidebar-width: 240px;
    --topbar-height: 56px;

    /* success-bg / warning-bg als rgba für Badge- und Alert-Kompatibilität */
    --success-bg: rgba(16, 185, 129, 0.12);
    --warning-bg: rgba(245, 158, 11, 0.12);
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: var(--fs-base); /* 16px — verhindert iOS-Zoom bei Inputs */
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Auth */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.auth-container { width: 100%; max-width: 400px; padding: 1rem; }
.auth-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 2rem;
}
.auth-logo {
    text-align: center;
    font-size: 2rem;
    color: var(--accent);
    margin-bottom: 0.25rem;
}
.auth-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
}
.auth-form .form-group { margin-bottom: 1rem; }

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
}
.sidebar-close { display: none; }
.sidebar-header {
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}
.sidebar-logo {
    font-size: 1.25rem; font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.sidebar-version { color: var(--text-muted); font-size: 0.75rem; }
.sidebar-nav { flex: 1; padding: 0.5rem 0; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    color: var(--text-secondary);
    transition: all 0.15s;
    font-size: 0.875rem;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent-bg); color: var(--accent); border-right: 3px solid var(--accent); }
.nav-icon { font-size: 1rem; width: 1.25rem; text-align: center; }
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-user { color: var(--text-secondary); font-size: 0.875rem; }

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
}
.topbar {
    height: var(--topbar-height);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(26, 29, 39, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-title { font-size: 1.125rem; font-weight: 600; flex: 1; min-width: 0; word-break: break-word; overflow-wrap: anywhere; }
.topbar-actions { flex-shrink: 0; }
.sidebar-toggle { display: none; background: none; border: none; color: var(--text-primary); font-size: 1.5rem; cursor: pointer; }

/* Wortumbruch fuer lange Dateinamen */
.break-word, .document-title, .filename {
    word-break: break-word;
    overflow-wrap: anywhere;
    hyphens: auto;
}
.content-area { padding: 1.5rem; overflow-x: hidden; }

/* Cards */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.card-header {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h3 { font-size: 0.9375rem; font-weight: 600; }
.card-body { padding: 1.25rem; overflow-x: auto; }
.card-body > form { overflow-x: auto; }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}
.stats-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stats-grid-2 { grid-template-columns: repeat(2, 1fr); }

/* Responsive Grid-Klassen */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }

/* Split-View Dokument-Detail (UX-Phase 3) */
.doc-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    gap: 1rem;
    align-items: start;
}
.doc-split--no-preview {
    grid-template-columns: minmax(0, 1fr);
}
.doc-preview {
    position: sticky;
    top: 1rem;
}
.doc-preview-frame {
    width: 100%;
    height: calc(100vh - 8rem);
    min-height: 420px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: #fff;
    display: block;
}
.doc-tabs {
    display: none;
    gap: 0;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}
.doc-tab-btn {
    padding: 0.5rem 1rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    min-height: 40px;
    transition: color 0.15s, border-color 0.15s;
}
.doc-tab-btn.is-active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
@media (max-width: 900px) {
    .doc-split {
        grid-template-columns: 1fr;
    }
    .doc-tabs {
        display: flex;
    }
    .doc-preview {
        position: static;
    }
    .doc-preview:not(.is-active),
    .doc-pane-data:not(.is-active) {
        display: none;
    }
}
.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--accent);
    opacity: 0.5;
}
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.stat-value svg { width: 20px; height: 20px; vertical-align: middle; opacity: 0.5; margin-right: 0.25rem; }
.stat-label { color: var(--text-secondary); font-size: 0.8125rem; margin-top: 0.375rem; }
.stat-card.stat-success { border-color: rgba(34, 197, 94, 0.3); }
.stat-card.stat-success::before { background: var(--success); }
.stat-card.stat-success .stat-value { color: var(--success); }
.stat-card.stat-warning { border-color: rgba(245, 158, 11, 0.3); }
.stat-card.stat-warning::before { background: var(--warning); }
.stat-card.stat-warning .stat-value { color: var(--warning); }
.stat-card.stat-error { border-color: rgba(239, 68, 68, 0.3); }
.stat-card.stat-error::before { background: var(--error); }
.stat-card.stat-error .stat-value { color: var(--error); }
.stat-card.stat-info { border-color: rgba(59, 130, 246, 0.3); }
.stat-card.stat-info::before { background: var(--info); }
.stat-card.stat-info .stat-value { color: var(--info); }

/* Detail Grid */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}
.detail-list { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem 1rem; }
.detail-list dt { color: var(--text-secondary); font-weight: 500; }
.detail-list dd { color: var(--text-primary); }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: 0.625rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.table th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}
.table tr:hover { background: var(--bg-hover); }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.row-disabled { opacity: 0.5; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
    min-height: 44px; /* Touch-Target ≥ 44px */
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 3px rgba(99,102,241,0.3); }
.btn-primary:hover { background: var(--accent-hover); color: #fff; box-shadow: 0 2px 8px rgba(99,102,241,0.4); transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.9; color: #fff; }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { opacity: 0.9; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { opacity: 0.9; color: #fff; }
.btn-outline { border-color: var(--border-color); color: var(--text-secondary); background: transparent; }
.btn-outline:hover { border-color: var(--text-secondary); color: var(--text-primary); }
.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.8125rem; }
.btn-block { width: 100%; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.375rem; font-weight: 500; font-size: 0.875rem; color: var(--text-secondary); }
.form-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--fs-base); /* min. 16px — verhindert iOS-Zoom */
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-bg); }
select.form-input { cursor: pointer; }
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 0.875rem; }
.filter-form { margin-bottom: 0; }
.filter-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.filter-row .form-input { width: auto; min-width: 150px; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}
.badge-default { background: var(--bg-tertiary); color: var(--text-secondary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-storno { background: var(--error-bg); color: var(--error); }

/* Buchungs-Storno-Styles */
.booking-storno td { text-decoration: line-through; opacity: 0.7; }
.booking-storno td a { text-decoration: line-through; }
.booking-storno-ref { background: rgba(239, 68, 68, 0.08); }

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.875rem;
}
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(34, 197, 94, 0.2); }
.alert-error { background: var(--error-bg); color: var(--error); border: 1px solid rgba(239, 68, 68, 0.2); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.2); }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid rgba(59, 130, 246, 0.2); }
.alert-close { background: none; border: none; color: inherit; font-size: 1.25rem; cursor: pointer; padding: 0; margin-left: 1rem; }

/* Page Actions */
.page-actions { display: flex; gap: 0.5rem; margin-bottom: 1rem; align-items: center; flex-wrap: wrap; }
.page-actions-split { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem; }

/* Sub-Navigation (Tab-Bar fuer Unterbereiche) */
.sub-nav {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.sub-nav::-webkit-scrollbar { display: none; }
.sub-nav a {
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}
.sub-nav a:hover {
    color: var(--text-primary);
    border-bottom-color: var(--text-secondary);
}
.sub-nav a.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* Queue Status */
.queue-status { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* OCR Text */
.ocr-text {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.8125rem;
    max-height: 400px;
    overflow-y: auto;
    color: var(--text-secondary);
}

code {
    background: var(--bg-tertiary);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
}

/* Bulk Actions */
.bulk-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    margin-top: 0.75rem;
    background: var(--accent-bg);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
}
.bulk-actions-label { color: var(--text-primary); font-size: 0.875rem; }
.bulk-actions-buttons { display: flex; gap: 0.5rem; align-items: center; }

/* Correction UI */
.field-edit-row { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.field-edit-row label { min-width: 140px; font-weight: 500; color: var(--text-secondary); font-size: 0.875rem; }
.field-edit-row input { flex: 1; }
.prediction-actions { display: flex; gap: 0.375rem; }

/* ═══════════════════════════════════════
   NEUE KOMPONENTEN
   ═══════════════════════════════════════ */

/* 1. Toast/Notification System */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 1000; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { padding: 0.75rem 1rem; border-radius: var(--radius); font-size: 0.875rem; animation: slideIn 0.3s ease; display: flex; align-items: center; gap: 0.5rem; max-width: 400px; }
.toast-success { background: var(--success-bg); border: 1px solid var(--success); color: var(--success); }
.toast-error { background: var(--error-bg); border: 1px solid var(--error); color: var(--error); }
.toast-info { background: var(--info-bg); border: 1px solid var(--info); color: var(--info); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }
.toast.removing { animation: slideOut 0.3s ease forwards; }

/* 2. Loading-Button */
.btn-loading { position: relative; pointer-events: none; opacity: 0.7; }
.btn-loading::after { content: ''; width: 14px; height: 14px; border: 2px solid transparent; border-top-color: currentColor; border-radius: 50%; animation: spin 0.6s linear infinite; display: inline-block; margin-left: 0.5rem; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 3. Modern Modal */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200; backdrop-filter: blur(4px); }
.modal-backdrop.active { display: flex; align-items: center; justify-content: center; animation: fadeIn 0.2s ease; }
.modal { background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius); width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto; animation: scaleIn 0.2s ease; }
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: 0.75rem 1.25rem; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 0.5rem; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* 4. Confirm Dialog */
.confirm-dialog .modal { max-width: 400px; }
.confirm-dialog .modal-body { text-align: center; padding: 1.5rem; }
.confirm-dialog .modal-body p { color: var(--text-secondary); margin-top: 0.5rem; }

/* 5. Better Transitions */
.alert { transition: opacity 0.3s, transform 0.3s; }
.card { transition: border-color 0.2s, box-shadow 0.2s; }
.card:hover { border-color: rgba(99, 102, 241, 0.3); box-shadow: 0 2px 12px rgba(0,0,0,0.2); }

/* 6. Badge-Erweiterungen (neue Varianten) */
.badge { gap: 0.25rem; }
.badge-accent { background: var(--accent-bg); color: var(--accent); }
.badge-muted { background: var(--bg-tertiary); color: var(--text-muted); }

/* 7. Details/Summary (aufklappbare Bereiche) */
details { border-radius: var(--radius); }
details summary { display: flex; align-items: center; gap: 0.375rem; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: ''; border: 5px solid transparent; border-left: 6px solid var(--text-muted); transition: transform 0.2s; }
details[open] summary::before { transform: rotate(90deg); }
details summary:hover { color: var(--text-primary); }

/* 8. Empty State */
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 1rem; opacity: 0.5; }
.empty-state h3 { color: var(--text-secondary); margin-bottom: 0.5rem; }

/* 8. Bottom-Nav (Mobile only — via Media Query unten) */
.bottom-nav { display: none; }

/* 9. Sub-Nav Pill-Style (ergaenzt die bestehende Tab-Bar-Version) */
.sub-nav-pills { display: flex; gap: 0.25rem; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding: 0.5rem 0; margin-bottom: 1rem; }
.sub-nav-pills::-webkit-scrollbar { display: none; }
.sub-nav-pills a { flex-shrink: 0; padding: 0.375rem 0.75rem; border-radius: 999px; font-size: 0.8125rem; color: var(--text-secondary); background: var(--bg-tertiary); white-space: nowrap; text-decoration: none; transition: all 0.15s; }
.sub-nav-pills a:hover { background: var(--bg-hover); color: var(--text-primary); }
.sub-nav-pills a.active { background: var(--accent-bg); color: var(--accent); }

/* 10. Drag-Drop Upload Zone */
.drop-zone { border: 2px dashed var(--border-color); border-radius: var(--radius); padding: 2rem; text-align: center; transition: all 0.2s; cursor: pointer; }
.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); background: var(--accent-bg); }
.drop-zone svg { width: 40px; height: 40px; color: var(--text-muted); margin-bottom: 0.5rem; }
.drop-zone p { color: var(--text-secondary); font-size: 0.875rem; }

/* ═══════════════════════════════════════
   RESPONSIVE — Mobile (max 768px)
   ═══════════════════════════════════════ */
@media (max-width: 768px) {

    /* Sidebar */
    .sidebar { transform: translateX(-100%); transition: transform 0.3s; bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
    .sidebar.open { transform: translateX(0); }
    body.menu-open { overflow: hidden; }
    .sidebar-close {
        display: flex; align-items: center; justify-content: center;
        position: absolute; top: 0.5rem; right: 0.75rem;
        background: none; border: none; color: var(--text-secondary);
        font-size: 1.5rem; cursor: pointer;
        min-width: 44px; min-height: 44px;
    }
    .sidebar-toggle {
        display: flex; align-items: center; justify-content: center;
        min-width: 44px; min-height: 44px; font-size: 1.5rem;
    }
    .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 90; }
    .sidebar-backdrop.active { display: block; }
    .main-content { margin-left: 0; }
    .content-area { padding: 0.75rem; }

    /* Grids */
    .stats-grid, .stats-grid-3 { grid-template-columns: repeat(2, 1fr); }
    .stats-grid-2, .detail-grid, .grid-2, .grid-3 { grid-template-columns: 1fr; }

    /* Forms */
    .form-row { flex-direction: column; gap: 0; }
    .filter-row { flex-direction: column; }
    .filter-row .form-input { width: 100%; min-width: 0; }
    .field-edit-row { flex-direction: column; align-items: stretch; }
    .field-edit-row label { min-width: 0; }

    /* Touch-Targets */
    .btn { min-height: 36px; }
    .btn-sm { min-height: 32px; padding: 0.375rem 0.75rem; }
    .nav-item { min-height: 44px; }

    /* Topbar Mobile */
    .topbar { flex-wrap: wrap; padding: 0.75rem; gap: 0.5rem; height: auto; min-height: var(--topbar-height); }
    .topbar-title { font-size: 1rem; order: 1; flex: 1; min-width: 0; }
    .topbar-actions { order: 3; width: 100%; }
    .topbar-actions form { width: 100%; }
    .topbar-actions .form-input { width: 100% !important; flex: 1; }
    .sidebar-toggle { order: 0; }

    /* Card-Header */
    .card-header { flex-wrap: wrap; gap: 0.5rem; }

    /* Page Actions */
    .page-actions { flex-wrap: wrap; }

    /* Bulk Actions */
    .bulk-actions { flex-direction: column; gap: 0.5rem; }

    /* Provider Cards */
    .provider-card > div:first-child { flex-direction: column; gap: 0.5rem !important; }
    .provider-card > div:first-child > div:last-child { justify-content: flex-start; }

    /* ═══ TABELLEN → CARD-LAYOUT auf Mobile ═══
       Jede Tabellenzeile wird zu einer gestapelten Karte.
       <td data-label="Spaltenname"> wird als Label angezeigt. */

    .table thead { display: none; }

    .table,
    .table tbody,
    .table tr,
    .table td {
        display: block;
        width: 100%;
    }

    .table tr {
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        margin-bottom: 0.5rem;
        padding: 0.5rem 0.75rem;
    }
    .table tr:hover { background: var(--bg-hover); }

    .table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.375rem 0;
        border-bottom: 1px solid var(--border-color);
        font-size: 0.8125rem;
    }
    .table td:last-child { border-bottom: none; }

    .table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted);
        flex-shrink: 0;
        margin-right: 0.75rem;
    }

    /* Bottom-Nav */
    .bottom-nav {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0;
        background: var(--bg-secondary); border-top: 1px solid var(--border-color);
        z-index: 100; padding: 0.25rem 0;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .bottom-nav a, .bottom-nav button {
        flex: 1; display: flex; flex-direction: column; align-items: center;
        gap: 0.125rem; padding: 0.5rem 0; color: var(--text-muted);
        font-size: 0.625rem; text-decoration: none;
        background: none; border: none; cursor: pointer; font-family: inherit;
    }
    .bottom-nav a.active, .bottom-nav button.active { color: var(--accent); }
    .bottom-nav a svg, .bottom-nav button svg { width: 22px; height: 22px; }
    .content-area { padding-bottom: 4.5rem; }

    /* Mobile Schrift kleiner */
    body { font-size: 13px; }
    .topbar-title { font-size: 0.9375rem; }
    h1 { font-size: 1.25rem; }
    h2 { font-size: 1.125rem; }
    h3 { font-size: 1rem; }

    /* Chat-Fix: kein horizontales Scrollen */
    .chat-messages, .chat-container, .content-area { overflow-x: hidden; max-width: 100vw; }
    .chat-message { max-width: 100%; word-break: break-word; }

    /* Sub-Nav auf Mobile kompakter */
    .sub-nav, .sub-nav-pills { font-size: 0.75rem; gap: 0.25rem; padding: 0.375rem 0; }
    .sub-nav a, .sub-nav-pills a { padding: 0.25rem 0.625rem; font-size: 0.75rem; }

    /* Checkbox-Spalte auf Mobile: kein Label, inline */
    .table td[data-label=""]::before,
    .table td:not([data-label])::before {
        display: none;
    }
    .table td[data-label=""] {
        justify-content: flex-start;
        padding: 0.25rem 0;
    }
}

/* Desktop: Filter-Row bei vielen Filtern */
@media (min-width: 769px) {
    .filter-row { flex-wrap: wrap; }
    .filter-row .form-input { min-width: 100px; flex: 1 1 0; }
    .filter-row .btn { flex-shrink: 0; }
}

/* Tablet: Grids reduzieren */
@media (max-width: 1024px) {
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    [style*="grid-template-columns: 1fr 1fr 1fr"] {
        grid-template-columns: 1fr 1fr !important;
    }
}

/* Mobile: Alle Grids zu 1 Spalte */
@media (max-width: 640px) {
    .grid-2, .grid-3, .grid-auto { grid-template-columns: 1fr; }
    [style*="grid-template-columns: 1fr 1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns: repeat"] {
        grid-template-columns: 1fr !important;
    }
}

/* Workspace-Toggle (Pill-Switch in der Topbar) */
.workspace-toggle {
    display: flex;
    align-items: center;
    gap: 0;
    margin: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 2px;
    flex-shrink: 0;
}
.workspace-toggle button {
    background: transparent;
    border: none;
    border-radius: calc(var(--radius) - 2px);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.2rem 0.65rem;
    line-height: 1.6;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.workspace-toggle button:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}
.workspace-toggle button.active {
    background: var(--accent-primary);
    color: #fff;
}

/* ── Dashboard: KPI-Strip + Liquiditaetschart (Phase K-UI) ──────────────────── */
.liquidity-chart { width: 100%; height: 240px; display: block; }
.liquidity-line { fill: none; stroke: var(--accent-primary); stroke-width: 2; }
.liquidity-area { fill: var(--accent-primary); opacity: 0.1; }
.liquidity-marker { stroke: var(--text-muted); stroke-dasharray: 4 4; stroke-width: 1; }
.liquidity-axis { stroke: var(--border-default); stroke-width: 1; }
.liquidity-label { fill: var(--text-secondary); font-size: var(--fs-xs); font-family: var(--font-sans); }
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-5); }
.kpi-card { padding: var(--space-4); border-radius: var(--radius-lg); background: var(--bg-elevated); border: 1px solid var(--border-subtle); }
.kpi-value { font-size: var(--fs-2xl); font-weight: 700; color: var(--text-primary); margin: var(--space-1) 0; }
.kpi-label { font-size: var(--fs-sm); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-delta { font-size: var(--fs-xs); margin-top: var(--space-1); }
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }

@media (max-width: 640px) {
    .kpi-strip { grid-template-columns: repeat(2, 1fr); }
}

/* ═══════════════════════════════════════
   PHASE B+C — Menü-Gruppen (details/summary)
   ═══════════════════════════════════════ */

/* Überschreibt den globalen details-Marker nur für nav-group */
.nav-group { border: none; background: none; }
.nav-group > summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    cursor: pointer;
    list-style: none;
    color: var(--text-muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    user-select: none;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
}
.nav-group > summary::before { display: none; } /* globalen Marker deaktivieren */
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary:hover { color: var(--text-secondary); background: var(--bg-hover); }
.nav-group .nav-chevron {
    margin-left: auto;
    transition: transform 0.2s;
    width: 1em;
    height: 1em;
    flex-shrink: 0;
}
.nav-group[open] .nav-chevron { transform: rotate(90deg); }
.nav-group-header svg:first-child { width: 14px; height: 14px; opacity: 0.7; flex-shrink: 0; }
.nav-group-items {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-left: var(--space-2);
    padding-bottom: var(--space-1);
}
.nav-group-items .nav-item { padding-left: var(--space-4); }
/* Sub-Items (eingerückt) */
.nav-sub {
    padding-left: var(--space-5) !important;
    font-size: var(--fs-sm) !important;
    opacity: 0.85;
}
/* Fristen-Item ausserhalb der Gruppen */
.nav-item-standalone {
    margin: var(--space-2) var(--space-2) 0;
    border-radius: var(--radius-sm);
    border-top: 1px solid var(--border-subtle);
    padding-top: var(--space-3);
}

/* ═══════════════════════════════════════
   PHASE B+C — Breadcrumbs
   ═══════════════════════════════════════ */

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
    padding: var(--space-2) var(--space-4);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    border-bottom: 1px solid var(--border-subtle);
}
.breadcrumbs a { color: var(--text-secondary); text-decoration: none; }
.breadcrumbs a:hover { color: var(--text-primary); }
.breadcrumbs .breadcrumb-separator { color: var(--text-muted); opacity: 0.5; }

/* ═══════════════════════════════════════
   PHASE B+C — Command Palette
   ═══════════════════════════════════════ */

#commandPalette {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 0;
    max-width: 600px;
    width: 90vw;
    max-height: 70vh;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
#commandPalette::backdrop { background: rgba(0,0,0,0.6); }
.cp-input {
    width: 100%;
    padding: var(--space-4);
    border: none;
    border-bottom: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-primary);
    font-size: var(--fs-base);
    outline: none;
    font-family: var(--font-sans);
}
.cp-list {
    max-height: 50vh;
    overflow-y: auto;
    padding: var(--space-2);
}
.cp-item {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    align-items: center;
    color: var(--text-secondary);
    transition: background 0.1s, color 0.1s;
}
.cp-item.active, .cp-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.cp-item-group {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    margin-left: auto;
    white-space: nowrap;
    flex-shrink: 0;
}
.cp-hint {
    padding: var(--space-2) var(--space-4);
    font-size: var(--fs-xs);
    color: var(--text-muted);
    border-top: 1px solid var(--border-subtle);
}

/* Command-Palette-Trigger in der Topbar */
.cp-trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--bg-overlay);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1) var(--space-3);
    font-size: var(--fs-xs);
    transition: border-color 0.15s, color 0.15s;
    flex-shrink: 0;
}
.cp-trigger:hover { border-color: var(--border-default); color: var(--text-secondary); }
.cp-trigger svg { width: 14px; height: 14px; }
.cp-trigger-hint { font-size: var(--fs-xs); opacity: 0.6; }

/* ═══════════════════════════════════════
   PHASE B+C — Bottom-Nav Polish
   ═══════════════════════════════════════ */

@media (max-width: 768px) {
    .bottom-nav a.active, .bottom-nav button.active {
        color: var(--accent-primary);
        background: rgba(99, 102, 241, 0.1);
        border-top: 2px solid var(--accent-primary);
        margin-top: -2px;
    }
    .bottom-nav a:active, .bottom-nav button:active {
        transform: scale(0.95);
        transition: transform 0.1s;
    }
}

/* ═══════════════════════════════════════
   PHASE B+C — Tabellen-Verbesserungen
   ═══════════════════════════════════════ */

/* Tablet: erste Spalte sticky */
@media (min-width: 768px) and (max-width: 1023px) {
    .table-sticky-first th:first-child,
    .table-sticky-first td:first-child {
        position: sticky;
        left: 0;
        background: var(--bg-elevated);
        z-index: 1;
    }
}

/* Mobile Card-View: besseres Spacing */
@media (max-width: 768px) {
    .table tr {
        padding: var(--space-3) var(--space-3);
        margin-bottom: var(--space-2);
    }
    .table td {
        padding: var(--space-2) 0;
        border-bottom: 1px solid var(--border-subtle);
        gap: var(--space-2);
    }
    .table td:last-child { border-bottom: none; padding-bottom: 0; }
    .table td::before {
        min-width: 90px;
        flex-shrink: 0;
    }
}

/* ═══════════════════════════════════════
   PHASE B+C — Skeleton-Loader
   ═══════════════════════════════════════ */

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-overlay) 0%,
        var(--bg-hover) 50%,
        var(--bg-overlay) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}
.skeleton-row { height: 1em; margin: var(--space-2) 0; }
.skeleton-block { height: 60px; }
@keyframes skeleton-pulse {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ═══════════════════════════════════════
   PHASE B+C — View Transitions API
   ═══════════════════════════════════════ */

@view-transition { navigation: auto; }
@media (prefers-reduced-motion: reduce) {
    @view-transition { navigation: none; }
}

/* ═══════════════════════════════════════
   PHASE E — HTMX-States
   ═══════════════════════════════════════ */

.htmx-request .htmx-spinner { display: inline-block; }
.htmx-spinner {
    display: none;
    width: 1em;
    height: 1em;
    border: 2px solid var(--border-default, var(--border-color));
    border-top-color: var(--accent-primary, var(--accent));
    border-radius: 50%;
    animation: htmx-spin 0.6s linear infinite;
    vertical-align: middle;
    margin-left: 0.25rem;
}
@keyframes htmx-spin { to { transform: rotate(360deg); } }
.htmx-request { opacity: 0.7; pointer-events: none; }
.htmx-swapping { opacity: 0.5; transition: opacity 0.15s; }
.htmx-settling { opacity: 1; transition: opacity 0.15s; }

/* ═══════════════════════════════════════
   LIGHTBOX — Dokument-Vorschau (iOS-PWA)
   ═══════════════════════════════════════ */

/* Default: <dialog> ohne [open] bleibt unsichtbar (Browser-default) */
dialog.lightbox:not([open]) {
    display: none;
}
dialog.lightbox[open] {
    padding: 0;
    border: none;
    border-radius: var(--radius);
    background: var(--bg-secondary);
    width: 100dvw;
    height: 100dvh;
    max-width: 100dvw;
    max-height: 100dvh;
    margin: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
@media (min-width: 768px) {
    dialog.lightbox[open] {
        width: 90vw;
        height: 90vh;
        max-width: 1200px;
        max-height: 90vh;
        margin: auto;
        border: 1px solid var(--border-color);
    }
}
dialog.lightbox::backdrop {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}
.lightbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 0.75rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
}
.lightbox-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.lightbox-close {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    flex-shrink: 0;
    font-size: 1.25rem;
    line-height: 1;
    transition: background 0.15s;
    position: absolute;
    top: max(0.5rem, env(safe-area-inset-top));
    right: max(0.75rem, env(safe-area-inset-right));
}
.lightbox-close:hover,
.lightbox-close:focus {
    background: var(--bg-secondary);
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.lightbox-body {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 0;
}
#lightbox-iframe,
#lightbox-object {
    width: 100%;
    height: 100%;
    border: 0;
    display: none;
    background: #fff;
}
#lightbox-spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    flex-direction: column;
    gap: 1rem;
}
.lightbox-spinner-ring {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: htmx-spin 0.7s linear infinite;
}
.lightbox-footer {
    display: flex;
    justify-content: flex-end;
    padding: 0.6rem 1rem;
    padding-bottom: max(0.6rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}
.lightbox-unavailable {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 2rem;
    text-align: center;
}

/* Page-Loader: Top-Bar bei Seitenwechseln */
.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent);
    transform-origin: left center;
    transform: scaleX(0);
    transition: transform 0.4s ease-out;
    z-index: 10000;
    pointer-events: none;
    box-shadow: 0 0 8px var(--accent);
    opacity: 0;
}

.page-loader.is-loading {
    opacity: 1;
    transform: scaleX(0.7);
    transition: transform 8s cubic-bezier(0, 0.5, 0.3, 1), opacity 0.2s ease-in;
}

.page-loader.is-done {
    transform: scaleX(1);
    opacity: 0;
    transition: transform 0.2s ease-out, opacity 0.4s ease-out 0.1s;
}

@media (prefers-reduced-motion: reduce) {
    .page-loader { transition: opacity 0.1s linear; }
    .page-loader.is-loading { transform: none; }
}
