/* ══════════════════════════════════════════════════════════
   Rewards System — Main Stylesheet
   ══════════════════════════════════════════════════════════ */

:root {
  --sidebar-w:    240px;
  --sidebar-collapsed: 60px;
  --primary:      #0d6efd;
  --sidebar-bg:   #0f172a;
  --sidebar-hover:#1e293b;
  --sidebar-active: #1d4ed8;
  --topnav-h:     56px;
  --card-radius:  .75rem;
  --card-shadow:  0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --font:         'Inter', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--font);
  background: #f1f5f9;
  color: #1e293b;
  font-size: .9rem;
  overflow-x: hidden;
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar-nav {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  transition: width .25s ease;
  z-index: 1040;
}

.sidebar-brand {
  border-bottom: 1px solid rgba(255,255,255,.08);
  min-height: var(--topnav-h);
}

.brand-text {
  color: #fff;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity .2s;
}

.sidebar-link {
  color: rgba(255,255,255,.65);
  border-radius: .5rem;
  padding: .55rem .85rem;
  margin-bottom: 2px;
  font-size: .85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  transition: background .15s, color .15s;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-link.active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: 0 2px 8px rgba(29,78,216,.35);
}

.sidebar-link i { font-size: 1rem; flex-shrink: 0; }
.link-text { transition: opacity .2s; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,.06); }

/* Collapsed sidebar */
.sidebar-collapsed .sidebar-nav { width: var(--sidebar-collapsed); }
.sidebar-collapsed .brand-text,
.sidebar-collapsed .link-text,
.sidebar-collapsed .sidebar-footer { opacity: 0; pointer-events: none; }

/* ── Top Nav ─────────────────────────────────────────── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 1030;
  min-height: var(--topnav-h);
}

/* ── Page Body ───────────────────────────────────────── */
.page-body { min-height: calc(100vh - var(--topnav-h)); }

/* ── Cards ───────────────────────────────────────────── */
.card {
  border: none;
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
}

.card-header {
  border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
  border-bottom: 1px solid rgba(0,0,0,.06);
  font-weight: 600;
  font-size: .875rem;
  padding: .85rem 1.1rem;
}

/* ── Stat Cards ──────────────────────────────────────── */
.stat-card {
  background: #fff;
  border-radius: var(--card-radius);
  padding: 1.25rem 1.25rem;
  box-shadow: var(--card-shadow);
  transition: transform .15s;
}
.stat-card:hover { transform: translateY(-2px); }

.stat-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #64748b;
  margin-bottom: .25rem;
}

.stat-value {
  font-size: 1.65rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.1;
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: .6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

/* ── ATM Reward Card ─────────────────────────────────── */
.reward-card {
  width: 340px;
  height: 215px;
  border-radius: 14px;
  /* Default gradient — overridden by inline style from design settings */
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 40%, #0ea5e9 100%);
  position: relative;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(29,78,216,.45);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  /* CSS custom properties set by inline style */
  --card-text:   #ffffff;
  --card-accent: #facc15;
}

/* Glossy shimmer overlay (replaces ::before — now a real element for JS toggle) */
.card-shimmer-overlay {
  position: absolute;
  top: -60%;
  left: -40%;
  width: 100%;
  height: 180%;
  background: linear-gradient(
    105deg,
    rgba(255,255,255,0)    30%,
    rgba(255,255,255,.13)  50%,
    rgba(255,255,255,0)    70%
  );
  transform: rotate(-15deg);
  pointer-events: none;
  z-index: 1;
}

/* Decorative circle (replaces ::after — real element) */
.card-circle-deco {
  position: absolute;
  right: -40px;
  top: -40px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
  pointer-events: none;
  z-index: 1;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
  position: relative;
  z-index: 2;
}

/* Top-left QR (replaces EMV chip) */
.card-top-qr {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 5px;
  overflow: hidden;
}

.card-top-qr img,
.card-top-qr canvas {
  width: 48px !important;
  height: 48px !important;
  display: block;
  border-radius: 4px;
}

.card-store-name {
  color: rgba(255,255,255,.85);
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .18em;
}

.card-logo {
  font-size: 1.25rem;
}

/* Barcode stripe (replaces black mag strip) */
.card-stripe {
  background: rgba(0,0,0,.25);
  padding: 4px 0 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
}

.card-stripe svg {
  width: 100%;
  height: 40px;
  padding: 0 8px;
}

/* Bottom: card number + QR */
.card-bottom {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 6px 16px 14px;
  position: relative;
  z-index: 2;
}

.card-label {
  font-size: .5rem;
  letter-spacing: .12em;
  color: rgba(255,255,255,.6);
  text-transform: uppercase;
  margin-bottom: 3px;
}

.card-number {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .12em;
  color: #fff;
  font-family: 'Courier New', monospace;
}

.card-validity {
  font-size: .55rem;
  color: rgba(255,255,255,.6);
  letter-spacing: .1em;
}

/* QR code wrapper on card — Bug Fix #3: class-based, not ID-based */
.card-qr-wrap img,
.card-qr-wrap canvas {
  width:  76px !important;
  height: 76px !important;
  border-radius: 4px;
  display: block;
}

/* ── Login Page ──────────────────────────────────────── */
.login-page { background: #0f172a; }

.login-bg {
  background:
    radial-gradient(ellipse at 20% 50%, rgba(29,78,216,.25) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(14,165,233,.2) 0%, transparent 55%),
    #0f172a;
  position: relative;
  overflow: hidden;
  padding: 1rem;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: .3;
  pointer-events: none;
}

.blob-1 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, #1d4ed8, transparent);
  top: -100px; left: -100px;
}

.blob-2 {
  width: 350px; height: 350px;
  background: radial-gradient(circle, #0ea5e9, transparent);
  bottom: -80px; right: -80px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  border-radius: 1.25rem !important;
  overflow: hidden;
  position: relative;
  z-index: 1;
  border: 1px solid rgba(255,255,255,.08) !important;
}

.login-header {
  background: linear-gradient(135deg, #1e3a8a, #1d4ed8, #0ea5e9);
  border-bottom: none !important;
}

.shadow-xl {
  box-shadow: 0 20px 60px rgba(0,0,0,.5), 0 4px 20px rgba(0,0,0,.3) !important;
}

/* ── Tables ──────────────────────────────────────────── */
.table th { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.table td { vertical-align: middle; }

/* ── Points Preview ──────────────────────────────────── */
.points-preview { border: 2px dashed #198754; }

/* ── Print ───────────────────────────────────────────── */
@media print {
  /* ── Hide everything on the page ── */
  body > * {
    display: none !important;
  }

  /* ── Show only the print card area (moved to body by JS) ── */
  body > #printArea {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: fixed !important;
    top: 0; left: 0;
    width: 100vw;
    height: 100vh;
    background: #ffffff;
    margin: 0;
    padding: 0;
  }

  /* ── Card size: CR80 standard (credit card) ── */
  .reward-card {
    width:  3.375in !important;
    height: 2.125in !important;
    box-shadow: none !important;
    margin: 0 !important;
    border-radius: 14px !important;
    /* Force colour / gradient printing in all browsers */
    -webkit-print-color-adjust: exact !important;
            print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  /* Force all child elements to print colours */
  .reward-card *,
  .reward-card::before,
  .reward-card::after {
    -webkit-print-color-adjust: exact !important;
            print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  /* Keep barcode stripe correct height in print units */
  .card-stripe {
    height: 0.52in !important;
  }

  .card-stripe svg {
    height: 0.46in !important;
  }

  /* QR size in print units */
  .card-qr-wrap img,
  .card-qr-wrap canvas {
    width:  0.85in !important;
    height: 0.85in !important;
  }

  /* No page margin, no header/footer from browser */
  @page {
    size: letter portrait;
    margin: 0.5in;
  }
}

/* ── Utilities ───────────────────────────────────────── */
.font-monospace { font-family: 'Courier New', monospace; }
.btn-xs { padding: .2rem .5rem; font-size: .7rem; }

/* ── Card Design Settings UI ─────────────────────────── */

/* Gradient preset swatches */
.preset-swatch {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  padding: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.preset-swatch:hover  { transform: scale(1.15); box-shadow: 0 4px 12px rgba(0,0,0,.3); }
.preset-swatch.active { border-color: #fff; box-shadow: 0 0 0 3px #0d6efd, 0 4px 12px rgba(0,0,0,.3); }

/* Image drop zone */
.upload-drop-zone {
  border: 2px dashed #94a3b8;
  border-radius: .75rem;
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: #f8fafc;
}
.upload-drop-zone:hover,
.upload-drop-zone.drag-over {
  border-color: #0d6efd;
  background: #eff6ff;
}
.upload-drop-zone.drag-over {
  box-shadow: 0 0 0 3px rgba(13,110,253,.15);
}

/* Icon picker buttons */
.icon-pick-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  border-radius: .4rem;
  transition: transform .12s;
}
.icon-pick-btn:hover { transform: scale(1.15); }

/* Card preview placeholder elements (shown in settings live preview) */
.barcode-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 42px;
  padding: 0 12px;
}
.barcode-lines {
  width: 100%;
  height: 32px;
  background: repeating-linear-gradient(
    90deg,
    rgba(255,255,255,.7) 0px,
    rgba(255,255,255,.7) 2px,
    transparent         2px,
    transparent         4px
  );
  border-radius: 1px;
  opacity: .6;
}
.qr-placeholder {
  width: 64px;
  height: 64px;
  background: #fff;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.qr-grid {
  width: 52px;
  height: 52px;
  background:
    repeating-linear-gradient(0deg,   transparent, transparent 5px, rgba(0,0,0,.15) 5px, rgba(0,0,0,.15) 6px),
    repeating-linear-gradient(90deg,  transparent, transparent 5px, rgba(0,0,0,.15) 5px, rgba(0,0,0,.15) 6px),
    #1e3a8a;
  border-radius: 2px;
}

/* Spinner inside buttons */
.btn .spinner-border-sm { width: .85rem; height: .85rem; }

/* DataTables in Bootstrap 5 */
div.dataTables_wrapper div.dataTables_length label,
div.dataTables_wrapper div.dataTables_filter label { font-size: .8rem; }

/* Scrollable sidebar on small screens */
@media (max-width: 768px) {
  .sidebar-nav { width: 0; overflow: hidden; }
  #app-wrapper.mobile-open .sidebar-nav { width: var(--sidebar-w); position: fixed; height: 100vh; }
}

/* ══════════════════════════════════════════════════════════
   Mobile Responsive Overrides
   ══════════════════════════════════════════════════════════ */

/* ── Login Page — Small phones (≤ 575px) ──────────────── */
@media (max-width: 575px) {

  /* Card fills screen width with comfortable side margins */
  .login-card {
    border-radius: .875rem !important;
  }

  /* Reduce card body padding so form fields have breathing room */
  .login-card .card-body {
    padding: 1.25rem 1rem !important;
  }

  /* Shrink header brand area */
  .login-header {
    padding: 1.25rem 1rem !important;
  }
  .login-header h4 {
    font-size: 1.05rem;
  }
  .login-header .fs-1 {
    font-size: 2rem !important;
  }
  .login-header .small {
    font-size: .75rem !important;
  }

  /* Card footer */
  .login-card .card-footer {
    padding: .65rem 1rem !important;
    font-size: .75rem;
  }

  /* Input groups — ensure proper touch targets (min 44px) */
  .login-card .input-group-lg .form-control,
  .login-card .input-group-lg .input-group-text {
    padding-top: .65rem;
    padding-bottom: .65rem;
    font-size: .95rem;
  }
  .login-card .input-group-lg .btn {
    padding: .65rem .85rem;
    font-size: .95rem;
  }

  /* Sign In button */
  .login-card .btn-lg {
    padding: .75rem 1rem;
    font-size: 1rem;
  }

  /* Error alert */
  .login-card .alert {
    font-size: .82rem;
    padding: .6rem .75rem;
  }

  /* Shrink decorative blobs so they don't inflate layout */
  .blob-1 { width: 220px; height: 220px; top: -60px; left: -60px; }
  .blob-2 { width: 190px; height: 190px; bottom: -50px; right: -50px; }
}

/* ── Login Page — Medium phones / landscape (576–767px) ── */
@media (min-width: 576px) and (max-width: 767px) {
  .login-bg { padding: 1.5rem; }
  .blob-1 { width: 300px; height: 300px; }
  .blob-2 { width: 260px; height: 260px; }
}

/* ── Admin / Desktop Pages on Mobile (≤ 768px) ─────────── */
@media (max-width: 768px) {

  /* Reduce page body padding */
  .page-body {
    padding: .875rem !important;
  }

  /* Stat cards — smaller text, tighter padding */
  .stat-card {
    padding: .875rem 1rem;
  }
  .stat-value {
    font-size: 1.35rem;
  }
  .stat-icon {
    width: 44px;
    height: 44px;
    font-size: 1.25rem;
  }

  /* Card body — reduce excessive padding */
  .card-body {
    padding: .875rem !important;
  }
  .card-header {
    padding: .65rem .875rem;
  }

  /* Tables — make them scroll horizontally instead of breaking layout */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Wrap any bare table inside a scroll container */
  .card .table:not(.table-responsive table) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  /* Top nav — prevent button / text overflow */
  .topnav .fw-bold {
    font-size: .85rem;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topnav .btn-outline-danger {
    font-size: .78rem;
    padding: .3rem .55rem;
    min-height: 36px;
  }
  /* Hide full-name text on very small screens — role badge is enough */
  .topnav .d-none.d-md-inline {
    display: none !important;
  }

  /* Ensure all clickable buttons meet 44px touch target */
  .btn:not(.btn-xs) {
    min-height: 38px;
  }
  .btn-sm {
    min-height: 34px;
  }

  /* DataTables controls stack nicely */
  div.dataTables_wrapper div.dataTables_length,
  div.dataTables_wrapper div.dataTables_filter {
    text-align: left;
    margin-bottom: .4rem;
  }
  div.dataTables_wrapper div.dataTables_info,
  div.dataTables_wrapper div.dataTables_paginate {
    text-align: left;
    margin-top: .4rem;
  }
}
