/**
 * Core Download Plugin v2 — Download Card
 *
 * Utilitarian precision (Swiss-influenced): hairline rules carry structure,
 * one restrained cobalt accent on the primary action + focus + links only,
 * a strong but honest type ramp, near-flat surfaces. Every color/size/
 * duration below is a `--cdp-*` token from tokens.css — dark mode and
 * owner-tuned accent/radius/font follow automatically; nothing here is
 * re-declared for `[data-cdp-theme="dark"]`.
 *
 * Layout responds to its own box, not the viewport (`container-type:
 * inline-size` on the card root) so it holds up in a 280px sidebar column
 * exactly as well as a full-width content area. See the breakpoint
 * reference at the bottom of tokens.css: the one card breakpoint is 480px,
 * below which per-file meta stacks under the filename and the gated-form
 * fields stack vertically.
 */

.cdp-card {
  container-type: inline-size;
  container-name: cdp-card;

  box-sizing: border-box;
  width: 100%;
  background: var(--cdp-bg);
  color: var(--cdp-text);
  border: var(--cdp-border-hairline) solid var(--cdp-border);
  border-radius: var(--cdp-radius);
  box-shadow: var(--cdp-shadow-sm);
  font-family: var(--cdp-font-body);
  font-size: var(--cdp-text-base);
  line-height: var(--cdp-leading-normal);
  text-align: left;
}

.cdp-card * {
  box-sizing: border-box;
}

.cdp-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--cdp-space-8);
  padding: var(--cdp-space-9);
}

@container cdp-card (width < 480px) {
  .cdp-card__body {
    padding: var(--cdp-space-8);
    gap: var(--cdp-space-7);
  }
}

/* ----------------------------------------------------------------------
 * Header — title + description
 * -------------------------------------------------------------------- */

.cdp-card__header {
  display: flex;
  flex-direction: column;
  gap: var(--cdp-space-4);
}

.cdp-card__title {
  margin: 0;
  font-family: var(--cdp-font-display);
  font-size: var(--cdp-text-lg);
  font-weight: var(--cdp-weight-semibold);
  line-height: var(--cdp-leading-tight);
  letter-spacing: var(--cdp-tracking-tight);
  color: var(--cdp-text);
}

.cdp-card__description {
  margin: 0;
  font-size: var(--cdp-text-md);
  line-height: var(--cdp-leading-relaxed);
  color: var(--cdp-text-secondary);
}

.cdp-card__description > *:first-child {
  margin-top: 0;
}

.cdp-card__description > *:last-child {
  margin-bottom: 0;
}

.cdp-card__description a {
  color: var(--cdp-text-link);
  text-underline-offset: 0.15em;
}

/* ----------------------------------------------------------------------
 * File rows
 * -------------------------------------------------------------------- */

.cdp-card__files {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: var(--cdp-border-hairline) solid var(--cdp-border);
}

/* Header off (see CardRenderer's `header` arg / the shortcode's `header`
   attribute): the file list is the first thing in `.cdp-card__body`, so its
   own top border would sit right under the card's top padding with nothing
   above it to separate from -- a redundant line doubling the card's own top
   edge. `.cdp-card__body`'s padding already gives the top breathing room
   the header used to introduce, so only the duplicate rule needs removing. */
.cdp-card--no-header .cdp-card__files {
  border-top: 0;
}

.cdp-card__file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--cdp-space-6);
  padding: var(--cdp-space-7) 0;
  border-bottom: var(--cdp-border-hairline) solid var(--cdp-border);
}

.cdp-card__file-info {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--cdp-space-4) var(--cdp-space-6);
  min-width: 0;
}

.cdp-card__file-name {
  font-size: var(--cdp-text-md);
  font-weight: var(--cdp-weight-medium);
  color: var(--cdp-text);
  overflow-wrap: anywhere;
}

.cdp-card__file-meta {
  display: inline-flex;
  align-items: center;
  gap: var(--cdp-space-5);
  flex-shrink: 0;
}

@container cdp-card (width < 480px) {
  .cdp-card__file-info {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--cdp-space-3);
  }
}

.cdp-card__badge {
  display: inline-flex;
  align-items: center;
  padding: var(--cdp-space-3) var(--cdp-space-5);
  background: var(--cdp-bg-tertiary);
  color: var(--cdp-text-secondary);
  border-radius: var(--cdp-radius-sm);
  font-size: var(--cdp-text-xs);
  font-weight: var(--cdp-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--cdp-tracking-wide);
  white-space: nowrap;
}

.cdp-card__badge--muted {
  color: var(--cdp-text-tertiary);
}

.cdp-card__file-size {
  font-size: var(--cdp-text-sm);
  color: var(--cdp-text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cdp-card__file--unavailable .cdp-card__file-name {
  color: var(--cdp-text-tertiary);
}

.cdp-card__file-status {
  display: inline-flex;
  align-items: center;
  gap: var(--cdp-space-3);
  flex-shrink: 0;
  font-size: var(--cdp-text-xs);
  font-weight: var(--cdp-weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--cdp-tracking-wide);
  color: var(--cdp-text-tertiary);
}

.cdp-card__icon {
  flex-shrink: 0;
}

/* Compact per-file link, shown only on multi-file cards. */
.cdp-card__file-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--cdp-space-3);
  flex-shrink: 0;
  min-height: 44px;
  min-width: 44px;
  padding: var(--cdp-space-4) var(--cdp-space-6);
  margin: calc(var(--cdp-space-4) * -1) calc(var(--cdp-space-6) * -1);
  border-radius: var(--cdp-radius-sm);
  color: var(--cdp-text-link);
  font-size: var(--cdp-text-sm);
  font-weight: var(--cdp-weight-medium);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--cdp-duration-fast) var(--cdp-ease);
}

.cdp-card__file-link:hover {
  background: var(--cdp-accent-subtle);
  text-decoration: underline;
}

.cdp-card__file-link:focus-visible {
  outline: none;
  box-shadow: var(--cdp-focus-ring);
}

.cdp-card__file-link.is-busy {
  opacity: 0.7;
  pointer-events: none;
}

/* ----------------------------------------------------------------------
 * Action area — primary button, login prompt, or gated form
 * -------------------------------------------------------------------- */

.cdp-card__action {
  display: flex;
  flex-direction: column;
  gap: var(--cdp-space-6);
}

.cdp-card__button {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--cdp-space-5);
  width: 100%;
  min-height: 44px;
  padding: var(--cdp-space-6) var(--cdp-space-8);
  background: var(--cdp-accent);
  color: var(--cdp-on-accent);
  border: var(--cdp-border-hairline) solid transparent;
  border-radius: var(--cdp-radius);
  font: inherit;
  font-size: var(--cdp-text-md);
  font-weight: var(--cdp-weight-medium);
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--cdp-duration-fast) var(--cdp-ease),
    opacity var(--cdp-duration-fast) var(--cdp-ease);
}

.cdp-card__button:hover {
  background: var(--cdp-accent-hover);
}

.cdp-card__button:active {
  background: var(--cdp-accent-active);
}

.cdp-card__button:focus-visible {
  outline: none;
  box-shadow: var(--cdp-focus-ring);
}

.cdp-card__button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.cdp-card__button.is-busy {
  opacity: 0.85;
  cursor: progress;
}

/* Non-spinner busy cue: a thin bar sweeping the button's bottom edge. */
.cdp-card__button.is-busy::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 40%;
  background: var(--cdp-on-accent);
  opacity: 0.7;
  animation: cdp-card-progress 900ms var(--cdp-ease) infinite;
}

@keyframes cdp-card-progress {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(350%);
  }
}

/* Quiet secondary affordance: "log in to download". Deliberately a link,
   not a filled button — the accent is reserved for the one primary action. */
.cdp-card__link {
  display: inline-flex;
  align-items: center;
  gap: var(--cdp-space-3);
  min-height: 44px;
  width: fit-content;
  color: var(--cdp-text-link);
  font-size: var(--cdp-text-md);
  font-weight: var(--cdp-weight-medium);
  text-decoration: none;
}

.cdp-card__link:hover {
  text-decoration: underline;
}

.cdp-card__link:focus-visible {
  outline: none;
  box-shadow: var(--cdp-focus-ring);
  border-radius: var(--cdp-radius-sm);
}

.cdp-card__note {
  display: flex;
  align-items: flex-start;
  gap: var(--cdp-space-4);
  margin: 0;
  font-size: var(--cdp-text-md);
  line-height: var(--cdp-leading-normal);
  color: var(--cdp-text-secondary);
}

.cdp-card__note .cdp-card__icon {
  margin-top: 0.2em;
  color: var(--cdp-text-tertiary);
}

.cdp-card__action--empty .cdp-card__note {
  font-size: var(--cdp-text-base);
}

/* ----------------------------------------------------------------------
 * Gated form. `instant` delivery renders this fully enabled and working
 * (card.js posts it to REST `cdp/v2/leads`); `verify` delivery renders the
 * identical markup with every control `disabled`
 * (`data-cdp-verify-pending` on the wrapper) until Task 5.
 * -------------------------------------------------------------------- */

.cdp-card__form {
  position: relative; /* contains the honeypot field's absolute offset */
  display: flex;
  flex-direction: column;
  gap: var(--cdp-space-6);
}

.cdp-card__form-row {
  display: flex;
  gap: var(--cdp-space-6);
}

@container cdp-card (width < 480px) {
  .cdp-card__form-row {
    flex-direction: column;
  }
}

.cdp-card__field {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: var(--cdp-space-3);
  min-width: 0;
}

.cdp-card__label {
  font-size: var(--cdp-text-xs);
  font-weight: var(--cdp-weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--cdp-tracking-wide);
  color: var(--cdp-text-secondary);
}

/* Scoped under .cdp-card (0,2,0) so a host theme's generic form reset
   (e.g. `input[type="email"] { border-radius: 3px }` at 0,1,1) cannot
   outrank the card's own radius, border, padding and colour. */
.cdp-card .cdp-card__input {
  min-height: 44px;
  padding: 0 var(--cdp-space-7);
  background: var(--cdp-bg);
  color: var(--cdp-text);
  border: var(--cdp-border-hairline) solid var(--cdp-border-strong);
  border-radius: var(--cdp-radius);
  font: inherit;
  font-size: var(--cdp-text-md);
}

.cdp-card .cdp-card__input::placeholder {
  color: var(--cdp-text-tertiary);
}

.cdp-card .cdp-card__input:focus-visible {
  outline: none;
  border-color: var(--cdp-border-focus);
  box-shadow: var(--cdp-focus-ring);
}

.cdp-card .cdp-card__input:disabled {
  background: var(--cdp-bg-tertiary);
  color: var(--cdp-text-tertiary);
  cursor: not-allowed;
}

/* Error state is never color-only: the field also gets aria-invalid (a
   screen reader announces it) and the paired .cdp-card__field-error text
   names the problem -- the red border is a sighted-user accelerant, not
   the only signal. */
.cdp-card .cdp-card__input[aria-invalid="true"] {
  border-color: var(--cdp-error);
}

.cdp-card .cdp-card__input[aria-invalid="true"]:focus-visible {
  box-shadow: 0 0 0 2px var(--cdp-bg), 0 0 0 4px var(--cdp-error);
}

.cdp-card__field-error {
  font-size: var(--cdp-text-sm);
  color: var(--cdp-error);
}

.cdp-card__field-error:empty {
  display: none;
}

/* Honeypot: visually hidden (not display:none/hidden, which some bots
   specifically skip) and unreachable by keyboard (tabindex="-1" in markup)
   -- a no-op for every genuine visitor. */
.cdp-card__hp {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Gated-form success confirmation (card.js swaps the form region into
   this after a successful submission). Success is never color-only: the
   check icon + message carry the meaning, the tint is secondary. */
.cdp-card__action--done {
  background: var(--cdp-success-subtle);
  border-radius: var(--cdp-radius);
  padding: var(--cdp-space-7);
}

.cdp-card__note--done {
  color: var(--cdp-success);
  font-weight: var(--cdp-weight-medium);
}

/* Programmatically focused right after the form swaps out (moves
   screen-reader/keyboard focus to the confirmation instead of dropping it
   to <body>) -- gets the same token-based ring as every other focusable
   element rather than the browser's mismatched default outline. */
.cdp-card__note--done:focus,
.cdp-card__note--done:focus-visible {
  outline: none;
  box-shadow: var(--cdp-focus-ring);
  border-radius: var(--cdp-radius-sm);
}

.cdp-card__note--done .cdp-card__icon {
  color: var(--cdp-success);
}

/* Verify-delivery "link sent" confirmation (card.js's showVerifySentState()
   swaps the gated form into this on a `verify` response). Same shape as the
   success confirmation above -- tinted panel, focusable note -- but info
   tokens, not success tokens: nothing has downloaded yet, the visitor is
   only being told where to look next. */
.cdp-card__action--info {
  background: var(--cdp-info-subtle);
}

.cdp-card__note--info {
  color: var(--cdp-info);
  font-weight: var(--cdp-weight-medium);
}

.cdp-card__note--info:focus,
.cdp-card__note--info:focus-visible {
  outline: none;
  box-shadow: var(--cdp-focus-ring);
  border-radius: var(--cdp-radius-sm);
}

.cdp-card__note--info .cdp-card__icon {
  color: var(--cdp-info);
}

/* ----------------------------------------------------------------------
 * Status line (aria-live). "success" and "error" are both reachable now
 * (download confirmations, gated-form failures); "info" is scaffolding
 * for Task 5's verify-sent state. Never color-only: every message carries
 * a leading glyph or explicit text, not just a tint.
 * -------------------------------------------------------------------- */

.cdp-card__status {
  display: flex;
  align-items: center;
  gap: var(--cdp-space-4);
  font-size: var(--cdp-text-sm);
  font-weight: var(--cdp-weight-medium);
  line-height: var(--cdp-leading-normal);
}

.cdp-card__status:empty {
  display: none;
}

.cdp-card__status[data-state="success"] {
  color: var(--cdp-success);
}

.cdp-card__status[data-state="error"] {
  color: var(--cdp-error);
}

.cdp-card__status[data-state="info"] {
  color: var(--cdp-info);
}

/* Status icon -- drawn, not typed. card.js used to prefix the announced
   text with a literal "✓ " / "! " character; that read as stray punctuation
   (a typo) beside the sentence rather than a designed glyph. It now inserts
   `<span class="cdp-card__status-icon" aria-hidden="true"></span>` ahead of
   a plain text node holding the sentence -- the glyph lives here, entirely
   in CSS, as a 14px currentColor shape masked from an inline SVG data URI,
   so it always matches the status colour above and is invisible to screen
   readers (aria-hidden, no text content of its own; the announced sentence
   never contains the glyph). */
.cdp-card__status-icon {
  display: inline-block;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
}

.cdp-card__status-icon::before {
  content: "";
  display: block;
  width: 14px;
  height: 14px;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

.cdp-card__status--success .cdp-card__status-icon::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M13.7 4.3a1 1 0 0 1 0 1.4l-6.5 6.5a1 1 0 0 1-1.4 0l-3-3a1 1 0 1 1 1.4-1.4L6.5 10.1l5.8-5.8a1 1 0 0 1 1.4 0Z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M13.7 4.3a1 1 0 0 1 0 1.4l-6.5 6.5a1 1 0 0 1-1.4 0l-3-3a1 1 0 1 1 1.4-1.4L6.5 10.1l5.8-5.8a1 1 0 0 1 1.4 0Z'/%3E%3C/svg%3E");
}

.cdp-card__status--error .cdp-card__status-icon::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M7.25 2.5h1.5v7h-1.5v-7ZM7.25 11h1.5v1.5h-1.5V11Z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M7.25 2.5h1.5v7h-1.5v-7ZM7.25 11h1.5v1.5h-1.5V11Z'/%3E%3C/svg%3E");
}

.cdp-card__status--info .cdp-card__status-icon::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M7.25 3h1.5v1.5h-1.5V3ZM7.25 6h1.5v7h-1.5V6Z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M7.25 3h1.5v1.5h-1.5V3ZM7.25 6h1.5v7h-1.5V6Z'/%3E%3C/svg%3E");
}

/* ----------------------------------------------------------------------
 * Footer — quiet status line + optional count chip
 * -------------------------------------------------------------------- */

.cdp-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--cdp-space-5);
  padding-top: var(--cdp-space-6);
  border-top: var(--cdp-border-hairline) solid var(--cdp-border);
}

.cdp-card__footer-status {
  font-size: var(--cdp-text-xs);
  font-weight: var(--cdp-weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--cdp-tracking-wide);
  color: var(--cdp-text-tertiary);
}

.cdp-card__count {
  display: inline-flex;
  align-items: center;
  padding: var(--cdp-space-3) var(--cdp-space-6);
  background: var(--cdp-bg-tertiary);
  color: var(--cdp-text-secondary);
  border-radius: var(--cdp-radius-full);
  font-size: var(--cdp-text-xs);
  font-weight: var(--cdp-weight-medium);
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------------
 * Preview mode (Task 7 block editor, Task 13 live preview): identical
 * stylesheet, submission just inert. Cursor communicates it, nothing moves.
 * -------------------------------------------------------------------- */

.cdp-card--preview .cdp-card__button,
.cdp-card--preview .cdp-card__file-link,
.cdp-card--preview .cdp-card__link {
  cursor: default;
}

/* ----------------------------------------------------------------------
 * Motion
 * -------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .cdp-card *,
  .cdp-card *::before,
  .cdp-card *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  /* The busy cue must still communicate "in progress" without motion:
     freeze it as a full-width static bar rather than a frozen sliver. */
  .cdp-card__button.is-busy::after {
    width: 100%;
    transform: none;
    opacity: 0.9;
  }
}
