/* --- The dialog: the form beside the email as it will arrive ---
   A .multi-panel house dialog (application.css), whose frame and parts are
   its own: the form panel and the preview scroll separately, so a long email
   scrolls inside its panel and Send stays put, and on a phone they stack with
   the Send row stuck to the bottom. Folded in from the share-control
   prototype's dialog, as share.css says. */
.share-dialog {
  --dialog-width: 72rem;

  .footer {
    .copy-you {
      flex: 0 1 auto;
      min-width: 0;
      color: var(--color-text-muted);
      font-size: 0.9rem;
    }

    /* The copy line keeps the start of the row; Cancel and Send go to its
       end. */
    .button--subtle {
      margin-left: auto;
    }
  }

  .form-field textarea {
    min-height: 9rem;
  }

  .optional {
    margin-left: 0.3rem;
    font-weight: 400;
    color: var(--color-text-muted);
  }

  .hint {
    display: flex;
    gap: 0.8rem;
    margin: 0.3rem 0 0;
    color: var(--color-text-muted);
    font-size: 0.8rem;
  }

  .count {
    margin-left: auto;
    font-variant-numeric: tabular-nums;

    &.over {
      color: var(--color-fail);
      font-weight: 600;
    }
  }

  .combo {
    position: relative;
  }

  .suggest {
    position: absolute;
    z-index: 20;
    top: calc(100% + 0.25rem);
    left: 0;
    right: 0;
    margin: 0;
    padding: 0.3rem;
    list-style: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 10px 24px -12px rgb(0 0 0 / 0.3);

    [hidden] {
      display: none;
    }
  }

  .suggest-heading {
    padding: 0.4rem 0.5rem 0.2rem;
  }

  .suggest-item {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.4rem 0.5rem;
    border-radius: calc(var(--radius) - 4px);
    cursor: pointer;

    &:hover {
      background: var(--color-warm-accent-bg);
    }
  }

  .suggest-meta {
    color: var(--color-text-muted);
    font-size: 0.85rem;
  }

  .panel.preview {
    padding-bottom: var(--dialog-pad);
    background: var(--color-bg);
    border-left: 1px solid var(--color-border);

    .header {
      padding-bottom: 0.9rem;

      /* A label over the email's headers, drawn as an .eyebrow. */
      h2 {
        margin: 0 0 0.6rem;
      }
    }

    dl {
      display: grid;
      grid-template-columns: auto 1fr;
      gap: 0.2rem 0.8rem;
      margin: 0;
      font-size: 0.85rem;

      dt {
        color: var(--color-text-muted);
      }

      dd {
        margin: 0;
        overflow-wrap: anywhere;
      }
    }
  }

  /* shares/_document, as the mail draws it (layouts/share_mailer), on a card
     of its own that takes only the height it needs and scrolls past that. */
  .preview .body {
    flex: 0 1 auto;
    margin-inline: var(--dialog-pad);
    padding: 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;

    p {
      margin: 0 0 0.6rem;
      line-height: 1.5;
    }

    .share-note {
      padding: 0.6rem 0.7rem;
      border-left: 3px solid var(--color-warm-accent);
      background: var(--color-warm-accent-bg);
      white-space: pre-wrap;
      overflow-wrap: anywhere;
    }

    .share-card {
      margin: 0 0 0.6rem;
      padding: 0.8rem 0.9rem;
      border: 1px solid var(--color-border);
      border-radius: var(--radius-sm);
    }

    .share-tone--fail {
      border-top: 4px solid var(--color-fail);
    }

    .share-tone--degraded {
      border-top: 4px solid var(--color-degraded);
    }

    .share-title {
      margin: 0.3rem 0 0.5rem;
      font-size: 1.1rem;
    }

    .share-heading {
      margin: 0.8rem 0 0.3rem;
      font-size: 0.95rem;
    }

    .share-list {
      margin: 0 0 0.6rem;
      padding-left: 1.25rem;
    }

    .share-subheading {
      margin: 0.7rem 0 0.3rem;
      font-size: 0.9rem;
    }

    .share-rule {
      margin: 0.9rem 0 0;
      border: 0;
      border-top: 1px solid var(--color-border);
    }

    /* A table wider than its card scrolls inside it, never the page. */
    .share-table-scroll {
      overflow-x: auto;
    }

    .share-table {
      width: 100%;
      margin: 0 0 0.6rem;
      border-collapse: collapse;
      font-size: 0.85rem;
      line-height: 1.4;

      th,
      td {
        padding: 0.3rem 0.4rem;
        border-bottom: 1px solid var(--color-border);
        text-align: left;
        vertical-align: top;
      }

      /* The first and last columns are short labels (#, How sure) that
         hold their width; an address wraps anywhere. */
      :is(th, td):is(:first-child, :last-child):not(.share-table-group) {
        white-space: nowrap;
      }
    }

    .share-table-group {
      background: var(--color-bg);
    }

    /* break-word, not anywhere: anywhere lowers the cell's min-content
       width to one character, so the table's auto layout starves the column
       and breaks words in it. The table scrolls in .share-table-scroll
       instead. */
    .share-cell-address {
      overflow-wrap: break-word;
    }

    .share-cell-note {
      display: block;
      color: var(--color-text-muted);
      font-size: 0.8rem;
    }

    .share-closing {
      color: var(--color-text-muted);
    }
  }

  @media (max-width: 48rem) {
    .panel.preview {
      border-left: none;
      border-top: 1px solid var(--color-border);
    }
  }

  /* Too narrow for all three in a row: Send and Cancel keep it, the copy line
     goes under them. Wider than the stack, as the form's panel beside the
     preview runs out of room for them first. */
  @media (max-width: 59rem) {
    .footer {
      row-gap: 0.4rem;
      padding-block: 0.8rem;

      .copy-you {
        order: 3;
        flex-basis: 100%;
        font-size: 0.8rem;
      }
    }
  }
}
