/*!
 * static/css/accounts.css - backend:accounts-upload
 *
 * Two features, one stylesheet:
 *   A. .acct-*      the 3-tab account manager on admin/product-edit
 *   B. .delivery-*  the delivered-accounts block on the checkout receipt and on
 *                   order/delivery
 *
 * Loaded AFTER main.css (and admin.css on admin pages), so it only adds the
 * pieces the design system does not already ship. Component classes that already
 * exist - .btn, .badge, .table, .table-wrap, .select, .textarea, .label, .muted,
 * .mono, .card, .pagination - are REUSED, never re-styled from scratch.
 *
 * Every colour comes from an ACHER token. The literal after each comma is a
 * fallback for the (theoretical) case where main.css did not load, so a missing
 * variable can never collapse to `initial` and produce unreadable text.
 */

/* =========================================================================
 * A. ADMIN - account manager
 * ========================================================================= */

.acct-section .acct-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--acher-border, #1a1a1a);
}

.acct-section .acct-switch .label {
  margin: 0;
  white-space: nowrap;
}

.acct-section .acct-switch .select {
  max-width: 320px;
}

.acct-manager {
  display: block;
}

.acct-manager[hidden] {
  display: none;
}

/* ---- head + counters --------------------------------------------------- */

.acct-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.acct-head-name {
  font-family: var(--acher-font-display, "Share Tech Mono", monospace);
  font-size: 1.02rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--acher-text, #e8e8e8);
}

.acct-head-sku {
  font-family: var(--acher-font-mono, ui-monospace, monospace);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--acher-muted, #666666);
}

.acct-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.acct-stat {
  display: inline-block;
  padding: 3px 9px;
  border: 1px solid var(--acher-border-strong, #2a2a2a);
  border-radius: var(--radius-sm, 4px);
  background: var(--acher-surface, #0f0f0f);
  font-family: var(--acher-font-mono, ui-monospace, monospace);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  color: var(--acher-dim, #9a9a9a);
  white-space: nowrap;
}

.acct-stat-available {
  border-color: rgba(var(--acher-primary-rgb, 0, 255, 65), 0.35);
  color: var(--acher-primary-soft, #7dff9b);
}

.acct-stat-sold {
  color: var(--acher-dim, #9a9a9a);
}

.acct-mismatch {
  margin: 0 0 14px;
  padding: 9px 12px;
  border: 1px solid rgba(var(--acher-warning-rgb, 255, 170, 0), 0.4);
  border-left-width: 3px;
  border-radius: var(--radius-sm, 4px);
  background: rgba(var(--acher-warning-rgb, 255, 170, 0), 0.08);
  color: var(--acher-warning-soft, #ffcc55);
  font-size: 0.84rem;
  line-height: 1.5;
}

.acct-mismatch[hidden] {
  display: none;
}

/* ---- tabs -------------------------------------------------------------- */

.acct-tabs {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin-bottom: 0;
  border-bottom: 1px solid var(--acher-border, #1a1a1a);
}

.acct-tab {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-sm, 4px) var(--radius-sm, 4px) 0 0;
  background: transparent;
  color: var(--acher-muted, #666666);
  font-family: var(--acher-font-display, "Share Tech Mono", monospace);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--transition, 0.16s ease),
    background var(--transition, 0.16s ease),
    border-color var(--transition, 0.16s ease);
}

.acct-tab:hover {
  color: var(--acher-text, #e8e8e8);
  background: var(--acher-surface-2, #141414);
}

.acct-tab:focus-visible {
  outline: 2px solid var(--acher-primary, #00ff41);
  outline-offset: -2px;
}

.acct-tab.is-active {
  color: var(--acher-primary, #00ff41);
  border-bottom-color: var(--acher-primary, #00ff41);
  background: rgba(var(--acher-primary-rgb, 0, 255, 65), 0.06);
  text-shadow: var(--acher-glow-text, 0 0 12px rgba(0, 255, 65, 0.45));
}

.acct-panel {
  padding: 18px 0 4px;
}

.acct-panel[hidden] {
  display: none;
}

.acct-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

/* ---- tab 1: upload file ------------------------------------------------ */

.acct-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 132px;
  padding: 22px 18px;
  border: 1px dashed var(--acher-border-strong, #2a2a2a);
  border-radius: var(--radius, 6px);
  background: var(--acher-bg-deep, #050505);
  color: var(--acher-dim, #9a9a9a);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition, 0.16s ease),
    background var(--transition, 0.16s ease),
    box-shadow var(--transition, 0.16s ease);
}

.acct-drop:hover,
.acct-drop:focus-visible {
  border-color: rgba(var(--acher-primary-rgb, 0, 255, 65), 0.5);
  background: var(--acher-surface, #0f0f0f);
  outline: none;
}

.acct-drop.is-dragover {
  border-color: var(--acher-primary, #00ff41);
  border-style: solid;
  background: rgba(var(--acher-primary-rgb, 0, 255, 65), 0.07);
  box-shadow: var(--acher-glow-sm, 0 0 8px rgba(0, 255, 65, 0.28));
}

.acct-drop.is-loaded {
  border-style: solid;
  border-color: rgba(var(--acher-primary-rgb, 0, 255, 65), 0.35);
}

.acct-drop-icon {
  font-size: 1.6rem;
  line-height: 1;
  color: var(--acher-primary, #00ff41);
}

.acct-drop-hint {
  font-size: 0.92rem;
  color: var(--acher-text, #e8e8e8);
}

.acct-drop-note {
  font-family: var(--acher-font-display, "Share Tech Mono", monospace);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  color: var(--acher-muted, #666666);
}

.acct-found {
  margin: 14px 0 0;
  font-family: var(--acher-font-mono, ui-monospace, monospace);
  font-size: 0.85rem;
  color: var(--acher-primary-soft, #7dff9b);
}

.acct-found[hidden],
.acct-preview[hidden],
.acct-progress[hidden] {
  display: none;
}

.acct-preview {
  margin: 10px 0 0;
  padding: 12px 14px;
  max-height: 190px;
  overflow: auto;
  border: 1px solid var(--acher-border, #1a1a1a);
  border-radius: var(--radius-sm, 4px);
  background: var(--acher-bg-deep, #050505);
  color: var(--acher-dim, #9a9a9a);
  font-family: var(--acher-font-mono, ui-monospace, monospace);
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre;
  tab-size: 4;
}

.acct-progress {
  margin-top: 16px;
}

.acct-progress-track {
  position: relative;
  height: 6px;
  overflow: hidden;
  border: 1px solid var(--acher-border, #1a1a1a);
  border-radius: var(--radius-pill, 999px);
  background: var(--acher-bg-deep, #050505);
}

.acct-progress-fill {
  display: block;
  width: 0;
  height: 100%;
  background: var(--gradient-primary, linear-gradient(135deg, #00ff41, #00cc33));
  box-shadow: var(--acher-glow-sm, 0 0 8px rgba(0, 255, 65, 0.28));
  transition: width 0.2s ease;
}

.acct-progress-label {
  margin: 8px 0 0;
  font-family: var(--acher-font-mono, ui-monospace, monospace);
  font-size: 0.78rem;
  color: var(--acher-dim, #9a9a9a);
}

/* ---- tab 2: paste text ------------------------------------------------- */

.acct-paste {
  width: 100%;
  min-height: 190px;
  font-family: var(--acher-font-mono, ui-monospace, monospace);
  font-size: 0.85rem;
  line-height: 1.6;
  tab-size: 4;
  resize: vertical;
}

.acct-line-count {
  margin: 8px 0 0;
  font-family: var(--acher-font-mono, ui-monospace, monospace);
  font-size: 0.78rem;
}

/* ---- tab 3: view stock ------------------------------------------------- */

.acct-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.acct-toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.acct-toolbar-group .label {
  margin: 0;
  white-space: nowrap;
}

.acct-toolbar-group .select {
  min-width: 140px;
}

.acct-table {
  width: 100%;
}

.acct-table .acct-col-pick {
  width: 38px;
  text-align: center;
}

.acct-cell-preview {
  font-family: var(--acher-font-mono, ui-monospace, monospace);
  letter-spacing: 0.02em;
  /* The API caps the preview at 10 characters, so it never needs to wrap - and
     wrapping mid-token reads as corruption in a credentials table. */
  white-space: nowrap;
}

.acct-row.is-sold {
  opacity: 0.62;
}

.acct-row.is-sold .acct-cell-preview {
  text-decoration: line-through;
  text-decoration-color: var(--acher-muted, #666666);
}

.acct-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.acct-pager-summary {
  font-family: var(--acher-font-mono, ui-monospace, monospace);
  font-size: 0.78rem;
}

/* =========================================================================
 * B. PUBLIC - delivered accounts
 * ========================================================================= */

.delivery-section {
  padding-block: clamp(28px, 5vw, 56px);
}

.delivery-panel {
  padding: clamp(22px, 3.5vw, 34px);
  border: 1px solid var(--acher-border, #1a1a1a);
  border-radius: var(--radius-lg, 10px);
  background: var(--acher-surface, #0f0f0f);
  box-shadow: var(--shadow-md, 0 10px 30px rgba(0, 0, 0, 0.55));
}

.delivery-title {
  margin: 0 0 10px;
  font-family: var(--acher-font-display, "Share Tech Mono", monospace);
  font-size: clamp(1.3rem, 1.1rem + 1vw, 1.9rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--acher-primary, #00ff41);
  text-shadow: var(--acher-glow-text, 0 0 12px rgba(0, 255, 65, 0.45));
}

.delivery-title-expired {
  color: var(--acher-danger, #ff2d2d);
  text-shadow: none;
}

.delivery-panel-expired {
  border-color: rgba(var(--acher-danger-rgb, 255, 45, 45), 0.4);
}

.delivery-lead {
  margin: 0 0 16px;
  color: var(--acher-text, #e8e8e8);
}

.delivery-note {
  margin: 0 0 16px;
  color: var(--acher-dim, #9a9a9a);
  font-size: 0.9rem;
}

/* ---- the 48h warning --------------------------------------------------- */

.delivery-warning {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 0 0 18px;
  padding: 11px 14px;
  border: 1px solid rgba(var(--acher-warning-rgb, 255, 170, 0), 0.42);
  border-left-width: 3px;
  border-radius: var(--radius-sm, 4px);
  background: rgba(var(--acher-warning-rgb, 255, 170, 0), 0.08);
  color: var(--acher-warning-soft, #ffcc55);
  font-size: 0.88rem;
  line-height: 1.55;
}

.delivery-warning-mark {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--acher-warning, #ffaa00);
  color: var(--acher-bg, #080808);
  font-family: var(--acher-font-display, "Share Tech Mono", monospace);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

/* ---- per line-item heading -------------------------------------------- */

.delivery-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 6px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--acher-border, #1a1a1a);
}

.delivery-group-name {
  font-family: var(--acher-font-display, "Share Tech Mono", monospace);
  font-size: 0.86rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--acher-text, #e8e8e8);
}

.delivery-group-qty {
  font-family: var(--acher-font-mono, ui-monospace, monospace);
  font-size: 0.82rem;
  color: var(--acher-primary-soft, #7dff9b);
}

/* ---- the code block --------------------------------------------------- */

.delivery-block {
  margin-top: 16px;
}

.delivery-code {
  position: relative;
  margin: 0;
  padding: 16px 18px;
  max-height: 420px;
  overflow: auto;
  border: 1px solid rgba(var(--acher-primary-rgb, 0, 255, 65), 0.28);
  border-radius: var(--radius, 6px);
  /* Deliberately darker than the surrounding card: this is a terminal. */
  background: #050505;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(var(--acher-primary-rgb, 0, 255, 65), 0.035) 0,
    rgba(var(--acher-primary-rgb, 0, 255, 65), 0.035) 1px,
    transparent 1px,
    transparent 3px
  );
  color: var(--acher-primary, #00ff41);
  font-family: var(--acher-font-mono, "JetBrains Mono", ui-monospace, monospace);
  font-size: 0.86rem;
  line-height: 1.75;
  letter-spacing: 0.01em;
  white-space: pre-wrap;
  word-break: break-all;
  tab-size: 4;
  text-shadow: 0 0 6px rgba(var(--acher-primary-rgb, 0, 255, 65), 0.28);
  -webkit-user-select: all;
  user-select: all;
}

.delivery-code:focus-visible {
  outline: 2px solid var(--acher-primary, #00ff41);
  outline-offset: 2px;
}

/* A duplicate full payload lives in a .sr-only textarea so COPY ALL does not
   have to scrape the styled terminal. main.css owns .sr-only; it stays
   selectable (clip, not display:none), which the execCommand fallback needs. */

.delivery-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.delivery-actions .btn {
  font-family: var(--acher-font-display, "Share Tech Mono", monospace);
  letter-spacing: 0.1em;
}

.delivery-copy.is-copied {
  box-shadow: var(--acher-glow, 0 0 20px rgba(0, 255, 65, 0.3));
}

.delivery-copy-status {
  margin: 10px 0 0;
  min-height: 1.2em;
  font-family: var(--acher-font-mono, ui-monospace, monospace);
  font-size: 0.8rem;
  color: var(--acher-primary-soft, #7dff9b);
}

.delivery-countdown {
  margin: 12px 0 0;
  padding: 9px 13px;
  border: 1px solid rgba(var(--acher-primary-rgb, 0, 255, 65), 0.3);
  border-radius: var(--radius-sm, 4px);
  background: rgba(var(--acher-primary-rgb, 0, 255, 65), 0.06);
  font-family: var(--acher-font-display, "Share Tech Mono", monospace);
  font-size: 0.84rem;
  letter-spacing: 0.08em;
  color: var(--acher-primary, #00ff41);
}

.delivery-countdown[hidden] {
  display: none;
}

/* The receipt reuses the site card; only the inner rhythm is ours. */
.delivery-receipt .block-title {
  margin-bottom: 12px;
}

/* =========================================================================
 * Responsive + motion
 * ========================================================================= */

@media (max-width: 720px) {
  .acct-tabs {
    gap: 0;
  }

  .acct-tab {
    flex: 1 1 auto;
    padding: 9px 8px;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
  }

  .acct-head,
  .acct-toolbar,
  .acct-pager {
    flex-direction: column;
    align-items: stretch;
  }

  .acct-toolbar-group .select {
    min-width: 0;
    flex: 1 1 auto;
  }

  .delivery-actions .btn {
    flex: 1 1 100%;
    text-align: center;
  }

  .delivery-code {
    font-size: 0.79rem;
    padding: 13px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .acct-tab,
  .acct-drop,
  .acct-progress-fill {
    transition: none;
  }
}

/* Scanlines and glow are decoration; a high-contrast user wants the text. */
@media (prefers-contrast: more) {
  .delivery-code {
    background-image: none;
    text-shadow: none;
  }

  .acct-tab.is-active,
  .delivery-title {
    text-shadow: none;
  }
}

@media print {
  .acct-section,
  .delivery-actions,
  .delivery-countdown,
  .delivery-copy-status {
    display: none !important;
  }

  .delivery-code {
    max-height: none;
    overflow: visible;
    background: #fff;
    background-image: none;
    color: #000;
    border-color: #999;
    text-shadow: none;
  }
}
