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

:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #16a34a;
  --gold: #d97706;
  --red: #dc2626;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --sidebar-w: 220px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  font-size: 14px;
  line-height: 1.5;
  min-width: 0;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: #1e293b;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

/* ── Sidebar top (brand + hamburger) ────────────────────────────── */
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}

.sidebar-brand {
  font-size: 15px;
  font-weight: 700;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.brand-icon { font-size: 18px; flex-shrink: 0; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Hamburger — hidden on desktop */
.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: #94a3b8;
  border-radius: 2px;
  transition: all .2s;
}

/* ── Nav links ──────────────────────────────────────────────────── */
.nav-links {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: #94a3b8;
  font-size: 14px;
  transition: background .15s, color .15s;
  text-decoration: none;
  white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #f1f5f9; text-decoration: none; }
.nav-item.active { background: rgba(37,99,235,.25); color: #93c5fd; }
.nav-icon { font-size: 16px; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.logout-link { color: #94a3b8; font-size: 13px; }
.logout-link:hover { color: #f1f5f9; text-decoration: none; }

/* ── Main content ───────────────────────────────────────────────── */
.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  min-width: 0;
  max-width: 1100px;
}

/* ── Auth ───────────────────────────────────────────────────────── */
.auth-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
  background: var(--gray-100);
}
.auth-flash { width: 100%; max-width: 400px; }
.auth-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.1);
  padding: 36px;
  width: 100%;
  max-width: 400px;
}
.auth-header { text-align: center; margin-bottom: 28px; }
.auth-logo { font-size: 40px; margin-bottom: 8px; }
.auth-header h1 { font-size: 22px; font-weight: 700; color: var(--gray-800); }
.auth-sub { color: var(--gray-600); font-size: 13px; margin-top: 4px; }

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  overflow: hidden;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-header h4 { font-size: 14px; font-weight: 600; }
.card-section { padding: 16px 20px; border-top: 1px solid var(--gray-100); }
.mt-16 { margin-top: 16px; }
.form-card { padding: 24px; }

/* ── Page header ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 22px; font-weight: 700; word-break: break-word; overflow-wrap: break-word; min-width: 0; }
.page-header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 500;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--blue); color: white; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-outline { background: white; color: var(--gray-600); border-color: var(--gray-200); }
.btn-outline:hover { background: var(--gray-50); color: var(--gray-800); }
.btn-ghost { background: transparent; color: var(--gray-600); border-color: transparent; }
.btn-ghost:hover { background: var(--gray-100); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-danger { background: #dc2626; color: white; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-full { width: 100%; justify-content: center; }
.btn-reward { background: var(--gold); color: white; border-color: var(--gold); padding: 8px 20px; }
.btn-reward:hover { background: #b45309; border-color: #b45309; }

/* ── Forms ──────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--gray-600); }
.form-group small { font-size: 12px; color: var(--gray-400); }
.form-group input, .form-group select, .form-group textarea {
  padding: 8px 12px; border: 1px solid var(--gray-200); border-radius: 6px;
  font-size: 14px; background: white; color: var(--gray-800);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.form-group input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-hint { font-size: 13px; color: var(--gray-600); margin-bottom: 16px; }
.input-lg { font-size: 16px; padding: 12px 14px; }
.input-sm { width: 80px; }
.input-search {
  flex: 1; min-width: 0;
  padding: 8px 14px; border: 1px solid var(--gray-200); border-radius: 6px; font-size: 14px;
}
.input-search:focus { outline: none; border-color: var(--blue); }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }

/* ── Table ──────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 10px 16px; text-align: left; font-size: 12px;
  font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  color: var(--gray-400); border-bottom: 1px solid var(--gray-200);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--gray-100); font-size: 13px; word-break: break-word; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--gray-50); }
.table tr.clickable { cursor: pointer; }
.col-center { text-align: center; }
.table-customers td:first-child { width: 50%; }
.table-customers td:nth-child(2) { width: 30%; }
.table-customers td:nth-child(3) { width: 20%; }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table-summary { font-size: 12px; color: var(--gray-400); margin-top: 8px; text-align: right; }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gold { background: #fef3c7; color: var(--gold); }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-orange { background: #ffedd5; color: #9a3412; }

/* ── Alerts ─────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 6px; font-size: 13px; margin-bottom: 16px; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: var(--red); border: 1px solid #fecaca; }

/* ── Stats ──────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 28px; }
.stat-card {
  background: white; border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 20px; text-align: center; box-shadow: var(--shadow);
}
.stat-card-reward { border-color: #fde68a; background: #fffbeb; }
.stat-number { font-size: 36px; font-weight: 700; color: var(--gray-800); line-height: 1; }
.stat-label { font-size: 13px; color: var(--gray-400); margin-top: 6px; }

/* ── Quick actions ──────────────────────────────────────────────── */
.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 12px; }
.quick-card {
  background: white; border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 4px;
  text-decoration: none; transition: border-color .15s, box-shadow .15s;
}
.quick-card:hover { border-color: var(--blue); box-shadow: 0 2px 8px rgba(37,99,235,.1); text-decoration: none; }
.quick-icon { font-size: 24px; }
.quick-label { font-weight: 600; color: var(--gray-800); font-size: 14px; }
.quick-sub { font-size: 12px; color: var(--gray-400); }
.quick-actions h2 { font-size: 16px; font-weight: 600; }

/* ── Info box ───────────────────────────────────────────────────── */
.info-box { background: var(--gray-100); border: 1px solid var(--gray-200); border-radius: 6px; padding: 12px 16px; font-size: 13px; color: var(--gray-600); }
.info-box-blue { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.info-box a { color: var(--blue); }

/* ── Empty ──────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--gray-400); background: white; border-radius: var(--radius); border: 1px solid var(--gray-200); }
.empty-msg { padding: 16px 20px; color: var(--gray-400); font-size: 13px; }

/* ── Customer page ──────────────────────────────────────────────── */
.customer-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 260px); gap: 20px; align-items: start; }
.customer-main { display: flex; flex-direction: column; min-width: 0; }
.customer-side { display: flex; flex-direction: column; min-width: 0; }

/* ── Reward banner ──────────────────────────────────────────────── */
.reward-banner {
  background: #fffbeb; border: 2px solid #fde68a; border-radius: var(--radius);
  padding: 16px 20px; display: flex; align-items: center; gap: 16px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.reward-icon { font-size: 32px; flex-shrink: 0; }
.reward-banner strong { display: block; font-size: 16px; color: var(--gold); }
.reward-banner p { font-size: 13px; color: var(--gray-600); margin: 0; }

/* ── Loyalty progress ───────────────────────────────────────────── */
.loyalty-stats { padding: 16px 20px; display: flex; flex-direction: column; gap: 16px; }
.loyalty-stat { display: flex; flex-direction: column; gap: 6px; }
.loyalty-label { font-size: 12px; font-weight: 600; color: var(--gray-400); text-transform: uppercase; letter-spacing: .5px; }
.loyalty-progress { display: flex; align-items: center; gap: 12px; }
.progress-bar { flex: 1; height: 8px; background: var(--gray-100); border-radius: 4px; overflow: hidden; min-width: 0; }
.progress-fill { height: 100%; background: var(--blue); border-radius: 4px; transition: width .3s; }
.progress-text { font-size: 13px; font-weight: 600; white-space: nowrap; min-width: 70px; text-align: right; }
.cycle-num { font-size: 12px; background: var(--gray-100); color: var(--gray-600); padding: 2px 8px; border-radius: 10px; font-weight: 500; }

/* ── Visit form ─────────────────────────────────────────────────── */
.visit-form { margin: 0; }
.visit-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.visit-row .form-group { flex: 1; min-width: 100px; }
.input-amount { width: 100%; padding: 8px 12px; border: 1px solid var(--gray-200); border-radius: 6px; font-size: 14px; }
.input-amount:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.visit-btn { flex-shrink: 0; align-self: flex-end; }

/* ── Info list ──────────────────────────────────────────────────── */
.info-list { padding: 16px 20px; display: grid; gap: 10px; }
.info-list dt { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--gray-400); font-weight: 600; margin-top: 4px; }
.info-list dd { font-size: 14px; font-weight: 500; color: var(--gray-800); margin: 0; word-break: break-word; overflow-wrap: break-word; }

/* ── Tag list ───────────────────────────────────────────────────── */
.tag-list { list-style: none; padding: 12px 20px; display: flex; flex-direction: column; gap: 6px; }
.tag-list li { font-size: 13px; }

/* ── Code ───────────────────────────────────────────────────────── */
code { font-family: 'Courier New', monospace; font-size: 12px; background: var(--gray-100); padding: 2px 6px; border-radius: 4px; word-break: break-all; }
.token-code { font-size: 13px; background: #f0f4ff; color: #1e40af; padding: 3px 8px; }
.nfc-url { font-size: 12px; color: var(--gray-600); font-family: monospace; word-break: break-all; }

/* ── Tabs ───────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--gray-200); }
.tab-btn { padding: 10px 18px; background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--gray-400); transition: all .15s; margin-bottom: -1px; }
.tab-btn:hover { color: var(--gray-800); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ── Search ─────────────────────────────────────────────────────── */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.search-inline { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.search-inline .input-search { flex: 1; min-width: 160px; }

/* ── Misc ───────────────────────────────────────────────────────── */
.text-muted { color: var(--gray-400); }
.link-muted { color: var(--gray-600); }
.link-muted:hover { color: var(--blue); }
.customer-link { color: var(--gray-800); font-weight: 500; }
.customer-link:hover { color: var(--blue); text-decoration: none; }

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile first
   ══════════════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
  .customer-grid { grid-template-columns: 1fr; }
  .customer-side { flex-direction: row; flex-wrap: wrap; gap: 16px; }
  .customer-side .card { flex: 1 1 260px; }
}

@media (max-width: 768px) {

  /* ── Sidebar → top nav ── */
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    position: static;
    flex-direction: column;
    height: auto;
  }

  .sidebar-top {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
  }

  /* Show hamburger on mobile */
  .nav-toggle { display: flex; }

  /* Nav links hidden by default, shown when .nav-open */
  .nav-links { display: none; border-top: 1px solid rgba(255,255,255,.08); }
  .sidebar.nav-open .nav-links { display: flex; }

  .sidebar-footer {
    margin-top: 0;
    border-top: 1px solid rgba(255,255,255,.08);
    padding: 12px 20px;
  }

  /* ── Content ── */
  .content {
    margin-left: 0;
    padding: 16px;
    max-width: 100%;
  }

  /* ── Page header ── */
  .page-header { align-items: flex-start; }
  .page-header h1 { font-size: 18px; }

  /* ── Stats ── */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
  .stat-number { font-size: 28px; }
  /* Third stat card full width */
  .stats-grid .stat-card:nth-child(3) { grid-column: 1 / -1; }

  /* ── Quick actions ── */
  .quick-grid { grid-template-columns: 1fr; gap: 10px; }

  /* ── Forms ── */
  .form-grid { grid-template-columns: 1fr; }
  .form-card { padding: 16px; }
  .form-row { flex-direction: column; align-items: stretch; }
  .form-row .btn { width: 100%; justify-content: center; }
  .input-sm { width: 100%; }

  /* ── Tables — horizontal scroll only where wrapped ── */
  .table-scroll { overflow-x: auto; }
  .table-scroll .table { min-width: 480px; }

  /* ── Customer page — stack columns ── */
  .customer-grid { grid-template-columns: 1fr; }

  /* ── Reward banner ── */
  .reward-banner { flex-direction: column; align-items: flex-start; gap: 12px; }
  .btn-reward { width: 100%; justify-content: center; }

  /* ── Progress text ── */
  .progress-text { min-width: 100px; font-size: 12px; }

  /* ── Auth card ── */
  .auth-card { padding: 24px 20px; }

  /* ── Tabs ── */
  .tab-btn { padding: 10px 12px; font-size: 13px; }

  /* ── Info box code wrap ── */
  .info-box code { word-break: break-all; }
}

@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stats-grid .stat-card:nth-child(3) { grid-column: auto; }
  .page-header { flex-direction: column; }
  .page-header-actions { width: 100%; }
  .page-header-actions .btn { flex: 1; justify-content: center; }
}

/* ── Public pages (mobile-first) ─────────────────────────────────── */
.public-wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.public-brand {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-600);
  margin-bottom: 8px;
}

.public-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 4px;
}

.public-subtitle {
  color: var(--gray-600);
  margin-bottom: 20px;
}

.public-card {
  margin-bottom: 16px;
}

.public-greeting {
  font-size: 18px;
  margin-bottom: 8px;
}

.public-card-label {
  font-size: 13px;
  color: var(--gray-600);
  margin-bottom: 16px;
}

.public-loyalty-card {
  padding: 20px;
}

.public-stat {
  margin-bottom: 20px;
}

.public-stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-600);
  margin-bottom: 4px;
}

.public-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 8px;
}

.public-reward-banner {
  background: var(--gold);
  color: #fff;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  font-size: 16px;
  margin-top: 8px;
}

.public-progress-info {
  font-size: 14px;
  color: var(--gray-600);
  margin-top: 4px;
}

/* ── Terms section ───────────────────────────────────────────────── */
.terms-section {
  margin: 16px 0;
}

.terms-intro {
  font-size: 13px;
  color: var(--gray-600);
  margin-bottom: 8px;
}

.terms-scroll {
  height: 240px;
  overflow-y: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--gray-600);
  background: var(--gray-50);
}

.terms-scroll h3 { font-size: 13px; margin-bottom: 8px; color: var(--gray-800); }
.terms-scroll h4 { font-size: 12px; margin: 12px 0 4px; color: var(--gray-800); }
.terms-scroll ol { padding-left: 18px; margin-bottom: 6px; }
.terms-scroll li { margin-bottom: 3px; }
.terms-scroll hr { border: none; border-top: 1px solid var(--gray-200); margin: 12px 0; }
.terms-scroll p { margin-bottom: 6px; }

/* ── Checkbox group ──────────────────────────────────────────────── */
.checkbox-group {
  margin: 16px 0;
}

.checkbox-label {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.5;
}

.checkbox-label input[type="checkbox"] {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  cursor: pointer;
}

/* ── Misc helpers ────────────────────────────────────────────────── */
.btn-lg { padding: 12px 20px; font-size: 15px; }
.required { color: var(--red); }

/* ── Support mode banner ─────────────────────────────────────────── */
.support-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  color: #92400e;
  flex-wrap: wrap;
}

.support-banner-back {
  white-space: nowrap;
  background: #f59e0b;
  color: #fff;
  border-radius: var(--radius);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.support-banner-back:hover {
  background: #d97706;
  text-decoration: none;
}
