/* ===== Dokumenti - CSS ===== */

:root {
    --primary: #4A90D9;
    --primary-dark: #357ABD;
    --primary-light: #E8F0FE;
    --accent: #27AE60;
    --accent-dark: #1E8449;
    --accent-light: #E8F8F0;
    --danger: #E74C3C;
    --danger-light: #FDEDEC;
    --warning: #F39C12;
    --warning-light: #FEF5E7;
    --bg: #F5F7FA;
    --bg-card: #FFFFFF;
    --text: #2C3E50;
    --text-light: #64748B;
    --text-muted: #94A3B8;
    --border: #E2E8F0;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

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

img { max-width: 100%; height: auto; }

/* ===== Utility ===== */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

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

.sidebar {
    width: 260px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

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

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ===== Logo SVG Sizes ===== */
.logo-svg {
    width: 64px;
    height: 64px;
    display: block;
    margin: 0 auto 8px;
    filter: drop-shadow(0 2px 8px rgba(74, 144, 217, 0.3));
}

.logo-svg-sidebar {
    width: 28px;
    height: 28px;
    vertical-align: middle;
    flex-shrink: 0;
}

.logo-svg-sm {
    width: 24px;
    height: 24px;
    vertical-align: middle;
}

.auth-logo {
    text-align: center;
    margin-bottom: 4px;
}

.mobile-logo {
    font-weight: 700;
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.sidebar-user {
    padding: 12px 24px;
    font-size: 0.875rem;
    color: var(--text-light);
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.sidebar-user strong {
    color: var(--text);
}

.sidebar-nav {
    flex: 1;
    padding: 8px 12px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.nav-item:hover {
    background: var(--bg);
    color: var(--primary);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.nav-item .nav-icon {
    font-size: 1.25rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 12px 24px;
    border-top: 1px solid var(--border);
}

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 32px;
    max-width: 1200px;
}

/* Mobile hamburger */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    z-index: 99;
    align-items: center;
    gap: 12px;
}

.hamburger {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
    color: var(--text);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
}

/* ===== Page Header ===== */
.page-header {
    margin-bottom: 28px;
}

.page-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.page-header p {
    color: var(--text-light);
    font-size: 1rem;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    font-size: 2rem;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    flex-shrink: 0;
}

.stat-icon.blue { background: var(--primary-light); }
.stat-icon.green { background: var(--accent-light); }
.stat-icon.orange { background: var(--warning-light); }

.stat-info h3 {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-info p {
    font-size: 0.875rem;
    color: var(--text-light);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: var(--font);
    line-height: 1.4;
}

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

.btn-accent {
    background: var(--accent);
    color: white;
}
.btn-accent:hover { background: var(--accent-dark); }

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

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); border-color: var(--text-muted); }

.btn-sm {
    padding: 6px 14px;
    font-size: 0.85rem;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1.05rem;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 20px;
}

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

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg-card);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
}

.form-control::placeholder {
    color: var(--text-muted);
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748B' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ===== Search Bar ===== */
.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.search-input-wrap {
    flex: 1;
    position: relative;
}

.search-input-wrap .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1.1rem;
    pointer-events: none;
}

.search-input-wrap input {
    padding-left: 42px;
}

/* ===== Document Grid ===== */
.doc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
}

.doc-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.doc-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.doc-card-thumb {
    height: 180px;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.doc-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.doc-card-thumb .placeholder-icon {
    font-size: 3.5rem;
    opacity: 0.6;
}

.doc-card-body {
    padding: 16px;
}

.doc-card-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-card-meta {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 10px;
    display: flex;
    gap: 12px;
}

.doc-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* ===== Tags ===== */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.tag-removable {
    gap: 4px;
}

.tag-remove {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    opacity: 0.7;
    padding: 0;
    line-height: 1;
}

.tag-remove:hover { opacity: 1; }

/* ===== Upload Area ===== */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-card);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-zone .upload-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    display: block;
}

.upload-zone h3 {
    font-size: 1.15rem;
    margin-bottom: 6px;
}

.upload-zone p {
    color: var(--text-light);
    font-size: 0.9rem;
}

.upload-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* Camera */
.camera-container {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    margin-bottom: 16px;
}

.camera-container video {
    width: 100%;
    display: block;
}

.camera-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 16px;
}

/* ===== Progress Bar ===== */
.progress-bar-wrap {
    background: var(--border);
    border-radius: 8px;
    height: 8px;
    overflow: hidden;
    margin: 12px 0;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 8px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 0.85rem;
    color: var(--text-light);
    text-align: center;
}

/* ===== OCR Status ===== */
.ocr-status {
    padding: 16px;
    border-radius: var(--radius-sm);
    margin: 16px 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.ocr-status.processing {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.ocr-status.done {
    background: var(--accent-light);
    color: var(--accent-dark);
}

.ocr-status .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Document Detail ===== */
.doc-detail {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 24px;
}

.doc-preview {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.doc-preview img {
    max-width: 100%;
    max-height: 80vh;
}

.doc-preview iframe {
    width: 100%;
    height: 80vh;
    border: none;
}

.doc-preview .preview-placeholder {
    text-align: center;
    padding: 48px;
    color: var(--text-light);
}

.doc-preview .preview-placeholder .big-icon {
    font-size: 4rem;
    margin-bottom: 12px;
    display: block;
}

.doc-sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.meta-list {
    list-style: none;
}

.meta-list li {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.meta-list li:last-child { border-bottom: none; }

.meta-label {
    color: var(--text-light);
    font-weight: 500;
}

.meta-value {
    font-weight: 600;
    text-align: right;
    max-width: 60%;
    word-break: break-word;
}

/* Tag input */
.tag-input-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    min-height: 42px;
    align-items: center;
    cursor: text;
}

.tag-input-wrap input {
    border: none;
    outline: none;
    flex: 1;
    min-width: 80px;
    font-size: 0.9rem;
    font-family: var(--font);
    padding: 2px 4px;
    background: transparent;
}

.tag-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    max-height: 200px;
    overflow-y: auto;
}

.tag-suggestion {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.9rem;
}

.tag-suggestion:hover { background: var(--bg); }

/* ===== Login & Setup ===== */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #E8F0FE 0%, #F5F7FA 50%, #E8F8F0 100%);
}

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

.auth-card h1 {
    font-size: 1.75rem;
    text-align: center;
    margin-bottom: 8px;
    color: var(--primary);
}

.auth-card .subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 32px;
    font-size: 0.95rem;
}

.auth-card .btn {
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 1rem;
}

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.alert-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #F5C6CB;
}

.alert-success {
    background: var(--accent-light);
    color: var(--accent-dark);
    border: 1px solid #A3D9B1;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-light);
}

.empty-state .empty-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    display: block;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.25rem;
    margin-bottom: 8px;
    color: var(--text);
}

.empty-state p {
    margin-bottom: 20px;
}

/* ===== Toast Notifications ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
    font-size: 0.9rem;
    animation: slideIn 0.3s ease;
    max-width: 360px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.success { border-left: 4px solid var(--accent); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }

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

/* ===== Modal ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 24px;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 32px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal h3 {
    font-size: 1.25rem;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* ===== Document Type Badges ===== */
.doc-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.doc-type-badge.rechnung { background: #DBEAFE; color: #1E40AF; }
.doc-type-badge.beleg { background: #FEF3C7; color: #92400E; }
.doc-type-badge.vertrag { background: #EDE9FE; color: #5B21B6; }
.doc-type-badge.brief { background: #FCE7F3; color: #9D174D; }
.doc-type-badge.dokument { background: #F1F5F9; color: #475569; }

/* ===== File Size Helper ===== */
.file-size {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .doc-detail {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .mobile-header {
        display: flex;
    }

    .main-content {
        margin-left: 0;
        padding: 80px 16px 24px;
    }

    .doc-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .search-bar {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .doc-grid {
        grid-template-columns: 1fr;
    }

    .auth-card {
        padding: 28px 20px;
    }
}

/* ===== PWA Standalone Mode ===== */
@media (display-mode: standalone) {
    .mobile-header {
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .main-content {
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }

    .sidebar {
        padding-top: max(24px, env(safe-area-inset-top));
    }
}
