/* ============================================================
   Promo dispenser - shared styles (public page + admin panel)
   Flat design: no radii, no gradients. The only depth is a hairline
   outer shadow under buttons and a hairline inset shadow in inputs.
   Panels use --surface, controls use --btn-bg, so the two are
   never confused. Two control sizes only: 44px and 34px.
   ============================================================ */

:root {
  /* Brand colors are written here at runtime by theme.js. */
  --primary: #4f46e5;
  --primary-btn: #4f46e5;
  --primary-contrast: #ffffff;
  --bg: #f5f6fa;
  --text: #14161c;
  --surface: #ffffff;

  /* Secondary text is full-contrast; hierarchy comes from size and
     weight, never from gray-on-gray color. */
  --text-muted: var(--text);
  --border: color-mix(in srgb, var(--text) 12%, transparent);
  --btn-bg: color-mix(in srgb, var(--text) 5%, transparent);
  --btn-bg-hover: color-mix(in srgb, var(--text) 9%, transparent);
  /* Hairline depth: a whisper of lift under buttons, a whisper of
     depth inside inputs. Dark theme strengthens them since black
     barely reads on dark surfaces. */
  --shadow-btn: 0 2px 5px rgba(0, 0, 0, 0.11);
  --shadow-inset: inset 0 1px 3px rgba(0, 0, 0, 0.09);
  --radius: 0;

  /* Status colors dark enough for small text on the light surface;
     .dark below swaps them for lighter variants. */
  --danger-text: #b91c1c;
  --warning-text: #92400e;
  --success-text: #166534;
}

.dark {
  --danger-text: #fca5a5;
  --warning-text: #fcd34d;
  --success-text: #6ee7a0;
  --shadow-btn: 0 2px 5px rgba(0, 0, 0, 0.55);
  --shadow-inset: inset 0 1px 3px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

/* Visible keyboard focus everywhere (custom buttons otherwise lose it). */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 0;
}

.noscript-note {
  max-width: 490px;
  margin: 80px auto;
  padding: 16px 20px;
  text-align: center;
  font-family: system-ui, sans-serif;
  color: var(--text-muted, #666);
}

.load-fail {
  padding: 48px 24px;
  text-align: center;
  font-family: system-ui, sans-serif;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---- Public page layout ---- */
/* Desktop: the card sits a fixed 16px under the floating controls -
   the same gap the controls have from the top of the page. */
.page {
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 66px 20px 48px;
}

.card {
  width: 100%;
  max-width: 490px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 32px 28px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  overflow: hidden;
}

/* Cover with the app icon overlapping its bottom edge. */
.card-head {
  position: relative;
  width: calc(100% + 56px);
  margin: -32px -28px 0;
}
.card-cover { height: 150px; overflow: hidden; }
.card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

.card-icon {
  position: absolute;
  left: 50%;
  bottom: -40px;
  transform: translateX(-50%);
  width: 80px;
  height: 80px;
  border-radius: 0;
  overflow: hidden;
  background: var(--btn-bg);
  box-shadow: var(--shadow-btn);
}
.card-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Without a cover the icon returns to normal flow. */
.card.no-cover .card-head { width: auto; margin: 0; }
.card.no-cover .card-icon { position: static; transform: none; }

.card-title {
  font-size: 25px;
  font-weight: 700;
  line-height: 1.2;
  margin: 52px 0 0;
  letter-spacing: -0.01em;
  overflow-wrap: break-word;
  /* Left-aligned like the description below: one clean left edge for
     the whole text block. Long names wrap naturally at full width. */
  width: 100%;
  text-align: left;
}
.card.no-cover .card-title { margin-top: 16px; }

.card-desc {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-muted);
  margin: 8px 0 0;
  width: 100%;
  text-align: left;
  overflow-wrap: break-word;
}

.ended-banner {
  margin-top: 14px;
  padding: 8px 14px;
  border-radius: 0;
  background: color-mix(in srgb, #ef4444 12%, transparent);
  border: 1px solid color-mix(in srgb, #ef4444 30%, transparent);
  color: var(--danger-text);
  font-size: 13px;
  font-weight: 600;
}

/* "Out of codes" uses a calmer amber tone - the campaign isn't over,
   it just has no codes left right now. */
.ended-banner.empty {
  background: color-mix(in srgb, #f59e0b 12%, transparent);
  border-color: color-mix(in srgb, #f59e0b 32%, transparent);
  color: var(--warning-text);
}

/* ---- Admin: codes toolbar ---- */
.codes-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 14px 0 8px;
}
.codes-search {
  flex: 1;
  min-width: 140px;
  height: 34px;
  padding: 0 10px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow-inset);
}
.pager {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
.btn-danger {
  color: var(--danger-text);
  border-color: color-mix(in srgb, #dc2626 35%, transparent);
}
.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, #dc2626 10%, transparent);
}
.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Upcoming end date/time shown while the campaign is still running. */
.ends-info {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

.card-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/* Onboarding line above the claim flow. */
.onboarding {
  width: 100%;
  margin: 18px 0 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: left;
}

.claim-zone { width: 100%; margin-top: 14px; }

/* Step label above the store selector. */
.step-label {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
}

/* Download section - visually separated from the claim flow. */
.download-section {
  width: 100%;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.section-label {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
}

/* One button system: every button is 44px tall, 14px/600 type, tinted
   background with a border. .btn-small (34px, 13px) is the only
   variant. Panels never share this background. */
.btn,
.store-opt,
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--btn-bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: var(--shadow-btn);
  transition: background 0.15s ease;
}
.btn:hover,
.store-opt:hover,
.action-btn:hover { background: var(--btn-bg-hover); }
.btn:disabled,
.store-opt:disabled,
.action-btn:disabled { opacity: 0.5; cursor: wait; }
.btn svg { width: 24px; height: 24px; flex-shrink: 0; }

.btn-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.15;
  text-align: center;
}
.btn-text small { font-size: 11px; font-weight: 500; }
.btn-text strong { font-size: 14px; font-weight: 600; }

.btn-primary {
  width: 100%;
  background: var(--primary-btn);
  border-color: transparent;
  color: var(--primary-contrast);
}
.btn-primary:hover { background: color-mix(in srgb, var(--primary-btn) 88%, #000); }

/* ---- Store selector (choose which store's code to claim) ---- */
.store-select {
  display: flex;
  gap: 8px;
  width: 100%;
  margin-bottom: 16px;
}
.store-opt { flex: 1; }
.store-opt svg { width: 20px; height: 20px; flex-shrink: 0; }
.store-opt.active {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

/* ---- Remaining codes counter ---- */
.remaining {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ---- Result card (claimed code) ---- */
/* Panel: surface background, so it reads as a container, not a button. */
.result-card {
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  border-radius: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  text-align: left;
}
/* The `hidden` attribute is otherwise overridden by `display: flex` above. */
.result-card[hidden] { display: none; }
.result-label { margin: 0; font-size: 13px; color: var(--text-muted); }

/* Code field: full-width box with the code on the left and an inline copy icon. */
.code-field {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 6px 6px 6px 14px;
  border-radius: 0;
  background: color-mix(in srgb, var(--text) 8%, transparent);
}
.result-code {
  flex: 1;
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  letter-spacing: 0.04em;
  word-break: break-all;
  text-align: left;
}
.copy-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 0;
  border: none;
  background: color-mix(in srgb, var(--text) 10%, transparent);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  transition: background 0.15s ease;
}
.copy-btn:hover { background: color-mix(in srgb, var(--text) 18%, transparent); }
.copy-btn svg { width: 18px; height: 18px; }

.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.result-note { margin: 0; font-size: 12px; color: var(--text-muted); text-align: left; }
.result-note a { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }
.result-note a:hover { text-decoration-thickness: 2px; }
.result-share { margin-top: 2px; }

/* ---- Share ---- */
.share-row { width: 100%; margin-top: 12px; }
.btn-share { width: 100%; }

/* ---- QR ---- */
.qr-block {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.qr-block[hidden] { display: none; }
.qr-code {
  width: 132px;
  height: 132px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0;
}
.qr-code svg { display: block; width: 100%; height: 100%; }
.qr-caption { margin: 0; font-size: 12px; color: var(--text-muted); }

/* ---- Controls (theme + language) ---- */
.controls {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 20;
}
.control-btn,
.lang-select {
  appearance: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.control-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  box-shadow: var(--shadow-btn);
}
.control-btn:hover,
.lang-select:hover { background: var(--btn-bg-hover); }
.lang-select {
  height: 34px;
  padding: 0 30px 0 14px;
  max-width: 160px;
  box-shadow: var(--shadow-inset);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* ---- Status messages (public) ---- */
.status-msg {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 0;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.status-msg.success { border-color: color-mix(in srgb, #22c55e 40%, transparent); color: var(--success-text); }
.status-msg.warning { border-color: color-mix(in srgb, #f59e0b 40%, transparent); color: var(--warning-text); }
.status-msg.error { border-color: color-mix(in srgb, #ef4444 40%, transparent); color: var(--danger-text); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 12px);
  z-index: 40;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  padding: 9px 18px;
  border-radius: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---- RTL ---- */
[dir='rtl'] .controls { right: auto; left: 16px; }
[dir='rtl'] .lang-select { padding: 0 14px 0 30px; background-position: left 12px center; }

/* ============================================================
   Admin panel
   ============================================================ */
.admin-body { min-height: 100dvh; }
.admin-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 64px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.admin-header h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.admin-view {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}

.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.admin-card h2 { margin: 0; font-size: 17px; }
.admin-card h3 { margin: 8px 0 0; font-size: 14px; color: var(--text-muted); }
.admin-card-head { display: flex; align-items: center; justify-content: space-between; }

/* The cards live inside #admin-content, so the wrap's gap does not reach
   them - give the container its own column layout and spacing. */
#admin-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { margin: 0; font-size: 13px; color: var(--text-muted); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field-hint { font-weight: 400; font-style: normal; font-size: 11px; }
.field-check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.field-check input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.field-check > span { font-size: 14px; color: var(--text); }
.field input[type='text'],
.field input[type='url'],
.field input[type='password'],
.field input[type='number'],
.field input[type='datetime-local'],
.field select,
.field textarea,
#login-form input {
  font: inherit;
  font-size: 14px;
  height: 44px;
  padding: 0 12px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 100%;
  box-shadow: var(--shadow-inset);
}
/* The login form is a plain block: without this the token field and the
   Sign in button render glued to each other. */
#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.field textarea {
  height: auto;
  min-height: 88px;
  padding: 10px 12px;
  resize: vertical;
}
/* Placeholders stay lighter than real text, but still readable. */
::placeholder { color: color-mix(in srgb, var(--text) 55%, transparent); opacity: 1; }
.row2 { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1.4fr 1fr 0.8fr; gap: 8px; }
@media (max-width: 560px) { .row3 { grid-template-columns: 1fr; } }

.btn-small {
  height: 34px;
  padding: 0 12px;
  font-size: 13px;
  gap: 6px;
}
.btn-file {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

/* i18n dynamic lists */
.i18n-list { display: flex; flex-direction: column; gap: 8px; }
.i18n-row { display: grid; grid-template-columns: 72px 1fr auto auto; gap: 8px; align-items: center; }
.i18n-row .i18n-lang {
  font: inherit; font-size: 13px; height: 34px; padding: 0 10px;
  border-radius: 0; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
  box-shadow: var(--shadow-inset);
}
.i18n-row .i18n-value {
  font: inherit; font-size: 13px; height: 34px; padding: 0 10px;
  border-radius: 0; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); width: 100%;
  box-shadow: var(--shadow-inset);
}
.i18n-row .ai-btn { color: var(--primary); border-color: color-mix(in srgb, var(--primary) 40%, transparent); }
@media (max-width: 560px) {
  .i18n-row { grid-template-columns: 60px 1fr; }
  .i18n-row .i18n-value { grid-column: 1 / -1; }
}

/* colors */
.colors-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
@media (max-width: 560px) { .colors-grid { grid-template-columns: repeat(2, 1fr); } }
.colors-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.colors-grid input[type='color'] {
  width: 100%;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  cursor: pointer;
}

/* media */
.media-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 560px) { .media-row { grid-template-columns: 1fr; } }
.media-item { display: flex; flex-direction: column; gap: 8px; }
.media-item > span { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.media-preview {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--bg);
}
.media-preview.cover { width: 100%; height: 90px; }
.media-item input[type='file'] { font-size: 13px; }
.codes-title { margin: 0; }

/* codes */
.codes-summary { display: flex; gap: 10px; flex-wrap: wrap; }
.code-pill {
  padding: 8px 14px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
}
.code-pill b { color: var(--primary); }
.codes-table-wrap { overflow-x: auto; }
.codes-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.codes-table th, .codes-table td {
  text-align: start;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}
.codes-table th { color: var(--text-muted); font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.admin-footer { display: flex; justify-content: flex-end; }

/* ---- Responsive (public) ---- */
/* Mobile: the card stops being a card - it becomes the page itself.
   No borders, no outer margins; the cover runs edge to edge and the
   controls float above it. */
@media (max-width: 480px) {
  .page { padding: 0; align-items: stretch; }
  .card {
    max-width: none;
    border: none;
    padding: 0 20px 40px;
    min-height: 100dvh;
  }
  .card-head { width: calc(100% + 40px); margin: 0 -20px; }
  .card-cover { height: 170px; }
  .card.no-cover { padding-top: 62px; }
  .card.no-cover .card-head { margin: 0; }
  .card-title { font-size: 23px; }
  .controls { top: 12px; right: 12px; }
  [dir='rtl'] .controls { left: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
