:root[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.18);
    --glass-shadow: rgba(0, 0, 0, 0.1);
    
    --text-primary: #1a1a1a;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    
    --accent-primary: #10b981;
    --accent-secondary: #059669;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --accent-info: #3b82f6;
    
    --border-color: #dee2e6;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.15);
}

:root[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: rgba(0, 0, 0, 0.5);
    
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    
    --accent-primary: #34d399;
    --accent-secondary: #10b981;
    --accent-success: #34d399;
    --accent-warning: #fbbf24;
    --accent-danger: #f87171;
    --accent-info: #60a5fa;
    
    --border-color: #334155;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.6);
}

* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', 'SF Pro Display', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
}

.glass-navbar {
    background: linear-gradient(90deg, #ffffff 0%, #ffffff 20%, #047857 20%, #065f46 50%, #064e3b 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
}

[dir="rtl"] .glass-navbar {
    background: linear-gradient(270deg, #ffffff 0%, #ffffff 20%, #047857 20%, #065f46 50%, #064e3b 100%);
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.5rem;
    color: white !important;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link {
    color: rgba(255, 255, 255, 0.9) !important;
    font-weight: 500;
    padding: 0.5rem 1rem !important;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white !important;
}

.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.2rem;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.lang-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    font-weight: 600;
    min-width: 50px;
}

.lang-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

html[dir="rtl"] {
    direction: rtl;
}

html[dir="rtl"] body {
    text-align: right;
}

html[dir="rtl"] .navbar-nav {
    margin-right: 0 !important;
    margin-left: auto !important;
}

.card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
}

.card-header {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
    border-bottom: 1px solid var(--border-color);
    padding: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.agent-status-rail {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.agent-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    font-weight: 500;
    font-size: 0.9rem;
}

.agent-indicator.active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border-color: transparent;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-dot.success { background: var(--accent-success); }
.status-dot.processing { background: var(--accent-info); }
.status-dot.pending { background: var(--text-muted); }
.status-dot.error { background: var(--accent-danger); }

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.1); }
}

.neural-pulse {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.neural-pulse span {
    width: 6px;
    height: 6px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: wave 1.5s infinite;
}

.neural-pulse span:nth-child(2) { animation-delay: 0.2s; }
.neural-pulse span:nth-child(3) { animation-delay: 0.4s; }

@keyframes wave {
    0%, 100% { transform: translateY(0); opacity: 1; }
    50% { transform: translateY(-8px); opacity: 0.5; }
}

.agent-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.agent-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateX(4px);
}

.agent-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.agent-card-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.agent-card-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.badge-processing {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
}

.badge-pending {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.agent-card-body {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.metric-item {
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.metric-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.metric-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.progress-bar-modern {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 4px;
    transition: width 0.5s ease;
    position: relative;
    overflow: hidden;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.btn-glass {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 0.5rem 1.25rem;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-glass:hover {
    background: var(--bg-tertiary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    color: var(--text-primary);
}

.btn-primary-gradient {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border: none;
    color: white;
    padding: 0.5rem 1.25rem;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-primary-gradient:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(16, 185, 129, 0.3);
    filter: brightness(1.1);
}

.status-badge {
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: capitalize;
}

.status-draft { background-color: var(--text-muted); color: white; }
.status-submitted { background-color: var(--accent-info); color: white; }
.status-under_review { background-color: var(--accent-warning); color: white; }
.status-approved { background-color: var(--accent-success); color: white; }
.status-rejected { background-color: var(--accent-danger); color: white; }

.stage-badge {
    padding: 0.3rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--bg-secondary);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.stage-badge.active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border-color: var(--accent-primary);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
    animation: pulseBadge 2s ease-in-out infinite;
}

.stage-badge i {
    font-size: 0.85rem;
}

@keyframes pulseBadge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.alert {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.container {
    max-width: 1400px;
}

.form-control {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.form-control:focus {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(16, 185, 129, 0.25);
}

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

.form-label {
    color: var(--text-primary);
    font-weight: 500;
}

.breadcrumb-item a {
    color: var(--accent-primary);
    text-decoration: none;
}

.breadcrumb-item.active {
    color: var(--text-secondary);
}

/* File name wrapping fixes */
.checklist-source {
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    max-width: 100%;
}

.file-item .file-name,
.file-item .file-info,
.file-item span {
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    max-width: 100%;
}

/* Ensure file metadata containers wrap properly */
.metric-value,
.metric-label {
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    max-width: 100%;
}

/* RTL support for file names */
[dir="rtl"] .checklist-source,
[dir="rtl"] .file-item span,
[dir="rtl"] .metric-value {
    text-align: right;
}

@media (max-width: 768px) {
    .agent-status-rail {
        flex-direction: column;
    }
    
    .metric-grid {
        grid-template-columns: 1fr;
    }
}

/* =============================================
   SIDEBAR LAYOUT SYSTEM
   ============================================= */

:root {
    --sb-w: 220px;
    --sb-cw: 64px;
    --sb-bg: #064e3b;
    --sb-transition: 0.25s ease;
    --topbar-h: 52px;
}

/* ---- Sidebar ---- */
.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    width: var(--sb-w);
    background: var(--sb-bg);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: width var(--sb-transition);
    overflow: hidden;
}

body.sb-collapsed .sidebar {
    width: var(--sb-cw);
}

/* ---- Content wrapper ---- */
.content-wrapper {
    flex: 1;
    min-width: 0;
    transition: margin-inline-start var(--sb-transition);
}

body.sb-authenticated .content-wrapper {
    margin-inline-start: var(--sb-w);
}

body.sb-authenticated.sb-collapsed .content-wrapper {
    margin-inline-start: var(--sb-cw);
}

/* ---- Sidebar header ---- */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.6rem 0 0.75rem;
    height: 68px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    gap: 0.4rem;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    overflow: hidden;
    flex: 1;
    min-width: 0;
}

.sidebar-brand img {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    object-fit: contain;
}

.sidebar-brand-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    max-width: 140px;
    transition: opacity var(--sb-transition), max-width var(--sb-transition);
}

body.sb-collapsed .sidebar-brand-name {
    opacity: 0;
    max-width: 0;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    padding: 0.35rem 0.45rem;
    border-radius: 6px;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
    font-size: 0.9rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle:hover {
    background: rgba(255,255,255,0.12);
    color: white;
}

/* ---- Nav area ---- */
.sidebar-nav {
    flex: 1;
    padding: 0.65rem 0.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar { display: none; }

.sidebar-section-label {
    font-size: 0.63rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: rgba(255,255,255,0.38);
    padding: 0.45rem 0.75rem 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    max-height: 2.5rem;
    transition: opacity var(--sb-transition), max-height var(--sb-transition), padding var(--sb-transition);
}

body.sb-collapsed .sidebar-section-label {
    opacity: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.sidebar-divider {
    height: 1px;
    background: rgba(255,255,255,0.1);
    margin: 0.4rem 0.75rem;
}

body.sb-collapsed .sidebar-divider {
    margin: 0.3rem 0.5rem;
}

/* Nav links */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.52rem 0.75rem;
    border-radius: 8px;
    text-decoration: none;
    color: rgba(255,255,255,0.72);
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
    margin-bottom: 2px;
    min-width: 0;
    position: relative;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

.sidebar-link.active {
    background: rgba(255,255,255,0.17);
    color: white;
    font-weight: 600;
}

.sidebar-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-label {
    overflow: hidden;
    white-space: nowrap;
    max-width: 160px;
    transition: opacity var(--sb-transition), max-width var(--sb-transition);
}

body.sb-collapsed .sidebar-label {
    opacity: 0;
    max-width: 0;
}

/* Tooltip on collapsed items (desktop only) */
@media (min-width: 992px) {
    body.sb-collapsed .sidebar-link:hover::after {
        content: attr(data-tooltip);
        position: absolute;
        inset-inline-start: calc(100% + 10px);
        top: 50%;
        transform: translateY(-50%);
        background: rgba(0,0,0,0.88);
        color: white;
        padding: 0.28rem 0.6rem;
        border-radius: 5px;
        font-size: 0.78rem;
        white-space: nowrap;
        pointer-events: none;
        z-index: 9999;
    }
}

/* ---- Sidebar footer ---- */
.sidebar-footer {
    padding: 0.5rem 0.5rem 0.65rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.45rem 0.75rem;
    color: rgba(255,255,255,0.65);
    font-size: 0.84rem;
    overflow: hidden;
}

.sidebar-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
    padding: 0.3rem 0.25rem 0;
}

.sb-icon-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: rgba(255,255,255,0.75);
    border-radius: 7px;
    padding: 0.38rem 0.5rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.sb-icon-btn:hover {
    background: rgba(255,255,255,0.2);
    color: white;
}

/* ---- Mobile top bar ---- */
.mobile-topbar {
    position: fixed;
    top: 0;
    inset-inline-start: 0;
    inset-inline-end: 0;
    height: var(--topbar-h);
    background: var(--sb-bg);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0 1rem;
    z-index: 1041;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.mobile-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: white;
    font-weight: 700;
    font-size: 1rem;
}

.mobile-ham {
    background: none;
    border: none;
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.2rem 0.35rem;
    line-height: 1;
    border-radius: 6px;
    transition: background 0.15s;
}

.mobile-ham:hover { background: rgba(255,255,255,0.12); }

/* ---- Mobile backdrop ---- */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1039;
}

body.sb-mobile-open .sidebar-backdrop {
    display: block;
}

/* ---- Mobile sidebar behaviour ---- */
@media (max-width: 991px) {
    .content-wrapper {
        margin-inline-start: 0 !important;
    }

    body.sb-authenticated .content-wrapper {
        padding-top: var(--topbar-h);
    }

    .sidebar {
        transform: translateX(-100%);
        width: var(--sb-w) !important;
        transition: transform var(--sb-transition);
    }

    [dir="rtl"] .sidebar {
        transform: translateX(100%);
    }

    body.sb-mobile-open .sidebar {
        transform: translateX(0) !important;
    }
}
