/* ===== DESIGN TOKENS / CSS CUSTOM PROPERTIES ===== */
:root {
    /* Brand */
    --brand-primary: #6366f1;
    --brand-primary-hover: #4f46e5;
    --brand-primary-light: rgba(99, 102, 241, 0.25);
    --brand-primary-glow: rgba(99, 102, 241, 0.25);
    --brand-primary-border: rgba(99, 102, 241, 0.4);
    --brand-primary-85: var(--brand-primary-85);
    --brand-secondary: #a855f7;
    --brand-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
    --brand-gradient-subtle: linear-gradient(135deg, rgba(99,102,241,0.15) 0%, rgba(168,85,247,0.08) 100%);

    /* Semantic */
    --color-success: #22c55e;
    --color-success-bg: rgba(34, 197, 94, 0.12);
    --color-success-border: rgba(34, 197, 94, 0.3);
    --color-warning: #f59e0b;
    --color-warning-bg: rgba(245, 158, 11, 0.12);
    --color-warning-border: rgba(245, 158, 11, 0.3);
    --color-danger: #ef4444;
    --color-danger-bg: rgba(239, 68, 68, 0.12);
    --color-danger-border: rgba(239, 68, 68, 0.3);
    --color-info: #3b82f6;
    --color-info-bg: rgba(59, 130, 246, 0.12);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-2xl: 32px;
    --space-3xl: 48px;

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.15), 0 4px 12px rgba(0,0,0,0.08);
    --shadow-xl: 0 25px 50px rgba(0,0,0,0.2);
    --shadow-glow: 0 0 20px var(--brand-primary-glow);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== DARK THEME (Default) ===== */
[data-theme="dark"], :root {
    --bg-base: #0c0f1a;
    --bg-surface: #141825;
    --bg-surface-hover: #1a1f30;
    --bg-elevated: #1e2336;
    --bg-elevated-hover: #252a3e;
    --bg-card: #181d2e;
    --bg-input: #0f1320;
    --bg-overlay: rgba(12, 15, 26, 0.85);

    --border-primary: rgba(255,255,255,0.06);
    --border-secondary: rgba(255,255,255,0.1);
    --border-hover: rgba(255,255,255,0.15);
    --border-active: var(--brand-primary);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --text-muted: #475569;
    --text-inverse: #0f172a;

    --glass-bg: rgba(20, 24, 37, 0.7);
    --glass-border: rgba(255,255,255,0.08);
    --glass-blur: 20px;

    --scrollbar-track: #141825;
    --scrollbar-thumb: #334155;
    --scrollbar-thumb-hover: #475569;
}

/* ===== LIGHT THEME ===== */
[data-theme="light"] {
    --bg-base: #eef0f4;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f5f6f9;
    --bg-elevated: #ffffff;
    --bg-elevated-hover: #f1f3f8;
    --bg-card: #f3f4f7;
    --bg-input: #ffffff;
    --bg-overlay: rgba(0, 0, 0, 0.4);

    --border-primary: rgba(0,0,0,0.10);
    --border-secondary: rgba(0,0,0,0.16);
    --border-hover: rgba(0,0,0,0.22);
    --border-active: var(--brand-primary);

    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-tertiary: #64748b;
    --text-muted: #94a3b8;
    --text-inverse: #f8fafc;

    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(0,0,0,0.12);
    --glass-blur: 20px;

    --scrollbar-track: #f0f2f5;
    --scrollbar-thumb: #cbd5e1;
    --scrollbar-thumb-hover: #94a3b8;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
    --shadow-xl: 0 25px 50px rgba(0,0,0,0.1);
}

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

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-base);
    min-height: 100vh;
    color: var(--text-primary);
    transition: background var(--transition-slow), color var(--transition-slow);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

input, select, textarea, button { font-family: inherit; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand-primary) !important;
    box-shadow: 0 0 0 3px var(--brand-primary-light), var(--shadow-sm);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* ===== THEME TOGGLE ===== */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-primary);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-normal);
}

.theme-toggle:hover {
    border-color: var(--border-hover);
    color: var(--brand-primary);
}

.theme-toggle-icon {
    width: 18px;
    height: 18px;
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
    display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

[data-theme="light"] .theme-toggle .icon-moon {
    display: block;
}

/* ===== LOGIN STYLES ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    position: relative;
    overflow: hidden;
}

/* Animated gradient background */
.login-container::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--brand-primary-glow) 0%, transparent 70%);
    top: -200px;
    right: -100px;
    animation: float 8s ease-in-out infinite;
    pointer-events: none;
}

.login-container::after {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(168,85,247,0.15) 0%, transparent 70%);
    bottom: -200px;
    left: -100px;
    animation: float 10s ease-in-out infinite reverse;
    pointer-events: none;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -20px) scale(1.05); }
    66% { transform: translate(-20px, 15px) scale(0.95); }
}

.login-box {
    width: 100%;
    max-width: 440px;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-radius: var(--radius-xl);
    border: 1px solid var(--glass-border);
    padding: var(--space-3xl);
    box-shadow: var(--shadow-xl);
    position: relative;
    z-index: 1;
    animation: fadeInUp 0.5s ease-out;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-logo { text-align: center; margin-bottom: var(--space-2xl); }

.login-logo-icon {
    margin-bottom: var(--space-lg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    background: var(--brand-gradient-subtle);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-secondary);
}

.login-logo-icon svg {
    width: 40px;
    height: 40px;
    color: var(--brand-primary);
}

.login-logo h1 {
    font-size: 26px;
    font-weight: 700;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.login-logo p {
    color: var(--text-tertiary);
    font-size: 14px;
    margin-top: var(--space-sm);
}

.tab-switcher {
    display: flex;
    background: var(--bg-input);
    border-radius: var(--radius-md);
    padding: 3px;
    margin-bottom: var(--space-2xl);
    border: 1px solid var(--border-primary);
}

.tab-btn {
    flex: 1;
    padding: var(--space-md) var(--space-lg);
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-weight: 600;
    font-size: 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
}

.tab-btn:hover:not(.active) { color: var(--text-secondary); }

.tab-btn.active {
    background: var(--brand-primary);
    color: white;
    box-shadow: 0 2px 8px var(--brand-primary-glow);
}

.form-group { margin-bottom: var(--space-xl); }

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.form-control {
    width: 100%;
    padding: 13px var(--space-lg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-secondary);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 15px;
    transition: all var(--transition-normal);
}

.form-control::placeholder { color: var(--text-muted); }
.form-control.mono { font-family: 'JetBrains Mono', monospace; }

.password-wrapper { position: relative; }

.password-toggle {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 18px;
    transition: color var(--transition-fast);
}

.password-toggle:hover { color: var(--text-primary); }

.remember-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xl);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
}

.checkbox-label input { width: 18px; height: 18px; accent-color: var(--brand-primary); }

.forgot-link {
    color: var(--brand-primary);
    text-decoration: none;
    font-size: 14px;
    transition: color var(--transition-fast);
}
.forgot-link:hover { color: var(--brand-primary-hover); text-decoration: underline; }

/* ===== BUTTONS ===== */
.btn {
    padding: 13px var(--space-xl);
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    border: none;
    font-size: 15px;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    width: 100%;
    background: var(--brand-primary);
    color: white;
    box-shadow: 0 2px 8px var(--brand-primary-glow);
}

.btn-primary:hover {
    background: var(--brand-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--brand-primary-glow);
}

.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--bg-elevated);
    border: 1px solid var(--border-secondary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-elevated-hover);
    border-color: var(--border-hover);
}

.divider {
    display: flex;
    align-items: center;
    margin: var(--space-xl) 0;
    color: var(--text-muted);
    font-size: 13px;
}

.divider::before, .divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-primary);
}

.divider span { padding: 0 var(--space-lg); }

.social-login { display: flex; gap: var(--space-md); }

.social-btn {
    flex: 1;
    padding: var(--space-md);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-secondary);
    background: var(--bg-input);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    font-size: 14px;
    font-weight: 500;
}

.social-btn:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.error-message {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-xl);
    font-size: 14px;
    display: none;
    border: 1px solid var(--color-danger-border);
}

.success-message {
    background: var(--color-success-bg);
    color: var(--color-success);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-xl);
    font-size: 14px;
    display: none;
    border: 1px solid var(--color-success-border);
}

/* ===== APP STYLES ===== */
.app-container { display: none; }

.header {
    padding: var(--space-md) var(--space-2xl);
    border-bottom: 1px solid var(--border-primary);
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background var(--transition-slow), border-color var(--transition-slow);
}

.header-content {
    max-width: 1920px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 20px;
    font-weight: 700;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.logo-icon {
    width: 22px;
    height: 22px;
    color: var(--brand-primary);
    /* Reset the text gradient for SVG */
    -webkit-text-fill-color: currentColor;
}
.logo-link,
.logo-link:hover,
.logo-link:visited,
.logo-link:active,
.logo-link:focus {
    text-decoration: none;
    cursor: pointer;
}
.logo-link:hover {
    opacity: 0.8;
    transition: opacity var(--transition-fast);
}

.header-right { display: flex; align-items: center; gap: var(--space-md); }

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 14px 5px 5px;
    background: var(--bg-elevated);
    border-radius: var(--radius-full);
    border: 1px solid var(--border-primary);
    transition: all var(--transition-normal);
}

.user-menu:hover { border-color: var(--border-hover); }

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--brand-primary-light);
    border: 1px solid var(--brand-primary-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 11px;
    color: var(--brand-primary);
}

.user-name { font-weight: 600; font-size: 13px; color: var(--text-primary); }

.logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-secondary);
    background: var(--bg-elevated);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition-normal);
}

.logout-btn .btn-icon {
    width: 16px;
    height: 16px;
}

.logout-btn:hover { background: var(--bg-elevated-hover); border-color: var(--border-hover); }

/* ===== MAIN LAYOUT ===== */
.main-container {
    display: flex;
    max-width: 1920px;
    margin: 0 auto;
    padding: var(--space-lg);
    gap: var(--space-lg);
    height: calc(100vh - 57px);
}

#detailPanel { display: none; }
#detailPanel.active { display: flex; }
#overviewPanel { display: flex; }
#overviewPanel.hidden { display: none; }

/* Invoice List Sidebar */
.sidebar {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.sidebar-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: var(--space-md);
}

.sidebar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    flex-shrink: 0;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.search-box { position: relative; width: 200px; flex-shrink: 0; transition: width 0.2s ease; }

.search-box input {
    padding: 7px 12px 7px 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-primary);
    background: var(--bg-surface);
    color: var(--text-primary);
    width: 100%;
    font-size: 13px;
    transition: all var(--transition-normal);
}

.search-box input::placeholder { color: var(--text-muted); }

.search-box:focus-within {
    width: 280px;
}

.search-box input:focus {
    background: var(--bg-input);
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.column-config-wrapper { position: relative; }

.column-config-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-primary);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-normal);
}

.column-config-btn .btn-icon {
    width: 14px;
    height: 14px;
}

.column-config-btn:hover { background: var(--bg-surface-hover); border-color: var(--border-hover); }

.column-config {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 220px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 10px;
    z-index: 10;
}

.column-config-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    color: var(--text-secondary);
    font-size: 12px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.column-config-item {
    cursor: grab;
    user-select: none;
}

.column-config-item:hover { background: var(--bg-surface-hover); }

.column-config-item.dragging {
    opacity: 0.4;
}

.column-config-item.drag-over {
    border-top: 2px solid var(--brand-primary);
    padding-top: 4px;
}

.column-config-item:active { cursor: grabbing; }

.drag-handle {
    color: var(--text-quaternary, var(--text-tertiary));
    font-size: 14px;
    line-height: 1;
    cursor: grab;
    flex-shrink: 0;
}

.drag-handle:active { cursor: grabbing; }

.column-config-label { flex: 1; }

.column-config-item input { width: 16px; height: 16px; accent-color: var(--brand-primary); flex-shrink: 0; }

/* ===== TABS ===== */
.tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-input);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-primary);
}

.tab-btn-invoices {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-weight: 600;
    font-size: 17px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
}

.tab-btn-invoices:hover:not(.active) {
    background: var(--bg-surface-hover);
    color: var(--text-secondary);
}

.tab-btn-invoices.active {
    background: var(--brand-primary-light);
    border: 1px solid var(--brand-primary-border);
    color: var(--brand-primary);
}
.tab-btn-invoices.active:hover {
    background: var(--brand-primary-85);
    color: white;
}

.tab-btn-invoices .badge {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.4;
}

.tab-btn-invoices:not(.active) .badge {
    background: var(--bg-surface);
    color: var(--text-tertiary);
}

.tab-btn-invoices.active .badge {
    background: var(--brand-primary-border);
    color: var(--brand-primary);
}
.tab-btn-invoices.active:hover .badge {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

/* Tab Icons (SVG) */
.tab-icon {
    width: 21px;
    height: 21px;
    flex-shrink: 0;
}

.tab-btn-invoices.active .tab-icon {
    stroke: var(--brand-primary);
}
.tab-btn-invoices.active:hover .tab-icon {
    stroke: white;
}

/* ===== INVOICE TABLE ===== */
.invoice-table-container {
    flex: 1;
    overflow-y: auto;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    transition: background var(--transition-slow);
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
}

.invoice-table thead {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.invoice-table th {
    text-align: left;
    padding: 11px 10px;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border-primary);
}

.invoice-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border-primary);
    color: var(--text-primary);
    transition: background var(--transition-fast);
}

.invoice-table tbody tr {
    cursor: pointer;
    transition: all var(--transition-fast);
}

.invoice-table tbody tr:hover {
    background: var(--brand-primary-light);
}

.invoice-table tbody tr.selected {
    background: var(--brand-primary-light);
    border-left: 3px solid var(--brand-primary);
}

.invoice-number-cell {
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    color: var(--brand-primary);
    font-size: 14px;
}

.invoice-total-cell {
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: var(--brand-primary);
    text-align: right;
    font-size: 14px;
}

/* ===== STATUS BADGES ===== */
.status-badge {
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.status-cell {
    font-size: 13px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    text-align: center;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Status icons (SVG) */
.status-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.status-icon.spin {
    animation: spin 1s linear infinite;
}

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

/* Individual status styles with icons */
.status-pending_review,
.status-pending,
.status-processing,
.status-uploaded {
    background: var(--color-warning-bg);
    color: var(--color-warning);
    border: 1px solid var(--color-warning-border);
}

.status-in_review {
    background: var(--color-info-bg, rgba(99,102,241,0.1));
    color: var(--color-info, #6366f1);
    border: 1px solid var(--color-info-border, rgba(99,102,241,0.25));
}

.status-approved,
.status-verified {
    background: var(--color-success-bg);
    color: var(--color-success);
    border: 1px solid var(--color-success-border);
}

.status-corrections_needed {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.status-extraction_failed,
.status-rejected {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border: 1px solid var(--color-danger-border);
}

.status-exported {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.status-imported {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-imported-warning {
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.status-import_error {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.status-archived {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-secondary);
}

.status-deleted {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border: 1px solid var(--color-danger-border);
    opacity: 0.7;
}

/* Duplicate badge for invoices */
.duplicate-badge {
    background: #ff9800;
    color: white;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    margin-left: 6px;
    cursor: help;
    vertical-align: middle;
}

/* ===== INVOICE CARD (legacy) ===== */
.invoice-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 8px;
}

.invoice-card {
    padding: 14px;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    cursor: pointer;
    transition: all var(--transition-normal);
}

.invoice-card:hover {
    transform: translateX(4px);
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
}

.invoice-card.selected {
    background: var(--brand-primary-light);
    border: 2px solid var(--brand-primary);
    box-shadow: var(--shadow-glow);
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.invoice-number {
    font-weight: 600;
    font-size: 14px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
}

.invoice-supplier { color: var(--text-tertiary); font-size: 12px; margin-top: 2px; }

.invoice-total {
    font-weight: 700;
    font-size: 15px;
    color: var(--brand-primary);
    font-family: 'JetBrains Mono', monospace;
    margin-top: 8px;
}

/* ===== SPLIT VIEW ===== */
.split-view {
    flex: 1;
    display: flex;
    gap: 0;
    min-width: 0;
    position: relative;
    min-height: 400px;
}

/* PDF Panel */
.pdf-panel {
    flex: 1 1 0;
    min-width: 280px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all var(--transition-normal);
}

.pdf-header {
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    min-height: 72px;
    box-sizing: border-box;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* PDF Title Block - nadpis + legenda pod ním */
.pdf-title-block {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-left: 5px;
}

.pdf-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* PDF Legend - vysvětlení barev rámečků (pod nadpisem) */
.pdf-legend {
    display: flex;
    gap: var(--space-md);
    align-items: center;
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
}

.pdf-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pdf-legend .legend-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 2px solid;
}

.pdf-legend .legend-learned .legend-color {
    border-color: #9b59b6;
    background: rgba(155, 89, 182, 0.2);
}

.pdf-legend .legend-ai .legend-color {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.2);
}

.pdf-controls { display: flex; gap: 6px; align-items: center; margin-top: 2px; }

.pdf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-secondary);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-normal);
}

.pdf-btn:hover {
    background: var(--bg-elevated-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.pdf-btn-icon {
    width: 16px;
    height: 16px;
}

.pdf-btn-download {
    gap: 6px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
}

.pdf-btn-export {
    gap: 6px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    background: #6366f1;
    color: #fff;
    border-color: #6366f1;
}

.pdf-btn-export:hover {
    background: #4f46e5;
    color: #fff;
    border-color: #4f46e5;
}

[data-theme="dark"] .pdf-btn-export {
    background: #818cf8;
    border-color: #818cf8;
    color: #1e1e2e;
}

[data-theme="dark"] .pdf-btn-export:hover {
    background: #a5b4fc;
    border-color: #a5b4fc;
    color: #1e1e2e;
}

.pdf-viewer {
    flex: 1;
    background: var(--bg-secondary);
    display: block;
    position: relative;
    overflow: auto;
}

.pdf-viewer iframe, .pdf-viewer embed, .pdf-viewer object {
    width: 100%;
    height: 100%;
    border: none;
}

/* Canvas-based PDF viewer (pdf.js) */
.pdf-pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    min-height: 100%;
}

.pdf-page-wrapper {
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    background: white;
}

.pdf-page-canvas {
    display: block;
}

.pdf-page-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.pdf-placeholder { text-align: center; color: var(--text-tertiary); }
.pdf-placeholder-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-lg);
    opacity: 0.4;
}

.pdf-placeholder-icon svg {
    width: 56px;
    height: 56px;
}
.pdf-placeholder h3 { margin-bottom: var(--space-sm); color: var(--text-secondary); font-size: 15px; }


/* Panel Splitter */
.panel-splitter {
    flex: 0 0 6px;
    margin: 0 7px;
    border-radius: var(--radius-sm);
    background: var(--border-primary);
    cursor: col-resize;
    position: relative;
    transition: background var(--transition-fast);
}

.panel-splitter::before {
    content: '';
    position: absolute;
    top: 25%;
    bottom: 25%;
    left: 1px;
    right: 1px;
    border-radius: var(--radius-sm);
    background: var(--brand-primary);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.panel-splitter:hover::before,
body.resizing .panel-splitter::before {
    opacity: 0.6;
}

/* Data Panel */
.data-panel {
    flex: 1 1 0;
    min-width: 280px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all var(--transition-normal);
}

.data-header {
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-md);
    min-height: 72px;
    box-sizing: border-box;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.data-title-block {
    margin-left: 5px;
}

.data-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.data-subtitle { color: var(--text-secondary); font-size: 12px; margin-top: 4px; }

/* Header icon (SVG) */
.header-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.data-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.btn-sm {
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    border: 1px solid transparent;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Button icon (SVG) */
.btn-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn-success {
    background: var(--color-success-bg);
    border: 1px solid var(--color-success-border);
    color: var(--color-success);
}
.btn-success:hover { background: rgba(34, 197, 94, 0.85); color: white; }

.btn-danger {
    background: var(--color-danger-bg);
    border: 1px solid var(--color-danger-border);
    color: var(--color-danger);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.85); color: white; }

.btn-sm.btn-primary {
    background: var(--brand-primary-light);
    border: 1px solid var(--brand-primary-border);
    color: var(--brand-primary);
}
.btn-sm.btn-primary:hover {
    background: var(--brand-primary-85);
    color: white;
}

/* Button extra small */
.btn-xs {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-secondary);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 150ms ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-xs:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-primary);
}
.btn-xs.btn-danger {
    background: var(--color-danger-bg);
    border-color: var(--color-danger-border);
    color: var(--color-danger);
}
.btn-xs.btn-danger:hover {
    background: rgba(239, 68, 68, 0.85);
    color: white;
}

/* Email config status badges */
.email-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-full, 9999px);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.email-status-active {
    background: var(--color-success-bg);
    color: var(--color-success);
    border: 1px solid var(--color-success-border);
}
.email-status-inactive {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-secondary);
}
.email-status-error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border: 1px solid var(--color-danger-border);
}
.email-status-connecting {
    background: var(--color-warning-bg);
    color: var(--color-warning);
    border: 1px solid var(--color-warning-border);
}

/* Email tab buttons */
.email-tab-btn.active {
    color: var(--brand-primary) !important;
    border-bottom-color: var(--brand-primary) !important;
}

/* Autosave status indicator */
.autosave-status {
    display: block;
    font-size: 10px;
    font-weight: 500;
    white-space: nowrap;
    transition: opacity var(--transition-normal), color var(--transition-normal);
    opacity: 0;
    margin-top: 2px;
    height: 14px;
}

.autosave-status.saving {
    color: var(--text-tertiary);
    opacity: 1;
}

.autosave-status.saved {
    color: var(--color-success);
    opacity: 1;
}

.autosave-status.error {
    color: var(--color-danger);
    opacity: 1;
}

.btn-sm.btn-secondary {
    background: var(--bg-elevated);
    border: 1px solid var(--border-secondary);
    color: var(--text-primary);
}
.btn-sm.btn-secondary:hover { background: var(--bg-elevated-hover); }

/* ===== PORTAL NAV BUTTON ===== */
.portal-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(99,102,241,0.3);
    background: transparent;
    color: var(--brand-primary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition-normal);
    white-space: nowrap;
}
.portal-nav-btn:hover { background: var(--brand-primary); color: white; }

.nav-arrow-icon {
    width: 14px;
    height: 14px;
}

/* ===== DRAG AND DROP ===== */
#detailPanel.dragging-over-pdf,
#detailPanel.dragging-over-data { background: var(--brand-primary-light); }

.pdf-panel.drag-over-pdf {
    border: 2px dashed var(--brand-primary);
    box-shadow: var(--shadow-glow);
}

.data-panel.drag-over-data {
    border: 2px dashed var(--color-success);
    box-shadow: 0 0 20px var(--color-success-bg);
}

.drag-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    padding: 15px;
    background: var(--bg-overlay);
    backdrop-filter: blur(12px);
    border-radius: var(--radius-md);
    text-align: center;
    pointer-events: none;
    z-index: 1000;
    border: 1px solid var(--border-secondary);
}

.drag-indicator-icon { font-size: 32px; margin-bottom: 10px; }
.drag-indicator-text { color: var(--text-primary); font-size: 14px; font-weight: 600; }

#detailPanel .drop-zone-pdf,
#detailPanel .drop-zone-data {
    height: 100%;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-zone-hint { color: var(--text-secondary); font-size: 12px; text-align: center; margin-top: 10px; }

.data-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-xl);
    user-select: text;
    -webkit-user-select: text;
}

/* ===== FORM STYLES ===== */
.form-section { margin-bottom: var(--space-xl); }

.form-section-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

/* Section Icons (SVG) - same style as tab icons */
.section-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    vertical-align: middle;
}

.form-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    border: 1px solid var(--border-primary);
    transition: all var(--transition-normal);
}

.form-card:hover { border-color: var(--border-hover); }

.form-row {
    display: grid;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}
.form-row:last-child { margin-bottom: 0; }
.form-row-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.form-group-sm { min-width: 0; }

.form-group-sm label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: var(--space-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-control-sm {
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-primary);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 15px;
    transition: all var(--transition-normal);
    min-width: 0;
}

.form-control-sm::placeholder { color: var(--text-muted); }
.form-control-sm.mono { font-family: 'JetBrains Mono', monospace; }

.form-control-sm.highlight {
    border-color: var(--color-warning);
    background: var(--color-warning-bg);
}

textarea.form-control-sm {
    resize: vertical;
    min-height: 60px;
    font-size: 13px;
    line-height: 1.5;
}

textarea.form-control-sm.textarea-error {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
    background: rgba(239, 68, 68, 0.05);
}

/* ===== ITEMS TABLE ===== */
.items-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.btn-add {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-success-border);
    background: var(--color-success-bg);
    color: var(--color-success);
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: all var(--transition-normal);
}
.btn-add:hover { background: var(--color-success); color: white; }

.items-table { width: 100%; font-size: 13px; }

.items-table-header {
    display: grid;
    grid-template-columns: 2fr 60px 50px 80px 50px 80px 28px;
    gap: 6px;
    padding: 8px 10px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.item-row {
    display: grid;
    grid-template-columns: 2fr 60px 50px 80px 50px 80px 28px;
    gap: 6px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    align-items: center;
    transition: background var(--transition-fast);
}

.item-row:hover { background: var(--brand-primary-light); }

.item-input {
    width: 100%;
    padding: 6px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-primary);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
    transition: all var(--transition-fast);
}

.item-input:focus {
    border-color: var(--brand-primary) !important;
    box-shadow: 0 0 0 2px var(--brand-primary-light);
}

.item-input.right { text-align: right; }

.item-total {
    text-align: right;
    font-weight: 600;
    color: var(--brand-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
}

.btn-remove {
    padding: 4px;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: var(--color-danger);
    cursor: pointer;
    font-size: 12px;
    transition: all var(--transition-fast);
}

.btn-remove:hover { background: var(--color-danger-bg); }

/* ===== ITEMS OVERLAY ===== */
.items-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.2s ease-out;
}

.items-overlay.visible {
    opacity: 1;
}

/* ===== ITEMS EXPANDED STATE ===== */
.items-expanded {
    position: fixed !important;
    z-index: 100;
    background: var(--bg-card);
    border: 2px solid var(--brand-primary);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px var(--brand-primary-glow);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    padding-top: 50px;
    overflow-y: auto;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

.items-expanded.visible {
    opacity: 1;
    transform: scale(1);
}

.items-close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-elevated);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    z-index: 10;
}

.items-close-btn:hover {
    background: var(--color-danger-bg);
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.items-expanded .items-table-header,
.items-expanded .items-table-header-6 {
    grid-template-columns: 3fr 90px 80px 120px 80px 130px 36px;
    gap: 14px;
    font-size: 11px;
    padding: 12px 20px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    border: 1px solid var(--border-primary);
}

.items-expanded .item-row,
.items-expanded .item-row-6 {
    grid-template-columns: 3fr 90px 80px 120px 80px 130px 36px;
    gap: 14px;
    padding: 12px 20px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border: 1px solid var(--border-primary);
}

.items-expanded .item-row:hover,
.items-expanded .item-row-6:hover {
    border-color: var(--border-secondary);
    background: var(--bg-elevated-hover);
}

.items-expanded .item-input {
    font-size: 14px;
    padding: 10px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border-secondary);
}

.items-expanded .item-input:focus {
    background: var(--bg-surface);
    border-color: var(--brand-primary);
}

.items-expanded .item-total {
    font-size: 15px;
    font-weight: 600;
}

.items-expanded .btn-add {
    font-size: 13px;
    padding: 10px 20px;
}

.items-expanded .btn-remove {
    width: 32px;
    height: 32px;
    font-size: 14px;
}

.items-expanded .items-header {
    margin-bottom: var(--space-lg);
}

.items-expanded .items-header span {
    font-size: 14px !important;
    font-weight: 600;
    color: var(--text-primary) !important;
}

/* Expand button in header */
.items-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.btn-expand-items {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-secondary);
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-expand-items:hover {
    border-color: var(--brand-primary);
    color: var(--brand-primary);
    background: var(--brand-primary-light);
}

.items-expanded .btn-expand-items {
    display: none;
}

.totals-box {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-primary);
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    color: var(--text-secondary);
    font-size: 15px;
}

.total-row.final {
    padding: 8px 0 4px;
    border-top: 2px solid var(--border-secondary);
    margin-top: 4px;
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
}

.total-row .value { font-family: 'JetBrains Mono', monospace; }
.total-row.final .value { color: var(--brand-primary); }

/* ===== 6-COLUMN ITEMS LAYOUT ===== */
.items-table-header-6 {
    display: grid;
    grid-template-columns: 2fr 60px 50px 80px 55px 90px 28px;
    gap: 6px;
    padding: 8px 10px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-size: 9px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.item-row-6 {
    display: grid;
    grid-template-columns: 2fr 60px 50px 80px 55px 90px 28px;
    gap: 6px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    align-items: center;
    transition: background var(--transition-fast);
}
.item-row-6:hover { background: var(--brand-primary-light); }

/* ===== SECTION CONFIG DROPDOWN ===== */
.section-config-wrapper {
    position: relative;
}
.section-config-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 100;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    min-width: 200px;
    max-height: 400px;
    overflow-y: auto;
}
.btn-ghost {
    background: transparent;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 14px;
    transition: all var(--transition-fast);
}
.btn-ghost:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

/* ===== TAX BREAKDOWN TABLE ===== */
.totals-section {
    padding: var(--space-md);
}

/* Tax breakdown header with label + add button */
.tax-breakdown-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.tax-breakdown-label {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Tax breakdown grid header */
.tax-breakdown-grid-header {
    display: grid;
    grid-template-columns: 70px 1fr 1fr 28px;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.tax-breakdown-grid-header .r { text-align: right; }

/* Tax breakdown editable rows */
.tax-row {
    display: grid;
    grid-template-columns: 70px 1fr 1fr 28px;
    gap: 6px;
    padding: 4px 0;
    align-items: center;
}
.tax-row-foreign {
    grid-template-columns: 70px 1fr 1fr 1fr 1fr 28px;
}
.tax-row .item-input {
    font-size: 15px;
    padding: 6px 10px;
}
.tax-rate-select {
    font-size: 15px !important;
}
.tax-empty-hint {
    padding: 8px 10px;
    font-size: 15px;
    color: var(--text-muted);
    font-style: italic;
}

/* Totals summary with editable inputs */
.totals-summary {
    padding-top: var(--space-sm);
    margin-top: var(--space-sm);
    border-top: 1px solid var(--border-primary);
}
.totals-input {
    width: 140px;
    padding: 6px 10px;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 15px;
    text-align: right;
    transition: all var(--transition-normal);
}
.totals-input:focus {
    border-color: var(--brand-primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}
.totals-input-final {
    font-size: 15px;
    font-weight: 700;
    padding: 6px 10px;
    width: 160px;
}
.totals-input.validation-error {
    border-color: var(--color-danger, #ef4444);
    background: var(--color-danger-bg, rgba(239,68,68,0.06));
    box-shadow: 0 0 0 2px rgba(239,68,68,0.15);
}

/* Validation messages */
#totalsValidation {
    margin-top: var(--space-sm);
}
.totals-check-ok {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--color-success, #22c55e);
    background: var(--color-success-bg, rgba(34,197,94,0.08));
    border: 1px solid var(--color-success-border, rgba(34,197,94,0.2));
}
.totals-check-error {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--color-danger, #ef4444);
    background: var(--color-danger-bg, rgba(239,68,68,0.06));
    border: 1px solid var(--color-danger-border, rgba(239,68,68,0.2));
    margin-bottom: 4px;
}
.totals-check-warning {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--color-warning, #f59e0b);
    background: var(--color-warning-bg, rgba(245,158,11,0.08));
    border: 1px solid var(--color-warning-border, rgba(245,158,11,0.2));
    margin-bottom: 4px;
}

.foreign-amount {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-left: 4px;
}

/* ===== CHECKBOX INLINE ===== */
.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 6px 0;
}
.checkbox-inline input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--brand-primary);
}

/* ===== TOGGLE SWITCH ===== */
.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 32px;
    height: 18px;
    cursor: pointer;
    user-select: none;
}

.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-input);
    border: 1px solid var(--border-secondary);
    border-radius: 9px;
    transition: all var(--transition-normal);
    pointer-events: none;
}

.toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: var(--text-tertiary);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: all var(--transition-normal);
    pointer-events: none;
}

.toggle-switch.checked .toggle-track {
    background: var(--brand-primary-light);
    border-color: var(--brand-primary-border);
}

.toggle-switch.checked .toggle-thumb {
    transform: translateX(14px);
    background: var(--brand-primary);
}

.toggle-switch:hover .toggle-track {
    border-color: var(--border-hover);
}

.toggle-switch.checked:hover .toggle-track {
    background: var(--brand-primary-light);
    border-color: var(--brand-primary);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--border-secondary);
    transition: all var(--transition-slow);
}

.empty-state-content { text-align: center; }
.empty-state-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-lg);
    opacity: 0.4;
}

.empty-state-icon svg {
    width: 48px;
    height: 48px;
}
.empty-state h3 { margin-bottom: var(--space-sm); color: var(--text-secondary); font-size: 16px; }
.empty-state p { color: var(--text-tertiary); font-size: 14px; }

/* ===== CONFIDENCE INDICATOR ===== */
.confidence-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 10px var(--space-lg);
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-lg);
    border: 1px solid var(--border-primary);
}

.confidence-bar {
    flex: 1;
    height: 6px;
    background: var(--border-secondary);
    border-radius: 3px;
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
    background: var(--brand-gradient);
}

.confidence-text {
    font-size: 12px;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: var(--brand-primary);
}

/* ===== NOTIFICATION ===== */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: var(--space-md) var(--space-xl);
    border-radius: var(--radius-md);
    color: white;
    font-weight: 500;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideIn 0.3s ease;
    display: none;
    backdrop-filter: blur(8px);
}

.notification.success { background: rgba(34, 197, 94, 0.9); }
.notification.info { background: rgba(99, 102, 241, 0.9); }
.notification.error { background: rgba(239, 68, 68, 0.9); }

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

/* ===== ADMIN USER MANAGEMENT MODAL ===== */
.admin-panel {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.admin-panel-content {
    width: min(1100px, 92vw);
    max-height: 85vh;
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-secondary);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: scaleIn 0.25s ease;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.admin-panel-header {
    padding: var(--space-xl);
    background: var(--brand-gradient-subtle);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.admin-panel-header h3 { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.admin-panel-header p { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }

.admin-panel-body {
    padding: var(--space-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    overflow: auto;
}

.admin-toolbar {
    display: flex;
    gap: var(--space-md);
    align-items: center;
}

.admin-toolbar input { flex: 1; }

.admin-form {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-primary);
    padding: var(--space-lg);
}

.admin-form-actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
    margin-top: var(--space-md);
}

.admin-table-wrapper {
    border-radius: var(--radius-md);
    border: 1px solid var(--border-primary);
    overflow: auto;
    background: var(--bg-card);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.admin-table th,
.admin-table td {
    text-align: left;
    padding: var(--space-md) 10px;
    border-bottom: 1px solid var(--border-primary);
    color: var(--text-primary);
}

.admin-table th {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    background: var(--bg-input);
    position: sticky;
    top: 0;
    z-index: 1;
    font-weight: 700;
}

.admin-table tr:hover { background: var(--brand-primary-light); }

.admin-table .role-select { min-width: 120px; }

.admin-action-btn {
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-secondary);
    background: transparent;
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.admin-action-btn.danger {
    border-color: var(--color-danger-border);
    color: var(--color-danger);
}

.admin-action-btn:hover { background: var(--bg-elevated-hover); }
.admin-action-btn.danger:hover { background: var(--color-danger); color: white; }

.hidden { display: none !important; }

/* ===== USER DROPDOWN MENU ===== */
.user-menu-wrapper {
    position: relative;
}

.user-menu-arrow {
    width: 14px;
    height: 14px;
    color: var(--text-tertiary);
    margin-left: 2px;
    transition: transform var(--transition-normal);
}

.user-menu:hover .user-menu-arrow {
    color: var(--text-secondary);
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    min-width: 180px;
    background: var(--bg-surface);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1100;
    overflow: hidden;
    animation: dropdownFadeIn 0.15s ease;
}

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

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.dropdown-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.user-dropdown-item:hover {
    background: var(--bg-elevated-hover);
}

.user-dropdown-item:not(:last-child) {
    border-bottom: 1px solid var(--border-primary);
}

.user-dropdown-item-danger {
    color: var(--color-danger);
}

.user-dropdown-item-danger:hover {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.user-dropdown-item-danger .dropdown-icon {
    color: var(--color-danger);
}

/* ===== MODAL OVERLAY ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1300;
    animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-box {
    width: min(480px, 90vw);
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-secondary);
    box-shadow: var(--shadow-xl);
    animation: modalScaleIn 0.25s ease;
}

@keyframes modalScaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: var(--space-xl);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    line-height: 1;
}

.modal-close:hover {
    background: var(--bg-elevated-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-xl);
}

.modal-body .form-group {
    margin-bottom: var(--space-lg);
}

.modal-footer {
    padding: var(--space-lg) var(--space-xl);
    border-top: 1px solid var(--border-primary);
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
}

.btn-secondary {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-secondary);
    background: var(--bg-elevated);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition-normal);
}

.btn-secondary:hover {
    background: var(--bg-elevated-hover);
}

/* ===== FORGOT PASSWORD ===== */
.forgot-back-link {
    background: none;
    border: none;
    color: var(--brand-primary);
    cursor: pointer;
    font-size: 13px;
    padding: 0;
    transition: color var(--transition-fast);
}

.forgot-back-link:hover {
    color: var(--brand-primary-hover);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    .split-view { flex-direction: column; }
    .panel-splitter { display: none; }
    .pdf-panel, .data-panel { max-width: 100%; min-width: 0; }
    .main-container { padding: var(--space-sm); gap: var(--space-sm); }
    .header { padding: var(--space-sm) var(--space-lg); }
    .data-header { flex-wrap: wrap; }
    .data-actions { gap: 4px; flex-wrap: wrap; }
    .btn-sm { padding: 6px 8px; font-size: 11px; }
}

/* ===== UPLOAD ZONE ===== */

.upload-row {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: var(--space-md);
    width: 100%;
    margin: 0;
    height: 56px;
}

.btn-upload {
    display: none;
}

.upload-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm) var(--space-md);
    border: 2px dashed var(--border-secondary);
    border-radius: var(--radius-md);
    background: transparent;
    cursor: pointer;
    transition: var(--transition-normal);
}

.upload-zone:hover,
.upload-zone-active {
    border-color: var(--brand-primary);
    background: rgba(99, 102, 241, 0.08);
    box-shadow: var(--shadow-glow);
}

.upload-zone-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    text-align: left;
}

.upload-zone-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    flex-shrink: 0;
}

.upload-zone-icon svg {
    width: 18px;
    height: 18px;
    color: var(--text-tertiary);
}

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

.upload-zone:hover .upload-zone-icon svg,
.upload-zone-active .upload-zone-icon svg {
    color: var(--brand-primary);
}

.upload-zone-text {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--space-sm);
}

.upload-zone-text strong {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.upload-zone-text span {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* Upload Progress */

.upload-progress {
    margin-top: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.upload-progress-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    font-size: 12px;
    transition: opacity 0.3s ease;
}

.upload-status-uploading {
    border-color: var(--color-info);
    background: var(--color-info-bg);
}

.upload-status-processing {
    border-color: var(--color-warning);
    background: var(--color-warning-bg);
    animation: pulse-processing 2s ease-in-out infinite;
}

.upload-status-complete {
    border-color: var(--color-success);
    background: var(--color-success-bg);
}

.upload-status-error {
    border-color: var(--color-danger);
    background: var(--color-danger-bg);
}

@keyframes pulse-processing {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.upload-progress-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.upload-status-icon {
    width: 16px;
    height: 16px;
}

.upload-status-icon.spinning {
    animation: spin 1s linear infinite;
}

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

.upload-status-complete .upload-status-icon {
    color: var(--color-success);
}

.upload-status-error .upload-status-icon {
    color: var(--color-danger);
}

.upload-status-processing .upload-status-icon {
    color: var(--brand-primary);
}

.upload-progress-name {
    flex: 1;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-progress-message {
    color: var(--text-secondary);
    font-size: 11px;
    flex-shrink: 0;
}

.upload-progress-dismiss {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
}

.upload-progress-dismiss:hover {
    color: var(--text-primary);
}

/* ===== PDF BOUNDING BOX HIGHLIGHTS ===== */

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

.pdf-highlight-box {
    position: absolute;
    border: 2px solid transparent;
    border-radius: 3px;
    cursor: pointer;
    pointer-events: all;
    transition: var(--transition-fast);
    opacity: 0.4;
}

.pdf-highlight-box:hover {
    opacity: 0.8;
    z-index: 11;
}

.pdf-highlight-box.active {
    opacity: 1;
    z-index: 12;
    border-color: #ef4444 !important;
    background: rgba(239, 68, 68, 0.18) !important;
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.5) !important;
    animation: highlight-pulse-red 1.5s ease-in-out infinite;
}

/* Confidence-based colors */
.highlight-high {
    border-color: var(--color-success);
    background: rgba(34, 197, 94, 0.08);
}
.highlight-high:hover {
    background: rgba(34, 197, 94, 0.15);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.3);
}

.highlight-medium {
    border-color: var(--color-warning);
    background: rgba(245, 158, 11, 0.08);
}
.highlight-medium:hover {
    background: rgba(245, 158, 11, 0.15);
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.3);
}

.highlight-low {
    border-color: var(--color-danger);
    background: rgba(239, 68, 68, 0.08);
}
.highlight-low:hover {
    background: rgba(239, 68, 68, 0.15);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.3);
}

@keyframes highlight-pulse-red {
    0%, 100% { opacity: 1; box-shadow: 0 0 12px rgba(239, 68, 68, 0.5); }
    50% { opacity: 0.7; box-shadow: 0 0 6px rgba(239, 68, 68, 0.3); }
}

/* Learned field mapping highlight - distinct purple/violet color with dashed border */
.highlight-learned {
    border-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.12);
    border-style: dashed;
    border-width: 2px;
}
.highlight-learned:hover {
    background: rgba(139, 92, 246, 0.25);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.4);
    opacity: 0.9;
}
.highlight-learned.active {
    border-color: #8b5cf6 !important;
    background: rgba(139, 92, 246, 0.3) !important;
    box-shadow: 0 0 14px rgba(139, 92, 246, 0.6) !important;
    animation: highlight-pulse-purple 1.5s ease-in-out infinite;
}

@keyframes highlight-pulse-purple {
    0%, 100% { opacity: 1; box-shadow: 0 0 14px rgba(139, 92, 246, 0.6); }
    50% { opacity: 0.8; box-shadow: 0 0 8px rgba(139, 92, 246, 0.3); }
}

/* Form field highlighting (when clicking PDF box) */
.form-field-highlighted {
    outline: 2px solid var(--brand-primary) !important;
    outline-offset: 2px;
    box-shadow: var(--shadow-glow) !important;
    animation: field-glow 2s ease-in-out;
}

@keyframes field-glow {
    0% { box-shadow: 0 0 0 0 var(--brand-primary-glow); }
    50% { box-shadow: 0 0 15px 3px var(--brand-primary-glow); }
    100% { box-shadow: var(--shadow-glow); }
}

/* Per-field confidence badges */
.field-confidence-badge {
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: var(--radius-full);
    line-height: 1.4;
    pointer-events: none;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    z-index: 1;
}

/* Badge positioned inside/above input when PDF select button is present */
.field-confidence-badge.badge-inline {
    position: absolute;
    top: -10px;
    right: 23px;
    z-index: 2;
}

/* Totals badges: inline before the input */
.field-confidence-badge.badge-before {
    position: static;
    display: inline-block;
    vertical-align: middle;
    margin-right: 4px;
}

.confidence-badge-high {
    background: var(--color-success-bg);
    color: var(--color-success);
    border: 1px solid var(--color-success-border);
}

.confidence-badge-medium {
    background: var(--color-warning-bg);
    color: var(--color-warning);
    border: 1px solid var(--color-warning-border);
}

.confidence-badge-low {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border: 1px solid var(--color-danger-border);
}

/* ARES verification badge */
.ares-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--color-success-bg);
    color: var(--color-success);
    border: 1px solid var(--color-success-border);
    text-transform: none;
    letter-spacing: 0;
    line-height: 1.4;
    vertical-align: middle;
    margin-left: 4px;
}

/* Warning badge (orange - bank account not verified) */
.warning-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--color-warning-bg);
    color: var(--color-warning);
    border: 1px solid var(--color-warning-border);
    text-transform: none;
    letter-spacing: 0;
    line-height: 1.4;
    vertical-align: middle;
    margin-left: 4px;
}

/* Danger badge (red - unreliable payer) */
.danger-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border: 1px solid var(--color-danger-border);
    text-transform: none;
    letter-spacing: 0;
    line-height: 1.4;
    vertical-align: middle;
    margin-left: 4px;
}

/* Inline field verification badges (bank account / IBAN) */
.field-verify-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-left: 4px;
    vertical-align: middle;
    line-height: 1;
}
.field-verify-ok {
    background: var(--color-success-bg);
    color: var(--color-success);
    border: 1px solid var(--color-success-border);
}
.field-verify-warn {
    background: var(--color-warning-bg);
    color: var(--color-warning);
    border: 1px solid var(--color-warning-border);
}

/* Processing status badge in invoice table */
.status-processing {
    color: var(--color-warning) !important;
    animation: pulse-processing 2s ease-in-out infinite;
}

.status-uploaded {
    color: var(--color-info) !important;
}

.status-extraction_failed {
    color: var(--color-danger) !important;
}

/* Extraction indicator in invoice table row */
.extraction-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-primary);
    background: var(--color-primary-light, rgba(37, 99, 235, 0.1));
    border-radius: 4px;
    animation: pulse-processing 2s ease-in-out infinite;
}

.extraction-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.row-processing {
    background: var(--color-primary-light, rgba(37, 99, 235, 0.05)) !important;
}

.row-processing:hover {
    background: var(--color-primary-light, rgba(37, 99, 235, 0.1)) !important;
}

/* PDF iframe for overlay support */
.pdf-iframe {
    border: none;
    width: 100%;
    height: 100%;
}

/* ===== PDF FIELD SELECTOR ===== */
/* Selection mode cursor and overlay */
#pdfViewer.selection-mode {
    cursor: crosshair !important;
}

#pdfViewer.selection-mode * {
    cursor: crosshair !important;
}

.pdf-selection-overlay {
    position: absolute;
    border: 3px solid var(--brand-primary);
    background: rgba(99, 102, 241, 0.25);
    pointer-events: none;
    z-index: 9999;
    border-radius: 2px;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8), 0 0 10px rgba(99, 102, 241, 0.5);
}

/* Live preview of selected text during drag - floating tooltip positioned by JS */
.pdf-selection-preview {
    position: fixed;
    background: #fef08a;
    color: #1f2937;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 19px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.1);
    border: 2px solid #eab308;
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 10001;
    pointer-events: none;
}

.pdf-selection-preview.has-text {
    background: #fef08a;
    border-color: #eab308;
    color: #1f2937;
}

.pdf-selection-preview.no-text {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #92400e;
    font-style: italic;
}

/* Target field highlight during selection */
.selection-target {
    outline: 2px solid var(--brand-primary) !important;
    outline-offset: 2px;
    animation: selection-target-pulse 1s ease-in-out infinite;
}

@keyframes selection-target-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
    50% { box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2); }
}

/* Selection instruction toast */
.pdf-selection-instruction {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    animation: slide-down 0.3s ease-out;
}

@keyframes slide-down {
    from { transform: translateX(-50%) translateY(-20px); opacity: 0; }
    to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

.pdf-selection-instruction .instruction-content {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--brand-primary-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg), 0 0 20px rgba(99, 102, 241, 0.2);
}

.pdf-selection-instruction .instruction-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--brand-primary-light);
    border-radius: var(--radius-sm);
    color: var(--brand-primary);
}

.pdf-selection-instruction .instruction-icon svg {
    width: 18px;
    height: 18px;
}

.pdf-selection-instruction .instruction-text {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.pdf-selection-instruction .instruction-cancel {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-surface);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
}

.pdf-selection-instruction .instruction-cancel:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

/* PDF Select button for form fields */
.btn-pdf-select {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    margin-left: 6px;
    background: var(--bg-surface);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.btn-pdf-select:hover {
    background: var(--brand-primary-light);
    border-color: var(--brand-primary-border);
    color: var(--brand-primary);
}

.btn-pdf-select:active {
    transform: scale(0.95);
}

.btn-pdf-select svg {
    width: 11px;
    height: 11px;
}

/* Button when field has learned mapping - shows X to delete */
.btn-pdf-select.has-mapping {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

.btn-pdf-select.has-mapping:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
    color: #dc2626;
}

/* Smaller variant for totals section */
.btn-pdf-select-sm {
    width: 18px;
    height: 18px;
    margin-left: 4px;
}

.btn-pdf-select-sm svg {
    width: 9px;
    height: 9px;
}

/* Totals row with PDF select button */
.total-row .value {
    display: flex;
    align-items: center;
}

/* Form field with PDF select button */
.field-with-pdf-select {
    display: flex;
    align-items: center;
}

.field-with-pdf-select input,
.field-with-pdf-select select {
    flex: 1;
    min-width: 0;
}

/* ===== EXPORT DROPDOWN ===== */
.export-dropdown-wrapper {
    position: relative;
    display: inline-block;
}

.export-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    z-index: 9999;
    min-width: 220px;
    overflow: hidden;
}

.export-dropdown.hidden {
    display: none;
}

.export-dropdown-item {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: var(--bg-primary, #ffffff);
    cursor: pointer;
    text-align: left;
    gap: 2px;
    transition: background 0.15s;
}

.export-dropdown-item:hover {
    background: var(--bg-hover, #f1f5f9);
}

.export-dropdown-item:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.export-dropdown-item strong {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.export-dropdown-item span {
    font-size: 11px;
    color: var(--text-secondary);
}

[data-theme="dark"] .export-dropdown {
    background: var(--bg-primary, #1e1e2e);
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

[data-theme="dark"] .export-dropdown-item:hover {
    background: var(--bg-hover, #1e293b);
}

/* ===== Learned Default Indicators ===== */

.learned-default select,
.learned-default input {
    border-color: var(--color-info, #3b82f6) !important;
    background: rgba(59, 130, 246, 0.04);
}

.learned-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin-left: 4px;
    vertical-align: middle;
    background: var(--color-info-bg, #eff6ff);
    color: var(--color-info, #3b82f6);
    border: 1px solid rgba(59, 130, 246, 0.3);
    cursor: help;
    line-height: 1;
}

/* Learned Default Dialog Overlay */
.learned-dialog-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.15s ease-out;
}

.learned-dialog {
    background: var(--bg-primary, #fff);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
    width: 420px;
    max-width: 90vw;
    overflow: hidden;
    animation: slideUp 0.2s ease-out;
}

.learned-dialog-header {
    padding: 16px 20px;
    font-weight: 600;
    font-size: 15px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    color: var(--text-primary);
}

.learned-dialog-body {
    padding: 16px 20px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.learned-dialog-body p {
    margin: 0 0 8px;
}

.learned-dialog-body p:last-child {
    margin-bottom: 0;
}

.learned-dialog-actions {
    display: flex;
    gap: 8px;
    padding: 12px 20px 16px;
    justify-content: flex-end;
}

.btn-learned-once {
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid var(--border-color, #e2e8f0);
    background: var(--bg-primary, #fff);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-learned-once:hover {
    background: var(--bg-hover, #f8fafc);
    border-color: var(--text-tertiary);
}

.btn-learned-permanent {
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: var(--color-primary, #3b82f6);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-learned-permanent:hover {
    filter: brightness(0.9);
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Dark mode overrides for learned defaults */
[data-theme="dark"] .learned-default select,
[data-theme="dark"] .learned-default input {
    background: rgba(59, 130, 246, 0.08);
}

[data-theme="dark"] .learned-badge {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.4);
}

[data-theme="dark"] .learned-dialog {
    box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}

[data-theme="dark"] .btn-learned-once {
    background: var(--bg-secondary, #1e293b);
}
