/*
 * Elections 2025 — Modern UI stylesheet
 * Mobile-first, RTL-aware, single-file.
 * Palette: deep navy + warm crimson accent on a soft ivory canvas.
 */

/* ---------- 1. Design tokens ---------- */
:root {
    --c-bg:           #f5f3ee;
    --c-surface:      #ffffff;
    --c-surface-alt:  #faf8f3;
    --c-border:       #e3ddd0;
    --c-border-strong:#c9bfa8;

    --c-ink:          #1a1f2e;
    --c-ink-soft:     #4a5266;
    --c-ink-mute:     #8a8e9c;

    --c-primary:      #1f3a5f;     /* deep navy */
    --c-primary-700:  #14274a;
    --c-primary-100:  #e7ecf3;

    --c-accent:       #a52a2a;     /* warm crimson */
    --c-accent-700:   #7c1e1e;
    --c-accent-100:   #f6e3e3;

    --c-success:      #2d6a4f;
    --c-success-100:  #d8ede1;
    --c-warning:      #b8860b;
    --c-warning-100:  #fbf0c8;
    --c-danger:       #b22222;

    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 2px rgba(20,30,60,.06), 0 1px 1px rgba(20,30,60,.04);
    --shadow:    0 4px 12px rgba(20,30,60,.08), 0 2px 4px rgba(20,30,60,.04);
    --shadow-lg: 0 12px 32px rgba(20,30,60,.14), 0 4px 8px rgba(20,30,60,.06);

    --font-arabic:  'Cairo', 'Segoe UI', 'Tahoma', sans-serif;
    --font-display: 'Playfair Display', 'Georgia', serif;

    --sidebar-w:    260px;
    --header-h:     64px;
    --t-fast:       150ms cubic-bezier(.4,0,.2,1);
    --t:            220ms cubic-bezier(.4,0,.2,1);
}

/* ---------- 2. Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font-arabic);
    font-size: 15px;
    line-height: 1.55;
    color: var(--c-ink);
    background: var(--c-bg);
    direction: rtl;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--c-primary); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--c-accent); }
img { max-width: 100%; display: block; }
hr { border: 0; border-top: 1px solid var(--c-border); margin: 1.25rem 0; }

h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 700; line-height: 1.25; color: var(--c-ink); }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

/* ---------- 3. Login page ---------- */
.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(ellipse at top, rgba(31,58,95,.08), transparent 60%),
        radial-gradient(ellipse at bottom, rgba(165,42,42,.06), transparent 50%),
        var(--c-bg);
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--c-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
    text-align: center;
    border: 1px solid var(--c-border);
}
.login-card .logo {
    display: inline-flex;
    align-items: center; justify-content: center;
    width: 88px; height: 88px;
    border-radius: 50%;
    background: var(--c-primary);
    color: #fff;
    font-family: var(--font-display);
    font-size: 2rem; font-weight: 700;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}
.login-card h1 {
    font-size: 1.35rem;
    color: var(--c-primary-700);
    margin-bottom: .25rem;
}
.login-card .subtitle {
    color: var(--c-ink-mute);
    font-size: .9rem;
    margin-bottom: 2rem;
}
.login-card form { text-align: right; }

/* ---------- 4. Forms ---------- */
.field { margin-bottom: 1.1rem; }
.field label {
    display: block;
    font-weight: 600;
    color: var(--c-ink-soft);
    margin-bottom: .35rem;
    font-size: .9rem;
}
.input,
.select,
.textarea {
    width: 100%;
    border: 1px solid var(--c-border-strong);
    background: var(--c-surface);
    border-radius: var(--radius-sm);
    padding: .65rem .8rem;
    font-family: inherit;
    font-size: .95rem;
    color: var(--c-ink);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px var(--c-primary-100);
}
.textarea { min-height: 80px; resize: vertical; }
.field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: .9rem;
}
.checkbox {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
    user-select: none;
}
.checkbox input { accent-color: var(--c-primary); width: 1.05em; height: 1.05em; }

/* ---------- 5. Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center; justify-content: center;
    gap: .4rem;
    padding: .6rem 1.2rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--t-fast), border-color var(--t-fast),
                color var(--t-fast), transform var(--t-fast);
    text-decoration: none;
    line-height: 1.2;
}
.btn:active { transform: translateY(1px); }
.btn-primary    { background: var(--c-primary); color: #fff; }
.btn-primary:hover  { background: var(--c-primary-700); color: #fff; }
.btn-accent     { background: var(--c-accent); color: #fff; }
.btn-accent:hover   { background: var(--c-accent-700); color: #fff; }
.btn-ghost      { background: transparent; color: var(--c-ink-soft); border-color: var(--c-border-strong); }
.btn-ghost:hover    { background: var(--c-surface-alt); color: var(--c-ink); }
.btn-danger     { background: var(--c-danger); color: #fff; }
.btn-danger:hover   { background: #911818; }
.btn-block      { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .5; pointer-events: none; }

/* ---------- 6. Layout (header + sidebar + main) ---------- */
.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas:
        "sidebar header"
        "sidebar main";
}

/* HEADER */
.app-header {
    grid-area: header;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    box-shadow: var(--shadow-sm);
    position: sticky; top: 0; z-index: 10;
}
.app-header .title {
    display: flex; flex-direction: column;
}
.app-header .title strong {
    font-family: var(--font-display);
    font-size: 1.1rem;
    color: var(--c-primary-700);
    letter-spacing: .2px;
}
.app-header .title span {
    font-size: .8rem;
    color: var(--c-ink-mute);
}
.app-header .user {
    display: flex; align-items: center; gap: .9rem;
}
.app-header .user .avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--c-primary);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 700; font-size: .85rem;
}
.app-header .user a { color: var(--c-ink-soft); font-weight: 600; font-size: .85rem; }
.app-header .user a:hover { color: var(--c-accent); }

.menu-toggle {
    display: none;
    background: none; border: 0; padding: .25rem;
    cursor: pointer;
    color: var(--c-primary-700);
}
.menu-toggle svg { width: 26px; height: 26px; }

/* SIDEBAR */
.app-sidebar {
    grid-area: sidebar;
    background: var(--c-primary-700);
    color: #d6dde9;
    padding: 1.25rem 0;
    position: sticky; top: 0;
    height: 100vh;
    overflow-y: auto;
    box-shadow: 2px 0 8px rgba(0,0,0,.08);
}
.app-sidebar .brand {
    display: flex; align-items: center; gap: .75rem;
    padding: 0 1.25rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    margin-bottom: 1rem;
}
.app-sidebar .brand .mark {
    width: 42px; height: 42px;
    background: var(--c-accent);
    border-radius: 10px;
    display: grid; place-items: center;
    color: #fff; font-weight: 800;
    font-family: var(--font-display);
}
.app-sidebar .brand h2 {
    color: #fff;
    font-size: 1.05rem;
    margin: 0;
}
.app-sidebar nav ul { list-style: none; padding: 0; margin: 0; }
.app-sidebar nav a {
    display: flex; align-items: center; gap: .7rem;
    padding: .8rem 1.4rem;
    color: #c5cdd9;
    font-weight: 600;
    font-size: .95rem;
    border-right: 3px solid transparent; /* RTL accent edge */
    transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.app-sidebar nav a:hover {
    background: rgba(255,255,255,.05);
    color: #fff;
}
.app-sidebar nav a.active {
    background: rgba(255,255,255,.08);
    color: #fff;
    border-right-color: var(--c-accent);
}
.app-sidebar nav .icon {
    width: 18px; height: 18px;
    flex-shrink: 0;
}

/* MAIN */
.app-main {
    grid-area: main;
    padding: 1.75rem;
    max-width: 100%;
    overflow-x: hidden;
}
.page-title {
    margin-bottom: 1.5rem;
}
.page-title h1 {
    font-family: var(--font-display);
    color: var(--c-primary-700);
    font-size: 1.6rem;
}
.page-title .crumbs {
    font-size: .85rem;
    color: var(--c-ink-mute);
}

/* ---------- 7. Cards / panels ---------- */
.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 1.5rem;
}
.card-header {
    padding: .9rem 1.2rem;
    border-bottom: 1px solid var(--c-border);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--c-surface-alt);
}
.card-header h3 { margin: 0; font-size: 1rem; color: var(--c-primary-700); }
.card-body { padding: 1.2rem; }

/* ---------- 8. Tables ---------- */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
}
table.data {
    width: 100%;
    border-collapse: collapse;
    background: var(--c-surface);
    font-size: .9rem;
}
table.data th,
table.data td {
    padding: .65rem .8rem;
    text-align: right;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}
table.data thead th {
    background: var(--c-primary-700);
    color: #fff;
    font-weight: 600;
    font-size: .85rem;
    letter-spacing: .2px;
    border-bottom: 0;
    white-space: nowrap;
}
table.data tbody tr:nth-child(even) { background: var(--c-surface-alt); }
table.data tbody tr:hover           { background: var(--c-primary-100); }
table.data tbody tr.modified        { background: #d4f0e8; } /* IsDataModified */
table.data tbody tr.modified:hover  { background: #b8e6d8; }
table.data .actions {
    display: flex; gap: .4rem; flex-wrap: wrap;
}
table.data .empty {
    text-align: center;
    color: var(--c-accent);
    padding: 2rem 1rem;
    font-weight: 600;
}

/* Pagination */
.pager {
    display: flex; gap: .25rem; flex-wrap: wrap;
    margin-top: 1rem;
    justify-content: center;
}
.pager a, .pager span {
    padding: .35rem .65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border-strong);
    color: var(--c-ink-soft);
    font-size: .85rem;
}
.pager .current {
    background: var(--c-primary);
    border-color: var(--c-primary);
    color: #fff;
    font-weight: 600;
}
.pager a:hover { background: var(--c-primary-100); }

/* ---------- 9. Alerts / messages ---------- */
.alert {
    padding: .8rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: .92rem;
    border: 1px solid transparent;
}
.alert-info    { background: var(--c-primary-100); color: var(--c-primary-700); border-color: #cdd9eb; }
.alert-success { background: var(--c-success-100); color: var(--c-success); border-color: #b6dac4; }
.alert-warn    { background: var(--c-warning-100); color: var(--c-warning); border-color: #f3e0a3; }
.alert-error   { background: var(--c-accent-100); color: var(--c-accent-700); border-color: #ecbcbc; }

/* ---------- 10. Stats / KPI cards (real-time) ---------- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}
.stat::before {
    content:''; position: absolute; top: 0; right: 0; bottom: 0;
    width: 4px; background: var(--c-primary);
}
.stat.accent::before  { background: var(--c-accent); }
.stat.success::before { background: var(--c-success); }
.stat .label { color: var(--c-ink-mute); font-size: .8rem; font-weight: 600; }
.stat .value {
    font-family: var(--font-display);
    font-size: 1.85rem;
    color: var(--c-primary-700);
    margin-top: .1em;
    line-height: 1.1;
}
.stat.accent  .value { color: var(--c-accent-700); }
.stat.success .value { color: var(--c-success); }

/* ---------- 11. Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(20,30,60,.55);
    display: none;
    align-items: center; justify-content: center;
    z-index: 100;
    padding: 1rem;
    overflow-y: auto;
}
.modal-backdrop.show { display: flex; }
.modal {
    background: var(--c-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 980px;
    max-height: 92vh;
    overflow-y: auto;
    animation: modalIn .25s cubic-bezier(.2,.8,.4,1);
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(8px) scale(.98); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}
.modal-header {
    padding: 1rem 1.4rem;
    border-bottom: 1px solid var(--c-border);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--c-surface-alt);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-header h2 {
    margin: 0; font-size: 1.1rem;
    color: var(--c-primary-700);
}
.modal-header .close {
    background: none; border: 0; cursor: pointer;
    font-size: 1.5rem; line-height: 1;
    color: var(--c-ink-mute);
}
.modal-header .close:hover { color: var(--c-accent); }
.modal-body { padding: 1.4rem; }
.modal-footer {
    padding: .9rem 1.4rem;
    border-top: 1px solid var(--c-border);
    background: var(--c-surface-alt);
    display: flex; gap: .6rem; justify-content: flex-start;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    flex-wrap: wrap;
}

/* Detail blocks inside the edit-voter modal */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
    background: var(--c-primary-100);
    padding: 1rem;
    border-radius: var(--radius-sm);
}
.detail-grid .item .k {
    font-size: .78rem; color: var(--c-ink-mute);
    font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.detail-grid .item .v {
    font-size: 1rem; color: var(--c-primary-700);
    font-weight: 600;
}
.section-title {
    font-family: var(--font-display);
    font-size: 1.05rem;
    color: var(--c-accent-700);
    margin: 1.25rem 0 .5rem;
    padding-bottom: .4rem;
    border-bottom: 2px solid var(--c-accent);
}

/* ---------- 12. Filter bar ---------- */
.filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: .75rem;
    background: var(--c-surface);
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--c-border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.25rem;
}
.filter-bar .field { margin-bottom: 0; }

/* ---------- 13. Footer ---------- */
.app-footer {
    text-align: center;
    color: var(--c-ink-mute);
    font-size: .82rem;
    padding: 1.5rem 1rem;
    border-top: 1px solid var(--c-border);
    margin-top: 1.5rem;
}

/* ---------- 14. Realtime / chart helpers ---------- */
.rt-banner {
    background: linear-gradient(135deg, var(--c-primary-700), var(--c-primary));
    color: #fff;
    padding: 1.5rem;
    border-radius: var(--radius);
    text-align: center;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}
.rt-banner h1 {
    color: #fff; font-family: var(--font-display);
    font-size: 1.7rem; margin-bottom: .35rem;
}
.rt-banner .scope { color: rgba(255,255,255,.85); font-size: .9rem; }
.rt-banner .updated { color: rgba(255,255,255,.65); font-size: .8rem; margin-top: .5rem; }

#chart { width: 100%; min-height: 380px; }

/* ---------- 15. Responsive ---------- */
@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "main";
    }
    .app-sidebar {
        position: fixed;
        top: 0; right: 0;
        height: 100vh; width: 80%; max-width: 320px;
        z-index: 50;
        transform: translateX(100%);
        transition: transform var(--t);
    }
    .app-sidebar.open { transform: translateX(0); }
    .menu-toggle { display: inline-flex; }
    .app-main { padding: 1.2rem; }
    .page-title h1 { font-size: 1.3rem; }
    table.data th, table.data td { padding: .55rem .55rem; font-size: .82rem; }
}
@media (max-width: 540px) {
    .app-header { padding: 0 .9rem; }
    .app-header .title strong { font-size: .98rem; }
    .app-header .title span   { font-size: .72rem; }
    .login-card { padding: 2rem 1.4rem; }
    .stat .value { font-size: 1.5rem; }
}

/* Backdrop for sidebar on mobile */
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(20,30,60,.4);
    z-index: 40;
}
.sidebar-backdrop.show { display: block; }

/* Print friendly */
@media print {
    .app-sidebar, .app-header, .filter-bar, .btn, .pager { display: none !important; }
    .app-main { padding: 0; }
    body { background: #fff; }
    .card { box-shadow: none; border: 1px solid #ccc; }
}

.login-card .logo img {
    max-width: 180px;
    height: auto;
    display: block;
    margin: 0 auto;
}
