* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    background: #f2f4f7;
    color: #1e2430;
}
a { text-decoration: none; color: inherit; }

/* ---------- Nav ---------- */
.topnav {
    background: #1c2b45;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 18px; }
.nav-links a {
    color: #d7e0f0;
    margin-left: 18px;
    font-size: 14px;
    padding: 6px 10px;
    border-radius: 4px;
}
.nav-links a:hover { background: rgba(255,255,255,0.12); }
.nav-links a.logout { color: #ffb4b4; }

.container { max-width: 1400px; margin: 0 auto; padding: 20px; }

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.stat { background: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.search-wrap { flex: 1; display: flex; gap: 8px; min-width: 280px; }
#searchBox { flex: 1; padding: 10px 12px; border: 1px solid #ccd3de; border-radius: 6px; font-size: 14px; }
.result-info { font-size: 13px; color: #556; margin-bottom: 8px; min-height: 18px; }

button {
    cursor: pointer;
    border: none;
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 14px;
    background: #2b57c8;
    color: #fff;
}
button:hover { background: #234aad; }
button.secondary { background: #e6eaf1; color: #26324a; }
button.secondary:hover { background: #d6dcea; }
button.primary { background: #1c8a4b; }
button.primary:hover { background: #156d3b; }

/* ---------- Table ---------- */
.table-scroll { overflow-x: auto; background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.voter-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.voter-table th {
    background: #eef1f6; text-align: left; padding: 10px 8px; white-space: nowrap;
    position: sticky; top: 0;
}
.voter-table td { padding: 8px; border-bottom: 1px solid #eef0f4; vertical-align: middle; white-space: nowrap; }
.voter-table tr:hover { background: #f7f9fc; }
.voter-row.row-green  { background: #e9f8ee; }
.voter-row.row-yellow { background: #fff8e1; }
.voter-row.row-red    { background: #fdecec; }

/* Keep the Name column visible while scrolling the table sideways (mobile) */
.col-name { position: sticky; left: 0; z-index: 1; background: #fff; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.voter-table th.col-name { z-index: 3; background: #eef1f6; }
.voter-table tr:hover .col-name { background: #f7f9fc; }
.voter-row.row-green .col-name  { background: #e9f8ee; }
.voter-row.row-yellow .col-name { background: #fff8e1; }
.voter-row.row-red .col-name    { background: #fdecec; }

.thumb { width: 42px; height: 42px; object-fit: cover; border-radius: 6px; border: 1px solid #ddd; }
.thumb-empty {
    width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
    background: #eef0f4; color: #99a; font-size: 9px; text-align: center; border-radius: 6px;
}

.color-btns { display: flex; gap: 4px; }
.c-btn {
    width: 26px; height: 26px; border-radius: 50%; padding: 0; font-size: 11px; font-weight: 700;
    color: #fff; opacity: 0.35; border: 2px solid transparent;
}
.c-btn.large { width: auto; height: auto; border-radius: 6px; padding: 8px 14px; opacity: 0.55; }
.c-btn.c-green  { background: #1c8a4b; }
.c-btn.c-yellow { background: #d1a300; }
.c-btn.c-red    { background: #c62d2d; }
.c-btn.active   { opacity: 1; border-color: #222; }

.remark-input { width: 160px; padding: 6px 8px; border: 1px solid #ccd3de; border-radius: 5px; font-size: 12px; }
.btn-edit { padding: 6px 12px; font-size: 12px; }

.load-more-wrap { text-align: center; padding: 16px; }

/* ---------- Overlay / Panels ---------- */
.overlay {
    position: fixed; inset: 0; background: rgba(15,20,30,0.5);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 40px 16px; z-index: 50; overflow-y: auto;
}
.panel { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 10px 40px rgba(0,0,0,0.25); }
.panel-wide { max-width: 900px; }
.panel-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid #eee;
}
.panel-head h3 { margin: 0; font-size: 17px; }
.close-x { background: none; color: #556; font-size: 22px; padding: 0 6px; }
.close-x:hover { color: #000; background:none; }
.panel-body { padding: 20px; max-height: 75vh; overflow-y: auto; }

/* Filter panel */
.filter-cat-list, .filter-val-list { list-style: none; padding: 0; margin: 0; }
.filter-cat-list li, .filter-val-list li { margin-bottom: 6px; }
.filter-cat-list button, .filter-val-list button {
    width: 100%; text-align: left; background: #f5f7fa; color: #1e2430;
    display: flex; justify-content: space-between;
}
.filter-cat-list button:hover, .filter-val-list button:hover { background: #e9edf5; }
.filter-count { color: #778; font-weight: 400; }
.back-link { display: inline-block; margin-bottom: 12px; background: none; color: #2b57c8; padding: 4px 0; }
.back-link:hover { background: none; text-decoration: underline; }

/* Edit form */
.edit-grid { display: grid; grid-template-columns: 160px 1fr; gap: 20px; }
.photo-col { text-align: center; }
.edit-thumb { width: 140px; height: 140px; object-fit: cover; border-radius: 8px; border: 1px solid #ddd; }
.file-label {
    display: block; margin-top: 10px; font-size: 12px; background: #eef1f6; padding: 8px; border-radius: 6px; cursor: pointer;
}
.file-label input { display: block; margin-top: 6px; font-size: 11px; }
.photo-hint { font-size: 11px; color: #889; margin-top: 6px; }

.fields-col label { display: block; font-size: 12px; color: #556; margin-bottom: 3px; font-weight: 600; }
.fields-col input, .fields-col select, .fields-col textarea {
    width: 100%; padding: 8px; border: 1px solid #ccd3de; border-radius: 5px; font-size: 13px; margin-bottom: 10px;
}
.field-row-2 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.edit-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 6px; }
#editStatusMsg { font-size: 13px; color: #1c8a4b; }

/* Upload pages */
.upload-form { background: #fff; padding: 18px; border-radius: 8px; display: flex; gap: 12px; align-items: center; margin: 14px 0; }
.upload-result { padding: 14px; border-radius: 8px; margin-top: 12px; }
.alert-ok { background: #e9f8ee; color: #14602f; }
.alert-error { background: #fdecec; color: #8a1c1c; }
.mono { font-family: monospace; background: #eef1f6; padding: 8px; border-radius: 6px; display: inline-block; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; background: #1c2b45; }
.login-box { background: #fff; padding: 32px; border-radius: 10px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,0.3); }
.login-box h2 { margin: 0 0 4px; font-size: 20px; }
.login-box .sub { color: #667; font-size: 13px; margin-bottom: 16px; }
.login-box label { display: block; font-size: 12px; color: #556; margin: 10px 0 4px; font-weight: 600; }
.login-box input { width: 100%; padding: 9px; border: 1px solid #ccd3de; border-radius: 5px; }
.login-box button { width: 100%; margin-top: 16px; }
.login-box .hint { font-size: 11px; color: #99a; margin-top: 14px; }

/* ---------- Scroll hint (mobile only) ---------- */
.scroll-hint { display: none; font-size: 12px; color: #778; text-align: center; padding: 6px 0 2px; }

/* =====================================================
   Mobile responsive
   ===================================================== */
@media (max-width: 768px) {
    .container { padding: 12px; }

    .topnav { padding: 10px 14px; }
    .brand { font-size: 15px; }
    .nav-links { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; width: 100%; }
    .nav-links a { margin-left: 0; font-size: 12px; padding: 6px 8px; }

    .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
    .stat { text-align: center; }
    .search-wrap { min-width: 0; width: 100%; }
    #filterBtn, #exportBtn { width: 100%; }

    .voter-table { font-size: 12px; }
    .voter-table th, .voter-table td { padding: 7px 6px; }
    .thumb, .thumb-empty { width: 34px; height: 34px; font-size: 8px; }
    .remark-input { width: 100px; }
    .btn-edit { padding: 8px 10px; }
    .c-btn { width: 30px; height: 30px; }

    .scroll-hint { display: block; }

    /* Full-screen panels on mobile */
    .overlay { padding: 0; align-items: stretch; }
    .panel, .panel-wide { max-width: 100%; width: 100%; min-height: 100vh; border-radius: 0; }
    .panel-body { max-height: calc(100vh - 60px); padding: 14px; }

    .edit-grid { grid-template-columns: 1fr; }
    .photo-col { margin-bottom: 10px; }
    .edit-thumb, .thumb-empty.edit-thumb { width: 110px; height: 110px; margin: 0 auto; }
    .field-row-2 { grid-template-columns: 1fr; gap: 0; }
    .c-btn.large { width: 100%; margin-bottom: 6px; }
    .color-btns.large { flex-direction: column; }

    .upload-form { flex-direction: column; align-items: stretch; }
}

@media (max-width: 480px) {
    .login-box { width: 88%; padding: 22px; }
    .nav-links a.logout { margin-left: auto; }
}
