/**
 * smart-textarea.css — Companion styles for the SmartTextarea library.
 *
 * Minimal layout-only styles for the wrapper, controls (mic + cancel),
 * and status element.  Colors and fonts inherit from the host page so
 * the component looks native in both Atlas and clinician shells.
 *
 * Class prefix: `.st-`
 */

/* ──────────────────────────────────────────────────────────────────────
   Tokens — safe fallbacks that match atlas / interview / clinician
   ────────────────────────────────────────────────────────────────────── */

:root {
  --st-accent:       var(--atlas-accent, #d06c52);
  --st-accent-dim:   var(--atlas-accent-dim, rgba(208, 108, 82, 0.12));
  --st-accent-text:  var(--atlas-accent-text, #9e3b1b);
  --st-text:         var(--atlas-text, #264653);
  --st-text-soft:    var(--atlas-text-soft, rgba(38, 70, 83, 0.72));
  --st-text-dim:     var(--atlas-text-dim, rgba(38, 70, 83, 0.44));
  --st-border:       #e8e0d1;
  --st-border-focus: rgba(208, 108, 82, 0.42);
  --st-bg:           #ffffff;
  --st-radius:       14px;
  --st-radius-sm:    8px;
  --st-red:          #dc2626;
  --st-red-dim:      rgba(220, 38, 38, 0.10);
}

/* ──────────────────────────────────────────────────────────────────────
   Wrapper — positions the textarea, controls, and status
   ────────────────────────────────────────────────────────────────────── */

.st-wrap {
  position: relative;
  width: 100%;
}

.st-wrap--inside {
  position: relative;
}

.st-field {
  position: relative;
  width: 100%;
}

.st-wrap--outside {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.st-wrap--outside .st-textarea {
  flex: 1;
  min-width: 0;
}

.st-wrap--below {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

/* ──────────────────────────────────────────────────────────────────────
   Textarea
   ────────────────────────────────────────────────────────────────────── */

.st-textarea {
  width: 100%;
  /* Block, not the default inline-block: an inline textarea leaves a few px
     of baseline/descender space below it inside .st-field, which offset the
     absolutely-positioned inside controls (the mic sat ~2px from the visible
     bottom edge but 8px from the right — non-uniform). Block removes that gap
     so the mic is a uniform 8px from both edges. */
  display: block;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--st-text);
  background: var(--st-bg);
  border: 1.5px solid var(--st-border);
  border-radius: var(--st-radius);
  font-family: inherit;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
}

/* Extra right padding when controls sit inside the textarea. */
.st-wrap--inside .st-textarea {
  padding-right: 48px;
}

/* More padding when stop + cancel are both visible during recording. */
.st-wrap--inside[data-voice-state="recording"] .st-textarea {
  padding-right: 96px;
  padding-bottom: 56px;
}

.st-wrap--inside[data-voice-mode="realtime"][data-voice-state="recording"] .st-textarea {
  padding-right: 58px;
}

/* Same bottom padding during transcription so the mic icon doesn't overlap. */
.st-wrap--inside[data-voice-state="transcribing"] .st-textarea {
  padding-bottom: 56px;
}

.st-textarea:focus {
  outline: none;
  border-color: var(--st-border-focus);
  box-shadow: 0 0 0 3px rgba(208, 108, 82, 0.10);
}

.st-textarea::placeholder {
  color: var(--st-text-dim);
}

.st-textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ReadOnly during recording / transcribing — visually muted but focusable. */
.st-textarea[readonly] {
  cursor: default;
  opacity: 0.7;
}

/* ──────────────────────────────────────────────────────────────────────
   Controls container — holds mic + cancel buttons
   ────────────────────────────────────────────────────────────────────── */

.st-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Inside-right: controls float at bottom-right of the textarea. */
.st-wrap--inside .st-controls {
  position: absolute;
  right: 8px;
  bottom: 8px;
}

.st-wrap--inside[data-voice-state="recording"] .st-controls,
.st-wrap--inside[data-voice-state="transcribing"] .st-controls {
  right: 10px;
  bottom: 10px;
  padding: 4px;
  border: 1px solid rgba(226, 232, 240, 0.92);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 22px rgba(38, 70, 83, 0.10);
}

/* ──────────────────────────────────────────────────────────────────────
   Mic button — common base
   ────────────────────────────────────────────────────────────────────── */

.st-mic {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
  color: var(--st-text-soft);
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}
.st-mic:hover {
  color: var(--st-accent-text);
}
.st-mic:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Icon style (compact circle) ──────────────────────────────────── */

.st-mic--icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--st-accent-dim);
  color: var(--st-accent-text);
}
.st-mic--icon:hover {
  background: rgba(208, 108, 82, 0.18);
}

/* ── Pill style ───────────────────────────────────────────────────── */

.st-mic--pill {
  gap: 6px;
  padding: 7px 14px 7px 10px;
  border-radius: 999px;
  background: var(--st-accent-dim);
  color: var(--st-accent-text);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
}
.st-mic--pill:hover {
  background: rgba(208, 108, 82, 0.18);
}

.st-mic-label {
  line-height: 1;
  white-space: nowrap;
}

/* ── Text style ───────────────────────────────────────────────────── */

.st-mic--text {
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--st-accent-text);
  padding: 4px 0;
  text-decoration: none;
  background: none;
}
.st-mic--text:hover {
  text-decoration: underline;
}

/* ──────────────────────────────────────────────────────────────────────
   Cancel button — shown during recording
   ────────────────────────────────────────────────────────────────────── */

.st-cancel {
  display: none;            /* hidden by default, shown via JS */
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: #faf4e8;
  color: var(--st-text-soft);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.st-cancel[style*="display: "] {
  /* When JS sets display to empty string, use flex. */
}
.st-wrap[data-voice-state="recording"] .st-cancel {
  display: inline-flex;
}
.st-cancel:hover {
  background: var(--st-red-dim);
  color: var(--st-red);
}

/* ──────────────────────────────────────────────────────────────────────
   Recording state — red treatment on the Stop button
   ────────────────────────────────────────────────────────────────────── */

.st-mic--recording.st-mic--icon {
  background: var(--st-red-dim);
  color: var(--st-red);
  animation: st-pulse 1.5s ease-in-out infinite;
}

.st-mic--recording.st-mic--pill {
  background: var(--st-red-dim);
  color: var(--st-red);
  animation: st-pulse 1.5s ease-in-out infinite;
}

.st-mic--recording.st-mic--text {
  color: var(--st-red);
}

@keyframes st-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.65; }
}

/* ── Busy (transcribing) — button is hidden via JS ────────────────── */

.st-mic--busy {
  opacity: 0.5;
  cursor: wait;
}

/* Blocked: the mic permission is denied. The button stays visible and
   clickable (a click surfaces the recovery hint), but is visually muted so it
   reads as unavailable rather than active. */
.st-mic--blocked {
  opacity: 0.5;
}
.st-mic--blocked.st-mic--icon {
  background: var(--st-surface-muted, rgba(0, 0, 0, 0.05));
  color: var(--st-text-soft);
}
.st-mic--blocked.st-mic--icon:hover {
  background: var(--st-surface-muted, rgba(0, 0, 0, 0.05));
  opacity: 0.7;
}

/* ──────────────────────────────────────────────────────────────────────
   Wrapper border glow by voice state
   ────────────────────────────────────────────────────────────────────── */

.st-wrap[data-voice-state="recording"] .st-textarea {
  border-color: rgba(220, 38, 38, 0.30);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.08);
}

.st-wrap[data-voice-state="transcribing"] .st-textarea {
  border-color: rgba(208, 108, 82, 0.30);
  box-shadow: 0 0 0 3px rgba(208, 108, 82, 0.08);
}

/* ──────────────────────────────────────────────────────────────────────
   Status text
   ────────────────────────────────────────────────────────────────────── */

.st-status {
  display: block;
  min-height: 18px;
  padding: 4px 2px 0;
  font-size: 12px;
  line-height: 1.3;
  color: var(--st-text-dim);
  transition: color 0.15s;
}

.st-status:empty {
  min-height: 0;
  padding: 0;
}

.st-status--active {
  color: var(--st-accent-text);
}

.st-status--done {
  color: var(--st-accent-text);
}

.st-status--error {
  color: var(--st-red);
}

/* ──────────────────────────────────────────────────────────────────────
   Focus ring on wrapper
   ────────────────────────────────────────────────────────────────────── */

.st-focused .st-mic--icon {
  box-shadow: 0 0 0 2px rgba(208, 108, 82, 0.12);
}

/* ──────────────────────────────────────────────────────────────────────
   Disabled state (whole component)
   ────────────────────────────────────────────────────────────────────── */

.st-disabled {
  opacity: 0.6;
  pointer-events: none;
}
