.c42-sms-editor {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-sizing: border-box;
}

.c42-sms-editor *,
.c42-sms-editor *::before,
.c42-sms-editor *::after {
  box-sizing: border-box;
}

.c42-sms-editor-input {
  width: 100%;
  min-height: 5rem;
  padding: 0.75rem;
  border: 1px solid var(--c42-color-border, #e5e7eb);
  border-radius: var(--c42-radius, 0.75rem);
  font: inherit;
  resize: vertical;
  transition: border-color var(--c42-transition, 200ms ease);
}

.c42-sms-editor-input:focus {
  outline: none;
  border-color: var(--c42-color-accent, #4f46e5);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--c42-color-accent, #4f46e5) 20%, transparent);
}

/* Status row: counts on the left, emoji affordance pushed to the right. */
.c42-sms-editor-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--c42-color-muted, #6b7280);
}

.c42-sms-editor-badge {
  font-variant-numeric: tabular-nums;
}

/* Positioned anchor so the picker drops from the bottom-right trigger. */
.c42-sms-editor-emoji {
  position: relative;
  display: inline-flex;
  margin-left: auto;
}

.c42-sms-editor-trigger {
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--c42-color-accent, #4f46e5);
  padding: 0.25rem;
  border-radius: 0.25rem;
  display: inline-flex;
  transition: background var(--c42-transition, 200ms ease);
}

.c42-sms-editor-trigger[hidden] {
  display: none;
}

.c42-sms-editor-trigger:hover {
  background: color-mix(in srgb, var(--c42-color-accent, #4f46e5) 10%, transparent);
}

/* Encoding pill reflects the active encoding via data-encoding on the root. */
.c42-sms-editor[data-encoding='UCS-2'] .c42-sms-editor-encoding {
  color: var(--c42-color-warning, #b45309);
  font-weight: 600;
}

.c42-sms-editor-panel {
  position: absolute;
  top: calc(100% + 0.375rem);
  right: 0;
  z-index: 10;
}

.c42-sms-editor-panel[hidden] {
  display: none;
}

/* Built-in inline emoji grid (used when you don't plug in a 3rd-party picker). */
.c42-sms-editor-panel--grid {
  background: var(--c42-color-bg, #ffffff);
  border: 1px solid var(--c42-color-border, #e5e7eb);
  border-radius: var(--c42-radius, 0.75rem);
  box-shadow: var(--c42-shadow, 0 4px 12px rgba(0, 0, 0, 0.1));
  padding: 0.5rem;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.25rem;
}

.c42-sms-editor-item {
  background: none;
  border: 0;
  font-size: 1.25rem;
  padding: 0.375rem;
  border-radius: 0.25rem;
  cursor: pointer;
  transition: background var(--c42-transition, 200ms ease);
}

.c42-sms-editor-item:hover {
  background: var(--c42-color-surface, #f9fafb);
}

/* Over the configured segment limit: flag the count + border. */
.c42-sms-editor[data-over-limit] .c42-sms-editor-segments {
  color: var(--c42-color-danger, #dc2626);
  font-weight: 700;
}

.c42-sms-editor[data-over-limit] .c42-sms-editor-input {
  border-color: var(--c42-color-danger, #dc2626);
}

/* Preview — a plain SMS bubble rendering of the message text. */
.c42-sms-editor-preview {
  padding: 0.625rem 0.875rem;
  border-radius: 1.25rem;
  background: var(--c42-color-surface, #e9e9eb);
  color: var(--c42-color-fg, #111827);
  font-size: 0.9375rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.c42-sms-editor-preview:empty,
.c42-sms-editor-preview[data-empty] {
  display: none;
}

/* ───────────────────────────────────────────────────────────────────────────
   Opt-in device preview (default phone skin).

   Wrap the preview in `.c42-sms-editor-device` to render it on an iPhone
   header background. Entirely optional — omit the wrapper to keep the plain
   bubble. The background image ships with @42/styles; positioning is tunable
   via the custom properties below.

   <div class="c42-sms-editor-device">
     <div data-c42-sms-preview class="c42-sms-editor-preview"></div>
   </div>
   ─────────────────────────────────────────────────────────────────────────── */
.c42-sms-editor-device {
  --c42-sms-device-width: 21rem;
  --c42-sms-device-min-height: 16rem;
  --c42-sms-device-pad-top: 6.5rem; /* clears the status bar + avatar header */
  --c42-sms-device-pad-x: 1.5rem;
  /* Cap the bubble height so long messages scroll instead of overflowing. */
  --c42-sms-device-msg-max-height: 8rem;

  position: relative;
  width: 100%;
  max-width: var(--c42-sms-device-width);
  min-height: var(--c42-sms-device-min-height);
  margin-inline: auto;
  padding: var(--c42-sms-device-pad-top) var(--c42-sms-device-pad-x) 1.25rem;
  background: #ffffff url('./assets/sms-phone.webp') top center / 100% auto no-repeat;
  box-sizing: border-box;
}

/* Inside the frame the bubble becomes the iMessage/SMS incoming grey bubble. */
.c42-sms-editor-device .c42-sms-editor-preview {
  position: relative;
  display: inline-block;
  max-width: 100%;
  max-height: var(--c42-sms-device-msg-max-height);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #e9e9eb;
  color: #000000;
  border-bottom-left-radius: 0.25rem; /* squared corner implies the received tail */
}

.c42-sms-editor-device .c42-sms-editor-preview:empty,
.c42-sms-editor-device .c42-sms-editor-preview[data-empty] {
  display: none;
}
