@import url('https://fonts.googleapis.com/css2?family=Almarai:wght@400;700;800&family=Cairo:wght@400;600;700;800&family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&family=Tajawal:wght@400;500;700;800;900&display=swap');

:root {
  --brisk-purple: #4c2481;
  --brisk-purple-dark: #34165c;
  --brisk-purple-soft: #f5f0fc;
  --brisk-gold: #e6b036;
  --brisk-gold-soft: #fdf8ea;
  --bg-page: #f6f7fb;
  --surface: #ffffff;
  --border: #e6e8f0;
  --text-main: #1d1a2c;
  --text-muted: #656178;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-sm: 0 2px 10px rgba(32, 18, 60, 0.05);
  --shadow-card: 0 18px 42px rgba(45, 20, 82, 0.14);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: 'Tajawal', sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
}

a { color: inherit; text-decoration: none; }

/* ---------------- Top Header ---------------- */
.topbar {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 60;
}
.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-lockup img {
  height: 40px;
  width: auto;
  object-fit: contain;
}
.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  color: var(--brisk-purple);
  line-height: 1.2;
}
.brand-text span {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--brisk-purple);
  color: #fff;
  box-shadow: 0 6px 16px rgba(76, 36, 129, 0.22);
}
.btn-primary:hover { background: var(--brisk-purple-dark); transform: translateY(-1px); }
.btn-gold {
  background: var(--brisk-gold);
  color: #26143d;
}
.btn-gold:hover { filter: brightness(0.96); transform: translateY(-1px); }
.btn-outline {
  background: #fff;
  border-color: var(--border);
  color: var(--text-main);
}
.btn-outline:hover { border-color: var(--brisk-purple); color: var(--brisk-purple); background: var(--brisk-purple-soft); }
.btn-danger {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-icon { padding: 7px 9px; }

/* ---------------- Status Badges ---------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
}
.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.status-active { background: #ecfdf5; color: #059669; border: 1px solid #a7f3d0; }
.status-trainee { background: var(--brisk-purple-soft); color: var(--brisk-purple); border: 1px solid #ddd6fe; }
.status-suspended { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }

.mode-badge-firebase { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.mode-badge-demo { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }

/* ---------------- Official Vertical ID Card (330 x 518) ---------------- */
.brisk-card {
  width: 330px;
  height: 518px;
  border-radius: 18px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(76, 36, 129, 0.12);
  user-select: none;
  flex-shrink: 0;
  background: #ffffff;
}
.card-decor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.card-front-content {
  position: relative;
  z-index: 2;
  height: 100%;
  padding: 20px 22px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.card-front-logo {
  margin-top: 2px;
  margin-bottom: 12px;
}
.front-logo-img {
  height: 54px;
  width: auto;
  object-fit: contain;
  display: block;
}

.card-photo-wrap {
  overflow: hidden;
  border: 3px solid var(--card-primary, #4c2481);
  background: #f5f3fa;
  box-shadow: 0 10px 26px rgba(76, 36, 129, 0.14);
  margin-bottom: 14px;
  position: relative;
  flex-shrink: 0;
}
.card-photo-wrap.shape-rounded { border-radius: 18px; }
.card-photo-wrap.shape-circle { border-radius: 50%; }
.photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: linear-gradient(145deg, #f7f3ff, #ede6fb);
  font-weight: 800;
  font-size: 20px;
}

.card-member-name {
  font-size: 22px;
  font-weight: 900;
  line-height: 1.25;
  margin-bottom: 4px;
}
.card-member-title {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.3;
}
.card-accent-bar {
  width: 46px;
  height: 3.5px;
  border-radius: 4px;
  margin: 9px auto 12px;
}

.card-meta-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px 12px;
  background: rgba(76, 36, 129, 0.035);
  border: 1px solid rgba(76, 36, 129, 0.08);
  border-radius: 12px;
  margin-top: auto;
  margin-bottom: 10px;
}
.card-meta-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  text-align: right;
}
.meta-ico { display: inline-flex; flex-shrink: 0; }
.meta-k { font-weight: 600; white-space: nowrap; }
.meta-v { font-weight: 800; margin-right: auto; text-align: left; }
.mono-num { font-family: 'Cairo', monospace; letter-spacing: 0.4px; }

.card-front-tagline {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  padding-top: 2px;
}

/* ---------------- Back Card Layout (Large Logo + Small QR) ---------------- */
.card-back-content {
  position: relative;
  z-index: 2;
  height: 100%;
  padding: 36px 22px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  text-align: center;
}
.card-back-logo {
  margin-top: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-back-note {
  width: 100%;
  padding: 0 8px;
}
.back-divider {
  width: 52px;
  height: 3.5px;
  border-radius: 4px;
  margin: 0 auto 12px;
}
.back-verify-text {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.65;
  color: #4b5563;
  font-weight: 600;
}

.card-back-bottom-row {
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}
.card-back-bottom-row.qr-align-left { flex-direction: row-reverse; }
.card-back-bottom-row.qr-align-right { flex-direction: row; }
.card-back-bottom-row.qr-align-center {
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.card-qr-box {
  background: #ffffff;
  border: 1.5px solid rgba(76, 36, 129, 0.16);
  border-radius: 12px;
  padding: 7px 7px 5px;
  box-shadow: 0 6px 16px rgba(76, 36, 129, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.qr-canvas-holder {
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-canvas-holder img, .qr-canvas-holder canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}
.qr-caption {
  font-size: 7.5px;
  font-weight: 800;
  letter-spacing: 0.9px;
}

.card-back-contact {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
}
.qr-align-left .card-back-contact { text-align: right; align-items: flex-start; }
.qr-align-right .card-back-contact { text-align: left; align-items: flex-end; }
.qr-align-center .card-back-contact { text-align: center; align-items: center; }

.back-mini-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.back-id-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  font-family: 'Cairo', monospace;
}
.back-info-line {
  font-size: 10.5px;
  color: #6b7280;
  font-weight: 600;
  word-break: break-all;
}
.back-brand-handle {
  font-size: 11.5px;
  font-weight: 800;
  direction: ltr;
}
.back-signature {
  margin-bottom: 4px;
}
.sig-script {
  font-size: 13px;
  font-weight: 800;
}
.sig-line {
  width: 90px;
  height: 1px;
  background: #d1d5db;
  margin: 2px 0;
}
.back-signature span {
  font-size: 9.5px;
  color: #9ca3af;
}

/* ---------------- Free-Move Editing ---------------- */
.free-move-active .card-el[data-draggable="true"] {
  cursor: grab;
  outline: 1.5px dashed rgba(76, 36, 129, 0.35);
  outline-offset: 3px;
  border-radius: 8px;
}
.free-move-active .card-el[data-draggable="true"]:hover {
  outline-color: var(--brisk-gold);
}
.free-move-active .card-el.is-selected {
  outline: 2px solid var(--brisk-gold) !important;
  background: rgba(230, 176, 54, 0.08);
}
.free-move-active .card-el.is-dragging {
  cursor: grabbing;
}

/* ---------------- 3D Flip Container ---------------- */
.flip-scene {
  width: 330px;
  height: 518px;
  perspective: 1200px;
  margin: 0 auto;
}
.flip-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.flip-inner.is-flipped {
  transform: rotateY(180deg);
}
.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flip-back {
  transform: rotateY(180deg);
}

/* ---------------- Lanyard Mockup ---------------- */
.lanyard-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 8px;
}
.lanyard-strap {
  width: 32px;
  height: 76px;
  background: linear-gradient(90deg, #3c1b69 0%, #4c2481 50%, #3c1b69 100%);
  position: relative;
  border-radius: 2px;
  box-shadow: 0 6px 14px rgba(0,0,0,0.16);
}
.lanyard-strap::after {
  content: "BRISK";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  color: #e6b036;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 2px;
}
.lanyard-clip {
  width: 24px;
  height: 30px;
  background: linear-gradient(180deg, #e5e7eb, #9ca3af, #d1d5db);
  border-radius: 6px;
  margin-top: -4px;
  border: 1px solid #6b7280;
  z-index: 2;
}
.lanyard-holder {
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid rgba(148, 163, 184, 0.55);
  border-radius: 24px;
  padding: 28px 12px 12px;
  margin-top: -8px;
  position: relative;
  box-shadow: 0 24px 50px rgba(45, 20, 82, 0.16), inset 0 1px 0 rgba(255,255,255,0.8);
}
.lanyard-holder::before {
  content: "";
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 9px;
  border-radius: 999px;
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(90px);
  background: #1f1436;
  color: #fff;
  padding: 12px 22px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.24);
  z-index: 9999;
  opacity: 0;
  transition: all 0.25s ease;
  border: 1px solid rgba(230, 176, 54, 0.45);
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ---------------- Print CR80 (55mm x 85mm) ---------------- */
@media print {
  body * { visibility: hidden !important; }
  #print-sheet, #print-sheet * { visibility: visible !important; }
  #print-sheet {
    position: fixed !important;
    inset: 0 !important;
    display: flex !important;
    justify-content: center;
    align-items: center;
    gap: 14mm;
    background: #fff !important;
    padding: 10mm;
  }
  #print-sheet .brisk-card {
    width: 55mm !important;
    height: 85mm !important;
    transform-origin: top center;
    box-shadow: none !important;
    border: 0.25mm dashed #999 !important;
    border-radius: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
