:root {
  --bg: #762f3f;
  --card: #e7cee1;
  --card-dark: #dcbfd3;
  --paper: #f3efe8;      /* punch card colour (customer page) */
  --paper-ink: #d1625a;  /* shapes, text, border and scattered circles on the punch card */
  --ink: #1f2933;
  --muted: #6b7280;
  --brand: #c36362;
  --brand-dark: #a84f4e;
  --green: #16a34a;
  --red: #dc2626;
  --line: #e5e7eb;
  --bit: #00b3a4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.card-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  opacity: 0.95;
}

h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }

.muted { color: var(--muted); margin: 0 0 16px; }
.small { font-size: 0.85rem; }
.error { color: var(--red); min-height: 1.2em; margin: 8px 0 0; }
.hidden { display: none !important; }

.row { display: flex; gap: 8px; }
.row input { flex: 1; }

input, select {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--brand);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 0; }

label { display: block; margin: 0 0 14px; font-weight: 600; font-size: 0.95rem; }
label input, label select { margin-top: 6px; font-weight: 400; }

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  transition: background .15s ease;
}
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: #eef2ff; color: var(--brand-dark); }
.btn.secondary:hover { background: #e0e7ff; }
.btn.success { background: var(--green); }
.btn.pay { background: var(--bit); }
.btn.pay:hover { background: #009488; }
.btn:disabled { opacity: .5; cursor: default; }

.actions { display: flex; gap: 10px; margin-top: 20px; }
.actions .btn { flex: 1; }

/* Punch card grid */
.punch-card {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin: 20px 0;
}
.hole {
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 2px dashed #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #cbd5e1;
  background: #f8fafc;
}
.hole.punched {
  border: 2px solid var(--brand);
  background: var(--brand);
  color: #fff;
}

.stats { display: flex; justify-content: space-around; margin: 16px 0; }
.stat { text-align: center; }
.stat .num { display: block; font-size: 1.8rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 0.85rem; }

.buy-panel {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.amount { font-size: 1.1rem; margin: 4px 0 14px; }
.buy-panel .btn { width: 100%; margin-bottom: 8px; }

.history { margin-top: 20px; }
.history summary { cursor: pointer; color: var(--muted); }
.history ul { list-style: none; padding: 0; margin: 12px 0 0; }
.history li {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
}

/* Admin table */
.admin-table { width: 100%; border-collapse: collapse; background: var(--card); }
.admin-table th, .admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-size: 0.92rem;
}
.admin-table th { background: var(--card-dark); font-weight: 700; }
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}
.badge.ok { background: #dcfce7; color: #166534; }
.badge.low { background: #fef9c3; color: #854d0e; }
.badge.empty { background: #fee2e2; color: #991b1b; }
.wrap.wide { max-width: 1000px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.topbar h1 { margin: 0; }
.mini-btn {
  padding: 6px 12px; font-size: 0.85rem; border-radius: 8px;
  border: none; cursor: pointer; background: var(--brand); color: #fff; font-weight: 600;
}
.mini-btn:hover { background: var(--brand-dark); }

.wrap.wider { max-width: 1300px; }
.table-scroll { overflow-x: auto; }
.summary { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.summary .tile { flex: 1; min-width: 130px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.summary .tile b { display: block; font-size: 1.5rem; }
.summary .tile span { color: var(--muted); font-size: 0.85rem; }
.admin-table tr.row-main { cursor: pointer; }
.admin-table tr.row-main:hover { background: var(--card-dark); }
.admin-table tr.row-detail > td { background: var(--card-dark); padding: 12px 16px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.detail-grid h3 { margin: 0 0 6px; font-size: 0.95rem; }
.detail-grid ul { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.detail-grid li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
@media (max-width: 700px) { .detail-grid { grid-template-columns: 1fr; } }

/* ---- Admin dashboard v2 ---- */
.login-box { max-width: 460px; margin: 40px auto; }
.top-actions { display: flex; gap: 8px; }
.mini-btn.ghost { background: var(--brand); color: #fff; }
.mini-btn.ghost:hover { background: var(--brand-dark); }
.mini-btn.danger { background: var(--brand); color: #fff; }
.mini-btn.danger:hover { background: var(--brand-dark); }
.mini-btn:disabled { opacity: .45; cursor: default; }
.summary .tile.accent b { color: var(--brand); }
.summary .tile.warn b { color: var(--red); }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.dash-grid .card-box { padding: 18px; }
.sell-form { display: grid; gap: 8px; }
.break-row { margin-bottom: 12px; }
.break-row .top { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 4px; }
.bar { height: 8px; border-radius: 999px; background: #fff; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 230px; overflow-y: auto; }
.feed li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
.feed .when { color: var(--muted); white-space: nowrap; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 2; min-width: 180px; }
.toolbar select { flex: 1; min-width: 150px; width: auto; }
.chips { display: flex; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 0.88rem; }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.mini-bar { display: inline-block; width: 90px; height: 8px; border-radius: 999px; background: #fff; overflow: hidden; vertical-align: middle; }
.mini-bar > i { display: block; height: 100%; background: var(--green); }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.detail-actions input { width: 200px; padding: 6px 10px; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

/* ---- Language switch ---- */
body { position: relative; }
.wrap { padding-top: 56px; }
.lang-btn {
  position: absolute; top: 14px; right: 16px; z-index: 10;
  padding: 6px 12px; font-size: 0.85rem; border-radius: 8px;
  border: none; cursor: pointer; background: var(--brand); color: #fff; font-weight: 600;
  font-family: inherit;
}
.lang-btn:hover { background: var(--brand-dark); }
.admin-table th, .admin-table td { text-align: start; }

.feed-panel { margin-top: 16px; }
.feed-panel .feed { max-height: 320px; }

/* collapsible activity days */
.feed details.day { border-bottom: 1px solid var(--line); }
.feed details.day > summary { display: flex; justify-content: space-between; gap: 8px; padding: 10px 4px; cursor: pointer; font-weight: 600; list-style-position: inside; }
.feed details.day > summary .count { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.feed details.day > ul { list-style: none; margin: 0 0 8px; padding: 0 4px; max-height: none; overflow: visible; }
.feed details.day li { border-bottom: none; padding: 4px 0 4px 16px; }
.feed-panel .feed { max-height: 360px; overflow-y: auto; }

/* ---- Sibling cards: two panels side by side ---- */
.wrap.two { max-width: 1040px; }
.children { display: grid; gap: 16px; }
.children.two { grid-template-columns: 1fr 1fr; }
.children.two { gap: 48px; }
@media (max-width: 720px) { .children.two { grid-template-columns: 1fr; gap: 36px; } }

.act-col { display: flex; flex-direction: column; gap: 4px; }
.detail-grid { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.detail-grid > div { min-width: 0; }

/* ---- Mobile ---- */
@media (max-width: 720px) {
  .wrap, .wrap.wider, .wrap.two { padding: 56px 12px 40px; }
  .card-box { padding: 16px; border-radius: 14px; }
  h1 { font-size: 1.3rem; }

  /* 16px inputs stop iOS from zooming the page on focus; bigger tap targets */
  input, select { font-size: 16px; padding: 12px; }
  .btn { padding: 13px 18px; }
  .mini-btn { padding: 10px 14px; font-size: 0.9rem; }
  .chip { padding: 8px 14px; }
  .lang-btn { padding: 8px 14px; }
  .login-box { margin: 16px auto; }

  /* Card page */
  .punch-card { gap: 8px; }
  .stat .num { font-size: 1.5rem; }

  /* Admin: header, tiles, panels */
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar h1 { flex: 1 1 100%; }
  .summary { gap: 8px; }
  .summary .tile { flex: 1 1 calc(50% - 8px); min-width: 0; padding: 10px 12px; }
  .summary .tile b { font-size: 1.3rem; }
  .dash-grid { gap: 12px; margin-bottom: 12px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input[type=search], .toolbar select { width: 100%; flex: none; }
  .chips { overflow-x: auto; padding-bottom: 2px; }
  .chip { flex: 1 0 auto; }

  /* Admin table -> one card per family */
  .table-scroll { overflow: visible; }
  .admin-table, .admin-table tbody, .admin-table tr, .admin-table td { display: block; width: 100%; }
  .admin-table { background: transparent; }
  .admin-table thead { display: none; }
  .admin-table tr.row-main {
    background: var(--card); border: 1px solid var(--line); border-radius: 12px;
    margin-bottom: 10px; padding: 6px 12px;
  }
  .admin-table tr.row-main:hover { background: var(--card); }
  .admin-table tr.row-main td {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
    border: none; padding: 6px 0; text-align: end;
  }
  .admin-table tr.row-main td[data-label]::before {
    content: attr(data-label); color: var(--muted); font-weight: 600; text-align: start; flex: none;
  }
  .admin-table td .cell { text-align: end; }
  .admin-table td.act-cell { padding-top: 10px; border-top: 1px solid var(--line); margin-top: 4px; }
  .act-col { flex-direction: row; flex-wrap: wrap; width: 100%; }
  .act-col .mini-btn { flex: 1 1 120px; }
  .admin-table tr.row-detail { margin: -6px 0 10px; }
  .admin-table tr.row-detail > td { display: block; border: 1px solid var(--line); border-radius: 12px; }
  .detail-actions input { width: 100%; }
  .detail-actions .mini-btn { flex: 1 1 auto; }
  .feed-panel .feed { max-height: 300px; }
}

/* ---- Logo watermark behind the whole system ---- */
/* Static fallback (no JS): hangs off the bottom-right corner. */
body::before {
  content: "";
  position: fixed;
  right: -10%;
  bottom: -12%;
  width: max(140vmin, 95vmax);
  aspect-ratio: 1 / 1;
  background: url("logo.png") center / contain no-repeat;
  opacity: 0.5;
  z-index: -1;
  pointer-events: none;
}
.bg-js body::before { display: none; }
/* Floating version, positioned and rotated by assets/logo-bg.js */
.bg-logo {
  position: fixed;
  left: 0;
  top: 0;
  background: url("logo.png") center / contain no-repeat;
  opacity: 0.5;
  z-index: -1;
  pointer-events: none;
  will-change: transform;
}

/* Customer pages: keep the panel in the middle of the screen */
.wrap.center {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* ---- Paper punch card (customer page) ---- */
.child-panel { display: flex; flex-direction: column; }
.paper {
  transform: rotate(-1.8deg);
}
.children .child-panel:nth-child(even) .paper { transform: rotate(1.5deg); }
.paper-svg { display: block; width: 100%; height: auto; }
.paper-note {
  margin: 18px 6px 0;
  padding: 10px 14px;
  background: var(--card);
  border-radius: 0;
}
.paper-note.history { margin-top: 18px; }
.paper-note p, p.paper-note { color: var(--muted); }
/* The tilted paper and scattered circles may stick out; clip at the screen edge, not the column. */
.stage { position: relative; width: 100%; overflow-x: hidden; overflow-x: clip; }

/* Punched-out circles scattered around the card (one per used hole) */
.child-panel { position: relative; }
.paper { position: relative; z-index: 1; }
@font-face {
  font-family: 'FB Philosof';
  src: url('fonts/FbPhilosof-Regular.otf') format('opentype');
  font-weight: 400;
  font-display: swap;
}
.paper-text { font-family: 'FB Philosof', system-ui, sans-serif; font-weight: 400; }
.chad {
  position: absolute;
  z-index: 0;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: var(--paper); /* punched-out bits of the card itself */
  pointer-events: none;
}

/* Admin heading sits directly on the dark background */
.topbar h1 { color: #fff; }

/* Right-click / long-press menu on admin names */
.ctx-menu {
  position: fixed;
  z-index: 1000;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  min-width: 170px;
}
.ctx-menu button {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: start;
}
.ctx-menu button:hover { background: var(--brand-dark); }
.admin-table td.name-cell { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }

.notify-line { margin: 8px 0 0; }

/* wrong-password shake */
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
.shake { animation: shake .35s; }
@media (prefers-reduced-motion: reduce) { .shake { animation: none; } }

/* Buy a new card (under the punch card) */
.buy { margin-top: 28px; text-align: center; }
.buy-toggle { width: 100%; }
.buy-panel { border-radius: 16px; display: flex; flex-direction: column; gap: 8px; margin: 12px 0 0; padding: 14px; text-align: center; }
.buy-panel.hidden { display: none; }
.buy-title { margin: 0 0 4px; font-weight: 600; color: var(--ink); }
.buy-opt { display: block; width: 100%; text-decoration: none; text-align: center; }
.buy-opt.disabled { opacity: .5; cursor: default; }
.buy-opt.disabled:hover { background: var(--brand); }
@media (max-width: 720px) { .buy-panel { border-radius: 14px; } }

/* Whole customer site uses the ticket font (admin keeps the system font) */
body.customer, body.customer button, body.customer input, body.customer select, body.customer textarea {
  font-family: 'FB Philosof', -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
body.customer .btn, body.customer .lang-btn, body.customer h1 { font-weight: 400; }

/* Front page: new-ticket section + pop-up */
.card-box.new-ticket { margin: 16px auto 0; width: 90%; padding: 18px 20px; }
.new-ticket h2 { font-size: 1.05rem; margin: 0 0 12px; }
.staff-link { margin: 20px 0 0; text-align: center; color: #fff; }
.staff-link a { color: #fff; }
.new-ticket .btn { width: 100%; }
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(31, 41, 51, .6); overflow-y: auto; }
.modal.hidden { display: none; }
.modal .card-box { width: 100%; max-width: 440px; margin: auto; opacity: 1; position: relative; }
.modal-close { position: absolute; top: 10px; inset-inline-end: 12px; border: none; background: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); font-family: inherit; }
.modal-form { display: grid; gap: 10px; }
.modal-form .btn, .modal-done .btn { width: 100%; text-align: center; text-decoration: none; display: block; }
.modal-done p { margin: 0 0 14px; }

/* Admin: pending sign-ups */
.pending-panel { margin-bottom: 16px; }
.pending-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--line); }
.pending-row .info { min-width: 0; }
.pending-row .acts { display: flex; gap: 6px; }

/* Customer pages: all text centred */
body.customer, body.customer input, body.customer select { text-align: center; }
body.customer select { text-align-last: center; }
body.customer .modal-close { text-align: center; }

/* Parent's name row at the top of an expanded admin row */
.parent-edit { margin: 0 0 12px; align-items: center; }
.parent-edit label { font-weight: 600; }

/* The "finished cards" summary tile is clickable */
.summary .tile.clickable { cursor: pointer; transition: transform .12s ease; }
.summary .tile.clickable:hover { transform: translateY(-2px); }
.summary .tile.clickable:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .summary .tile.clickable { transition: none; } }

/* "Send on WhatsApp" link styled like the other small buttons */
a.mini-btn { display: inline-block; text-align: center; text-decoration: none; }
a.mini-btn:visited { color: #fff; }
