/* ──────────────────────────────────────────────────────────────────
   SMS / Text Automation styles.
   - Settings page: sandbox toggle, template editor, variable cheatsheet,
     delivery rules (quiet hours, delay, retention, fallback, opt-out, test).
   - Side panel: per-record Messages timeline + simulate-reply dev panel.
   - Topbar bell: failed-SMS counter.
   ────────────────────────────────────────────────────────────────── */

/* ── Profile: SMS section header pill ── */

.sms-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
  font-family: var(--font-body);
}
.sms-pill-sandbox {
  background: rgba(216, 152, 60, 0.18);
  color: #a87033;
}
.sms-pill-live {
  background: var(--green-soft);
  color: var(--green);
}

.sms-section-blurb {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 16px;
  line-height: 1.5;
}

/* ── Sandbox toggle ── */

.sms-sandbox-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-warm);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  margin-bottom: 20px;
}

.sms-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.sms-toggle input { display: none; }

.sms-toggle-track {
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 999px;
  position: relative;
  transition: background 0.15s;
}
.sms-toggle-dot {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: left 0.15s;
}
.sms-toggle input:checked + .sms-toggle-track {
  background: #a87033;
}
.sms-toggle input:checked + .sms-toggle-track .sms-toggle-dot {
  left: 18px;
}

.sms-toggle-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.sms-sandbox-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Variable cheatsheet ── */

.sms-vars-cheatsheet {
  margin-bottom: 16px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--surface, var(--bg));
}
.sms-vars-cheatsheet summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 0;
}
.sms-vars-cheatsheet[open] summary { padding-bottom: 8px; }

.sms-vars-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 6px 18px;
  padding: 6px 0 10px;
}
.sms-var-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.sms-var-code {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 11px;
  background: var(--bg-warm);
  color: var(--text);
  padding: 2px 6px;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid var(--border-light);
  white-space: nowrap;
  flex-shrink: 0;
}
.sms-var-code:hover {
  border-color: var(--border);
}
.sms-var-desc {
  color: var(--text-muted);
}
.sms-vars-hint {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
}

/* ── Template editor block ── */

.sms-template-editor {
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--surface, var(--bg));
}

.sms-template-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.sms-template-icon {
  font-size: 16px;
  flex-shrink: 0;
}
.sms-template-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  font-family: var(--font-body);
  flex: 1;
}
.sms-template-counter {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  font-family: 'Menlo', 'Consolas', monospace;
}
.sms-template-restore {
  background: none;
  border: none;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}
.sms-template-restore:hover { color: var(--text); }

.sms-template-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 10px;
  line-height: 1.4;
}

.sms-template-textarea {
  width: 100%;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 10px 12px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  resize: vertical;
  min-height: 100px;
  box-sizing: border-box;
}
.sms-template-textarea:focus {
  outline: 2px solid var(--gold, #d8983c);
  outline-offset: 1px;
  border-color: transparent;
}

.sms-template-preview-wrap {
  margin-top: 8px;
  font-size: 12px;
}
.sms-template-preview-wrap summary {
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 500;
  padding: 4px 0;
}
.sms-template-preview {
  font-family: var(--font-body);
  font-size: 13px;
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-left: 3px solid #a87033;
  padding: 10px 12px;
  margin: 6px 0 0;
  border-radius: 4px;
  color: var(--text);
  line-height: 1.45;
}

/* ──────────────────────────────────────────────────────────────────
   Side panel — confirmation badges next to Callback status
   ────────────────────────────────────────────────────────────────── */

.cp-appt-confirm,
.cp-appt-decline {
  display: inline-block;
  margin-left: 4px;
  font-size: 13px;
  vertical-align: baseline;
  cursor: help;
}

/* ──────────────────────────────────────────────────────────────────
   Side panel — Messages section (per-record SMS timeline)
   ────────────────────────────────────────────────────────────────── */

.cp-messages-section .cp-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cp-messages-count {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-weight: 500;
  background: var(--bg-warm);
  padding: 1px 7px;
  border-radius: 999px;
}

.cp-messages-empty {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  padding: 12px 0 6px;
}

.cp-messages-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 6px;
}

.cp-msg-row {
  padding: 10px 12px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: var(--surface, var(--bg));
  font-size: 12px;
}

.cp-msg-row.cp-msg-needs-ack {
  border-color: rgba(138, 74, 64, 0.4);
  background: var(--red-soft);
}

.cp-msg-inbound {
  border-left: 3px solid #5a7aaa;
}

.cp-msg-row.cp-msg-type-manual-reply {
  border-left: 3px solid var(--green, #4a7a4a);
}

.cp-msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-body);
}
.cp-msg-type {
  font-weight: 600;
  color: var(--text);
  flex: 1;
}
.cp-msg-when {
  color: var(--text-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.cp-msg-status {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 3px;
  text-transform: uppercase;
}
.cp-msg-status-scheduled       { background: rgba(90,122,170,0.15); color: #4868a0; }
.cp-msg-status-sent            { background: var(--green-soft);    color: var(--green); }
.cp-msg-status-sent-sandbox    { background: rgba(216,152,60,0.18); color: #a87033; }
.cp-msg-status-failed          { background: var(--red-soft);      color: var(--red); }
.cp-msg-status-cancelled       { background: var(--bg-warm);       color: var(--text-dim); }
.cp-msg-status-skipped-opt-out { background: var(--bg-warm);       color: var(--text-muted); }
.cp-msg-status-skipped-quiet   { background: var(--bg-warm);       color: var(--text-muted); }
.cp-msg-status-yes             { background: var(--green-soft);    color: var(--green); }
.cp-msg-status-no              { background: var(--red-soft);      color: var(--red); }
.cp-msg-status-stop            { background: var(--red-soft);      color: var(--red); }
.cp-msg-status-help            { background: rgba(90,122,170,0.15); color: #4868a0; }
.cp-msg-status-freeform        { background: var(--bg-warm);       color: var(--text-muted); }

.cp-msg-body-wrap {
  margin-top: 8px;
  font-size: 11px;
}
.cp-msg-body-wrap summary {
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 0;
}
.cp-msg-body-pre {
  font-family: var(--font-body);
  font-size: 12px;
  white-space: pre-wrap;
  background: var(--bg-warm);
  padding: 8px 10px;
  border-radius: 4px;
  margin: 4px 0 0;
  color: var(--text);
  line-height: 1.4;
}

.cp-msg-body {
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--bg-warm);
  border-radius: 4px;
  font-size: 12px;
  color: var(--text);
  line-height: 1.4;
}

.cp-msg-action {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

.cp-msg-error {
  margin-top: 6px;
  font-size: 11px;
  color: var(--red);
}

.cp-msg-ack-btn {
  margin-top: 8px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
}
.cp-msg-ack-btn:hover { filter: brightness(1.1); }

/* ── Reply composer (agent-initiated outbound) ── */

.cp-msg-reply {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--surface, var(--bg));
  border: 1px solid var(--border-light);
  border-radius: 6px;
}
.cp-msg-reply.is-disabled {
  opacity: 0.6;
}
.cp-msg-reply-head {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-family: var(--font-body);
}
.cp-msg-reply-row {
  display: flex;
  gap: 6px;
  align-items: flex-start;
}
.cp-msg-reply-input {
  flex: 1;
  font-family: var(--font-body);
  font-size: 12px;
  line-height: 1.4;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  min-height: 36px;
  box-sizing: border-box;
}
.cp-msg-reply-input:focus {
  outline: 2px solid var(--gold, #d8983c);
  outline-offset: 1px;
  border-color: transparent;
}
.cp-msg-reply-input:disabled {
  background: var(--bg-warm);
  cursor: not-allowed;
}
.cp-msg-reply-btn {
  background: var(--green, #4a7a4a);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font-body);
}
.cp-msg-reply-btn:hover:not(:disabled) { filter: brightness(1.1); }
.cp-msg-reply-btn:disabled { cursor: not-allowed; opacity: 0.5; }
.cp-msg-reply-hint {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.4;
}

/* ── Simulate-inbound dev panel ── */

.cp-msg-sim {
  margin-top: 14px;
  padding: 8px 10px;
  background: rgba(216, 152, 60, 0.08);
  border: 1px dashed rgba(216, 152, 60, 0.4);
  border-radius: 6px;
  font-size: 12px;
}
.cp-msg-sim summary {
  cursor: pointer;
  font-size: 11px;
  color: #a87033;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.cp-msg-sim-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin: 8px 0;
  line-height: 1.4;
}
.cp-msg-sim-hint code {
  background: var(--bg-warm);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  font-family: 'Menlo', 'Consolas', monospace;
}
.cp-msg-sim-row {
  display: flex;
  gap: 6px;
}
.cp-msg-sim-input {
  flex: 1;
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface, var(--bg));
  color: var(--text);
}
.cp-msg-sim-btn {
  background: #a87033;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.cp-msg-sim-btn:hover { filter: brightness(1.1); }

/* ──────────────────────────────────────────────────────────────────
   CRM table — unread client-reply indicator on the name cell
   ────────────────────────────────────────────────────────────────── */

.crm-unread-replies {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-right: 6px;
  padding: 1px 6px 1px 4px;
  background: rgba(90, 122, 170, 0.15);
  border-radius: 999px;
  font-size: 11px;
  vertical-align: middle;
  cursor: help;
  white-space: nowrap;
}
.crm-unread-count {
  font-weight: 700;
  font-size: 10px;
  color: #4868a0;
  font-family: var(--font-body);
}

/* ──────────────────────────────────────────────────────────────────
   Topbar — SMS-failed counter bell
   ────────────────────────────────────────────────────────────────── */

.callback-bell-sms-failed {
  position: relative;
  background: var(--red-soft) !important;
}
.callback-bell-count {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 14px;
  height: 14px;
  padding: 0 4px;
  border-radius: 999px;
  line-height: 14px;
  text-align: center;
  font-family: var(--font-body);
}

/* ── Settings: Text Automation delivery rules ── */

.sms-rules {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border-light);
}
.sms-rules-head {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  font-family: var(--font-body);
  margin-bottom: 2px;
}
.sms-rules-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 14px;
}

.sms-rule {
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--surface, var(--bg));
}
.sms-rule-main {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.sms-rule-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  font-family: var(--font-body);
}
.sms-rule-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 10px;
  line-height: 1.45;
}
.sms-rule-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.sms-rule-controls.is-disabled { opacity: 0.45; }
.sms-rule-unit {
  font-size: 12px;
  color: var(--text-muted);
}
.sms-rule-controls input[type="time"],
.sms-rule-controls input[type="number"],
.sms-rule-controls select {
  font-family: var(--font-body);
  font-size: 13px;
  padding: 6px 10px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}
.sms-rule-controls input[type="number"] { width: 80px; }

/* Status badges on a rule (deferred-until-backend vs already active). */
.sms-soon-badge,
.sms-ok-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: var(--font-body);
  white-space: nowrap;
}
.sms-soon-badge {
  background: rgba(216, 152, 60, 0.18);
  color: #a87033;
}
.sms-ok-badge {
  background: var(--green-soft);
  color: var(--green);
}

.sms-test-output {
  margin-top: 10px;
}

/* ── Agent-fired confirmation modal (on live-call form submit) ── */

.sms-confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(var(--shadow-rgb), 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 20px;
}
.sms-confirm-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 24px;
  max-width: 460px;
  width: 100%;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(var(--shadow-rgb), 0.20);
}
.sms-confirm-dialog h3 {
  margin: 0 0 4px 0;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}
.sms-confirm-sub {
  margin: 0 0 14px 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* Which call this modal is about, during a multi-form submit run. Sits directly
   under the heading so "Submit with blank fields?" is never ambiguous about
   whose blank fields it means. */
.sms-confirm-who {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--wood);
  letter-spacing: 0.02em;
}

/* "Also submit your other open calls?" — the picker on the first modal only. */
.sms-confirm-also .sms-confirm-section-head { font-size: 16px; }

.sms-also-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  margin-bottom: 5px;
  border: 1px solid var(--border-light);
  border-radius: 7px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.sms-also-row:hover { border-color: var(--wood); background: var(--wood-soft); }
.sms-also-row input { cursor: pointer; }

.sms-also-note {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

/* Referral billing, MP marking, and the dial-tracker question. All three reuse
   .sms-also-row for their checkbox, so a row reads the same wherever it appears
   in the modal. */
.sms-confirm-billing .sms-confirm-section-head,
.sms-confirm-dials .sms-confirm-section-head,
.sms-confirm-marking .sms-confirm-section-head {
  font-size: 15px;
  margin-bottom: 8px;
}

.sms-confirm-marking-status {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 6px;
}

/* How the record will be counted. Bulleted rather than prose so the agent can
   check it at a glance mid-call instead of reading a sentence. */
.sms-confirm-marking-list {
  margin: 0 0 9px;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text-muted);
}
.sms-confirm-marking-list li { margin-bottom: 3px; }

/* Blank-fields section (folded into the unified submit modal). */
.sms-confirm-blanks {
  margin: 10px 0 14px;
}
.sms-confirm-blanks p {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--text-muted);
}
.sms-confirm-blanks ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text);
}
.sms-confirm-blanks ul li { margin-bottom: 2px; }

/* Text-automation section header inside the unified modal. */
.sms-confirm-section {
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}
.sms-confirm-section-head {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.sms-confirm-warn {
  background: rgba(216, 152, 60, 0.12);
  border: 1px solid rgba(216, 152, 60, 0.35);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
}
.sms-confirm-warn[hidden] { display: none; }

.sms-confirm-choice {
  display: flex;
  gap: 18px;
  padding: 10px 0 14px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 14px;
}
.sms-confirm-choice[hidden] { display: none; }
.sms-radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-body);
}
.sms-radio input { cursor: pointer; }

.sms-composer[hidden] { display: none; }
.sms-composer-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 12px 0 6px;
}
.sms-when {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}
.sms-when-custom[hidden] { display: none; }
.sms-when-custom {
  font-size: 12px;
  color: var(--text-muted);
}
.sms-when-custom input {
  width: 64px;
  padding: 4px 8px;
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}
.sms-confirm-dialog select#sms-kind {
  width: 100%;
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}
.sms-composer-body {
  width: 100%;
  margin-top: 10px;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 10px 12px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  resize: vertical;
}
.sms-composer-counter {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  font-family: 'Menlo', 'Consolas', monospace;
}
.sms-composer-warn {
  margin-top: 8px;
  font-size: 12px;
  color: var(--red);
  line-height: 1.4;
}

.sms-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}
