/* Link appearance editor: a preview of the booking page's header on top, the settings under it.
   The preview wears booking.css's own classes and custom properties. */
@layer page {
  /* The form fills the page's scroll area as a flex column, so the sticky save bar can push to the
     bottom of a short page. */
  .link-appearance-page .detail-content {
    display: flex;
    flex-direction: column;
  }

  .link-appearance {
    display: flex;
    flex-direction: column;
    flex: 1;
  }

  /* ── Preview ──────────────────────────────────────────────────── */
  .link-appearance-preview {
    display: flex;
    flex-direction: column;
    margin: 4px var(--content-padding) var(--section-gap);
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--color-bg);
    font: inherit;
    text-align: left;
    cursor: pointer;

    &:focus-visible {
      outline: 2px solid var(--color-primary);
      outline-offset: 2px;
    }
  }

  .link-appearance-preview-hero {
    display: block;
    padding-block: 16px;

    &.booking_hero--banner {
      padding-block: 0;
    }
  }

  .link-appearance-preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: color-mix(in srgb, var(--booking-header-ink, white) 80%, transparent);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
  }

  .link-appearance-preview-wordmark {
    display: block;

    .link-appearance-preview-placeholder {
      width: 180px;
      border: 1.5px dashed color-mix(in srgb, var(--booking-header-ink, white) 40%, transparent);
      border-radius: var(--radius-sm);
    }
  }

  .link-appearance-preview-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px var(--content-padding);
  }

  .link-appearance-preview-open {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-muted);
  }

  /* ── Sections ─────────────────────────────────────────────────── */
  .link-appearance-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 0 var(--content-padding);
  }

  .link-appearance-field-label {
    margin: 0;
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
  }

  /* Two choices as a segmented pill, the way the plan card switches cadence. */
  .link-appearance-switch {
    display: flex;
    padding: 3px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
  }

  .link-appearance-switch-option {
    flex: 1;
    padding: 0.5rem;
    border-radius: var(--radius-pill);
    color: var(--color-text-light);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    text-align: center;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;

    &:has(:checked) {
      background: var(--color-bg-white);
      color: var(--color-text);
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    }

    &:has(:focus-visible) {
      outline: 2px solid var(--color-primary);
      outline-offset: 2px;
    }
  }

  .link-appearance-switch-input,
  .link-appearance-swatch-input,
  .link-appearance-file,
  .link-appearance-remove-input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    pointer-events: none;
  }

  /* ── Images ───────────────────────────────────────────────────── */
  .link-appearance-image {
    display: flex;
    align-items: flex-start;
    gap: 14px;
  }

  .link-appearance-image-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--color-bg-tertiary);
    color: var(--color-muted);
    cursor: pointer;

    svg {
      width: 24px;
      height: 24px;
    }
  }

  .link-appearance-image--banner .link-appearance-image-thumb,
  .link-appearance-image--wordmark .link-appearance-image-thumb {
    width: 96px;
    height: 32px;
    border-radius: var(--radius-sm);

    svg {
      width: 18px;
      height: 18px;
    }
  }

  .link-appearance-image-empty {
    display: flex;
  }

  .link-appearance-image-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* A wide logo is often transparent: it sits on the header's colors, as on the page. */
  .link-appearance-image--wordmark {
    .link-appearance-image-thumb:has(.link-appearance-image-preview:not(.hidden)) {
      background: var(--booking-header-bg, linear-gradient(150deg, var(--booking-category-dark), var(--booking-category)));
    }

    .link-appearance-image-preview {
      padding: 4px;
      object-fit: contain;
    }
  }

  .link-appearance-image-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
  }

  .link-appearance-image-hint {
    font-size: var(--text-xs);
    line-height: var(--line-height-md);
    color: var(--color-text-light);
  }

  .link-appearance-error {
    font-size: var(--text-sm);
    color: var(--color-danger);
  }

  .link-appearance-image-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 6px;
  }

  .link-appearance-image-pick {
    position: relative;
    border-width: 1px;

    &:has(:focus-visible) {
      outline: 2px solid var(--color-primary);
      outline-offset: 2px;
    }
  }

  .link-appearance-image-remove {
    position: relative;
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-danger);
    cursor: pointer;

    &:has(:checked) span {
      text-decoration: line-through;
    }
  }

  /* ── Colors ───────────────────────────────────────────────────── */
  .link-appearance-color-value {
    display: flex;
    align-items: center;
  }

  .link-appearance-color-dot {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--swatch);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  }

  .link-appearance-drawer-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .link-appearance-drawer-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 10px;
  }

  .link-appearance-reset {
    margin-left: auto;
    padding: 8px 4px;
    border: none;
    background: none;
    color: var(--color-muted);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
  }

  .link-appearance-drawer .drawer-body {
    padding-bottom: calc(var(--content-padding) + env(safe-area-inset-bottom));
  }

  .link-appearance-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }

  .link-appearance-swatch {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--swatch);
    cursor: pointer;

    &:has(:checked) {
      box-shadow: 0 0 0 2px var(--color-bg), 0 0 0 4px var(--color-text);
    }

    &:has(:focus-visible) {
      outline: 2px solid var(--color-primary);
      outline-offset: 4px;
    }
  }

  /* Padrão: the category's color, named, as a pill. */
  .link-appearance-swatch--default {
    width: auto;
    padding: 0 12px;
    border-radius: var(--radius-pill);
  }

  .link-appearance-swatch-label {
    font-size: var(--text-xs);
    font-weight: var(--font-weight-semibold);
    color: white;
  }

  /* Outra cor: a hue ring with a plus, around the picked color once it is the one chosen. */
  .link-appearance-swatch--custom {
    --swatch-center: var(--color-bg-white);
    background:
      radial-gradient(circle, var(--swatch-center) 0 52%, transparent 54%),
      conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
    color: var(--color-text);

    svg {
      width: 16px;
      height: 16px;
    }

    &:has(:checked) {
      --swatch-center: var(--swatch);

      svg {
        display: none;
      }
    }
  }

  .link-appearance-swatch-picker {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
  }

  .link-appearance-gradient {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .link-appearance-field {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;

    .link-appearance-field-label {
      flex: 1;
    }
  }

  .link-appearance-color-input {
    width: 44px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: none;
    cursor: pointer;
  }

  .link-appearance-auto {
    padding: 0;
    border: none;
    background: none;
    color: var(--color-link);
    font: inherit;
    font-size: var(--text-sm);
    cursor: pointer;
  }

  .link-appearance-angle {
    flex: 1.4;
    accent-color: var(--color-primary);
  }

  .link-appearance-angle-value {
    width: 3.5ch;
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    text-align: right;
    color: var(--color-text-light);
  }

  .link-appearance .sticky-actions {
    margin-top: auto;
    padding-top: 12px;

    .btn {
      width: 100%;
    }
  }

  /* ── Crop ─────────────────────────────────────────────────────── */
  /* The picked photo under a fixed frame, before it is uploaded (image_crop_controller.js). */
  .image-crop-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: calc(var(--content-padding) + env(safe-area-inset-bottom));
  }

  .image-crop-stage {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-sm);
    background: var(--color-bg-tertiary);
    touch-action: none;
    user-select: none;
    cursor: grab;

    &:active {
      cursor: grabbing;
    }
  }

  .image-crop-stage--logo {
    align-self: center;
    width: min(100%, 320px);
    aspect-ratio: 1;

    /* The avatar is a circle: the corners it leaves out are dimmed. */
    &::after {
      content: "";
      position: absolute;
      inset: 0;
      border-radius: 50%;
      box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.5);
      pointer-events: none;
    }
  }

  .image-crop-stage--banner {
    aspect-ratio: 3;
  }

  .image-crop-image {
    position: absolute;
    top: 0;
    left: 0;
    max-width: none;
    pointer-events: none;
  }

  .image-crop-hint {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--color-muted);
    text-align: center;
  }

  .image-crop-zoom {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--color-muted);
  }

  .image-crop-zoom-input {
    flex: 1;
    accent-color: var(--color-primary);
  }
}
