:root {
  --navy: #0b3d91;
  --navy-dark: #082b67;
  --amber: #ffb300;
  --bg: #f5f7fa;
  --card: #ffffff;
  --line: #e3e8ef;
  --text: #1c2733;
  --muted: #6b7a8d;
  --green: #14804a;
  --red: #c62828;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: normal; font-size: 13px; }
.error { color: var(--red); font-size: 14px; min-height: 1em; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 320px; text-align: center; }
.brand-lg { font-size: 26px; font-weight: 800; color: var(--navy); }
.login-card input { width: 100%; margin: 16px 0 12px; }

/* Header */
header {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 800; font-size: 18px; }
.brand span { opacity: .7; font-weight: 400; font-size: 14px; }
nav { display: flex; gap: 6px; flex: 1; }
.tab {
  background: transparent; border: 0; color: #cddcff;
  padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.tab.active, .tab:hover { background: rgba(255,255,255,.14); color: #fff; }

main { max-width: 1180px; margin: 0 auto; padding: 20px; }

/* Cards & stats */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 800; margin-top: 4px; color: var(--navy); }
.stat.alert .value { color: var(--red); }

/* Forms */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; align-items: end; }
label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }
input, select {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 14px; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid #cfe0ff; border-color: var(--navy); }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 9px 14px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.btn:hover { border-color: #b9c6d8; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--navy-dark); }
.btn.danger { background: #fff1f1; border-color: #f3c2c2; color: var(--red); }
.btn.warn { background: #fff8e6; border-color: #f2ddaa; color: #8a6100; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.4); color: #fff; }
.btn.small { padding: 5px 9px; font-size: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fafd; }
td .actions { display: flex; gap: 6px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.active { background: #e3f5ec; color: var(--green); }
.badge.grace { background: #fff4d6; color: #8a6100; }
.badge.locked { background: #fdecea; color: var(--red); }
.badge.released { background: #eceff3; color: #4b5a6c; }
.badge.unknown, .badge.pending { background: #eceff3; color: #4b5a6c; }
/* P3: FRP sign-in window — tabular digits while counting, urgent when the
   phone has stopped reporting it (see frpWindowTag in app.js). */
[data-frp-until] .frp-countdown { font-variant-numeric: tabular-nums; }
[data-frp-until].overdue { background: #fdecea; color: var(--red); }

.code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: #eef3fb; padding: 3px 7px; border-radius: 5px; font-size: 13px;
}
.result {
  margin-top: 14px; padding: 12px; border-radius: 8px;
  background: #e3f5ec; border: 1px solid #bfe6d2; font-size: 14px;
}
.result b { color: var(--green); }
pre.qr {
  background: #0f1b30; color: #cfe0ff; padding: 12px; border-radius: 8px;
  overflow: auto; font-size: 12px; margin-top: 10px; white-space: pre-wrap;
}
/* Expandable customer detail row (six tabs) */
.detail-row td { background: #f8fafd; }
.ctabs {
  display: flex; flex-wrap: wrap; gap: 4px;
  border-bottom: 2px solid var(--line); margin-bottom: 14px; padding-bottom: 0;
}
.ctab {
  background: none; border: 0; border-bottom: 3px solid transparent;
  padding: 7px 13px; font-size: 13.5px; font-weight: 600; color: var(--muted);
  cursor: pointer; margin-bottom: -2px; border-radius: 6px 6px 0 0;
}
.ctab:hover { color: var(--text); background: #eef3fb; }
.ctab.active { color: var(--navy); border-bottom-color: var(--navy); }
.cpane h3 {
  font-size: 13.5px; margin: 16px 0 8px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.cpane h3:first-child { margin-top: 0; }

/* Fact lists (Device / Customer / EMI Details panes) */
.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px 18px; margin: 0;
}
.facts > div { min-width: 0; }
.facts dt {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); margin-bottom: 2px;
}
.facts dd { margin: 0; font-size: 14px; word-break: break-word; }
.facts dd .btn { margin-left: 6px; vertical-align: middle; }

/* Log + Offline Codes lists inside a customer's detail row */
.loglist { list-style: none; padding: 0; margin: 6px 0 0; font-size: 13.5px; }
.loglist li {
  padding: 6px 0; border-bottom: 1px dashed var(--line);
  display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline;
}
.loglist li:last-child { border-bottom: 0; }
.loglist .code { font-size: 12.5px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; font-size: 13px; display: flex; gap: 8px; align-items: center;
}
.chip.paid { background: #e3f5ec; border-color: #bfe6d2; color: var(--green); }
.chip.overdue { background: #fdecea; border-color: #f3c2c2; color: var(--red); }

/* Expandable device-controls panel */
.controls-row td { background: #f7f9fc; border-bottom: 2px solid var(--line); }
.ctrl-grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.ctrl-group.wide { grid-column: 1 / -1; }
.ctrl-group h3 { font-size: 14px; margin-bottom: 8px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ctrl-list { display: flex; flex-direction: column; gap: 6px; }

/* FRP pin editor (admin controls panel) — label/input come pre-styled from the
   global `label` rule, so only the grid wrapper and the inline checkbox label
   need anything here. */
.frp-form {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  align-items: end;
}
.frp-form label.inline { flex-direction: row; align-items: center; gap: 6px; }
.frp-form .btn { justify-self: start; }

.ctrl {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left; padding: 8px 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 7px;
  cursor: pointer; font-size: 13.5px; color: var(--text);
}
.ctrl:hover { border-color: #b9c6d8; }
.ctrl.active { border-color: #bfe6d2; background: #f4fbf7; }
.ctrl-label { font-weight: 600; }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; color: var(--muted); }
.switch i {
  width: 30px; height: 17px; border-radius: 999px; background: #cbd4e0;
  position: relative; transition: background .15s; flex: none;
}
.switch i::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 13px; height: 13px; border-radius: 50%; background: #fff;
  transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.switch.on { color: var(--green); }
.switch.on i { background: var(--green); }
.switch.on i::after { transform: translateX(13px); }

.action-row { display: flex; flex-wrap: wrap; gap: 7px; }
.action-row .btn { font-size: 12.5px; }
.action-row .btn b { font-weight: 800; opacity: .65; margin-left: 3px; }
.action-status { margin-top: 9px; font-size: 13px; }

.recent-actions { margin-top: 8px; font-size: 13px; }
.recent-actions summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
.recent-actions ul { margin: 7px 0 0; padding-left: 16px; }
.recent-actions li { margin-bottom: 5px; word-break: break-word; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #10233f; color: #fff; padding: 11px 18px; border-radius: 8px;
  font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.25); z-index: 50;
}
.toast.err { background: #8e1b1b; }

@media (max-width: 720px) {
  header { flex-wrap: wrap; gap: 8px; }
  nav { order: 3; width: 100%; }
}

/* Roles: header role tag (there is ONE sign-in card now) */
.login-wrap { gap: 14px; }
#whoami { font-size: 12.5px; white-space: nowrap; }

/* Retailer 2-step enrollment QR wizard + per-customer provisioning QR modal */
.whead { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.wnum {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto;
  background: var(--navy); color: #fff; font-size: 13px; font-weight: 800;
}
.wstep + .wstep { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
.wactions { display: flex; justify-content: flex-end; margin-top: 12px; }
.qrcode img { max-width: 100%; height: auto; image-rendering: pixelated; }
.install-qr { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.install-qr .qrcode img { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.install-qr > div:last-child { flex: 1; min-width: 240px; }
.break { word-break: break-all; }
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: flex;
  align-items: center; justify-content: center; z-index: 60; padding: 16px; }
.modal-card { width: min(430px, 94vw); text-align: center; }
.modal-card .qrcode { margin: 14px auto; }
.modal-card .qrcode img, .modal-card .qrcode span { background: #fff; padding: 8px;
  border: 1px solid var(--line); border-radius: 10px; display: inline-block; }
.modal-card .btn { margin-top: 6px; }

/* Device location map modal + fix lines in the controls panels */
.map-card { width: min(560px, 94vw); text-align: left; }
.map-card h2, .map-card p, .map-card a { text-align: center; }
.map-frame iframe { width: 100%; height: 300px; border: 1px solid var(--line);
  border-radius: 8px; background: #eef1f5; }
.loc-fix { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 13px; margin-top: 4px; }
.loc-fix .code { font-size: 12.5px; }
.loc-history { margin-top: 6px; font-size: 12.5px; }
.loc-history summary { cursor: pointer; color: var(--muted); }
.loc-history ul { margin: 6px 0 0; padding-left: 16px; }
.loc-history li { margin-bottom: 4px; }
.loc-history button { background: none; border: 0; color: var(--navy); cursor: pointer;
  font: inherit; text-decoration: underline; padding: 0; }

/* Inline account-edit row (Accounts tab) */
.edit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px; align-items: end; }
.edit-actions { display: flex; gap: 8px; align-items: center; }
.edit-row td { background: #f4f8ff; }

/* ---- Table search boxes (Customer ledger / My customers) ---- */
.table-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.table-tools input { flex: 1 1 260px; max-width: 460px; margin: 0; }
.table-tools .muted { white-space: nowrap; }

/* ---- Key status chips (Accounts / My enroll keys) ---- */
.badge.consumed { background: #f2e9fd; color: #6b21a8; }
.badge.drawn { background: #fff4d6; color: #8a6100; }

/* ---- Retailer Profile tab ---- */
.profile-head { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.profile-title { font-size: 18px; font-weight: 700; color: var(--navy); }
.avatar {
  width: 64px; height: 64px; border-radius: 50%; flex: 0 0 auto; overflow: hidden;
  background: var(--navy); color: #fff; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 800;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.empty { background: #eef2f7; color: var(--muted); font-size: 20px; }
.avatar.small { width: 34px; height: 34px; font-size: 14px; }
.grid .wide { grid-column: 1 / -1; }
.payqr-row { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.payqr-side { flex: 1 1 280px; min-width: 240px; }
.payqr-side .btn { margin-top: 8px; }
#payQrPreview img {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px; max-width: 180px; height: auto; image-rendering: pixelated;
}

/* ---------- Branding: LetzPay Locker logo ---------- */
.brand-logo {
  width: 34px; height: 34px; border-radius: 8px; object-fit: cover;
  vertical-align: middle; margin-right: 8px; background: #fff;
}
.brand-lg .brand-logo {
  width: 64px; height: 64px; border-radius: 16px;
  display: block; margin: 0 auto 10px;
}

/* Pager under the long tables (Recent activity / Accounts / Enroll keys):
   10 rows at a time, so a page is a glanceable list. */
.table-pager {
  display: flex; align-items: center; gap: 8px; justify-content: flex-end;
  margin-top: 10px; font-size: 12.5px;
}
.table-pager .page-of { color: var(--muted); min-width: 70px; text-align: center; }
.table-pager button:disabled { opacity: .4; cursor: default; }

/* Legal links under the sign-in cards */
.login-legal { margin: 2px 0 0; font-size: 12.5px; }
.login-legal a { color: var(--navy); text-decoration: none; }
.login-legal a:hover { text-decoration: underline; }
.login-legal span { margin: 0 6px; }

/* Customer photo: thumbnail beside the name, click enlarges */
.cust-name { display: flex; align-items: center; gap: 8px; }
.cust-name .avatar { cursor: zoom-in; flex: 0 0 auto; }
.cust-name .avatar:hover { border-color: var(--navy); box-shadow: 0 0 0 2px rgba(15,23,42,.15); }
.photo-card { width: min(560px, 94vw); }
.photo-card #photoBig {
  max-width: 100%; max-height: 60vh; display: block; margin: 8px auto;
  border-radius: 10px; background: #eef2f7;
}

/* Live preview beside the photo picker in the "New customer" forms */
.photo-preview img {
  width: 64px; height: 64px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--line); display: block;
}

/* ---------- Security alerts (Overview → "Needs attention") ---------- */
#navAlertChip { margin-left: 6px; font-size: 11px; padding: 1px 7px; }
#alertsCount { font-size: 13px; font-weight: 600; }
/* An open alert reads as a live item; an acknowledged one goes neutral. */
#alertsTable tr.open td { background: #fff8f7; }
#alertsTable tr.open td:first-child { box-shadow: inset 3px 0 0 var(--red); }
