/* ==========================================================================
   Election Manager - Modern SaaS Theme
   ========================================================================== */

:root {
    --em-primary: #008751;
    --em-primary-rgb: 0, 135, 81;
    --em-secondary: #64748b;
    --em-secondary-rgb: 100, 116, 139;
    --em-surface: #ffffff;
    --em-bg: #f8fafc;
    --em-border: #e2e8f0;
    --em-border-focus: #94a3b8;
    --em-text: #0f172a;
    --em-text-muted: #64748b;
    --em-sidebar-bg: #0f172a;
    --em-sidebar-text: #94a3b8;
    --em-sidebar-active: #ffffff;
    --em-sidebar-hover: #1e293b;
    --em-sidebar-width: 260px;
    --em-sidebar-collapsed-width: 76px;
    --em-header-height: 64px;
    --em-radius-sm: 0.375rem;
    --em-radius: 0.625rem;
    --em-radius-lg: 0.875rem;
    --em-radius-xl: 1rem;
    --em-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --em-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --em-shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --em-shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

/* Base & Typography */
body {
    background-color: var(--em-bg);
    color: var(--em-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--em-primary);
    text-decoration: none;
    transition: color 0.15s ease-in-out;
}
a:hover {
    color: rgba(var(--em-primary-rgb), 0.8);
}

/* ==========================================================================
   Primary Theme Overrides
   ========================================================================== */
.btn-primary,
.bg-primary,
.badge.bg-primary,
.page-item.active .page-link,
.nav-pills .nav-link.active {
    background-color: var(--em-primary) !important;
    border-color: var(--em-primary) !important;
    color: #ffffff !important;
}

.text-primary,
.nav-link.active,
a.link-primary {
    color: var(--em-primary) !important;
}

.btn-outline-primary {
    color: var(--em-primary);
    border-color: var(--em-primary);
}
.btn-outline-primary:hover {
    background-color: var(--em-primary);
    border-color: var(--em-primary);
    color: #ffffff;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--em-primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--em-primary-rgb), 0.18);
}

/* ==========================================================================
   App Shell Layout (Collapsible Sidebar + Topbar)
   ========================================================================== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
    overflow-x: hidden;
}

/* Sidebar (Desktop) */
.app-sidebar {
    width: var(--em-sidebar-width);
    background-color: var(--em-sidebar-bg);
    color: var(--em-sidebar-text);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1030;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--em-shadow-md);
    overflow: hidden;
}

.sidebar-header {
    height: var(--em-header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: #ffffff;
    font-weight: 700;
    font-size: 1.15rem;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-brand img {
    max-height: 36px;
    width: auto;
    border-radius: var(--em-radius-sm);
}

.sidebar-brand-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--em-primary);
    color: #ffffff;
    border-radius: var(--em-radius-sm);
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 0.75rem;
}

.sidebar-body::-webkit-scrollbar {
    width: 4px;
}
.sidebar-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

.sidebar-nav-group {
    margin-bottom: 1.25rem;
}

.sidebar-heading {
    padding: 0.4rem 0.75rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    white-space: nowrap;
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav-item {
    margin-bottom: 0.2rem;
}

.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    color: var(--em-sidebar-text);
    border-radius: var(--em-radius);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.15s ease-in-out;
    white-space: nowrap;
}

.sidebar-nav-link i {
    font-size: 1.15rem;
    width: 1.5rem;
    text-align: center;
    color: #94a3b8;
    flex-shrink: 0;
    transition: color 0.15s ease-in-out;
}

.sidebar-nav-link:hover {
    color: #ffffff;
    background-color: var(--em-sidebar-hover);
}
.sidebar-nav-link:hover i {
    color: #ffffff;
}

.sidebar-nav-link.active {
    color: #ffffff !important;
    background-color: var(--em-primary) !important;
    font-weight: 600;
}
.sidebar-nav-link.active i {
    color: #ffffff !important;
}

.sidebar-nav-link .badge {
    margin-left: auto;
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
}

/* Sidebar Footer / User Card */
.sidebar-footer {
    padding: 0.875rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.15);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: #ffffff;
}

.sidebar-user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.sidebar-user-info {
    overflow: hidden;
    white-space: nowrap;
}
.sidebar-user-name {
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.2;
    color: #ffffff;
}
.sidebar-user-role {
    font-size: 0.75rem;
    color: #94a3b8;
    line-height: 1.2;
}

/* Main Area */
.app-main {
    flex: 1 1 0%;
    min-width: 0;
    margin-left: var(--em-sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Header / Topbar */
.app-header {
    height: var(--em-header-height);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--em-border);
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    box-shadow: var(--em-shadow-sm);
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.app-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-sidebar-toggle {
    background: transparent;
    border: 1px solid var(--em-border);
    border-radius: var(--em-radius-sm);
    color: var(--em-text-muted);
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
}
.btn-sidebar-toggle:hover {
    background: #f1f5f9;
    color: var(--em-text);
}

/* Page Content Area */
.app-content {
    flex: 1 1 auto;
    padding: 1.75rem;
}

/* Collapsed Sidebar State (Desktop) */
@media (min-width: 992px) {
    .app-wrapper.sidebar-collapsed .app-sidebar {
        width: var(--em-sidebar-collapsed-width);
    }
    .app-wrapper.sidebar-collapsed .app-main {
        margin-left: var(--em-sidebar-collapsed-width);
    }
    .app-wrapper.sidebar-collapsed .sidebar-heading,
    .app-wrapper.sidebar-collapsed .sidebar-brand span,
    .app-wrapper.sidebar-collapsed .sidebar-nav-link span,
    .app-wrapper.sidebar-collapsed .sidebar-nav-link .badge,
    .app-wrapper.sidebar-collapsed .sidebar-user-info,
    .app-wrapper.sidebar-collapsed .sidebar-footer form {
        display: none !important;
    }
    .app-wrapper.sidebar-collapsed .sidebar-nav-link {
        justify-content: center;
        padding: 0.75rem 0;
    }
    .app-wrapper.sidebar-collapsed .sidebar-nav-link i {
        margin: 0;
        font-size: 1.35rem;
    }
    .app-wrapper.sidebar-collapsed .sidebar-header {
        justify-content: center;
        padding: 0;
    }
    .app-wrapper.sidebar-collapsed .sidebar-footer {
        padding: 0.75rem 0;
        display: flex;
        justify-content: center;
    }
}

/* Mobile Offcanvas / Responsive Rules */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        width: 270px;
    }
    .app-sidebar.show {
        transform: translateX(0);
    }
    .app-main {
        margin-left: 0 !important;
    }
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(15, 23, 42, 0.6);
        backdrop-filter: blur(4px);
        z-index: 1025;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    .sidebar-backdrop.show {
        opacity: 1;
        pointer-events: auto;
    }
    .app-content {
        padding: 1.25rem 1rem;
    }
    .app-header {
        padding: 0 1rem;
    }
}

/* ==========================================================================
   Modern Cards & Components
   ========================================================================== */
.card {
    background: var(--em-surface);
    border: 1px solid var(--em-border);
    border-radius: var(--em-radius-lg);
    box-shadow: var(--em-shadow-sm);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    overflow: hidden;
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--em-border);
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: 1rem;
    color: var(--em-text);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    background-color: transparent;
    border-top: 1px solid var(--em-border);
    padding: 0.875rem 1.25rem;
}

/* Stat Cards (Dashboard) */
.stat-card {
    background: var(--em-surface);
    border: 1px solid var(--em-border);
    border-radius: var(--em-radius-lg);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.15rem;
    box-shadow: var(--em-shadow-sm);
    transition: all 0.2s ease-in-out;
    height: 100%;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--em-shadow);
    border-color: #cbd5e1;
}

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

.stat-content {
    flex: 1 1 auto;
    min-width: 0;
}

.stat-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--em-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
}

.stat-number {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--em-text);
}

/* Metric color themes */
.stat-icon.primary { background: rgba(var(--em-primary-rgb), 0.12); color: var(--em-primary); }
.stat-icon.success { background: rgba(16, 185, 129, 0.12); color: #10b981; }
.stat-icon.warning { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.stat-icon.info    { background: rgba(6, 182, 212, 0.12); color: #06b6d4; }
.stat-icon.purple  { background: rgba(139, 92, 246, 0.12); color: #8b5cf6; }
.stat-icon.danger  { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.stat-icon.teal    { background: rgba(20, 184, 166, 0.12); color: #14b8a6; }

/* ==========================================================================
   Modern Tables
   ========================================================================== */
.table {
    --bs-table-bg: transparent;
    margin-bottom: 0;
    color: var(--em-text);
}

.table thead th {
    background-color: #f8fafc !important;
    color: #475569 !important;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--em-border) !important;
    white-space: nowrap;
    vertical-align: middle;
}

.table tbody td {
    padding: 0.875rem 1rem;
    vertical-align: middle;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--em-border);
}

.table-hover tbody tr:hover {
    background-color: #f8fafc;
}

/* ==========================================================================
   Badges (Modern Subtle Pills)
   ========================================================================== */
.badge {
    font-weight: 600;
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
    border-radius: 9999px;
    letter-spacing: 0.02em;
}

.badge-subtle-primary { background: rgba(var(--em-primary-rgb), 0.12); color: var(--em-primary); }
.badge-subtle-success { background: rgba(16, 185, 129, 0.12); color: #059669; }
.badge-subtle-warning { background: rgba(245, 158, 11, 0.15); color: #d97706; }
.badge-subtle-danger  { background: rgba(239, 68, 68, 0.12); color: #dc2626; }
.badge-subtle-info    { background: rgba(6, 182, 212, 0.15); color: #0891b2; }
.badge-subtle-secondary { background: rgba(100, 116, 139, 0.12); color: #475569; }

/* Avatars */
.avatar-xs { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.avatar-sm { width: 38px; height: 38px; border-radius: var(--em-radius-sm); object-fit: cover; }
.avatar-md { width: 52px; height: 52px; border-radius: var(--em-radius); object-fit: cover; }
.avatar-lg { width: 110px; height: 110px; border-radius: var(--em-radius-lg); object-fit: cover; }

.avatar-initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #e2e8f0;
    color: #334155;
    font-weight: 600;
    font-size: 0.85rem;
    border-radius: 50%;
    width: 36px;
    height: 36px;
}

/* Forms & Inputs */
.form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 0.35rem;
}

.form-control,
.form-select {
    border-color: #cbd5e1;
    border-radius: var(--em-radius);
    padding: 0.55rem 0.85rem;
    font-size: 0.925rem;
    color: #1e293b;
    background-color: #ffffff;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control[readonly],
.form-control:disabled {
    background-color: #f1f5f9;
    color: #64748b;
    cursor: not-allowed;
}

.input-group-text {
    background-color: #f8fafc;
    border-color: #cbd5e1;
    color: #64748b;
    border-radius: var(--em-radius);
}

.btn {
    font-weight: 500;
    border-radius: var(--em-radius);
    padding: 0.55rem 1rem;
    font-size: 0.875rem;
    transition: all 0.15s ease-in-out;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8125rem;
}
.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* Scanner & Camera */
.scanner-video {
    width: 100%;
    max-height: 280px;
    background: #0f172a;
    border-radius: var(--em-radius);
    object-fit: cover;
    box-shadow: inset 0 0 12px rgba(0,0,0,0.5);
}

.signature-box {
    border: 2px dashed #cbd5e1;
    border-radius: var(--em-radius);
    background: #ffffff;
    touch-action: none;
    transition: border-color 0.15s ease-in-out;
}
.signature-box:hover {
    border-color: var(--em-primary);
}

/* Offline Floating Badge with Pulse Animation */
.offline-badge {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1080;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    border-radius: 9999px;
    font-size: 0.8125rem;
    font-weight: 600;
    box-shadow: var(--em-shadow-lg);
    background: #ffffff;
    color: #0f172a;
    border: 1px solid var(--em-border);
}

.offline-pulse-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.offline-badge.is-online .offline-pulse-dot {
    background-color: #10b981;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse-green 2s infinite;
}

.offline-badge.is-offline .offline-pulse-dot {
    background-color: #ef4444;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    animation: pulse-red 2s infinite;
}

@keyframes pulse-green {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes pulse-red {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* HITL Comparison Desk */
.hitl-compare img {
    max-width: 100%;
    border-radius: var(--em-radius);
    border: 1px solid var(--em-border);
    box-shadow: var(--em-shadow-sm);
}

.form-review-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}
@media (max-width: 991.98px) {
    .form-review-grid {
        grid-template-columns: 1fr;
    }
}

.confidence-low {
    background-color: #fef3c7 !important;
}

/* Guest / Auth Pages Styling */
.auth-page-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top left, rgba(var(--em-primary-rgb), 0.08), transparent 50%),
                radial-gradient(circle at bottom right, rgba(100, 116, 139, 0.08), transparent 50%),
                #f8fafc;
    padding: 2.5rem 1rem;
}

.auth-card {
    border: 1px solid var(--em-border);
    border-radius: var(--em-radius-xl);
    box-shadow: var(--em-shadow-lg);
    background: #ffffff;
    overflow: hidden;
}

/* Landing Page Hero */
.hero-gradient {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #ffffff;
    position: relative;
    overflow: hidden;
}
.hero-gradient::before {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at center, rgba(var(--em-primary-rgb), 0.15) 0%, transparent 60%);
    pointer-events: none;
}
