/* =========================================================
   cards.css - FINAL NEW VERSION
   Proper Scroll + Download Bar + Bottom Nav Safe
   Replace complete cards.css with this
========================================================= */

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #f6f9ff;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #2563eb;
  --brand2: #0ea5e9;
  --radius: 22px;
}

/* =========================================================
   APP SCROLL FIX
   Body scroll nahi karega, main.page scroll karega
========================================================= */

html,
body {
  width: 100% !important;
  height: 100% !important;
  min-height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.mode-pre,
body {
  height: 100dvh !important;
  min-height: 100dvh !important;
  display: flex !important;
  flex-direction: column !important;
  position: relative !important;
  overflow: hidden !important;
}

/* =========================================================
   TOPBAR
========================================================= */

.topbar {
  position: relative !important;
  top: auto !important;
  flex: 0 0 auto !important;
  z-index: 30 !important;
  background: linear-gradient(180deg, #fff, rgba(255, 255, 255, 0.92));
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  backdrop-filter: blur(10px);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.18);
  flex: 0 0 auto;
}

.brandTxt {
  min-width: 0;
}

.brandName {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.1;
}

.brandSub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.topBtns {
  display: flex;
  gap: 10px;
}

.iconBtn {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
  color: inherit;
  flex: 0 0 auto;
}

.iconBtn:active {
  transform: scale(0.98);
}

.backBtn {
  text-decoration: none;
  color: inherit;
}

/* =========================================================
   MAIN PAGE - REAL SCROLL CONTAINER
========================================================= */

main.page,
.page {
  flex: 1 1 auto !important;
  height: 0 !important;
  min-height: 0 !important;
  max-height: none !important;

  width: 100%;
  max-width: 920px;
  margin: 0 auto;

  padding: 14px;
  padding-bottom: calc(220px + env(safe-area-inset-bottom)) !important;

  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch !important;

  box-sizing: border-box !important;
}

/* Bottom fixed bars ke liye extra blank space */
.spaceBottom {
  display: block !important;
  width: 100% !important;
  height: calc(220px + env(safe-area-inset-bottom)) !important;
  min-height: calc(220px + env(safe-area-inset-bottom)) !important;
}

/* =========================================================
   MINI PROFILE
========================================================= */

.miniProfile {
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.06);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.06);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mpLeft {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: #fff;
  overflow: hidden;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.avatarFallback {
  width: 100%;
  height: 100%;
  font-size: 24px;
  display: grid;
  place-items: center;
}

.mpTxt {
  min-width: 0;
}

.mpName {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.mpSub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.editBtn {
  text-decoration: none;
  border: none;
  padding: 10px 14px;
  border-radius: 16px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  color: #fff;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.12);
  white-space: nowrap;
  flex: 0 0 auto;
}

.editBtn:active {
  transform: scale(0.98);
}

/* =========================================================
   TABS
========================================================= */

.tabStrip {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.tabStrip::-webkit-scrollbar {
  display: none;
}

.tab {
  border: none;
  background: rgba(15, 23, 42, 0.06);
  color: rgba(15, 23, 42, 0.78);
  font-weight: 700;
  font-size: 13px;
  padding: 10px 15px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}

.tab.active {
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  color: #fff;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
}

/* =========================================================
   PANELS
========================================================= */

.panel {
  margin-top: 12px;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.06);
  box-shadow: 0 16px 45px rgba(15, 23, 42, 0.06);
  border-radius: var(--radius);
  padding: 12px;
  overflow: hidden;
}

.panelHead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.phTitle {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.15;
}

.phSub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
  white-space: nowrap;
}

/* =========================================================
   CANVAS
========================================================= */

.canvasWrap {
  display: flex;
  justify-content: center;
  width: 100%;
  overflow: visible;
}

.canvas {
  position: relative;
  width: min(92vw, 520px);
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: #fff;
  box-shadow: 0 16px 45px rgba(15, 23, 42, 0.08);
  transform: none !important;
  will-change: auto !important;
}

.canvas.idcard {
  aspect-ratio: 3 / 5;
}

.canvas.visiting {
  width: min(92vw, 720px);
  aspect-ratio: 16 / 9;
}

.canvas.cert {
  width: min(92vw, 720px);
  aspect-ratio: 7 / 10;
}

.canvas,
.canvas * {
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

.bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* =========================================================
   TIP
========================================================= */

.tip {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: rgba(15, 23, 42, 0.02);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}

/* =========================================================
   COMMON FIT TEXT
========================================================= */

.fitText {
  position: absolute;
  z-index: 3;
  color: rgba(15, 23, 42, 0.92);
  line-height: 1.05;
  min-width: 0;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.wrapText {
  white-space: normal;
  line-height: 1.14;
}

/* =========================================================
   ID CARD
========================================================= */

.idcard .photoRing {
  position: absolute;
  left: 50%;
  top: 35%;
  transform: translate(-50%, -50%);
  width: 25.5%;
  aspect-ratio: 1 / 1;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.16);
  overflow: hidden;
  background: #fff;
  display: grid;
  place-items: center;
  z-index: 3;
}

.idcard .photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.idcard .photoFallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 32px;
}

.idcard .tName {
  left: 50%;
  top: 52%;
  width: 78%;
  height: 5.2%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 500;
}

.idcard .tRole {
  left: 50%;
  top: 55.7%;
  width: 76%;
  height: 3.8%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 700;
  color: rgba(15, 23, 42, 0.78);
}

.idcard .row {
  position: absolute;
  left: 25%;
  width: 62%;
  transform: translateY(-50%);
  z-index: 3;
}

.idcard .row .txt {
  position: relative;
  width: 100%;
  transform: none !important;
  display: flex;
  align-items: center;
  font-weight: 600;
}

.idcard .rPhone {
  top: 64.5%;
  height: 4.2%;
}

.idcard .rEmail {
  top: 69%;
  height: 4.2%;
}

.idcard .rAddr {
  top: 75%;
  height: 7%;
}

.idcard .rAddr .txt {
  align-items: flex-start;
  white-space: normal;
  line-height: 1.14;
}

.idcard .rRef {
  position: absolute;
  left: 72%;
  top: 82.5%;
  width: 44%;
  height: 3.4%;
  transform: translate(-50%, -50%);
  z-index: 3;
  text-align: center;
}

.idcard .rRef .txt {
  position: relative;
  width: 100%;
  height: 100%;
  transform: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  letter-spacing: 0.4px;
}

/* =========================================================
   VISITING CARD
========================================================= */

.visitGrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.visitBox {
  background: rgba(15, 23, 42, 0.02);
  border: 1px solid rgba(15, 23, 42, 0.06);
  border-radius: 18px;
  padding: 10px;
}

.visitTag {
  display: inline-flex;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  margin-bottom: 8px;
}

.visiting .vName {
  left: 50%;
  top: 35.2%;
  width: 58%;
  height: 13%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #1f2937;
  font-weight: 600;
  line-height: 0.96;
  letter-spacing: -0.2px;
}

.visiting .vPhone {
  left: 10.4%;
  top: 76.8%;
  width: 28%;
  height: 5.2%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  color: #0f172a;
  font-weight: 400;
  line-height: 1;
}

.visiting .vEmail {
  left: 10.4%;
  top: 83.2%;
  width: 31%;
  height: 4.8%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  color: #0f172a;
  font-weight: 300;
  line-height: 1;
}

/* =========================================================
   CERTIFICATE
========================================================= */

.cert .cLine {
  transform: translate(0, -50%);
  font-weight: 500;
  color: rgba(15, 23, 42, 0.92);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#cApp {
  left: 33%;
  top: 68%;
  width: 52%;
}

#cOwner {
  left: 33%;
  top: 71%;
  width: 52%;
}

#cInstitute {
  left: 30%;
  top: 60%;
  width: 55%;
}

#cAddr {
  left: 33%;
  top: 74%;
  width: 52%;
  white-space: normal;
  line-height: 1.12;
}

#cRegDate {
  left: 33%;
  top: 76.5%;
  width: 52%;
}

/* =========================================================
   DOWNLOAD BAR + BOTTOM NAV
========================================================= */

.downloadBar {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: calc(66px + env(safe-area-inset-bottom)) !important;
  z-index: 70 !important;
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.90);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(15, 23, 42, 0.06);
}

.btnGhost,
.btnPrimary {
  flex: 1;
  border: none;
  border-radius: 16px;
  padding: 12px 12px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}

.btnGhost {
  background: rgba(15, 23, 42, 0.06);
  color: rgba(15, 23, 42, 0.78);
}

.btnPrimary {
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  color: #fff;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.12);
}

.btnGhost:active,
.btnPrimary:active {
  transform: scale(0.98);
}

.bottomNav {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  z-index: 80 !important;
}

/* =========================================================
   RESPONSIVE
========================================================= */

@media (min-width: 980px) {
  .visitGrid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 430px) {
  main.page,
  .page {
    padding: 12px;
    padding-bottom: calc(235px + env(safe-area-inset-bottom)) !important;
  }

  .spaceBottom {
    height: calc(235px + env(safe-area-inset-bottom)) !important;
    min-height: calc(235px + env(safe-area-inset-bottom)) !important;
  }

  .panel,
  .miniProfile {
    padding: 10px;
  }

  .mpName {
    max-width: 145px;
  }

  .editBtn {
    padding: 10px 12px;
    font-size: 13px;
  }

  .visiting .vName {
    width: 60%;
    height: 13%;
  }

  .visiting .vPhone {
    width: 29%;
  }

  .visiting .vEmail {
    width: 32%;
  }
}

@media (max-width: 360px) {
  .brandName {
    font-size: 16px;
  }

  .brandSub,
  .mpSub,
  .phSub {
    font-size: 11px;
  }

  .btnGhost,
  .btnPrimary {
    font-size: 14px;
  }

  .miniProfile {
    align-items: flex-start;
  }

  .editBtn {
    font-size: 12px;
    padding: 9px 10px;
  }
}