/* Safety Pay — shared look (light theme, indigo + teal brand).
   Brand: indigo #3a3587, teal #438e98. Logo files in /static/brand/. */
@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,500;0,600;0,700;1,800&display=swap");

:root {
  --bg: #f4f5fa;
  --panel: #ffffff;
  --panel-2: #f1f2fa;
  --line: #e3e5f1;
  --text: #1b1c3a;
  --muted: #6b6f8e;
  --brand: #3a3587;
  --brand-2: #5550b0;
  --brand-soft: #ecebf7;
  --teal: #438e98;
  --teal-soft: #e3f1f3;
  --gold: #d0a845;
  --gold-soft: #faf3e0;
  --green: #16a34a;
  --green-soft: #e3f6ea;
  --amber: #c27803;
  --amber-soft: #fdf3dc;
  --red: #e5484d;
  --red-soft: #fde8e8;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(27,28,58,.05), 0 4px 16px rgba(27,28,58,.06);
  --head: "Poppins", -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, .stat .value, .brandmark { font-family: var(--head); }
a { color: var(--brand); }

/* ---------- Brand ---------- */
.brandmark { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.brandmark img { width: 34px; height: 34px; }
.brandmark img.logo { width: auto; height: 32px; display: block; }
.brandmark .wm { font-size: 22px; font-weight: 800; font-style: italic; letter-spacing: -.5px; line-height: 1; }
.brandmark .wm b { color: var(--brand); font-weight: 800; }
.brandmark .wm span { color: var(--teal); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 10px; }
.topbar .tag { color: var(--muted); font-size: 12px; font-family: -apple-system, "Segoe UI", Roboto, sans-serif; font-weight: 500; }
.topbar .nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topbar a.link {
  font-size: 13px; color: var(--muted); text-decoration: none; padding: 7px 10px; border-radius: 10px;
}
.topbar a.link:hover { background: var(--panel-2); color: var(--text); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 22px 24px; }

/* ---------- Welcome hero ---------- */
.hero {
  background: linear-gradient(120deg, var(--brand) 0%, var(--brand-2) 70%, #6d5fe0 100%);
  color: #fff; border-radius: 20px; padding: 20px 22px; margin-bottom: 18px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  box-shadow: 0 8px 24px rgba(58,53,135,.25); position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -60px; width: 220px; height: 220px;
  border-radius: 50%; background: rgba(67,142,152,.28);
}
.hero h2 { margin: 0; font-size: 22px; position: relative; z-index: 1; }
.hero p { margin: 4px 0 0; opacity: .85; font-size: 13px; position: relative; z-index: 1; }
.hero button.primary {
  background: var(--teal); border-color: var(--teal); color: #fff; font-weight: 700;
  padding: 12px 18px; font-size: 15px; position: relative; z-index: 1; box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.hero button.primary:hover { filter: brightness(1.05); }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center;
  cursor: default; text-align: left; color: var(--text);
}
button.stat { cursor: pointer; font: inherit; }
button.stat:hover { border-color: var(--brand); }
button.stat.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft), var(--shadow); }
.stat .ico {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: inline-flex; align-items: center; justify-content: center; font-size: 19px;
  background: var(--brand-soft);
}
.stat.t-teal .ico { background: var(--teal-soft); }
.stat.t-green .ico { background: var(--green-soft); }
.stat.t-red .ico { background: var(--red-soft); }
.stat.t-amber .ico { background: var(--amber-soft); }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.stat .value { font-size: 24px; font-weight: 700; line-height: 1.15; }

/* ---------- Toolbar / search ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.search {
  flex: 1 1 260px; display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px;
}
.search input { border: 0; background: transparent; padding: 11px 0; box-shadow: none !important; }
.search input:focus { outline: none; }

/* ---------- Buttons ---------- */
button {
  font: inherit; cursor: pointer; border: 1px solid var(--line);
  background: var(--panel); color: var(--text);
  padding: 9px 14px; border-radius: 12px; font-weight: 600;
  transition: border-color .15s, background .15s, filter .15s;
}
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { filter: brightness(1.1); }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.ok { background: var(--green); border-color: var(--green); color: #fff; }
button.ghost { background: transparent; }
button.small { padding: 6px 10px; font-size: 12px; border-radius: 10px; }
button:disabled { opacity: .5; cursor: default; }

/* ---------- Cards / tables ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; font-size: 14px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); }
tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: var(--panel-2); cursor: pointer; }

/* ---------- Customer cards (dealer list) ---------- */
.clist { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.ccard {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); overflow: hidden; cursor: pointer; display: flex; flex-direction: column;
  transition: transform .12s, box-shadow .12s;
}
.ccard:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(27,28,58,.10); }
.ccard .top {
  display: flex; gap: 12px; align-items: center; padding: 14px 14px 10px;
  border-left: 5px solid var(--teal);
}
.ccard.is-locked .top { border-left-color: var(--red); }
.ccard.is-done .top { border-left-color: var(--muted); }
.ccard.is-pending .top { border-left-color: var(--amber); }
.ccard .who { min-width: 0; flex: 1; }
.ccard .name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccard .devid { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--brand); font-weight: 600; }
.ccard .meta {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; padding: 0 14px 12px 19px;
  font-size: 12.5px; color: var(--muted);
}
.ccard .meta div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccard .foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-top: 1px solid var(--line); background: var(--panel-2); margin-top: auto;
}
.ccard .badges { display: flex; gap: 5px; flex-wrap: wrap; }
.ccard .foot button { padding: 8px 16px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.active { background: var(--green-soft); color: var(--green); }
.badge.locked { background: var(--red-soft); color: var(--red); }
.badge.overdue { background: var(--amber-soft); color: var(--amber); }
.badge.paid { background: var(--teal-soft); color: #0f7f73; }
.badge.pending { background: var(--panel-2); color: var(--muted); }

/* ---------- Modals ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(20,18,50,.45);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.overlay.show { display: flex; }
.modal {
  background: var(--panel); border-radius: 20px; box-shadow: 0 20px 60px rgba(20,18,50,.25);
  width: 100%; max-width: 580px; max-height: 90vh; overflow: auto;
}
.modal header {
  padding: 16px 20px; border-bottom: 1px solid var(--line); display:flex; justify-content:space-between; align-items:center;
  position: sticky; top: 0; background: var(--panel); z-index: 2; font-family: var(--head);
}
.modal .body { padding: 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display:flex; gap:10px; justify-content:flex-end; position: sticky; bottom: 0; background: var(--panel); }

/* Detail: profile header + tabs */
.dhead {
  display: flex; gap: 14px; align-items: center; padding: 16px 20px; margin: -20px -20px 0;
  background: linear-gradient(120deg, var(--brand), var(--brand-2)); color: #fff;
}
.dhead .dname { font-family: var(--head); font-weight: 700; font-size: 17px; }
.dhead .devid { font-family: ui-monospace, Menlo, monospace; font-size: 13px; opacity: .9; }
.dhead button.small { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.35); color: #fff; margin-top: 6px; }
.tabs { display: flex; gap: 6px; margin: 14px 0 12px; background: var(--panel-2); padding: 4px; border-radius: 12px; }
.tabs button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px 6px; }
.tabs button.on { background: var(--panel); color: var(--brand); box-shadow: var(--shadow); }
.tabpane { display: none; }
.tabpane.on { display: block; }
.cmdgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cmd {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  padding: 14px; border-radius: 14px; min-height: 84px;
}
.cmd .ci { font-size: 22px; line-height: 1; }
.cmd small { font-weight: 500; opacity: .85; font-size: 11.5px; }
.cmd.ghost { background: var(--panel-2); }
.cmd.wide { grid-column: 1 / -1; }
.cmd.redline { border-color: var(--red); color: var(--red); background: var(--red-soft); }

label { display:block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; font-weight: 500; }
input, select {
  width: 100%; font: inherit; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.grid2 { display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.muted { color: var(--muted); }
.notice {
  background: var(--brand-soft); border: 1px solid #d6d2f6;
  color: #3a3480; padding: 10px 12px; border-radius: 12px; font-size: 13px; margin-bottom: 16px;
}
.detail-head { display:flex; justify-content:space-between; align-items:flex-start; gap: 16px; }
.kv { display:grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; margin: 10px 0; }
.kv .k { color: var(--muted); }
.logs { font-size: 12px; color: var(--muted); max-height: 220px; overflow:auto; margin-top: 8px; }
.logs div { padding: 6px 0; border-bottom: 1px solid var(--line); }
.empty { padding: 40px; text-align:center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- Responsive / mobile ---------- */
@media (max-width: 900px){
  .stats { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px){
  .topbar { padding: 10px 14px; }
  .topbar .who, .topbar .custview { display: none; }
  .brandmark img { width: 30px; height: 30px; }
  .brandmark .wm { font-size: 19px; }
  .wrap { padding: 14px; }
  .hero { padding: 16px; border-radius: 18px; }
  .hero h2 { font-size: 19px; }
  .hero button.primary { width: 100%; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
  .stat { padding: 11px 12px; gap: 10px; }
  .stat .ico { width: 36px; height: 36px; font-size: 17px; }
  .stat .value { font-size: 20px; }
  .grid2 { grid-template-columns: 1fr; }
  table { min-width: 560px; }
  th, td { padding: 10px 12px; font-size: 13px; }
  .clist { grid-template-columns: 1fr; gap: 12px; }
  .notice { font-size: 12px; padding: 8px 10px; margin-bottom: 12px; }
  .overlay { padding: 0; align-items: flex-end; }
  .modal { max-width: none; max-height: 94vh; border-radius: 20px 20px 0 0; }
  .modal .body { padding: 16px; }
  .dhead { margin: -16px -16px 0; padding: 14px 16px; }
  .modal footer { flex-wrap: wrap; }
  .modal footer button { flex: 1 1 auto; }
  .kv { grid-template-columns: 112px 1fr; gap: 6px 10px; font-size: 13px; word-break: break-word; }
  .detail-head { flex-direction: column; }
}
@media (max-width: 370px){
  .stat .ico { display: none; }
}

/* ---------- Mobile-first extras: bottom nav, big touch targets ---------- */
.bnav { display: none; }
@media (max-width: 760px){
  body.has-bnav { padding-bottom: 84px; }
  .bnav {
    display: grid; grid-template-columns: 1fr 1.2fr 1fr; align-items: end;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--panel); border-top: 1px solid var(--line);
    padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 18px rgba(27,28,58,.08);
  }
  .bnav button {
    border: 0; background: transparent; color: var(--muted); padding: 6px 4px;
    display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11.5px; font-weight: 600;
  }
  .bnav button .bi { font-size: 21px; line-height: 1; }
  .bnav button.on { color: var(--brand); }
  .bnav button.sell {
    background: var(--teal); color: #fff; border-radius: 16px; margin-top: -22px; padding: 10px 6px;
    box-shadow: 0 6px 16px rgba(67,142,152,.45); font-size: 12px;
  }
  .hero .heroBtn { display: none; }
  .stats > :first-child { grid-column: 1 / -1; }
  input, select { font-size: 16px; }          /* stops iPhone zoom on tap */
  button { min-height: 42px; }
  button.small { min-height: 34px; }
  .toolbar .search { flex-basis: 100%; }
  .toolbar > button { flex: 1 1 40%; }
  .ccard .name { font-size: 16px; }
  .ccard .foot button { padding: 10px 18px; font-size: 15px; }
  .tabs button { font-size: 12.5px; padding: 10px 2px; }
  .cmd { min-height: 92px; font-size: 15px; }
  .topbar a.link { padding: 8px; }
}
@media (max-width: 760px){
  /* compact one-row numbers, like a phone app home screen */
  .stats { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .stats > :first-child { grid-column: auto; }
  .stat { flex-direction: column; gap: 2px; padding: 9px 4px 8px; text-align: center; border-radius: 14px; min-height: 0; }
  .stat .ico { width: 28px; height: 28px; font-size: 14px; border-radius: 9px; display: inline-flex; }
  .stat .value { font-size: 19px; order: 2; }
  .stat .label { font-size: 10.5px; line-height: 1.2; }
  .stat > span:last-child { display: flex; flex-direction: column-reverse; align-items: center; }
  .toolbar { flex-wrap: nowrap; }
  .toolbar .search { flex: 1 1 auto; min-width: 0; }
  .toolbar > button { flex: none; }
  #trashBtn { display: none; }
  .brandmark .wm { font-size: 21px; }
}
@media (max-width: 370px){ .stat .ico { display: none; } }
@media (max-width: 760px){
  .modal table { min-width: 0; }
  .modal th, .modal td { padding: 9px 8px; font-size: 12.5px; }
  .tabs button { white-space: nowrap; }
}
.tabs button:hover { border-color: transparent; color: var(--brand); }
.ccard .foot button { white-space: nowrap; flex: none; }

/* Financier (bank / NBFC) picker: search + free text + logo */
.fin-box { position: relative; }
.fin-box input { padding-left: 46px; }
.fin-logo { position:absolute; left:10px; top:50%; transform:translateY(-50%); width:26px; height:26px; pointer-events:none; }
.fin-list { position:absolute; z-index:30; left:0; right:0; top:calc(100% + 4px); max-height:260px; overflow:auto;
  background: var(--panel); border:1px solid var(--line); border-radius:12px; box-shadow:0 8px 24px rgba(0,0,0,.15); }
.fin-opt { display:flex; align-items:center; gap:10px; padding:9px 12px; cursor:pointer; font-size:14px; }
.fin-opt:hover, .fin-opt.on { background: var(--brand-soft); }
.fin-opt small { color: var(--muted); }
.bank-ico { width:26px; height:26px; border-radius:7px; object-fit:contain; background:#fff; flex:none; vertical-align:middle; }
.bank-ini { display:inline-flex; align-items:center; justify-content:center; width:26px; height:26px; border-radius:7px;
  color:#fff; font-size:11px; font-weight:700; flex:none; vertical-align:middle; }
.fin-list.up { top:auto; bottom:calc(100% + 4px); }
