:root {
  --cream: #FBF5EC;
  --card-bg: #FFFDF9;
  --ink: #1C1008;
  --stone: #6B5C4A;
  --mist: #EDE5D8;
  --border: rgba(107,92,74,0.18);
  --fire: #D44D2A;
  --fire-light: #F26B3F;
  --fire-tint: #FBE4DA;
  --success: #3D7A5C;
  --success-tint: #E1EEE6;
  --tint: #F3E7DA;
  --overlay: rgba(28,16,8,0.42);
  --shadow: 0 2px 14px rgba(28,16,8,0.07);
  --shadow-lg: 0 12px 40px rgba(28,16,8,0.22);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cream: #17110B;
    --card-bg: #241A12;
    --ink: #F5EAD9;
    --stone: #BBA48C;
    --mist: #2E2116;
    --border: rgba(245,234,217,0.14);
    --fire: #EA6944;
    --fire-light: #F5875F;
    --fire-tint: #3A2015;
    --success: #63A886;
    --success-tint: #1E2C24;
    --tint: #2A1D12;
    --overlay: rgba(0,0,0,0.55);
    --shadow: 0 2px 18px rgba(0,0,0,0.35);
    --shadow-lg: 0 18px 50px rgba(0,0,0,0.5);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: "DM Sans", ui-sans-serif, system-ui, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
code, .mono { font-family: "DM Mono", ui-monospace, monospace; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--fire); outline-offset: 2px; }
/* Elements marked hidden via the HTML "hidden" attribute must actually hide,
   even when a class on them (like .auth-screen) sets its own display value. */
[hidden] { display: none !important; }

.app { max-width: 980px; margin: 0 auto; padding: 2.4rem 1.5rem 5rem; }

/* ---- auth screen ---- */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 16px; padding: 2rem 1.8rem; box-shadow: var(--shadow-lg);
}
.auth-title { font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 1.6rem; margin: 0.5rem 0 0.3rem; }
.auth-copy { color: var(--stone); font-size: 0.9rem; margin: 0 0 1.2rem; }
.auth-status { font-size: 0.85rem; color: var(--stone); min-height: 1.2em; margin-top: 0.8rem; }

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap;
  margin-bottom: 2.2rem; padding-bottom: 1.6rem; border-bottom: 1px solid var(--border);
}
.brand-eyebrow {
  font-family: "DM Mono", monospace; font-size: 0.72rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--fire); margin-bottom: 0.5rem;
}
.topbar h1 { font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 2.1rem; margin: 0 0 0.35rem; letter-spacing: -0.01em; }
.topbar p { margin: 0; color: var(--stone); font-size: 0.95rem; max-width: 46ch; }

.btn {
  display: inline-flex; align-items: center; gap: 0.45rem; border: none; border-radius: 9px;
  padding: 0.72rem 1.15rem; font-size: 0.9rem; font-weight: 700; cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--fire); color: #FFFBF6; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--fire-light); }
.btn-ghost { background: transparent; color: var(--stone); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--ink); border-color: var(--stone); }
.btn-danger { background: transparent; color: #B0432A; border: 1px solid rgba(176,67,42,0.35); }
.btn-danger:hover { background: rgba(176,67,42,0.08); }
.btn-sm { padding: 0.42rem 0.75rem; font-size: 0.78rem; border-radius: 7px; }
.btn-xs { padding: 0.3rem 0.6rem; font-size: 0.72rem; border-radius: 6px; }

.stats { display: flex; gap: 2.2rem; margin-bottom: 2rem; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; gap: 0.15rem; }
.stat .n { font-family: "Fraunces", serif; font-weight: 600; font-size: 1.6rem; }
.stat .l { font-family: "DM Mono", monospace; font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--stone); }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
@media (max-width: 680px) { .grid { grid-template-columns: 1fr; } }

.rcard {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 16px;
  padding: 1.3rem 1.3rem 1.1rem; box-shadow: var(--shadow); display: flex; flex-direction: column;
  gap: 0.85rem; transition: opacity 0.15s ease;
}
.rcard.is-paused { opacity: 0.6; }
.rcard-head { display: flex; align-items: flex-start; gap: 0.8rem; }
.ricon {
  width: 44px; height: 44px; border-radius: 11px; background: var(--fire-tint);
  display: flex; align-items: center; justify-content: center; font-size: 1.35rem; flex-shrink: 0;
}
.rcard-title { flex: 1; min-width: 0; }
.rcard-title h3 { font-family: "Fraunces", serif; font-weight: 600; font-size: 1.15rem; margin: 0 0 0.3rem; letter-spacing: -0.005em; }
.pill {
  display: inline-flex; align-items: center; gap: 0.35rem; font-family: "DM Mono", monospace; font-size: 0.68rem;
  letter-spacing: 0.05em; text-transform: uppercase; padding: 0.2rem 0.55rem; border-radius: 100px;
}
.pill-active { background: var(--success-tint); color: var(--success); }
.pill-paused { background: var(--mist); color: var(--stone); }
.pill-active::before, .pill-paused::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.rcard-rule { font-size: 0.9rem; color: var(--stone); background: var(--tint); border-radius: 9px; padding: 0.65rem 0.8rem; line-height: 1.5; }
.rcard-rule b { color: var(--ink); font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip { font-family: "DM Mono", monospace; font-size: 0.7rem; background: var(--mist); color: var(--stone); padding: 0.22rem 0.5rem; border-radius: 6px; }
.chip.more { color: var(--fire); background: var(--fire-tint); }

.rcard-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-top: 0.2rem; }
.switch-row { display: flex; align-items: center; gap: 0.5rem; }
.switch-row .swlabel { font-size: 0.78rem; color: var(--stone); font-family: "DM Mono", monospace; }
.switch { position: relative; width: 34px; height: 19px; flex-shrink: 0; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: var(--mist); border-radius: 100px; transition: background 0.15s ease; }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: var(--card-bg); box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: transform 0.15s ease; }
.switch input:checked + .track { background: var(--success); }
.switch input:checked + .track + .knob { transform: translateX(15px); }
.switch input:focus-visible + .track { outline: 2px solid var(--fire); outline-offset: 2px; }

.rowbtns { display: flex; gap: 0.4rem; }

.empty {
  grid-column: 1 / -1; border: 1.5px dashed var(--border); border-radius: 16px; padding: 2.6rem 1.5rem;
  text-align: center; color: var(--stone);
}
.empty .em-icon { font-size: 1.8rem; margin-bottom: 0.6rem; }
.empty h3 { font-family: "Fraunces", serif; color: var(--ink); margin: 0 0 0.4rem; font-weight: 600; }
.empty p { margin: 0 0 1.1rem; font-size: 0.9rem; }

.scrim { position: fixed; inset: 0; background: var(--overlay); opacity: 0; pointer-events: none; transition: opacity 0.18s ease; z-index: 40; }
.scrim.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--cream);
  border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(.4,0,.2,1); z-index: 41; display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }

.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 1.3rem 1.4rem; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-family: "Fraunces", serif; font-size: 1.25rem; font-weight: 600; margin: 0; }
.iconbtn {
  background: none; border: none; color: var(--stone); cursor: pointer; width: 30px; height: 30px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
}
.iconbtn:hover { background: var(--tint); color: var(--ink); }

.drawer-body { flex: 1; overflow-y: auto; padding: 1.4rem; display: flex; flex-direction: column; gap: 1.4rem; }
.field { display: flex; flex-direction: column; gap: 0.45rem; }
.field label { font-family: "DM Mono", monospace; font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--stone); }
.field .hint { font-size: 0.8rem; color: var(--stone); font-family: "DM Sans", sans-serif; text-transform: none; letter-spacing: normal; margin-top: -0.2rem; }
.input, select.input {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.65rem 0.75rem;
  font-size: 0.95rem; color: var(--ink); font-family: "DM Sans", sans-serif; width: 100%;
}
.input:focus { outline: none; border-color: var(--fire); box-shadow: 0 0 0 3px var(--fire-tint); }

.stepper { display: flex; align-items: center; gap: 0.6rem; }
.stepper button { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--card-bg); color: var(--ink); font-size: 1.1rem; cursor: pointer; font-family: "DM Mono", monospace; }
.stepper button:hover { border-color: var(--fire); color: var(--fire); }
.stepper .stepper-val { font-family: "Fraunces", serif; font-weight: 600; font-size: 1.5rem; min-width: 3ch; text-align: center; font-variant-numeric: tabular-nums; }
.stepper .unit { color: var(--stone); font-size: 0.85rem; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
.seg button { border: 1px solid var(--border); background: var(--card-bg); color: var(--stone); border-radius: 8px; padding: 0.55rem 0.4rem; font-size: 0.8rem; cursor: pointer; font-weight: 500; }
.seg button.active { border-color: var(--fire); background: var(--fire-tint); color: var(--fire); font-weight: 700; }

.chipgrid { display: flex; flex-direction: column; gap: 0.7rem; max-height: 240px; overflow-y: auto; }
.chipgroup .cg-label { font-family: "DM Mono", monospace; font-size: 0.68rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--stone); margin-bottom: 0.4rem; display: block; }
.cg-items { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.toggle-chip { border: 1px solid var(--border); background: var(--card-bg); color: var(--stone); border-radius: 100px; padding: 0.35rem 0.75rem; font-size: 0.8rem; cursor: pointer; }
.toggle-chip.on { border-color: var(--fire); background: var(--fire); color: #FFFBF6; font-weight: 600; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle-row .trlabel { font-size: 0.92rem; }
.toggle-row .trhint { font-size: 0.8rem; color: var(--stone); }

.drawer-foot { padding: 1.1rem 1.4rem; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.err { font-size: 0.82rem; color: #B0432A; min-height: 1.1em; }

@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr; }
  .drawer { width: 100vw; }
}

.note {
  margin-top: 2.6rem; padding-top: 1.4rem; border-top: 1px dashed var(--border);
  font-size: 0.82rem; color: var(--stone); font-family: "DM Mono", monospace; line-height: 1.6;
}

/* ---- tabs ---- */
.tabs { display: flex; gap: 0.3rem; margin-bottom: 1.4rem; border-bottom: 1px solid var(--border); }
.tab {
  background: none; border: none; padding: 0.65rem 0.9rem; font-size: 0.86rem; font-weight: 600;
  color: var(--stone); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
  font-family: "DM Sans", sans-serif; transition: color 0.12s ease, border-color 0.12s ease;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--fire); border-bottom-color: var(--fire); }

/* ---- search ---- */
.search-row { margin-bottom: 1.2rem; }
.search-input { max-width: 340px; }

/* ---- data tables ---- */
.tablewrap { background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.tablewrap { overflow-x: auto; }
table.dtable { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
table.dtable th {
  text-align: left; font-family: "DM Mono", monospace; font-size: 0.66rem; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--stone); padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.dtable td { padding: 0.9rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.dtable tr:last-child td { border-bottom: none; }
table.dtable tr:hover td { background: var(--tint); }
.cname { font-weight: 600; }
.cphone { color: var(--stone); font-family: "DM Mono", monospace; font-size: 0.82rem; }

.progress-cell { display: flex; align-items: center; gap: 0.6rem; min-width: 160px; }
.progress-track { flex: 1; height: 7px; border-radius: 100px; background: var(--mist); overflow: hidden; }
.progress-fill { height: 100%; background: var(--fire); border-radius: 100px; }
.progress-fill.is-full { background: var(--success); }
.progress-label { font-family: "DM Mono", monospace; font-size: 0.76rem; color: var(--stone); white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; gap: 0.3rem; font-family: "DM Mono", monospace; font-size: 0.68rem;
  letter-spacing: 0.05em; text-transform: uppercase; padding: 0.2rem 0.55rem; border-radius: 100px;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-available, .badge-sent { background: var(--success-tint); color: var(--success); }
.badge-redeemed { background: var(--mist); color: var(--stone); }
.badge-expired, .badge-failed { background: var(--fire-tint); color: var(--fire); }
.badge-pending { background: var(--tint); color: var(--stone); }

/* ---- grouped-by-customer chips (Customers / Redemptions tabs) ----
   One reward per line, in a lightweight aligned column — NOT inline/wrapped
   chips, which crowd together unreadably once a customer has 2-3 cards. */
.progress-chip-list { display: flex; flex-direction: column; gap: 0.5rem; min-width: 260px; }
.progress-chip {
  display: grid; grid-template-columns: 7.5rem 80px 3rem; align-items: center; gap: 0.7rem;
}
.progress-chip-name {
  font-size: 0.8rem; color: var(--stone); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.progress-track-sm { width: 80px; flex: none; }

.redeem-chip-list { display: flex; flex-direction: column; align-items: flex-start; gap: 0.55rem; }
.redeem-chip { display: flex; align-items: center; gap: 0.65rem; }


.errtext { color: #B0432A; font-size: 0.8rem; max-width: 320px; white-space: normal; }

.filter-row { display: flex; gap: 0.4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.chipf {
  border: 1px solid var(--border); background: var(--card-bg); color: var(--stone); border-radius: 100px;
  padding: 0.4rem 0.85rem; font-size: 0.8rem; cursor: pointer; font-family: "DM Sans", sans-serif; font-weight: 500;
}
.chipf.active { border-color: var(--fire); background: var(--fire-tint); color: var(--fire); font-weight: 700; }

.rowbtn-redeem { white-space: nowrap; }

.empty-row td { text-align: center; color: var(--stone); padding: 2.2rem 1rem; font-size: 0.9rem; }
