/* ==========================================================================
   OCRVault — Main Stylesheet
   ========================================================================== */

:root {
    --sidebar-width: 240px;
    --sidebar-bg: #1a1d23;
    --sidebar-text: #adb5bd;
    --sidebar-active-bg: rgba(99, 102, 241, 0.15);
    --sidebar-active-text: #818cf8;
    --sidebar-hover-bg: rgba(255,255,255,0.05);
    --topbar-height: 56px;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-app: #f1f5f9;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-muted: #94a3b8;
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius: 10px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow: 0 4px 12px rgba(0,0,0,.1);
}

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

body {
    font-family: var(--font-main);
    background: var(--bg-app);
    color: #1e293b;
    margin: 0;
    font-size: 14px;
}

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

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
    transition: transform .25s ease;
}

.sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,.07);
}

.sidebar-brand {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    display: flex;
    align-items: center;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,.07);
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}

.sidebar-user-name {
    font-weight: 600;
    color: #f1f5f9;
    font-size: 13px;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.sidebar-nav {
    list-style: none;
    padding: 12px 0;
    margin: 0;
    flex: 1;
}

.sidebar-nav-divider {
    padding: 14px 20px 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #475569;
}

.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0;
    font-size: 13.5px;
    transition: background .15s, color .15s;
}

.sidebar-nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: #e2e8f0;
}

.sidebar-nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
    border-left: 3px solid var(--primary);
}

.sidebar-nav-link i {
    font-size: 16px;
    width: 20px;
}

.sidebar-footer {
    padding: 16px 0;
    border-top: 1px solid rgba(255,255,255,.07);
}

/* ─── Main Content ──────────────────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ─── Topbar ────────────────────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 900;
    box-shadow: var(--shadow-sm);
}

.topbar-title {
    flex: 1;
    font-weight: 600;
    font-size: 15px;
    color: #1e293b;
}

.sidebar-toggle {
    display: none;
}

/* ─── Content Area ──────────────────────────────────────────────────────────── */
.content-area {
    padding: 24px;
    flex: 1;
}

/* ─── Cards ─────────────────────────────────────────────────────────────────── */
.card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    padding: 14px 20px;
    font-weight: 600;
    border-radius: var(--radius) var(--radius) 0 0 !important;
}

/* ─── Stat Cards (Dashboard) ────────────────────────────────────────────────── */
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: box-shadow .2s;
}

.stat-card:hover { box-shadow: var(--shadow); }

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.stat-icon.blue    { background: #eff6ff; color: #3b82f6; }
.stat-icon.green   { background: #f0fdf4; color: #10b981; }
.stat-icon.red     { background: #fef2f2; color: #ef4444; }
.stat-icon.purple  { background: #f5f3ff; color: #8b5cf6; }
.stat-icon.orange  { background: #fff7ed; color: #f97316; }
.stat-icon.teal    { background: #f0fdfa; color: #14b8a6; }

.stat-value {
    font-size: 26px;
    font-weight: 700;
    color: #1e293b;
    line-height: 1;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: .5px;
}

/* ─── Upload Zone ───────────────────────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed #cbd5e1;
    border-radius: var(--radius);
    padding: 60px 30px;
    text-align: center;
    cursor: pointer;
    background: #fafbfc;
    transition: border-color .2s, background .2s;
    position: relative;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary);
    background: rgba(99,102,241,.04);
}

.upload-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.upload-zone-icon {
    font-size: 48px;
    color: var(--primary);
    margin-bottom: 12px;
    display: block;
}

.upload-zone-title {
    font-size: 17px;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 6px;
}

.upload-zone-hint {
    color: var(--text-muted);
    font-size: 13px;
}

/* ─── Progress Bar ──────────────────────────────────────────────────────────── */
.progress { height: 10px; border-radius: 6px; background: #e2e8f0; }
.progress-bar { background: var(--primary); border-radius: 6px; transition: width .4s ease; }

/* ─── Document Table ────────────────────────────────────────────────────────── */
.doc-table th {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    white-space: nowrap;
    background: #f8fafc;
    border-bottom: 2px solid var(--border-color);
}

.doc-table td { vertical-align: middle; font-size: 13.5px; }

.doc-thumbnail {
    width: 40px;
    height: 54px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: #f1f5f9;
}

.doc-thumbnail-placeholder {
    width: 40px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 18px;
}

.doc-name {
    font-weight: 500;
    color: #1e293b;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Badges ────────────────────────────────────────────────────────────────── */
.badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 20px; }

/* ─── Document Viewer ───────────────────────────────────────────────────────── */
.page-section {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 24px;
    overflow: hidden;
}

.page-header {
    background: #f8fafc;
    padding: 10px 16px;
    font-weight: 600;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
    color: #475569;
}

.page-image-container {
    background: #374151;
    text-align: center;
    padding: 16px;
}

.page-image {
    max-width: 100%;
    max-height: 600px;
    border-radius: 4px;
    box-shadow: var(--shadow);
}

.page-text {
    padding: 16px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    background: #fafafa;
    min-height: 100px;
    max-height: 400px;
    overflow-y: auto;
    border-top: 1px solid var(--border-color);
}

/* ─── Text Editor ───────────────────────────────────────────────────────────── */
.text-editor {
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    line-height: 1.7;
    resize: vertical;
    min-height: 300px;
    background: #fafafa;
}

/* ─── Auth Layout ───────────────────────────────────────────────────────────── */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1d23 0%, #2d3748 100%);
    padding: 20px;
}

.auth-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

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

.auth-logo-icon {
    font-size: 40px;
    color: var(--primary);
}

.auth-logo-name {
    font-size: 22px;
    font-weight: 700;
    color: #1e293b;
    margin-top: 6px;
}

/* ─── Processing Status ─────────────────────────────────────────────────────── */
.processing-box {
    text-align: center;
    padding: 48px 24px;
}

.processing-spinner {
    width: 56px;
    height: 56px;
    border: 4px solid #e2e8f0;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.processing-status-text {
    font-size: 16px;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 8px;
}

.processing-detail {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 20px;
}

/* ─── Search Highlights ─────────────────────────────────────────────────────── */
mark {
    background: #fef08a;
    color: #1e293b;
    border-radius: 2px;
    padding: 0 2px;
}

/* ─── System Diagnostics ─────────────────────────────────────────────────────── */
.diag-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
}

.diag-row:last-child { border-bottom: none; }

.diag-label { font-weight: 500; font-size: 13.5px; }

.diag-value { font-size: 13px; color: var(--text-muted); }

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.status-dot.ok      { background: var(--success); }
.status-dot.fail    { background: var(--danger); }
.status-dot.warn    { background: var(--warning); }

/* ─── Flash Container ───────────────────────────────────────────────────────── */
.flash-container { position: relative; z-index: 10; }

/* ─── Toasts ────────────────────────────────────────────────────────────────── */
#toastContainer {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.app-toast {
    background: #1e293b;
    color: #f1f5f9;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 13.5px;
    box-shadow: var(--shadow);
    animation: slideIn .3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 320px;
}

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

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

/* ─── Bulk Actions Bar ──────────────────────────────────────────────────────── */
.bulk-actions {
    background: #1e293b;
    color: #f1f5f9;
    padding: 10px 16px;
    border-radius: 8px;
    display: none;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.bulk-actions.visible { display: flex; }

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

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

    .main-content {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: flex !important;
    }

    .content-area {
        padding: 16px;
    }

    .stat-card { padding: 14px; }
    .stat-value { font-size: 20px; }
}

/* ─── Utilities ─────────────────────────────────────────────────────────────── */
.text-monospace { font-family: 'Courier New', Courier, monospace; }
.cursor-pointer { cursor: pointer; }
.overflow-hidden { overflow: hidden; }

/* ─── Filters Bar ───────────────────────────────────────────────────────────── */
.filters-bar {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
}

/* ─── Confidence Meter ──────────────────────────────────────────────────────── */
.confidence-bar {
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
    width: 80px;
    display: inline-block;
    vertical-align: middle;
}

.confidence-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--success);
}

.confidence-bar-fill.medium { background: var(--warning); }
.confidence-bar-fill.low    { background: var(--danger); }
