/* ============================================================
   NEMSU Election Management System — Design System v2
   ============================================================ */

/* ── 1. DESIGN TOKENS ─────────────────────────────────────── */
:root {
    /* Brand palette */
    --primary:          #1a3c6e;
    --primary-dark:     #122d54;
    --primary-mid:      #2d63a8;
    --secondary:        #c8a020;
    --secondary-dark:   #b08918;

    /* Semantic */
    --success:          #16a34a;
    --danger:           #dc3545;
    --warning:          #d97706;
    --info:             #0891b2;

    /* Surfaces */
    --light-bg:         #f0f4fa;
    --surface:          #ffffff;
    --surface-2:        #f8faff;

    /* Borders */
    --border:           #e2e8f0;
    --border-light:     #f1f5f9;

    /* Text */
    --text:             #0f172a;
    --text-muted:       #64748b;
    --text-light:       #94a3b8;

    /* Elevation */
    --shadow-sm:        0 1px 3px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.03);
    --shadow:           0 4px 12px rgba(0,0,0,.07);
    --shadow-md:        0 8px 24px rgba(0,0,0,.10);
    --shadow-lift:      0 12px 28px rgba(26,60,110,.14);
    --card-shadow:      var(--shadow);

    /* Geometry */
    --radius-sm:        6px;
    --radius:           10px;
    --radius-lg:        14px;
    --radius-xl:        20px;

    /* Sidebar */
    --sidebar-w:        248px;
}

/* ── 2. BASE ──────────────────────────────────────────────── */
body {
    background: var(--light-bg);
    font-family: 'Plus Jakarta Sans', 'Segoe UI', system-ui, sans-serif;
    font-size: .9375rem;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6,
.fs-1, .fs-2, .fs-3, .fs-4 {
    font-family: 'Sora', 'Segoe UI', system-ui, sans-serif;
}

/* ── 3. LOGIN PAGE ────────────────────────────────────────── */
.login-bg {
    background:
        radial-gradient(ellipse at 20% 50%, rgba(45,99,168,.4) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(200,160,32,.25) 0%, transparent 50%),
        linear-gradient(135deg, #0d2444 0%, var(--primary) 55%, #1e4d8c 100%);
    min-height: 100vh;
}

/* ── 4. SIDEBAR ───────────────────────────────────────────── */
.sidebar {
    background: linear-gradient(180deg, var(--primary) 0%, #0e2340 100%);
}

/* Desktop: undo Bootstrap's offcanvas-lg transform/position and restore sidebar geometry */
@media (min-width: 992px) {
    .sidebar.offcanvas-lg {
        background: linear-gradient(180deg, var(--primary) 0%, #0e2340 100%) !important;
        transform: none !important;
        position: sticky !important;
        top: 0 !important;
        left: auto !important;
        bottom: auto !important;
        width: var(--sidebar-w) !important;
        height: 100vh;
        min-height: 100vh;
        overflow-y: auto;
        flex-shrink: 0;
        z-index: 1 !important;
        visibility: visible !important;
    }
}

.sidebar-link {
    color: rgba(255,255,255,.75) !important;
    border-radius: var(--radius-sm);
    padding: .5rem .9rem;
    transition: background .15s, color .15s, box-shadow .15s;
    box-shadow: inset 3px 0 0 transparent;
}

.sidebar-link:hover {
    color: #fff !important;
    background: rgba(255,255,255,.10) !important;
}

.sidebar-link.active {
    color: #fff !important;
    background: rgba(255,255,255,.12) !important;
    box-shadow: inset 3px 0 0 var(--secondary);
    font-weight: 600;
}

/* ── 5. LAYOUT ─────────────────────────────────────────────── */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    padding: 1.75rem;
    overflow-x: auto;
    min-width: 0;
}

/* ── 6. TOP NAV ────────────────────────────────────────────── */
.top-nav {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: .75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
}

/* ── 7. CARDS ──────────────────────────────────────────────── */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    background: var(--surface);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-light);
    padding: .875rem 1.25rem;
}

.card-header-primary {
    background: var(--primary);
    color: #fff;
    border-color: transparent;
}

.card-footer {
    background: transparent;
    border-top: 1px solid var(--border-light);
}

/* ── 8. STAT CARDS ─────────────────────────────────────────── */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: box-shadow .2s, transform .2s;
}

.stat-card:hover {
    box-shadow: var(--shadow-lift);
    transform: translateY(-2px);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

/* Gradient icon tiles */
.stat-icon.bg-primary.bg-opacity-10 {
    background: linear-gradient(135deg, rgba(26,60,110,.12) 0%, rgba(45,99,168,.20) 100%) !important;
}
.stat-icon.bg-warning.bg-opacity-10 {
    background: linear-gradient(135deg, rgba(200,160,32,.12) 0%, rgba(217,119,6,.20) 100%) !important;
}
.stat-icon.bg-success.bg-opacity-10 {
    background: linear-gradient(135deg, rgba(22,163,74,.12) 0%, rgba(34,197,94,.20) 100%) !important;
}
.stat-icon.bg-danger.bg-opacity-10 {
    background: linear-gradient(135deg, rgba(220,53,69,.10) 0%, rgba(248,113,113,.18) 100%) !important;
}
.stat-icon.bg-info.bg-opacity-10 {
    background: linear-gradient(135deg, rgba(8,145,178,.10) 0%, rgba(6,182,212,.18) 100%) !important;
}

/* ── 9. BUTTONS ────────────────────────────────────────────── */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    font-weight: 600;
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(26,60,110,.3);
}

.btn-primary:active {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-gold {
    background: var(--secondary);
    border-color: var(--secondary);
    color: #fff;
    font-weight: 600;
}

.btn-gold:hover,
.btn-gold:focus {
    background: var(--secondary-dark);
    border-color: var(--secondary-dark);
    color: #fff;
    box-shadow: 0 4px 12px rgba(200,160,32,.35);
}

/* ── 10. STATUS BADGES ─────────────────────────────────────── */
.badge-status-draft {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}
.badge-status-open {
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
}
.badge-status-ongoing {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}
.badge-status-closed {
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fed7aa;
}
.badge-status-proclaimed {
    background: #f3e8ff;
    color: #7e22ce;
    border: 1px solid #e9d5ff;
}

/* ── 11. TABLES ────────────────────────────────────────────── */
.table-hover tbody tr:hover {
    background: rgba(26,60,110,.03);
}

.table th {
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    padding-top: .7rem;
    padding-bottom: .7rem;
}

/* ── 12. BALLOT CARDS ──────────────────────────────────────── */
.ballot-card {
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    transition: border-color .15s, box-shadow .15s, background .15s;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.ballot-card:hover {
    border-color: var(--primary-mid);
    box-shadow: 0 0 0 4px rgba(26,60,110,.08);
}

.ballot-card.selected {
    border-color: var(--primary);
    background: rgba(26,60,110,.04);
    box-shadow: 0 0 0 4px rgba(26,60,110,.14);
}

/* Checkmark indicator when selected */
.ballot-card.selected::after {
    content: '\F26B';
    font-family: 'bootstrap-icons';
    position: absolute;
    top: .55rem;
    right: .75rem;
    font-size: 1.15rem;
    color: var(--primary);
    font-style: normal;
}

.ballot-card input[type=radio],
.ballot-card input[type=checkbox] {
    display: none;
}

.candidate-photo {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid var(--border);
    transition: border-color .15s;
}

.ballot-card.selected .candidate-photo {
    border-color: var(--primary);
}

/* ── 13. COUNTDOWN TIMER ───────────────────────────────────── */
.countdown-box {
    display: flex;
    gap: .75rem;
    justify-content: center;
}

.countdown-unit {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-mid) 100%);
    color: #fff;
    border-radius: var(--radius-lg);
    padding: .875rem 1.25rem;
    text-align: center;
    min-width: 72px;
    box-shadow: var(--shadow-md);
}

.countdown-unit .num {
    font-family: 'Sora', monospace, system-ui;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -.02em;
}

.countdown-unit .lbl {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    opacity: .75;
    margin-top: .2rem;
}

/* ── 14. RECEIPT ───────────────────────────────────────────── */
.receipt-card {
    max-width: 540px;
    margin: 0 auto;
    border: 2px dashed #16a34a;
    border-radius: var(--radius-xl);
    padding: 2rem;
    text-align: center;
}

/* ── 15. ANALYTICS ─────────────────────────────────────────── */
.chart-wrapper {
    position: relative;
    height: 260px;
}

/* LIVE badge pulse animation */
.badge-live {
    animation: badge-pulse 2s ease-in-out infinite;
}

@keyframes badge-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .6; }
}

/* ── 16. VOTER LAYOUT ──────────────────────────────────────── */
.voter-layout {
    max-width: 760px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ── 17. SPINNER OVERLAY ───────────────────────────────────── */
.spinner-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.50);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.spinner-overlay.show {
    display: flex;
}

/* ── 18. SECTION HEADINGS ──────────────────────────────────── */
.section-heading {
    border-left: 4px solid var(--secondary);
    padding-left: .75rem;
    margin-bottom: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    font-family: 'Sora', system-ui, sans-serif;
}

/* ── 19. INITIALS AVATAR ───────────────────────────────────── */
.initials-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-mid) 100%);
    color: #fff;
    font-family: 'Sora', system-ui, sans-serif;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -.02em;
    border: 3px solid rgba(255,255,255,.25);
    flex-shrink: 0;
    user-select: none;
}

.initials-avatar.sm {
    width: 40px;
    height: 40px;
    font-size: .85rem;
    border-width: 2px;
}

/* ── 20. FORM POLISH ───────────────────────────────────────── */
.form-label.fw-semibold {
    font-weight: 600;
    color: var(--text);
    margin-bottom: .375rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-mid);
    box-shadow: 0 0 0 .2rem rgba(26,60,110,.15);
}

/* ── 21. RESPONSIVE ────────────────────────────────────────── */
@media (max-width: 991.98px) {
    .layout-wrapper { display: block; }
    .main-content { padding: 1rem; }
    .stat-card { flex-direction: column; text-align: center; }
    .stat-icon { margin: 0 auto; }
}

/* ── 22. PRINT ─────────────────────────────────────────────── */
@media print {
    .sidebar, .top-nav, .btn, .no-print { display: none !important; }
    .main-content { padding: 0; }
    .card { box-shadow: none; border: 1px solid #dee2e6; }
}

/* ── 23. REDUCED MOTION ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}
