/* ============================================================
   Admin console — dark, laid out like the HR HERO Random Chest admin
   (hrhero-bountybox/src/app/admin + components/AdminPanel):
   - sidebar 260px + main column; stacks on narrow / portrait screens
   - solid panels on a near-black page, 0.5px hairlines, no glow
   - orange only for the primary action and "selected"; state colours by meaning
   Primary is empeo Flame (the original used HR HERO orange) and type is Gofive.
   `.ad` carries the tokens so dialogs appended to <body> get them too.
   ============================================================ */

.ad {
  --r-lg: 20px;
  --r-row: 14px;
  --r-xl: 30px;
  --r-pill: 9999px;

  --line: rgba(255, 255, 255, 0.10);
  --line-card: #33333d;
  --line-strong: #525260;

  --bg: #0d0d11;
  --panel: #16161c;
  --panel-2: #1e1e26;
  --panel-hover: #23232c;
  --text: #f4f4f7;
  --text-muted: #b4b4c2;
  --text-faint: #8e8e9e;

  --primary: #F05B2F;
  --primary-hover: #E54111;
  --primary-soft: rgba(240, 91, 47, 0.16);
  --primary-text: #ff8a63;
  --info: #5b9dff;
  --success: #00cc99;
  --success-soft: rgba(0, 204, 153, 0.14);
  --warn: #f5b544;
  --warn-soft: rgba(245, 181, 68, 0.14);
  --danger: #ff6b5e;
  --danger-soft: rgba(255, 107, 94, 0.14);

  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  color-scheme: dark;
  -webkit-user-select: text;
  user-select: text;
}
.ad ::selection { background: rgba(240, 91, 47, 0.35); color: #fff; }
.ad :focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.ad button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.ad input, .ad select { font: inherit; font-size: 16px; color: inherit; }
.ad .num { font-variant-numeric: tabular-nums; }
.ad .nowrap { white-space: nowrap; }
.ad svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.ad * { scrollbar-width: thin; scrollbar-color: #3a3a46 transparent; }
.ad-dim { color: var(--text-faint); }
.ad-muted { color: var(--text-muted); }

/* ===== Shell ===== */
.ad-page { min-height: 100dvh; display: grid; grid-template-columns: 260px minmax(0, 1fr); background: var(--bg); }

.ad-side {
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  padding: calc(22px + var(--safe-t)) 14px calc(22px + var(--safe-b)) calc(14px + var(--safe-l));
  background: var(--panel); border-right: 0.5px solid var(--line-card);
}
.ad-side__logo { padding: 0 10px 22px; }
.ad-brand { font-weight: 700; font-size: 16px; letter-spacing: 0.02em; white-space: nowrap; }
.ad-brand b { color: var(--primary-text); font-weight: 700; }
.ad-brand-sub { font-size: 14px; color: var(--text-muted); }
.ad-side__title { padding: 0 10px 6px; font-size: 14px; font-weight: 500; color: var(--text-faint); }

.ad-nav { display: flex; flex-direction: column; gap: 2px; }
.ad-nav__item {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left;
  min-height: 56px; padding: 10px 12px; border-radius: var(--r-row);
  transition: background 0.15s;
}
.ad-nav__item:hover { background: var(--panel-hover); }
.ad-nav__item.is-selected, .ad-nav__item.is-selected:hover { background: var(--primary-soft); }
.ad-nav__head { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--text-muted); }
.ad-nav__name { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ad-nav__item.is-selected .ad-nav__head { color: var(--primary-text); }
.ad-nav__item.is-selected .ad-nav__name { font-weight: 600; }
.ad-nav__meta { padding-left: 30px; font-size: 14px; color: var(--text-faint); }
.ad-live {
  display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: var(--r-pill);
  font-size: 13px; font-weight: 600; background: var(--success-soft); color: var(--success);
}
.ad-live.is-off { background: var(--panel-2); color: var(--text-muted); }

.ad-side__foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding: 14px 10px 0; border-top: 0.5px solid var(--line); }
.ad-side__row { display: flex; gap: 6px; flex-wrap: wrap; }
.ad-back { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; font-size: 14px; color: var(--text-muted); }
.ad-back:hover { color: var(--text); }
.ad-back svg.i { width: 16px; height: 16px; stroke-width: 2.4; }

/* small quiet pills (.pia in the original) */
.ad-pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px;
  border-radius: var(--r-pill); border: 0.5px solid var(--line-strong) !important;
  font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; cursor: pointer;
  transition: background 0.15s, transform 0.12s;
}
.ad-pill:hover { background: var(--panel-hover); }
.ad-pill:active { transform: scale(0.96); }
.ad-pill svg.i { width: 15px; height: 15px; stroke-width: 2.4; }

.ad-main { min-width: 0; padding: calc(28px + var(--safe-t)) calc(32px + var(--safe-r)) calc(48px + var(--safe-b)) 32px; display: flex; flex-direction: column; gap: 20px; }

/* ===== Page head ===== */
.ad-panel-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 2px; }
.ad-title { margin: 0; font-size: 26px; line-height: 1.25; font-weight: 700; }
.ad-sub { margin: 2px 0 0; font-size: 14px; color: var(--text-muted); }
.ad-sub strong { color: var(--text); font-weight: 600; }
.ad-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ===== Buttons ===== */
.ad-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: var(--r-pill);
  font-size: 15px; font-weight: 600; white-space: nowrap;
  transition: transform 0.12s, background 0.15s, opacity 0.15s, color 0.15s;
}
.ad-btn:active:not(:disabled) { transform: scale(0.97); }
.ad-btn svg.i { width: 18px; height: 18px; stroke-width: 2.4; }
.ad-btn--primary { background: var(--primary) !important; color: #fff; }
.ad-btn--primary:hover:not(:disabled) { background: var(--primary-hover) !important; }
.ad-btn--outline { border: 0.5px solid var(--line-strong) !important; color: var(--text); }
.ad-btn--outline:hover:not(:disabled) { background: var(--panel-hover) !important; }
.ad-btn--danger-outline { border: 0.5px solid rgba(255, 107, 94, 0.4) !important; color: var(--danger); }
.ad-btn--danger-outline:hover:not(:disabled) { background: var(--danger-soft) !important; }
.ad-btn--sm { min-height: 36px; padding: 0 14px; font-size: 14px; gap: 6px; }
.ad-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ===== Flash + empty ===== */
.ad-flash { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--r-row); font-size: 14px; font-weight: 500; }
.ad-flash--warn { background: var(--warn-soft); color: var(--warn); }
.ad-flash--err { background: var(--danger-soft); color: var(--danger); }
.ad-empty { padding: 40px 24px; text-align: center; color: var(--text-muted); background: var(--panel); border: 0.5px solid var(--line-card); border-radius: var(--r-lg); }
.ad-empty p { margin: 0; }
.ad-empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }
.ad-empty strong { color: var(--text); font-weight: 600; }

/* ===== Table in a panel ===== */
.ad-table-wrap { background: var(--panel); border: 0.5px solid var(--line-card); border-radius: var(--r-lg); overflow-x: auto; overscroll-behavior-x: contain; }
.ad-table-wrap--flat { background: none; border: 0; border-radius: 0; }
.ad-table { width: 100%; min-width: 760px; border-collapse: collapse; }
.ad-table th { padding: 12px 12px 10px; text-align: left; font-size: 14px; font-weight: 500; color: var(--text-faint); border-bottom: 0.5px solid var(--line); white-space: nowrap; }
.ad-table td { padding: 10px 12px; border-bottom: 0.5px solid var(--line); vertical-align: middle; }
.ad-table th.num, .ad-table td.num { text-align: right; }
.ad-table tbody tr:last-child td { border-bottom: 0; }
.ad-table th:first-child, .ad-table td:first-child { padding-left: 16px; }
.ad-table th:last-child, .ad-table td:last-child { padding-right: 20px; }
.ad-table tbody tr { transition: background 0.12s; }
.ad-table tbody tr:hover { background: var(--panel-hover); }
/* a switched-off row fades, but its switch and actions stay legible so it's easy to turn back on */
.ad-table tr.is-off td:not(.keep):not(.ad-order) { opacity: 0.45; }
.ad-table--history { min-width: 560px; }

.ad-order { width: 40px; padding-right: 0 !important; }
.ad-mini { display: grid; place-items: center; width: 32px; height: 24px; border-radius: 8px; color: var(--text-faint); }
.ad-mini:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.ad-mini:disabled { opacity: 0.25; cursor: default; }
.ad-mini svg.i { width: 16px; height: 16px; stroke-width: 2.4; }

.ad-item { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ad-item__name { font-weight: 600; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ad-thumb {
  width: 44px; height: 44px; flex-shrink: 0; display: grid; place-items: center; overflow: hidden;
  border-radius: 10px; background: var(--panel-2);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tint, transparent) 45%, transparent);
}
.ad-thumb img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.ad-thumb--wide { width: 72px; height: 48px; object-fit: cover; box-shadow: none; }
.ad-dot { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 0.5px solid var(--line-strong); vertical-align: middle; }

.ad-stock { white-space: nowrap; }
.ad-stock b { font-weight: 600; color: var(--text); }
.ad-stock b.is-out { color: var(--danger); }

.ad-badge { display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: var(--r-pill); font-size: 14px; font-weight: 500; white-space: nowrap; }
.ad-badge--ok { background: var(--success-soft); color: var(--success); }
.ad-badge--low { background: var(--warn-soft); color: var(--warn); }
.ad-badge--out { background: var(--danger-soft); color: var(--danger); }
.ad-badge--off { background: var(--panel-2); color: var(--text-muted); }

.ad-row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.ad-tbl-btn {
  min-height: 36px; padding: 0 14px; border-radius: var(--r-pill); border: 0.5px solid var(--line-strong) !important;
  font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; transition: background 0.15s, transform 0.12s;
}
.ad-tbl-btn:hover { background: var(--panel-hover) !important; }
.ad-tbl-btn:active { transform: scale(0.96); }
/* quiet on purpose: a column of red buttons invites the mis-tap it warns against */
.ad-tbl-btn--quiet { color: var(--text-muted); border-color: var(--line-card) !important; }

/* ===== Switch ===== */
.ad-toggle { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; cursor: pointer; }
.ad-toggle input { position: absolute; inset: -9px; width: calc(100% + 18px); height: calc(100% + 18px); opacity: 0; margin: 0; cursor: pointer; }
.ad-toggle__slider { position: absolute; inset: 0; border-radius: var(--r-pill); background: var(--panel-2); border: 0.5px solid var(--line-strong); transition: background 0.15s, border-color 0.15s; pointer-events: none; }
.ad-toggle__slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; border-radius: 50%; background: var(--text-faint); transition: transform 0.18s cubic-bezier(0.22, 1, 0.36, 1), background 0.15s; }
.ad-toggle input:checked + .ad-toggle__slider { background: var(--success); border-color: var(--success); }
.ad-toggle input:checked + .ad-toggle__slider::after { transform: translateX(18px); background: #fff; }
.ad-toggle input:focus-visible + .ad-toggle__slider { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ===== History panel ===== */
.ad-history { background: var(--panel); border: 0.5px solid var(--line-card); border-radius: var(--r-lg); overflow: hidden; }
.ad-history__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 18px 20px 14px; border-bottom: 0.5px solid var(--line); }
.ad-history__title { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.35; }
.ad-history__empty { margin: 0; padding: 32px 24px; text-align: center; font-size: 14px; color: var(--text-muted); }
.ad-history .ad-thumb { width: 36px; height: 36px; border-radius: 8px; }

/* ===== Settings ===== */
.ad-card { background: var(--panel); border: 0.5px solid var(--line-card); border-radius: var(--r-lg); padding: 6px 20px; }
.ad-card__title { margin: 0; padding: 14px 0 6px; font-size: 17px; font-weight: 700; }
.ad-setting { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 64px; padding: 12px 0; border-top: 0.5px solid var(--line); }
.ad-card__title + .ad-setting { border-top: 0; }
.ad-setting > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ad-setting b { font-weight: 600; }
.ad-setting span { font-size: 14px; color: var(--text-muted); }

/* ===== Dialog ===== */
/* flex + auto margins (not place-items:center): a dialog taller than the screen must scroll from its top, not get clipped */
.ad-overlay {
  position: fixed; inset: 0; z-index: 1000; display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px; background: rgba(0, 0, 0, 0.6); overflow-y: auto;
  animation: adFade 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes adFade { from { opacity: 0; } }
@keyframes adPop { from { opacity: 0; transform: scale(0.97); } }
.ad-modal {
  width: min(520px, 100%); margin: auto 0; padding: 24px; display: flex; flex-direction: column; gap: 16px;
  background: var(--panel); border: 0.5px solid var(--line-strong); border-radius: var(--r-xl);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5); animation: adPop 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.ad-modal--wide { width: min(600px, 100%); }
.ad-modal__title { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.3; }
.ad-form { display: flex; flex-direction: column; gap: 16px; }
.ad-label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text-muted); }
.ad-input {
  width: 100%; height: 46px; padding: 0 14px; background: var(--panel-2);
  border: 0.5px solid var(--line-strong); border-radius: var(--r-row); color: var(--text); outline: none;
  transition: border-color 0.15s;
}
.ad-input:focus { border-color: var(--primary); }
.ad-input::placeholder { color: var(--text-faint); }
.ad-input:disabled { opacity: 0.45; }
.ad-input.is-err { border-color: var(--danger); }
.ad-input--sm { width: 120px; text-align: center; font-weight: 600; }
.ad-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ad-row--between { justify-content: space-between; }
.ad-hint { font-size: 14px; color: var(--text-faint); }
.ad-error { margin: 0; min-height: 20px; font-size: 14px; color: var(--danger); }
.ad-modal__foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.ad-colors { display: flex; gap: 10px; flex-wrap: wrap; }
.ad-color { width: 36px; height: 36px; border-radius: 50%; border: 0.5px solid var(--line-strong) !important; transition: transform 0.12s, box-shadow 0.15s; }
.ad-color:hover { transform: scale(1.06); }
.ad-color.is-selected { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--primary); }

.ad-stepper { display: grid; grid-template-columns: 46px 1fr 46px; gap: 8px; }
.ad-stepper .ad-input { text-align: center; font-size: 24px; font-weight: 700; }
.ad-stepper button { height: 46px; border-radius: var(--r-row); border: 0.5px solid var(--line-strong) !important; font-size: 22px; font-weight: 600; color: var(--text); }
.ad-stepper button:hover { background: var(--panel-hover); }
.ad-distractors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ad-distractors .ad-input { text-align: center; font-size: 18px; font-weight: 600; }

.ad-card-preview {
  align-self: flex-start; display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 18px 20px 14px; border-radius: var(--r-row); background: #fff; color: var(--charcoal);
}
.ad-card-preview p { margin: 0; font-size: 15px; font-weight: 600; text-align: center; max-width: 180px; word-break: break-word; }
.ad-card-preview .prize-stage.sm { width: 150px; height: 150px; }

/* image drop zone */
.ad-drop {
  position: relative; min-height: 140px; display: grid; place-items: center; padding: 16px;
  border-radius: var(--r-row); border: 1px dashed var(--line-strong); background: var(--panel-2); cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.ad-drop:hover { border-color: var(--text-faint); }
.ad-drop.is-over { border-color: var(--primary); background: var(--primary-soft); }
.ad-drop.has-img { border-style: solid; border-color: var(--line-card); }
.ad-drop__empty { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.ad-drop__empty svg.i { width: 28px; height: 28px; color: var(--text-faint); stroke-width: 1.8; }
.ad-drop__text { font-size: 15px; color: var(--text); }
.ad-drop__text u { color: var(--primary-text); text-underline-offset: 3px; }
.ad-drop__hint { font-size: 13px; color: var(--text-faint); }
.ad-drop__img { max-width: 100%; max-height: 160px; object-fit: contain; border-radius: 10px; }
.ad-drop__replace {
  position: absolute; right: 10px; bottom: 10px; min-height: 32px; padding: 0 12px; display: inline-flex; align-items: center;
  border-radius: var(--r-pill); background: var(--panel); border: 0.5px solid var(--line-strong); font-size: 13px; font-weight: 600; color: var(--text);
}

/* answer-choice preview (reuses the player's .choice colours) */
.ad .preview-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ad .preview-choices .choice { min-height: 46px; font-size: 20px; box-shadow: 0 3px 0 var(--cd); padding: 0 12px; gap: 8px; border-radius: 12px; }
.ad .preview-choices .choice svg { width: 20px; height: 20px; }
.ad .preview-choices .choice .num { margin-right: 20px; }
.ad .preview-choices .choice.is-ans { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--success); }

/* ===== PIN gate (login card of the original) ===== */
.ad-login {
  position: relative; width: min(380px, 100%); margin: auto 0; display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 32px 28px 26px; background: var(--panel); border: 0.5px solid var(--line-card); border-radius: var(--r-xl);
  animation: adPop 0.18s cubic-bezier(0.2, 0.8, 0.2, 1); text-align: center;
}
.ad-login__x { position: absolute; top: 14px; right: 14px; }
.ad-icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--text-muted); }
.ad-icon-btn:hover { background: var(--panel-hover); color: var(--text); }
.ad-icon-btn svg.i { width: 18px; height: 18px; stroke-width: 2.4; }
.ad-login__title { margin: 4px 0 0; font-size: 22px; font-weight: 700; }
.ad-login__sub { margin: -8px 0 0; font-size: 14px; color: var(--text-muted); }
.ad-login__hint { margin: 0; font-size: 13px; color: var(--text-faint); }
.ad-pin-dots { display: flex; gap: 14px; height: 24px; align-items: center; }
.ad-pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--line-strong); }
.ad-pin-dots i.on { background: var(--primary); border-color: var(--primary); }
.ad-pin-dots.shake { animation: shake .4s; }
.ad-keys { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; }
.ad-keys button { height: 72px; border-radius: 50%; background: var(--panel-2); border: 0.5px solid var(--line-card) !important; font-size: 26px; font-weight: 600; color: var(--text); }
.ad-keys button:active { background: var(--primary-soft); border-color: var(--primary) !important; }

/* ===== Narrow / portrait: sidebar becomes a top bar ===== */
@media (max-width: 900px) {
  .ad-page { grid-template-columns: minmax(0, 1fr); }
  .ad-side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: calc(16px + var(--safe-t)) 16px 14px; border-right: 0; border-bottom: 0.5px solid var(--line-card); }
  .ad-side__logo { padding: 0 6px; }
  .ad-side__title { display: none; }
  .ad-nav { flex-direction: row; flex: 1 1 100%; order: 3; }
  .ad-nav__item { flex: 1; }
  .ad-side__foot { margin: 0 0 0 auto; padding: 0; border: 0; flex-direction: row; align-items: center; }
  .ad-main { padding: 20px 16px calc(48px + var(--safe-b)); }
}

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

/* keep overscroll / safe-area edges dark while the console is open */
body:has(.ad-page) { background: #0d0d11; }

/* prize dialog: settings left, live preview right — keeps the dialog within an iPad screen */
.ad-split { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 20px; align-items: start; }
.ad-split .ad-card-preview { align-self: stretch; }
@media (max-width: 560px) { .ad-split { grid-template-columns: 1fr; } }

/* round dialog: photo + name left, answer settings right */
.ad-modal--xl { width: min(820px, 100%); }
.ad-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.ad-cols .ad-drop { min-height: 220px; }
.ad-cols .ad-drop__img { max-height: 200px; }
@media (max-width: 760px) { .ad-cols { grid-template-columns: 1fr; } }

/* portrait iPad: drop the colour column (the thumb already carries the tint) so the table fits without side-scrolling */
@media (max-width: 900px) {
  .ad-col-color { display: none; }
  .ad-table { min-width: 0; }
  .ad-table th, .ad-table td { padding-left: 8px; padding-right: 8px; }
  .ad-item__name { max-width: 170px; }
}
