/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    /* Brand Colors: Royal Blue & Clean Slate */
    --primary: #2563eb;
    --primary-light: #eff6ff;
    --primary-hover: #1d4ed8;
    
    --text-dark: #0f172a;
    --text-medium: #475569;
    --text-light: #94a3b8;
    
    --bg-body: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    
    --success-bg: #dcfce7;
    --success-text: #166534;
    --danger-bg: #fee2e2;
    --danger-text: #991b1b;

    --radius: 12px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    margin: 0;
    font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-dark);
    line-height: 1.5;
    padding-bottom: 40px;
}

/* =========================================
   2. LOADER
   ========================================= */
.loader-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--surface); z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.4s ease;
}
.loader-content { text-align: center; }
.loader-content h2 { margin: 15px 0 5px; font-size: 1.4rem; color: var(--text-dark); }
.loader-content p { color: var(--text-light); font-size: 0.95rem; margin: 0; }

.spinner {
    width: 45px; height: 45px; 
    border: 4px solid var(--border);
    border-top-color: var(--primary); 
    border-radius: 50%;
    animation: spin 0.8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================
   3. NAVIGATION (Right-Aligned)
   ========================================= */
.top-nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
    box-shadow: 0 2px 10px rgba(0,0,0,0.02);
}

.nav-container {
    max-width: 1100px; 
    margin: 0 auto; 
    padding: 15px 20px;
    
    /* FLEXBOX MAGIC: Forces Logo Left, Menu Right */
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
}

/* Brand/Logo */
.brand { display: flex; align-items: center; gap: 12px; }
.logo-box {
    width: 40px; height: 40px; background: var(--primary-light);
    color: var(--primary); border-radius: 10px;
    display: flex; align-items: center; justify-content: center; font-size: 1.4rem;
}
.brand-text h1 { margin: 0; font-size: 1.1rem; font-weight: 700; color: var(--text-dark); }
.badge { font-size: 0.7rem; background: var(--text-dark); color: white; padding: 2px 6px; border-radius: 4px; vertical-align: middle; }

/* Menu Links */
.nav-menu { display: flex; gap: 15px; align-items: center; }
.nav-link {
    text-decoration: none;
    color: var(--text-medium);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 8px 14px;
    border-radius: 8px;
    transition: all 0.2s;
}
.nav-link:hover { background: var(--bg-body); color: var(--primary); }
.nav-link.active { background: var(--primary-light); color: var(--primary); }

/* =========================================
   4. LAYOUT & CARDS
   ========================================= */
.main-content {
    max-width: 1100px; margin: 0 auto; padding: 30px 20px;
}

.card, .control-panel, .upload-card, .table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

.panel-header { margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid var(--border); }
.panel-header h2 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.panel-header p { margin: 5px 0 0; color: var(--text-medium); font-size: 0.95rem; }

/* =========================================
   5. FORMS & INPUTS
   ========================================= */
.filter-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.filter-group label, .form-section label {
    display: block; font-size: 0.85rem; font-weight: 600; 
    color: var(--text-medium); margin-bottom: 12px;
}

.select-wrapper { position: relative; }
.arrow-icon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 0.75rem; color: var(--text-light); pointer-events: none; }

select, .premium-input, .modern-input {
    width: 100%; padding: 12px 14px; font-size: 0.95rem; font-family: inherit;
    border: 1px solid var(--border); border-radius: 10px; background: var(--bg-body);
    color: var(--text-dark); appearance: none; transition: all 0.2s; box-sizing: border-box;
}
select:focus, .premium-input:focus, .modern-input:focus {
    outline: none; border-color: var(--primary); background: var(--surface);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.disabled { opacity: 0.6; pointer-events: none; }

/* Buttons */
.save-btn, .btn-action, .primary-btn, .btn-start {
    width: 100%; background: var(--text-dark); color: white; border: none; padding: 16px;
    border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: 0.2s;
    margin-top: 20px;
}
.save-btn:hover, .btn-action:hover, .primary-btn:hover, .btn-start:hover { background: black; transform: translateY(-1px); }
.btn-action:disabled { background: var(--text-light); cursor: not-allowed; transform: none; }

/* =========================================
   6. EVENT GRID (The 3x2 Request)
   ========================================= */
/* Container Grid */
.chip-grid, .event-chips {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3 Columns Fixed = 3x2 Layout */
    gap: 12px;
}

/* Individual Card */
.chip { display: block; width: 100%; cursor: pointer; height: 100%; }
.chip input { display: none; }

/* Card Content */
.chip span {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 500;
    text-align: center;
    transition: all 0.2s;
    height: 100%; /* Ensures all cards same height */
}

/* Active/Selected State */
.chip input:checked + span {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.15);
    font-weight: 600;
    transform: translateY(-2px);
}

/* =========================================
   7. SEARCH SECTION
   ========================================= */
.search-section { animation: fadeIn 0.3s ease; }
.search-wrapper { position: sticky; top: 80px; z-index: 40; background: var(--bg-body); padding: 10px 0; margin-bottom: 20px; }

.search-bar { position: relative; }
.search-icon { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); color: var(--text-light); }
#searchInput {
    width: 100%; padding: 18px 18px 18px 50px; font-size: 1.05rem;
    border: 1px solid var(--border); border-radius: 50px; background: var(--surface);
    box-shadow: var(--shadow-sm); transition: 0.2s;
}
#searchInput:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-light); }
.search-stats { text-align: right; font-size: 0.85rem; color: var(--text-medium); margin-top: 8px; }

/* =========================================
   8. VOTER GRID & CARDS
   ========================================= */
.voter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

.voter-card {
    background: var(--surface); padding: 20px; border-radius: 12px;
    border: 1px solid var(--border); cursor: pointer; transition: all 0.2s;
    display: flex; gap: 15px; align-items: start;
}
.voter-card:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: var(--shadow-md); }

.card-avatar {
    width: 45px; height: 45px; background: var(--primary-light); color: var(--primary);
    border-radius: 12px; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1rem; flex-shrink: 0;
}
.card-content h4 { margin: 0; font-size: 1.05rem; font-weight: 700; color: var(--text-dark); }
.card-content p { margin: 4px 0 8px; font-size: 0.9rem; color: var(--text-medium); }
.address-preview { font-size: 0.8rem; color: var(--text-light); display: block; }

/* =========================================
   9. MODAL & OVERLAY
   ========================================= */
.overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(3px);
    z-index: 100; display: flex; align-items: center; justify-content: center;
    visibility: hidden; opacity: 0; transition: all 0.2s;
}
.overlay.visible { visibility: visible; opacity: 1; }

.modal-panel {
    background: var(--surface); width: 100%; max-width: 550px; max-height: 90vh;
    border-radius: 16px; display: flex; flex-direction: column;
    box-shadow: var(--shadow-lg); transform: translateY(30px); transition: 0.3s;
}
.overlay.visible .modal-panel { transform: translateY(0); }

.modal-header { padding: 18px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; font-size: 1.1rem; font-weight: 700; }
.close-btn, .icon-btn { background: none; border: none; font-size: 1.5rem; color: var(--text-medium); cursor: pointer; }

.modal-body { padding: 24px; overflow-y: auto; }

/* Profile Card inside Modal */
.voter-identity-card, .profile-header {
    display: flex; align-items: center; gap: 16px; margin-bottom: 24px;
    background: var(--bg-body); padding: 16px; border-radius: 12px; border: 1px solid var(--border);
}
.id-avatar, .avatar-circle {
    width: 60px; height: 60px; background: var(--primary); color: white;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem; font-weight: 700;
}
.id-info h2, .profile-info h2 { margin: 0; font-size: 1.3rem; font-weight: 700; }
.id-info p, .profile-info p { margin: 2px 0 6px; color: var(--text-medium); font-size: 0.9rem; }
.meta-tag, .tag-pill { font-size: 0.8rem; background: white; padding: 2px 10px; border-radius: 4px; border: 1px solid var(--border); font-weight: 600; }

.info-grid, .info-card-row { display: flex; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.info-box, .info-card { flex: 1; border: 1px solid var(--border); padding: 12px 15px; border-radius: 8px; min-width: 140px; background: white; }
.info-box.wide, .info-card.wide { flex: 2; width: 100%; }
.info-box .label, .info-card .label { display: block; font-size: 0.7rem; font-weight: 700; color: var(--text-light); margin-bottom: 4px; }
.info-box .value, .info-card .value { font-size: 1rem; font-weight: 600; color: var(--text-dark); word-break: break-word; }
.info-box .highlight { color: var(--primary); font-family: monospace; font-size: 1.1rem; }

.grid-2, .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 30px; }

/* =========================================
   10. UPLOAD PAGE SPECIFIC
   ========================================= */
.upload-wrapper { max-width: 600px; margin: 40px auto; padding: 0 20px; }

.drop-zone {
    border: 2px dashed #cbd5e1; border-radius: 12px; padding: 40px;
    background: #f8fafc; cursor: pointer; text-align: center; transition: 0.2s;
    position: relative;
}
.drop-zone:hover, .drop-zone.active { border-color: var(--primary); background: var(--primary-light); }
.drop-zone input { position: absolute; top:0; left:0; width:100%; height:100%; opacity:0; cursor:pointer; }

.icon-large { font-size: 3rem; display: block; margin-bottom: 10px; }
.file-info b { display: block; font-size: 1.1rem; margin-bottom: 5px; }

.loading-area { margin-top: 30px; display: none; text-align: center; }
.spin { width: 30px; height: 30px; border: 3px solid #e2e8f0; border-top-color: var(--primary); border-radius: 50%; animation: spin 1s infinite linear; margin: 0 auto 10px; }

.success-msg, .success-message { margin-top: 20px; padding: 15px; background: var(--success-bg); color: var(--success-text); border-radius: 8px; font-weight: 600; display: none; text-align: center; }
.error-msg { margin-top: 20px; padding: 15px; background: var(--danger-bg); color: var(--danger-text); border-radius: 8px; font-weight: 600; display: none; text-align: center; }

/* =========================================
   11. VIEW DATA / TABLE STYLES
   ========================================= */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 800px; }
th { background: #f8fafc; text-align: left; padding: 16px; font-size: 0.8rem; font-weight: 700; color: var(--text-medium); text-transform: uppercase; border-bottom: 1px solid var(--border); }
td { padding: 16px; border-bottom: 1px solid var(--border); font-size: 0.9rem; color: var(--text-dark); vertical-align: middle; }
tr:hover { background: #f1f5f9; }

.badge-event { padding: 4px 10px; border-radius: 50px; font-size: 0.75rem; font-weight: 700; }
.bg-Birthday { background: #dbeafe; color: #1e40af; }
.bg-Death { background: #fee2e2; color: #991b1b; }
.bg-Job { background: #dcfce7; color: #166534; }
.bg-Accident { background: #ffedd5; color: #9a3412; }
.bg-New { background: #f3e8ff; color: #6b21a8; }
.bg-Animal { background: #fef3c7; color: #92400e; }

.action-btn { width: 30px; height: 30px; border: 1px solid var(--border); background: white; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; margin-right: 5px; }
.btn-del:hover { background: #fee2e2; border-color: #ef4444; color: #b91c1c; }

/* =========================================
   12. TOAST NOTIFICATION
   ========================================= */
#toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px);
    background: var(--text-dark); color: white; padding: 12px 24px; border-radius: 50px;
    display: flex; align-items: center; gap: 10px; font-weight: 600; box-shadow: var(--shadow-lg);
    visibility: hidden; opacity: 0; transition: all 0.3s; z-index: 200;
}
#toast.show { visibility: visible; opacity: 1; transform: translateX(-50%) translateY(0); }

/* =========================================
   13. MOBILE MEDIA QUERIES & HAMBURGER
   ========================================= */

/* Hide toggle button by default on desktop */
.menu-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    z-index: 101;
}

.menu-toggle .bar {
    width: 25px;
    height: 3px;
    background-color: var(--text-dark);
    border-radius: 3px;
    transition: 0.3s;
}

/* Visibility Control: Ensures Desktop and Mobile don't overlap */
.mobile-only { display: none !important; }
.desktop-only { display: block !important; }

@media (max-width: 768px) {
    /* Hide Desktop Elements strictly */
    .desktop-only { display: none !important; }
    /* Show Mobile Elements strictly */
    .mobile-only { display: grid !important; }

    /* FIX: Force Logo Left and Hamburger Right */
    .nav-container { 
        flex-direction: row !important; 
        justify-content: space-between !important;
        align-items: center !important;
        padding: 10px 20px;
    }

    /* Show Hamburger on mobile */
    .menu-toggle {
        display: flex;
    }

    /* Sidebar/Drawer Menu */
    .nav-menu {
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        background: var(--surface);
        flex-direction: column;
        gap: 0;
        border-top: 1px solid var(--border);
        box-shadow: var(--shadow-lg);
        max-height: 0; /* Hidden */
        overflow: hidden;
        transition: max-height 0.3s ease-in-out;
        z-index: 100;
    }

    /* When Menu is toggled open */
    .nav-menu.active {
        max-height: 400px;
    }

    .nav-link {
        width: 100%;
        padding: 16px 20px;
        border-radius: 0;
        border-bottom: 1px solid var(--border);
        display: block;
        text-align: left;
    }

    /* Filters Stack */
    .filter-row { grid-template-columns: 1fr; }
    
    /* Event Grid -> 2 Columns on Mobile */
    .chip-grid, .event-chips { grid-template-columns: repeat(2, 1fr); }
    
    /* Modal Bottom Sheet */
    .overlay { align-items: flex-end; }
    .modal-panel { border-radius: 20px 20px 0 0; width: 100%; max-height: 85vh; transform: translateY(100%); }
    .overlay.visible .modal-panel { transform: translateY(0); }
    
    /* Info Stacking */
    .info-grid { flex-wrap: wrap; }
    .info-box.wide, .info-card.wide { width: 100%; flex: 100%; }

    /* Animation for Hamburger to X */
    .menu-toggle.open .bar:nth-child(1) { transform: translateY(8px) rotate(45deg); }
    .menu-toggle.open .bar:nth-child(2) { opacity: 0; }
    .menu-toggle.open .bar:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }
}

/* =========================================
   14. AJAX SEARCH & LOGIN SYSTEM STYLES
   ========================================= */

/* AJAX Search Box Inner Styling */
.search-container-ajax {
    position: relative;
    flex: 2;
    min-width: 200px;
}
.search-container-ajax span {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    pointer-events: none;
    z-index: 5;
}
/* Adjust internal padding for the search input to fit the icon */
#tableSearch {
    padding-left: 42px !important;
}

/* Login Specifics */
.login-wrapper { max-width: 400px; margin: 100px auto; padding: 0 20px; }
.login-card { 
    background: var(--surface); 
    padding: 40px; 
    border-radius: 20px; 
    box-shadow: var(--shadow-lg); 
    border: 1px solid var(--border); 
}
.login-logo { text-align: center; margin-bottom: 30px; }
.login-logo .logo-box { width: 60px; height: 60px; font-size: 2rem; margin: 0 auto 10px; }

/* Dashboard & Admin Tables */
.admin-badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.role-admin { background: var(--text-dark); color: white; }
.role-user { background: var(--text-light); color: white; }

/* Form Field Spacing */
.form-section { margin-bottom: 20px; }

/* Overlay for Modals */
.overlay.hidden { display: none; }

/* Ensuring consistent button design for admin tasks */
.btn-mobile-delete {
    width: 100%; padding: 10px; margin-top: 10px; 
    background: #fee2e2; color: #991b1b; border: 1px solid #fecaca;
    border-radius: 8px; font-weight: 600; cursor: pointer;
}

/* Navigation Badge for User Roles */
.nav-badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 800;
    margin-left: 10px;
    border: 1px solid var(--primary);
}