/* Election Hub — control room
   Layout follows the approved backend reference: navy rail, white workspace,
   one card per job, and a bordered entry table for candidates. */

html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--body);
  background: #E9EEF5;
  color: #14243D;
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 3px solid #2563EB; outline-offset: 2px; border-radius: 6px; }

/* ---------------- Sign in ---------------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background:
    linear-gradient(180deg, rgba(4,16,31,.9), rgba(4,16,31,.96)),
    url("../img/background.jpg") center/cover;
}
.gate-card {
  width: min(420px, 92vw);
  background: #fff; border-radius: 18px; padding: 34px 32px 26px;
  box-shadow: 0 30px 80px rgba(0,0,0,.5); text-align: center;
}
.gate-card img { height: 42px; filter: invert(1) brightness(.2); }
.gate-card h1 {
  font-family: var(--display); font-size: 32px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .04em; margin: 10px 0 2px;
}
.gate-card p { color: #5B738F; font-size: 14px; margin: 0 0 20px; }
.gate-card input {
  width: 100%; font-size: 16px; padding: 13px 14px; text-align: center; letter-spacing: .12em;
  border: 1.5px solid #D9E1EA; border-radius: 10px; background: #F3F6FA;
}
.gate-card button { width: 100%; margin-top: 12px; }
.gate-err { color: #C8302F; font-size: 14px; min-height: 20px; margin-top: 10px; }

/* ---------------- Frame ---------------- */
.app { display: grid; grid-template-columns: 282px 1fr; min-height: 100vh; }

.side {
  background: linear-gradient(180deg, #1B3358 0%, #12233E 100%);
  color: #fff; padding: 26px 18px 20px;
  position: sticky; top: 0; height: 100vh; overflow: auto;
  display: flex; flex-direction: column;
}
.side-brand { display: flex; align-items: center; gap: 14px; padding: 0 8px 26px; }
.side-brand img { height: 38px; }
.side-brand .t {
  font-family: var(--display); font-size: 22px; font-weight: 700; line-height: .98;
  letter-spacing: .1em; text-transform: uppercase;
}
.side-brand .t small { display: block; font-size: 12px; letter-spacing: .22em; color: #8FA9CC; font-weight: 600; }

.nav-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 13px 16px; margin-bottom: 4px;
  border: 0; border-radius: 10px; cursor: pointer;
  font-family: var(--body); font-size: 16px; font-weight: 500;
  color: #C3D5EC; background: none; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.on { background: #2C5C96; color: #fff; font-weight: 600; }
.nav-item svg { width: 20px; height: 20px; fill: currentColor; flex: none; }

.side-foot { margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.14); }
.side-foot .mode { font-size: 12.5px; line-height: 1.55; color: #8FA9CC; padding: 6px 14px 12px; }
.side-foot .mode b { color: #FFD66B; }

.main { min-width: 0; display: flex; flex-direction: column; }

/* status bar */
.statusbar {
  background: #fff; border-bottom: 1px solid #DCE4EE;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 34px; position: sticky; top: 0; z-index: 20;
}
.statusbar .crumb {
  margin-left: auto; font-size: 15px; font-weight: 600; color: #23385A;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.crumb .sep { color: #A9BACE; font-weight: 400; }
.pill-online {
  background: #16A34A; color: #fff; font-size: 13px; font-weight: 700;
  letter-spacing: .06em; padding: 4px 11px; border-radius: 6px;
}
.pill-online.local { background: #C9871A; }
.savestate { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: #5B738F; }
.savestate .dot { width: 9px; height: 9px; border-radius: 50%; background: #16A34A; }
.savestate.dirty .dot { background: #E0A21A; }
.savestate.error .dot { background: #C8302F; }

.wrap { padding: 26px 34px 60px; max-width: 1500px; width: 100%; }
.page-title {
  font-size: 30px; font-weight: 700; letter-spacing: -.01em;
  color: #14243D; margin: 0 0 22px;
}
.page-title span { color: #2C5C96; }
.panel { display: none; }
.panel.on { display: block; animation: fade .22s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

/* ---------------- Cards ---------------- */
.card {
  background: #fff; border: 1px solid #DFE6EF; border-radius: 14px;
  padding: 22px 24px 24px; margin-bottom: 22px;
  box-shadow: 0 1px 2px rgba(20,36,61,.05);
}
.card > h2 { font-size: 21px; font-weight: 700; margin: 0 0 4px; color: #14243D; }
.card > .hint { color: #5B738F; font-size: 14px; line-height: 1.55; margin: 0 0 18px; }
.card > h2 + .hint { margin-top: 6px; }

.cols { display: grid; grid-template-columns: 360px 1fr; gap: 22px; align-items: start; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
@media (max-width: 1150px) { .cols, .cols-2 { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .wrap { padding: 20px 16px 50px; }
  .statusbar { padding: 12px 16px; }
}

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1000px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

/* ---------------- Fields ---------------- */
label.field { display: block; margin-bottom: 16px; }
label.field > span {
  display: block; font-size: 15px; font-weight: 600; color: #23385A; margin-bottom: 7px;
}
input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%; font-family: var(--body); font-size: 15px; color: #14243D;
  padding: 11px 13px; border: 1px solid #D9E1EA; border-radius: 8px; background: #F1F5F9;
}
input[readonly] { color: #5B738F; }
input[dir=rtl], textarea[dir=rtl] { font-family: var(--urdu); font-size: 17px; line-height: 2.1; }
input:focus, select:focus, textarea:focus { background: #fff; border-color: #2563EB; }
textarea { min-height: 96px; resize: vertical; line-height: 1.6; }

button {
  font-family: var(--body); font-size: 14.5px; font-weight: 600;
  padding: 11px 20px; border: 0; border-radius: 8px; cursor: pointer;
  background: #2563EB; color: #fff;
}
button:hover { background: #1D4FD0; }
button.ghost { background: #fff; color: #2563EB; border: 1.5px solid #B9CDF0; }
button.ghost:hover { background: #EEF4FF; }
button.danger { background: #fff; color: #C8302F; border: 1.5px solid #F0CFCF; }
button.danger:hover { background: #FDF2F2; }
button.sm { padding: 7px 13px; font-size: 13px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.right { justify-content: flex-end; }
.spacer { flex: 1; }

/* ---------------- Entry table ---------------- */
.entry-table { border: 1px solid #D9E1EA; border-radius: 8px; overflow: hidden; }
.entry-head, .entry-row {
  display: grid;
  grid-template-columns: 158px minmax(190px,1.2fr) minmax(170px,1fr) 190px 200px 52px;
}
.entry-head > div {
  background: #F1F4F8; border-bottom: 1px solid #D9E1EA; border-right: 1px solid #D9E1EA;
  padding: 13px 14px; font-size: 15px; font-weight: 700; color: #14243D;
}
.entry-head > div:last-child { border-right: 0; }
.entry-row > div {
  border-bottom: 1px solid #E4EAF2; border-right: 1px solid #E4EAF2;
  padding: 14px; min-width: 0;
}
.entry-row > div:last-child { border-right: 0; }
.entry-row:last-child > div { border-bottom: 0; }
.entry-row.lead { background: #F2FBF5; }
.entry-row.second { background: #FFFCF2; }
.entry-row .cell-label { font-size: 14px; font-weight: 600; color: #23385A; margin-bottom: 7px; }
.entry-row input, .entry-row select { padding: 9px 11px; font-size: 14.5px; }

.upload-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: #2563EB; color: #fff; font-size: 13px; font-weight: 600;
  padding: 7px 12px; border-radius: 6px; cursor: pointer; border: 0;
}
.upload-btn:hover { background: #1D4FD0; }
.cand-thumb {
  width: 100%; max-width: 118px; aspect-ratio: 1/1; margin-top: 9px;
  border-radius: 8px; object-fit: cover; background: #E4EAF2;
  border: 1px solid #D9E1EA; display: grid; place-items: center;
  font-size: 12px; color: #7C90AB; text-align: center; overflow: hidden; cursor: pointer;
}
.cand-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.party-mark { display: flex; align-items: center; gap: 9px; margin-top: 9px; }
.party-mark .chip {
  width: 48px; height: 32px; border-radius: 5px; display: grid; place-items: center;
  color: #fff; font-family: var(--display); font-size: 13px; font-weight: 700; flex: none; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.18);
}
.party-mark .chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.party-mark b { font-size: 19px; font-weight: 700; color: #14243D; }

.vote-step { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.vote-step button {
  flex: 1; background: #E8EDF4; color: #23385A; font-size: 17px; line-height: 1;
  padding: 8px 0; border-radius: 6px; font-weight: 700;
}
.vote-step button:hover { background: #D7E0EC; }
.vote-step input { flex: 1.2; text-align: center; padding: 7px 4px; font-size: 13px; }

.status-auto { font-size: 12.5px; color: #5B738F; margin-top: 7px; }
.status-auto b { color: #16A34A; }
.status-auto b.p { color: #C9871A; }

.row-del { display: grid; place-items: center; padding: 0 !important; }
.row-del button { background: none; color: #A9BACE; font-size: 20px; padding: 6px 10px; line-height: 1; }
.row-del button:hover { background: #FDF2F2; color: #C8302F; }

@media (max-width: 1150px) {
  .entry-head { display: none; }
  .entry-row { grid-template-columns: 1fr 1fr; }
  .entry-row > div { border-right: 0; }
  .entry-row .row-del { justify-items: end; }
}
@media (max-width: 560px) {
  .entry-row { grid-template-columns: 1fr; }
  .cand-thumb { max-width: 160px; }
}

/* ---------------- Halka picker ---------------- */
.halka-strip { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.halka-chip {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border: 1px solid #DFE6EF; border-radius: 10px;
  padding: 9px 14px; cursor: pointer; font-size: 14.5px; color: #23385A;
}
.halka-chip:hover { border-color: #2563EB; }
.halka-chip.on { background: #2C5C96; border-color: #2C5C96; color: #fff; }
.halka-chip .code { font-family: var(--display); font-size: 17px; font-weight: 700; letter-spacing: .03em; }
.halka-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #E0A21A; }
.halka-chip .dot.done { background: #16A34A; }
.halka-chip.add { border-style: dashed; color: #2563EB; font-weight: 600; }

/* ---------------- Dashboard ---------------- */
.stat {
  background: linear-gradient(180deg, #1B3358, #12233E); color: #fff;
  border-radius: 12px; padding: 16px 18px;
}
.stat .k { font-family: var(--display); font-size: 13px; letter-spacing: .16em; text-transform: uppercase; color: #8FA9CC; }
.stat .v { font-family: var(--numeric); font-size: 30px; font-weight: 600; margin-top: 4px; }
.stat .v.g { color: #3CE887; }

.halka-list { display: flex; flex-direction: column; gap: 9px; }
.halka-row {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center;
  border: 1px solid #DFE6EF; border-radius: 10px; padding: 12px 16px; background: #FAFCFF; cursor: pointer;
}
@media (max-width: 560px) {
  .halka-row { grid-template-columns: auto 1fr auto; row-gap: 6px; }
  .halka-row .meta { grid-column: 1 / -1; text-align: left; }
}
.halka-row:hover { border-color: #2563EB; background: #F5F9FF; }
.halka-row .code {
  font-family: var(--display); font-size: 19px; font-weight: 700; color: #fff;
  background: #2C5C96; border-radius: 7px; padding: 3px 10px;
}
.halka-row .nm { font-weight: 600; font-size: 15.5px; }
.halka-row .sub { font-size: 13px; color: #5B738F; }
.halka-row .meta { text-align: right; font-family: var(--numeric); font-size: 13px; color: #5B738F; }
.tag {
  font-family: var(--display); font-size: 12px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; padding: 4px 9px; border-radius: 999px; background: #E4EAF2; color: #5B738F;
}
.tag.win { background: #16A34A; color: #fff; }
.tag.live { background: #F3B32A; color: #241A05; }

.preview {
  width: 100%; max-width: 400px; aspect-ratio: 4/5; border: 0; border-radius: 12px;
  box-shadow: 0 14px 34px rgba(20,36,61,.25); background: #04101F; display: block;
}

/* ---------------- Drop zone ---------------- */
.drop {
  border: 2px dashed #B9CDF0; border-radius: 12px; padding: 30px 22px; text-align: center;
  background: #F5F9FF; transition: .18s var(--ease);
}
.drop.hot { border-color: #16A34A; background: #EFFBF3; }
.drop h3 { font-size: 19px; margin: 0 0 8px; }
.drop p { margin: 0 auto; max-width: 620px; color: #5B738F; font-size: 14px; line-height: 1.6; }
.drop code { background: #E4EAF2; padding: 2px 7px; border-radius: 5px; font-size: 13px; }
.droplog { margin-top: 14px; font-size: 13px; text-align: left; max-height: 200px; overflow: auto; }
.droplog div { padding: 6px 11px; border-radius: 7px; margin-bottom: 4px; background: #E7F5EC; color: #17603A; }
.droplog div.warn { background: #FCF3DF; color: #7A5310; }

/* ---------------- Parties / media ---------------- */
.party-row {
  display: grid; grid-template-columns: 56px 1fr 1fr 110px 120px auto; gap: 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid #EDF2F8;
}
.party-row label.field { margin-bottom: 0; }
.party-row .swatch {
  height: 40px; border-radius: 8px; display: grid; place-items: center; color: #fff;
  font-family: var(--display); font-weight: 700; font-size: 13px; overflow: hidden;
}
.party-row .swatch img { width: 100%; height: 100%; object-fit: cover; }
@media (max-width: 1000px) { .party-row { grid-template-columns: 56px 1fr 1fr; } }
@media (max-width: 560px) {
  .party-row { grid-template-columns: 1fr; text-align: left; padding: 14px 0; }
  .party-row .swatch { width: 56px; }
  .party-row [data-delp] { justify-self: start; }
}

.media-thumb {
  width: 220px; max-width: 100%; height: 165px; border-radius: 10px; object-fit: cover;
  border: 1px solid #D9E1EA; background: #E4EAF2;
}

/* ---------------- Footer contact card ---------------- */
.social-picks { display: flex; gap: 10px; }
.social-picks button {
  width: 44px; height: 44px; border-radius: 9px; padding: 0;
  display: grid; place-items: center; background: #E4EAF2; color: #7C90AB;
}
.social-picks button.on { background: #1B3358; color: #fff; }
.social-picks svg { width: 20px; height: 20px; fill: currentColor; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: #14243D; color: #fff; padding: 13px 22px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .28s var(--ease); z-index: 200;
  box-shadow: 0 14px 40px rgba(0,0,0,.3);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: #C8302F; }

/* ============================================================
   RESPONSIVE OVERHAUL  (mobile-first control room)
   ~95% of operators/viewers are on phones. These rules fix the
   dashboard side-scroll, turn the desk sidebar into a fast
   thumb-friendly tab bar, and size controls for touch. Kept at the
   end so they take precedence over the earlier desk-first rules.
   ============================================================ */

/* Never allow the page to scroll sideways on a phone. */
html, body { overflow-x: hidden; }
.main, .wrap { min-width: 0; max-width: 100%; }

/* ---- Dashboard: two columns on desktop, stacked on smaller screens ----
   (replaces the old hard-coded `1fr 400px` that forced 320px of
   horizontal overflow on a phone). */
.dash-cols { grid-template-columns: minmax(0,1fr) minmax(320px, 400px); }
.dash-preview { position: sticky; top: 88px; }
.dash-preview .preview { max-width: 100%; }
@media (max-width: 980px) {
  .dash-cols { grid-template-columns: 1fr; }
  .dash-preview { position: static; }
  .dash-preview .preview { margin: 0 auto; }
}

/* ---- Entry table labels ----
   Show the per-cell labels only when the column header row is hidden
   (i.e. on the stacked mobile/tablet layout), not duplicated on desktop. */
.entry-row .cell-label { display: none; }
@media (max-width: 1150px) {
  .entry-row .cell-label { display: block; }
}

/* ---- Sidebar becomes a horizontal, swipeable tab bar on phones/tablets ----
   No more scrolling past a tall vertical menu before every action; every
   screen is one thumb-swipe away and the bar stays pinned at the top. */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }

  .side {
    position: sticky; top: 0; z-index: 30;
    height: auto; overflow-x: auto; overflow-y: hidden;
    flex-direction: row; align-items: center; gap: 6px;
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255,255,255,.14);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .side::-webkit-scrollbar { display: none; }

  .side-brand { display: none; }             /* brand still shows in the crumb */

  .nav-item {
    flex: 0 0 auto; width: auto; margin: 0;
    white-space: nowrap; border-radius: 999px;
    padding: 10px 14px; font-size: 13.5px;
  }
  .nav-item svg { width: 18px; height: 18px; }

  .side-foot {
    margin: 0; padding: 0; border: 0;
    display: flex; flex-direction: row; gap: 6px; flex: 0 0 auto;
  }
  .side-foot .mode { display: none; }        /* status shown by the ONLINE pill */

  /* One sticky bar is enough on a small screen — let the status bar scroll
     away so the tab bar isn't fighting it for the top edge. */
  .statusbar { position: static; }
}

/* ---- Touch sizing: bigger tap targets, and 16px inputs so iOS Safari
   doesn't zoom in when a field is focused. ---- */
@media (max-width: 640px) {
  input[type=text], input[type=number], input[type=password], select, textarea {
    font-size: 16px;
  }
  .entry-row input, .entry-row select { font-size: 16px; }
  .page-title { font-size: 24px; }
  .wrap { padding: 18px 13px 46px; }
}
@media (hover: none), (pointer: coarse) {
  .nav-item { min-height: 44px; }
  button { min-height: 42px; }
  button.sm { min-height: 38px; }
  .vote-step button { min-height: 44px; font-size: 20px; }
  .row-del button { min-height: 40px; min-width: 40px; }
  .social-picks button { width: 48px; height: 48px; }
}
