/* The send panel and a document's email line (production-booking task 29;
   js/send-panel.js). The panel is the app's modal (.modal-box) laid out as a
   form with its labels in a left column, the way the folder's facts read;
   on a phone it fills the screen, with the actions in reach at the bottom.
   The email line sits under a document's status and is quiet unless
   something needs the owner (a failure). */

/* ── The panel ───────────────────────────────────────────────────────────── */

.send-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  padding: 20px 16px 16px;
  border: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.send-panel .modal-title {
  margin-bottom: 8px;
}
.sp-intro {
  margin-bottom: 20px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.sp-fields {
  display: grid;
  gap: 18px;
}
.sp-row {
  display: grid;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.sp-label,
.send-panel .field > label,
.sp-when legend {
  font-size: var(--font-size-sm);
  letter-spacing: var(--letter-spacing-normal);
  color: var(--muted);
}
.sp-when legend {
  float: left; /* lets the legend sit in the grid's first column */
  padding: 0;
}
.send-panel .field input,
.send-panel .field textarea {
  width: 100%;
}
.send-panel textarea {
  min-height: 7.5em;
  line-height: 1.55;
  resize: vertical;
}
.sp-hint {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}
.sp-hint:empty {
  display: none;
}
.sp-fixed {
  padding: 9px 0;
  font-size: 13px;
  color: var(--text);
}
.sp-fixed .sp-hint {
  display: inline;
  margin: 0;
}

/* Now / Later: two halves of one control, the chosen one filled. */
.sp-seg {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  border: 1px solid var(--border);
}
.sp-seg label {
  position: relative;
  display: flex;
  cursor: pointer;
}
.sp-seg input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.sp-seg span {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  font-size: var(--font-size-sm);
  letter-spacing: var(--letter-spacing-normal);
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.sp-seg label + label span {
  border-left: 1px solid var(--border);
}
.sp-seg input:checked + span {
  background: var(--accent);
  color: var(--color-text-on-accent);
  font-weight: 600;
}
.sp-seg label:hover input:not(:checked) + span {
  color: var(--text);
}
.sp-seg input:focus-visible + span {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--shadow-focus);
}

.sp-at {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.sp-at[hidden] {
  display: none;
}
.sp-at .field label {
  display: block;
  margin-bottom: 6px;
}

/* Email isn't connected: said before the button that would fail. */
.sp-email-off {
  margin-top: 18px;
  padding: 10px 12px;
  border-left: 2px solid var(--accent);
  background: color-mix(in srgb, var(--color-accent-primary) 8%, transparent);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
}
.sp-email-off[hidden] {
  display: none;
}
/* A date the client couldn't accept on (task 33 DR7): said before Confirm. */
.sp-warn {
  margin-top: 18px;
  font-size: 13px;
  line-height: 1.5;
  font-weight: 600;
  color: var(--err-text);
}
.sp-inline-link {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--accent-text, var(--accent));
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.sp-inline-link:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--shadow-focus);
}

/* What Confirm will do, in one line, before it's pressed. */
.sp-summary {
  margin-top: 18px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
}
.sp-summary:empty {
  display: none;
}

/* Copy link to the side (D43); Cancel and Confirm on the right. On a phone
   the actions sit at the bottom of the screen, Confirm first in reach, and
   Copy link below them with what it does. */
.sp-actions {
  flex-wrap: wrap;
  align-items: flex-start;
  margin-top: auto;
}
@media (max-width: 599px) {
  /* Pinned to the bottom of the screen while the form scrolls above them,
     so Confirm is always in reach. */
  .sp-actions {
    position: sticky;
    bottom: -16px; /* over the panel's bottom padding */
    margin-left: -16px;
    margin-right: -16px;
    padding: 14px 16px 16px;
    background: var(--surface);
    box-shadow: 0 -10px 18px -12px rgba(0, 0, 0, 0.6);
  }
}
.sp-actions > .btn {
  flex: 1 1 0;
  justify-content: center;
  min-height: 44px;
}
.sp-aside {
  order: 3;
  flex: 1 1 100%;
  padding-top: 12px;
  border-top: 1px solid var(--cal-rule, var(--border));
}
.sp-aside .btn {
  width: 100%;
  justify-content: center;
  min-height: 44px;
}
.send-panel .spinner {
  display: none;
}

@media (min-width: 600px) {
  .send-panel {
    width: 600px;
    max-width: 95vw;
    height: auto;
    max-height: calc(100dvh - 48px);
    padding: 28px 32px;
    border: 1px solid var(--border);
  }
  .sp-row {
    grid-template-columns: 7.5rem minmax(0, 1fr);
    gap: 16px;
    align-items: start;
  }
  .sp-row > .sp-label,
  .sp-when legend {
    padding-top: 12px;
  }
  .sp-seg {
    width: auto;
    min-width: 13rem;
  }
  .sp-seg span {
    min-height: 38px;
    padding: 0 18px;
  }
  .sp-at {
    max-width: 22rem;
  }
  .sp-actions {
    flex-wrap: nowrap;
    margin-top: 18px;
  }
  .sp-actions > .btn {
    flex: 0 0 auto;
    min-height: 0;
  }
  .sp-aside {
    order: 0;
    flex: 0 1 15rem;
    margin-right: auto;
    padding-top: 0;
    border-top: 0;
  }
  .sp-aside .btn {
    width: auto;
    min-height: 0;
  }
}

/* ── A document's email line ─────────────────────────────────────────────── */

.send-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 12px;
  margin-top: 2px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}
.send-status-text {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
  overflow-wrap: anywhere;
}
/* The mark before the words says the same thing they do. */
.send-status-text::before {
  content: '';
  flex: none;
  width: 6px;
  height: 6px;
  border: 1px solid var(--muted);
  transform: translateY(-1px);
}
.send-status.is-wait .send-status-text {
  color: var(--text);
}
.send-status.is-wait .send-status-text::before {
  border-color: var(--accent);
}
.send-status.is-ok .send-status-text::before {
  background: var(--ok);
  border-color: var(--ok);
}
.send-status.is-late .send-status-text::before {
  background: var(--cal-pencilled);
  border-color: var(--cal-pencilled);
}
.send-status.is-err .send-status-text {
  color: var(--err-text);
}
.send-status.is-err .send-status-text::before {
  background: var(--err-text);
  border-color: var(--err-text);
}
.send-status-act {
  min-height: 44px;
  padding: 0 2px;
  border: 0;
  background: none;
  font: inherit;
  font-size: 11px;
  color: var(--accent-text, var(--accent));
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.send-status-act:hover {
  color: var(--text);
}
.send-status-act:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--shadow-focus);
}
.send-status-act:disabled {
  opacity: 0.5;
  cursor: default;
}
@media (min-width: 768px) {
  .send-status-act {
    min-height: 24px;
  }
}
/* On the invoice screen it sits under the status pill. */
.inv-status + .send-status {
  margin-top: 6px;
}

@media (prefers-reduced-motion: reduce) {
  .sp-seg span {
    transition: none;
  }
}

/* ── Share the call sheet (trip-planner task 11; js/call-sheet-share.js) ─────
   The send panel's frame and form rows, in two sections: the link, then
   (while it's on) the email. One terracotta action at a time: Turn on link
   while it's off, Send once it's on. Tokens only. */

.css-section {
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border-hairline);
}
.css-section + .css-section {
  margin-top: var(--space-7);
}
.css-head {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.css-h {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-snug);
  color: var(--color-text-primary);
}
.css-text {
  margin-bottom: var(--space-5);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  color: var(--color-text-secondary);
}
.css-on {
  width: 100%;
  justify-content: center;
  min-height: var(--touch-min);
}
.css-panel .spinner {
  margin-right: var(--space-3);
}

/* The link: read-only, in mono like every other reference, with Copy beside it. */
.css-url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-3);
}
.css-panel .css-url {
  min-width: 0;
  min-height: var(--touch-min);
  padding: 0 var(--space-4);
  border: 1px solid var(--input-border);
  border-radius: var(--input-radius);
  background: var(--color-bg-inset);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  text-overflow: ellipsis;
}
.css-panel .css-url:focus-visible {
  outline: 2px solid transparent;
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-focus);
}
.css-copy {
  min-height: var(--touch-min);
}
/* Turn off link: quiet, in the danger colour, a full target on a phone. */
.css-link-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 var(--space-4);
}
.css-link-foot .sp-hint {
  margin-top: 0;
}
.btn.css-off {
  min-height: var(--touch-min);
  margin-right: calc(var(--space-4) * -1);
  padding: 0 var(--space-4);
  color: var(--color-status-error-text);
}

/* To: chips and the field share one input-like box, so it reads as one field. */
.css-to {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-min);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--input-border);
  border-radius: var(--input-radius);
  background: var(--input-bg);
  cursor: text;
  transition: border-color var(--duration-fast) var(--easing-default);
}
.css-to:focus-within {
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-focus);
}
.css-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}
.css-chips[hidden] {
  display: none;
}
.css-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 28px;
  padding-left: var(--space-4);
  border-radius: var(--chip-radius);
  background: var(--color-bg-float);
  box-shadow: inset 0 0 0 1px var(--color-border-subtle);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-snug);
  color: var(--color-text-primary);
}
.css-chip-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.css-chip-x {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--chip-radius);
  background: none;
  color: var(--color-text-secondary);
  cursor: pointer;
}
/* 44px to a finger, without a 44px chip. */
.css-chip-x::after {
  content: '';
  position: absolute;
  inset: -8px;
}
.css-chip-x:hover {
  color: var(--color-text-primary);
}
.css-chip-x:focus-visible {
  outline: 2px solid transparent;
  box-shadow: var(--shadow-focus);
}
.send-panel .css-to input {
  flex: 1 1 10rem;
  width: auto;
  min-width: 0;
  min-height: 28px;
  padding: 0 var(--space-1);
  border: 0;
  background: transparent;
  box-shadow: none;
}
.send-panel .css-to input:focus {
  border: 0;
}
.css-field-err {
  margin-top: var(--space-3);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  color: var(--color-status-error-text);
}
.css-field-err:empty {
  display: none;
}

@media (min-width: 600px) {
  .css-on {
    width: auto;
  }
  .css-panel .css-url,
  .css-copy,
  .css-on {
    min-height: var(--control-h);
  }
  .btn.css-off {
    min-height: var(--control-h-sm);
  }
  .css-to {
    min-height: var(--control-h);
  }
  .css-chip-x::after {
    inset: -4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .css-to {
    transition: none;
  }
}
