:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #eef2f5;
  --text: #17212b;
  --muted: #5c6873;
  --border: #d9e0e6;
  --focus: #1f5fbf;
  --danger: #9f1c1c;
  --warning: #7c5600;
  --success: #245c2f;
  --customer: #e8f1ff;
  --company: #ffffff;
  --shadow: 0 8px 24px rgba(23, 33, 43, 0.08);
  --radius: 18px;
  --tap: 48px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.45;
}

body {
  min-height: 100dvh;
}

button, textarea, input {
  font: inherit;
}

button {
  min-width: var(--tap);
  min-height: var(--tap);
  cursor: pointer;
}

button:focus-visible,
textarea:focus-visible,
.message-list:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 100;
  padding: 10px 14px;
  background: #fff;
  color: #000;
  border: 2px solid #000;
  transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

.app-shell {
  width: min(100%, 980px);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--surface);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  border-inline: 1px solid var(--border);
}

.app-header {
  min-height: 82px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #1c2732;
  background: #111a22;
  color: #ffffff;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-block {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-logo-symbol {
  width: 50px;
  height: 50px;
  flex: 0 0 50px;
  object-fit: contain;
}

.brand-copy {
  display: grid;
}

.brand-name {
  letter-spacing: 0.04em;
  font-size: 1.08rem;
}

.brand-subtitle {
  color: #d7dee5;
  font-size: 0.9rem;
}

.header-actions,
.audio-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.text-button,
.secondary-button,
.close-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 14px;
}

.connection-bar {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
  font-size: 0.94rem;
  font-weight: 650;
}

.connection-bar[data-state="offline"] {
  border-left: 5px solid var(--danger);
}

.connection-bar[data-state="reconnecting"] {
  border-left: 5px dashed var(--warning);
}

.connection-bar[data-state="ready"] {
  border-left: 5px solid var(--success);
}

.connection-icon {
  font-size: 0.9rem;
}

.conversation-layout {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  position: relative;
}

.mock-notice {
  margin: 12px 14px 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff9e8;
  color: #5e4b16;
  font-size: 0.92rem;
}

.message-list {
  min-height: 280px;
  overflow-y: auto;
  padding: 18px 14px 28px;
  scroll-behavior: smooth;
  background:
    linear-gradient(rgba(244,246,248,0.86), rgba(244,246,248,0.86));
}

.loading-state,
.empty-state {
  min-height: 160px;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  gap: 10px;
  color: var(--muted);
}

.loading-state[hidden],
.empty-state[hidden] {
    display: none;
}

.empty-state p {
  margin: 0;
  max-width: 34ch;
}

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--text);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 8px 0;
}

.message-row[data-author="customer"] {
  justify-content: flex-start;
  flex-direction: row-reverse;
  align-items: center;
  gap: 8px;
}

.message-row[data-author="company"] {
  justify-content: flex-start;
  align-items: flex-start;
  gap: 8px;
}

.sender-badge {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--text);
  background: var(--surface);
  font-weight: 800;
  font-size: 0.88rem;
}

.message-bubble {
  width: fit-content;
  max-width: min(78%, 620px);
  padding: 4px 7px 3px;
  border-radius: 9px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(23, 33, 43, 0.025);
}

.message-row[data-author="customer"] .message-bubble {
  background: var(--customer);
  border-bottom-right-radius: 5px;
}

.message-row[data-author="company"] .message-bubble {
  background: var(--company);
  border-bottom-left-radius: 5px;
}

.message-sender {
  display: none;
  margin-bottom: 4px;
  font-size: 0.84rem;
  font-weight: 800;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.32;
}

.message-meta {
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  color: var(--muted);
  font-size: 0.70rem;
}

.message-status {
  font-weight: 700;
  line-height: 1;
}

.message-row[data-status="pending"] .message-status::before {
  content: "… ";
}

.message-row[data-status="failed"] .message-bubble {
  border: 2px solid var(--danger);
}

.message-row[data-status="failed"] .message-status {
  color: var(--danger);
}

.retry-button {
  margin-top: 8px;
  border: 1px solid var(--danger);
  color: var(--danger);
  background: #fff;
  border-radius: 10px;
  min-height: 42px;
  padding: 7px 11px;
}

.new-message-button {
  display: none;
  position: absolute;
  right: 18px;
  bottom: 112px;
  z-index: 8;
  border: 1px solid var(--text);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 8px 16px;
  font-weight: 750;
}

.composer-wrap {
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: end;
  gap: 8px;
}

.composer textarea {
  min-height: 50px;
  max-height: 150px;
  resize: none;
  padding: 12px 14px;
  border: 1px solid #aeb8c2;
  border-radius: 16px;
  background: #fff;
  color: var(--text);
}

.icon-text-button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 6px 10px;
  display: grid;
  justify-items: center;
  gap: 1px;
  color: var(--text);
}

.button-label {
  font-size: 0.72rem;
  font-weight: 700;
}

.send-button,
.primary-button {
  border: 2px solid var(--text);
  background: var(--text);
  color: #fff;
  border-radius: 14px;
  padding: 8px 16px;
  font-weight: 800;
}

.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.composer-hint {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.attachment-preview {
  margin-bottom: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
}

.preview-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.preview-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.preview-copy {
  min-width: 0;
  flex: 1;
}

.preview-copy strong,
.preview-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-preview {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 6px 10px;
}

.sheet-dialog {
  width: min(92vw, 620px);
  max-height: 88dvh;
  padding: 0;
  border: 0;
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.sheet-dialog::backdrop {
  background: rgba(23, 33, 43, 0.45);
}

.sheet {
  padding: 18px;
  background: var(--surface);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.sheet-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.sheet-help {
  color: var(--muted);
}

.action-grid {
  display: grid;
  gap: 10px;
  margin-block: 16px;
}

.action-card {
  width: 100%;
  min-height: 74px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
}

.action-icon {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1.35rem;
}

.action-card strong,
.action-card small {
  display: block;
}

.action-card small {
  margin-top: 3px;
  color: var(--muted);
}

.pending-documents-placeholder {
  padding: 14px;
  border: 1px dashed #9aa6b2;
  border-radius: 14px;
  background: var(--surface-muted);
}

.pending-documents-placeholder h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.pending-documents-placeholder p {
  margin: 0;
  color: var(--muted);
}


.attachment-composer[hidden] {
  display: none !important;
}

.attachment-composer {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  align-items: end;
  background: rgba(17, 24, 39, 0.34);
}

.attachment-sheet {
  width: min(100%, 520px);
  margin: 0 auto;
  padding-top: 10px;
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(18px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  border-radius: 22px 22px 0 0;
  background: var(--text);
  box-shadow: 0 -8px 24px rgba(23, 33, 43, 0.14);
}

.attachment-sheet-header {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 8px;
  font-size: 1rem;
  color: #f8fafc;
}

.attachment-picker-back {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  display: grid;
  place-items: center;
}

.attachment-picker-back svg,
.attachment-picker-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.attachment-picker-actions {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.attachment-picker-option {
  min-width: 0;
  min-height: 88px;
  padding: 10px 6px;
  border: 1px solid #cfd9e4;
  border-radius: 16px;
  background: #f8fafc;
  color: var(--text);
  display: grid;
  grid-template-rows: 40px auto;
  align-items: center;
  justify-items: center;
  gap: 7px;
  font-size: 0.8rem;
  font-weight: 750;
  text-align: center;
}

.attachment-picker-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--customer);
  color: var(--focus);
}

.attachment-picker-option:active {
  background: #eef3f8;
  border-color: #b8c7d8;
}

.attachment-picker-option:focus-visible,
.attachment-picker-back:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.audio-failure-feedback {
  margin: 0 4px 6px;
  padding: 0 4px;
  color: var(--danger);
  font-size: 0.84rem;
  font-weight: 750;
  line-height: 1.25;
}

.audio-failure-feedback[hidden] {
  display: none !important;
}

.normal-composer[hidden],
.audio-composer[hidden] {
  display: none !important;
}

.normal-composer,
.audio-composer {
  width: 100%;
  min-width: 0;
}

.audio-composer {
  margin: 0;
  padding: 0;
  background: transparent;
}

.audio-state {
  min-height: 0;
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.audio-actions {
  width: 100%;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 50px;
  grid-template-areas: "trash core send";
  align-items: center;
  gap: 9px;
}

.audio-actions [hidden] {
  display: none !important;
}

.audio-core {
  grid-area: core;
  min-width: 0;
  min-height: 66px;
  display: grid;
  grid-template-rows: auto 24px;
  gap: 3px;
  padding: 7px 10px 6px;
  border-radius: 17px;
  background: #f3f9fd;
  box-shadow: inset 0 0 0 1px rgba(91, 159, 201, 0.12);
}

.audio-core-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.audio-center-controls {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
}

.audio-duration {
  flex: 0 0 auto;
  min-width: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  color: var(--text);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  letter-spacing: 0.01em;
}

.audio-status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: #78b7da;
}

.audio-state[data-state="recording"] .audio-status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(201, 63, 63, 0.10);
}

.audio-state[data-state="recording_paused"] .audio-status-dot,
.audio-state[data-state="draft_ready"] .audio-status-dot {
  background: #5b9fc9;
}

.audio-state[data-playback="playing"] .audio-status-dot {
  background: #2f8fc7;
  box-shadow: 0 0 0 4px rgba(47, 143, 199, 0.10);
}

.audio-actions button {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  box-shadow: none;
}

.audio-trash-button {
  grid-area: trash;
  justify-self: center;
  color: #a64b4b;
  background: #ffffff;
  border: 1px solid #dce5eb;
}

.audio-send-button {
  grid-area: send;
  justify-self: center;
  width: 50px !important;
  height: 50px !important;
  min-width: 50px !important;
  min-height: 50px !important;
  border-color: #2d86b9;
  background: #2d86b9;
  color: #ffffff;
}

.audio-record-button,
.audio-playback-button {
  color: #17384d;
  background: #ffffff;
  border: 1px solid #cfe0ea;
}

.audio-record-button[data-icon="pause"] {
  color: #a83f3f;
  border-color: #e0bcbc;
  background: #fffafa;
}

.audio-record-button[data-icon="resume-recording"] {
  color: #216f9d;
  border-color: #b8d7e9;
  background: #f8fcff;
}

.audio-playback-button[data-icon="pause"] {
  color: #216f9d;
  border-color: #b8d7e9;
  background: #f8fcff;
}

.audio-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.audio-control-icon {
  width: 24px;
  height: 24px;
  display: none;
  place-items: center;
  pointer-events: none;
}

.audio-send-button .audio-control-icon {
  width: 25px;
  height: 25px;
}

.audio-control-icon svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.audio-control-icon .audio-icon-fill {
  fill: currentColor;
  stroke: currentColor;
}

[data-icon="trash"] > .audio-icon-trash,
[data-icon="play"] > .audio-icon-play,
[data-icon="pause"] > .audio-icon-pause,
[data-icon="microphone"] > .audio-icon-microphone,
[data-icon="resume-recording"] > .audio-icon-resume-recording,
[data-icon="retry"] > .audio-icon-retry,
[data-icon="send"] > .audio-icon-send {
  display: inline-grid;
}

.audio-progress-shell {
  position: relative;
  min-width: 0;
  height: 24px;
  display: flex;
  align-items: center;
}

.audio-waveform {
  position: absolute;
  inset: 2px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  pointer-events: none;
  opacity: 0.82;
}

.audio-waveform span {
  width: 2px;
  min-width: 2px;
  height: 8px;
  border-radius: 999px;
  background: #8abbd7;
}

.audio-waveform span:nth-child(4n + 1) { height: 6px; }
.audio-waveform span:nth-child(4n + 2) { height: 14px; }
.audio-waveform span:nth-child(4n + 3) { height: 10px; }
.audio-waveform span:nth-child(8n) { height: 18px; }

.audio-state[data-state="recording"] .audio-waveform span {
  background: #9abdd1;
}

.audio-state[data-playback="playing"] .audio-waveform span {
  background: #5aa7d2;
}

.audio-timeline {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 24px;
  min-height: 24px;
  margin: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  opacity: 1;
}

.audio-timeline:disabled {
  cursor: default;
  opacity: 1;
}

.audio-timeline::-webkit-slider-runnable-track {
  height: 24px;
  background: transparent;
  border: 0;
}

.audio-timeline::-moz-range-track {
  height: 24px;
  background: transparent;
  border: 0;
}

.audio-timeline::-webkit-slider-thumb {
  width: 12px;
  height: 12px;
  margin-top: 6px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #2f8fc7;
  box-shadow: 0 1px 4px rgba(23, 56, 77, 0.28);
  -webkit-appearance: none;
}

.audio-timeline::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #2f8fc7;
  box-shadow: 0 1px 4px rgba(23, 56, 77, 0.28);
}

@media (max-width: 640px) {
  .audio-composer {
    width: 100%;
  }

  .audio-actions {
    grid-template-columns: 46px minmax(0, 1fr) 48px;
    gap: 7px;
  }

  .audio-core {
    min-height: 64px;
    padding: 6px 8px 5px;
    border-radius: 16px;
  }

  .audio-actions button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .audio-send-button {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    min-height: 48px !important;
  }

  .audio-center-controls {
    gap: 5px;
  }

  .audio-duration {
    min-width: 46px;
    gap: 5px;
    font-size: 0.78rem;
  }

  .audio-control-icon {
    width: 23px;
    height: 23px;
  }

  .audio-send-button .audio-control-icon {
    width: 24px;
    height: 24px;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 200;
  width: min(calc(100% - 24px), 560px);
  padding: 12px 14px;
  border-radius: 14px;
  background: #17212b;
  color: #fff;
  box-shadow: var(--shadow);
  text-align: center;
  font-weight: 700;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 640px) {
  html, body { font-size: 17px; }

  .app-shell {
    border-inline: 0;
  }

  .app-header {
    min-height: 70px;
    padding: 10px 12px;
  }

  .brand-fallback {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .brand-subtitle {
    font-size: 0.82rem;
  }

  .message-bubble {
    max-width: 84%;
  }

  .composer {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .composer .send-button {
    grid-column: 2 / 4;
    width: 100%;
  }

  .composer-hint {
    display: none;
  }

  .button-label {
    font-size: 0.7rem;
  }
}

@media (max-width: 390px) {
  .brand-subtitle {
    display: none;
  }

  .message-bubble {
    max-width: 86%;
  }

  .message-row {
    gap: 7px;
  }

  .sender-badge {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }
}

@media (min-width: 820px) {
  body {
    padding: 24px;
  }

  .app-shell {
    min-height: calc(100dvh - 48px);
    max-height: calc(100dvh - 48px);
    border: 1px solid var(--border);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: var(--shadow);
  }

  .conversation-layout {
    min-height: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}


/* D13 approved visual baseline correction */
.app-header .text-button {
  border-color: rgba(255,255,255,0.45);
  background: transparent;
  color: #ffffff;
}

.message-list {
  background: #f3f5f6;
}

.message-row[data-author="company"] .sender-badge {
  background: #111a22;
  color: #ffffff;
  border-color: #111a22;
}

.message-row[data-author="company"] .message-bubble {
  border-top-left-radius: 5px;
}

.message-row[data-author="customer"] .message-bubble {
  background: #dfeaf6;
  border-color: #adc7de;
  box-shadow: 0 4px 12px rgba(31, 71, 101, 0.10);
}

.composer-wrap {
  padding-top: 12px;
}

.composer {
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  align-items: end;
  gap: 7px;
}

.composer-action {
  min-width: 54px;
  min-height: 54px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  border-radius: 16px;
  padding: 5px 8px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
}

.composer-action-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.send-button {
  min-height: 54px;
}

.file-card {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafb;
  padding: 10px 11px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-card-icon {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #e7ebef;
  font-size: 0.72rem;
  font-weight: 800;
}

.file-card-copy {
  min-width: 0;
}

.file-card-copy strong,
.file-card-copy span {
  display: block;
}

.file-card-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-card-copy span {
  color: var(--muted);
  font-size: 0.78rem;
}

.history-image-frame {
  margin-top: 8px;
  max-width: 100%;
  overflow: hidden;
  border-radius: 12px;
}

.history-image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  border-radius: inherit;
}

.history-image-state {
  margin-top: 8px;
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafb;
  color: var(--muted);
  font-size: 0.82rem;
}

.history-image-state-error {
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .composer {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
  }

  .composer .send-button {
    grid-column: auto;
    width: auto;
  }

  .composer-action {
    min-width: 50px;
    padding-inline: 6px;
  }
}

@media (max-width: 430px) {
  .composer {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 5px;
  }

  .composer-action {
    min-width: 46px;
    min-height: 50px;
    padding: 4px 5px;
  }

  .composer textarea {
    min-height: 50px;
    padding-inline: 10px;
  }

  .send-button {
    min-width: 52px;
    min-height: 50px;
    padding-inline: 10px;
  }
}


.sender-badge-logo {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.sender-badge-text {
  font-weight: 800;
  font-size: 0.88rem;
}

.message-row[data-author="company"] .sender-badge {
  display: none;
}

.message-row[data-author="customer"] .sender-badge {
  background: #ffffff;
  margin-top: 0;
}

/* D13-F02 approved conversation background + watermark */
/* Runtime diagnosis proved v3 active. V4 anchors ambience to the
   conversation viewport instead of the scrollable message content. */
.conversation-layout {
  position: relative;
  isolation: isolate;
  background:
    radial-gradient(circle at 82% 20%, rgba(172, 214, 241, 0.22) 0%, rgba(194, 225, 245, 0.09) 28%, transparent 52%),
    radial-gradient(circle at 12% 82%, rgba(184, 221, 244, 0.17) 0%, rgba(211, 234, 248, 0.07) 26%, transparent 50%),
    linear-gradient(145deg, #ffffff 0%, #fbfdff 46%, #f3f9fd 100%);
}

.conversation-layout::before,
.conversation-layout::after {
  content: "";
  position: absolute;
  display: block;
  aspect-ratio: 441 / 369;
  background-image: url("../assets/branding/ascendia-symbol-transparent.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

.conversation-layout::before {
  width: min(46vw, 390px);
  top: 11%;
  right: -14%;
  opacity: 0.060;
}

.conversation-layout::after {
  width: min(32vw, 260px);
  left: -12%;
  bottom: 9%;
  opacity: 0.035;
}

.conversation-layout > * {
  position: relative;
  z-index: 1;
}

.message-list {
  background: transparent;
}

/* Disable the v3 scroll-content watermarks. The viewport-anchored
   conversation layer above is now the single watermark mechanism. */
.message-list::before,
.message-list::after {
  content: none;
}

@media (max-width: 819px) {
  /* The mobile chat is a true viewport: the message list scrolls inside
     it while decorative ambience remains anchored behind that viewport. */
  .app-shell {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .conversation-layout {
    min-height: 0;
    overflow: hidden;
  }

  .message-list {
    min-height: 0;
    overflow-y: auto;
  }
}

@media (max-width: 640px) {
  .conversation-layout {
    background:
      radial-gradient(circle at 88% 19%, rgba(170, 214, 242, 0.24) 0%, rgba(196, 226, 246, 0.10) 30%, transparent 54%),
      radial-gradient(circle at 9% 84%, rgba(184, 221, 244, 0.19) 0%, rgba(215, 237, 250, 0.08) 28%, transparent 52%),
      linear-gradient(145deg, #ffffff 0%, #fbfdff 44%, #f2f9fd 100%);
  }

  .conversation-layout::before {
    width: min(68vw, 320px);
    top: 11%;
    right: -24%;
    opacity: 0.055;
  }

  .conversation-layout::after {
    width: min(46vw, 220px);
    left: -20%;
    bottom: 7%;
    opacity: 0.030;
  }
}

@media (min-width: 820px) {
  .conversation-layout::before {
    width: min(34vw, 390px);
    top: 9%;
    right: -7%;
    opacity: 0.055;
  }

  .conversation-layout::after {
    width: min(24vw, 260px);
    left: -8%;
    bottom: 8%;
    opacity: 0.030;
  }
}

/* D13-F04 bubble tone + watermark tint */
.message-row[data-author="customer"] .message-bubble {
  background: rgba(108, 205, 255, 0.40);
  border-color: #A9CBE7;
  box-shadow: 0 1px 4px rgba(31, 71, 101, 0.06);
}

/* Preserve D13-F02 geometry/opacity; change only presentation tint.
   The official PNG remains the mask/source of the Ascendia symbol. */
.conversation-layout::before,
.conversation-layout::after {
  background-image: none;
  background-color: #69B7E6;
  -webkit-mask-image: url("../assets/branding/ascendia-symbol-transparent.png");
  mask-image: url("../assets/branding/ascendia-symbol-transparent.png");
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

/* D13 QUALITY R1 — trust/install dialog */
.trust-dialog {
  width: min(calc(100vw - 24px), 560px);
  max-height: min(92dvh, 760px);
  padding: 0;
  border: 0;
  border-radius: 22px;
  box-shadow: var(--shadow);
  color: var(--text);
}

.trust-dialog::backdrop {
  background: rgba(17, 26, 34, 0.52);
}

.trust-sheet {
  padding: 20px;
  background: #ffffff;
}

.trust-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin-bottom: 16px;
  border-radius: 16px;
  background: #111a22;
  color: #ffffff;
}

.trust-logo {
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  object-fit: contain;
}

.trust-brand-copy {
  min-width: 0;
  display: grid;
}

.trust-brand-copy strong {
  font-size: 1.08rem;
  letter-spacing: 0.04em;
}

.trust-brand-copy span {
  color: #d7dee5;
  font-size: 0.92rem;
}

.trust-dialog h2 {
  margin: 0 0 14px;
  font-size: 1.32rem;
  line-height: 1.25;
}

.trust-copy {
  font-size: 1rem;
}

.trust-copy p,
.trust-security-note {
  margin: 0 0 12px;
}

.trust-security-note {
  padding: 12px 14px;
  border-left: 4px solid #5c9ec8;
  border-radius: 10px;
  background: #f3f8fb;
  font-weight: 650;
}

.trust-fallback {
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
}

.trust-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.trust-primary,
.trust-secondary {
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  font-weight: 800;
}

@media (max-width: 360px) {
  .trust-sheet {
    padding: 16px;
  }

  .trust-logo {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
  }

  .trust-dialog h2 {
    font-size: 1.2rem;
  }

  .trust-copy {
    font-size: 1rem;
  }
}

/* INSTALL UX V1 — one clear action at a time, senior-friendly. */
.install-no-store-note {
  padding: 12px 14px;
  border-radius: 12px;
  background: #eef8fd;
  border: 1px solid #b9dff3;
  color: #17384d;
}

.install-guide {
  display: grid;
  gap: 12px;
  font-size: 1.05rem;
  line-height: 1.45;
}

.install-guide-lead,
.install-guide-finish {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f3f8fb;
  border: 1px solid #d6e5ee;
}

.install-guide-finish {
  background: #eef9f2;
  border-color: #c5e4d0;
}

.install-step {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  padding: 12px;
  border: 2px solid #d4e0e7;
  border-radius: 16px;
  background: #ffffff;
}

.install-step-number {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #111a22;
  color: #ffffff;
  font-size: 1.2rem;
  font-weight: 900;
}

.install-step div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.install-step strong {
  color: #111a22;
  font-size: 1.08rem;
  line-height: 1.3;
}

.install-step span:not(.install-step-number):not(.install-step-cue) {
  color: #52616c;
  font-size: 0.96rem;
}

.install-step-cue {
  min-width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 3px solid #e59b32;
  background: #fff8eb;
  color: #111a22;
  font-size: 1.55rem;
  font-weight: 900;
}

.install-share-cue {
  font-size: 1.25rem;
}

@media (max-width: 420px) {
  .trust-dialog {
    width: min(calc(100vw - 16px), 560px);
    max-height: 94dvh;
  }

  .trust-dialog h2 {
    font-size: 1.35rem;
  }

  .trust-copy,
  .install-guide {
    font-size: 1.04rem;
  }

  .trust-primary,
  .trust-secondary {
    min-height: 58px;
    font-size: 1.04rem;
  }

  .install-step {
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 10px;
    min-height: 82px;
  }
}


/* INSTALL UX V2 — staged guidance: one instruction screen at a time. */
.install-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -2px 0 14px;
}

.install-progress-text {
  color: #53616c;
  font-size: 0.94rem;
  font-weight: 800;
}

.install-progress-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.install-progress-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #d6e1e8;
  border: 1px solid #bfccd5;
}

.install-progress-dot.is-active {
  width: 14px;
  height: 14px;
  background: #69b7e6;
  border-color: #4e9ccc;
}

.install-progress-dot.is-done {
  background: #2f9c61;
  border-color: #2f9c61;
}

.install-stage-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 52px;
  align-items: center;
  gap: 12px;
  min-height: 132px;
  padding: 16px 14px;
  border: 2px solid #c9d9e3;
  border-radius: 18px;
  background: #ffffff;
}

.install-stage-number {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #111a22;
  color: #ffffff;
  font-size: 1.28rem;
  font-weight: 900;
}

.install-stage-body {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.install-stage-action {
  color: #111a22;
  font-size: 1.24rem;
  line-height: 1.28;
}

.install-stage-helper {
  color: #4d5d69;
  font-size: 1rem;
  line-height: 1.4;
}

.install-after-card {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  padding: 13px 14px;
  border-radius: 14px;
  background: #eef8fd;
  border: 1px solid #badff1;
  color: #17384d;
}

.install-after-card strong {
  font-size: 0.96rem;
}

.install-after-card span {
  font-size: 1rem;
  line-height: 1.4;
}

.install-finished-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 18px 14px;
  border: 2px solid #c5e4d0;
  border-radius: 18px;
  background: #eef9f2;
  text-align: center;
}

.install-finished-check {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #2f9c61;
  color: #ffffff;
  font-size: 2rem;
  font-weight: 900;
}

.install-finished-card strong {
  color: #173a26;
  font-size: 1.18rem;
  line-height: 1.3;
}

.install-finished-card span {
  color: #365544;
  font-size: 1rem;
  line-height: 1.4;
}

.install-wizard-actions {
  position: sticky;
  bottom: -20px;
  padding-top: 6px;
  padding-bottom: 2px;
  background: #ffffff;
}

@media (max-width: 420px) {
  .install-stage-card {
    grid-template-columns: 44px minmax(0, 1fr) 48px;
    gap: 10px;
    min-height: 142px;
    padding: 14px 12px;
  }

  .install-stage-number {
    width: 44px;
    height: 44px;
  }

  .install-stage-action {
    font-size: 1.16rem;
  }

  .install-stage-helper,
  .install-after-card span {
    font-size: 0.98rem;
  }
}



/* D127 — MOBILE WHATSAPP-LIKE COMPOSER + NO HORIZONTAL EXPANSION
   Preserves approved Ascendia colors and transport/business semantics. */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.app-shell,
.conversation-layout,
.message-list,
.composer-wrap,
.composer,
.attachment-preview,
.preview-card,
.message-row,
.message-bubble {
  min-width: 0;
  max-width: 100%;
}

.message-list {
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

.message-row {
  width: 100%;
  min-width: 0;
}

.message-row[data-author="customer"] {
  justify-content: flex-end;
  flex-direction: row;
}

.message-row[data-author="customer"] .sender-badge {
  display: none;
}

.message-row[data-author="customer"] .message-bubble {
  margin-left: auto;
  max-width: min(86%, 620px);
}

.message-row[data-author="company"] .message-bubble {
  max-width: min(86%, 620px);
}

.message-bubble {
  overflow: hidden;
}

.message-text,
.message-files,
.file-card,
.file-card-copy {
  min-width: 0;
  max-width: 100%;
}

.composer-wrap {
  overflow: hidden;
}

.normal-composer,
.audio-composer {
  width: 100%;
  min-width: 0;
}

.composer {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: end;
  gap: 7px;
  width: 100%;
}

.composer textarea {
  grid-column: 2;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  max-height: calc((1.35em * 5) + 22px);
  line-height: 1.35;
  padding: 11px 12px;
  resize: none;
  overflow-y: hidden;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#attachmentButton {
  grid-column: 1;
}

#audioButton,
#sendButton {
  grid-column: 3;
}

.composer-action,
.send-button {
  width: 48px;
  min-width: 48px;
  height: 48px;
  min-height: 48px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.composer-icon-only .composer-action-icon,
.composer-send-icon svg {
  width: 24px;
  height: 24px;
  font-size: 24px;
}

.composer-send-icon {
  border: 2px solid var(--text);
  background: var(--text);
  color: #fff;
}

.composer-hint {
  display: none;
}

.attachment-preview {
  width: 100%;
  max-width: 100%;
  max-height: 86px;
  margin: 0 0 7px;
  padding: 7px 8px;
  overflow: hidden;
}

.preview-card {
  width: 100%;
  max-width: 100%;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 8px;
}

.preview-thumb {
  width: 48px;
  height: 48px;
}

.preview-copy {
  min-width: 0;
  overflow: hidden;
}

.preview-copy strong,
.preview-copy span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-preview {
  width: 36px;
  min-width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.45rem;
  line-height: 1;
}

@media (max-width: 819px) {
  .app-shell {
    width: 100%;
    max-width: 100vw;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100svh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .conversation-layout {
    min-height: 0;
    overflow: hidden;
  }

  .message-list {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-inline: 10px;
  }

  .composer-wrap {
    padding-top: 8px;
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    padding-left: max(8px, env(safe-area-inset-left));
  }
}

@media (max-width: 430px) {
  .composer {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 6px;
  }

  .composer-action,
  .send-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .composer textarea {
    min-height: 44px;
    padding: 9px 11px;
    font-size: 16px;
  }

  .message-row[data-author="customer"] .message-bubble {
    max-width: 88%;
  }

  .message-row[data-author="company"] .message-bubble {
    max-width: 88%;
  }
}


/* D128 — SW transition compatibility fence.
   Keeps the legacy cameraButton present for stale-cache compatibility
   without consuming composer width or becoming focusable/visible. */
.composer-compat-camera,
.composer-compat-camera[hidden] {
  display: none !important;
}


/* D130 — compact online presence below ASCENDIA; no standalone status bar */
.brand-copy {
  gap: 2px;
}

.brand-presence {
  color: #d7dee5;
  font-size: 0.88rem;
  line-height: 1.1;
}

.connection-bar,
.connection-bar[hidden] {
  display: none !important;
}

/* D129 finalized with coherent versioning: hidden action must never render. */
.composer #audioButton[hidden],
.composer #sendButton[hidden] {
  display: none !important;
}

/* D130 — WhatsApp-like compact customer delivery status inside blue bubble */
.message-row[data-author="customer"] .message-meta {
  gap: 3px;
}

.message-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1rem;
  min-height: 1rem;
  color: #2f5878;
}

.message-status svg {
  width: 1rem;
  height: 1rem;
  display: block;
  stroke: currentColor;
  fill: none;
}

.message-status.status-sent {
  color: #2f5878;
}

.message-status.status-pending,
.message-status.status-uncertain {
  color: #2f5878;
}

.message-status.status-failed {
  color: var(--danger);
}

.message-status-text {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}


/* D131 — MOBILE FULL-VIEW CONVERSATION + FLOATING BOTTOM COMPOSER
   Visual-only correction. Transport/status/business semantics unchanged. */
@media (max-width: 819px) {
  .app-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100%;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    max-height: 100vh;
    max-height: 100svh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .app-header {
    grid-row: 1;
  }

  .connection-bar,
  .connection-bar[hidden] {
    display: none !important;
  }

  .conversation-layout {
    grid-row: 2;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .mock-notice:not([hidden]) {
    flex: 0 0 auto;
  }

  .message-list {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 14px;
  }

  .composer-wrap {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    margin: 0;
    border-top: 0;
    background: transparent;
    padding-top: 6px;
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(7px, env(safe-area-inset-bottom));
    padding-left: max(8px, env(safe-area-inset-left));
    overflow: visible;
  }

  .composer {
    width: 100%;
    align-items: end;
  }

  .composer textarea,
  .composer-action,
  .send-button {
    background-color: rgba(255, 255, 255, 0.98);
    box-shadow: 0 2px 10px rgba(23, 33, 43, 0.13);
  }

  .composer-send-icon {
    background-color: var(--text);
  }

  .attachment-preview:not([hidden]) {
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 2px 10px rgba(23, 33, 43, 0.11);
  }
}
/* D015 — compact AUDIO message player */
.message-audio-player {
  display: grid;
  grid-template-columns: 36px minmax(92px, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: min(260px, 72vw);
}

.message-audio-toggle {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  display: inline-grid;
  place-items: center;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
}

.message-audio-progress {
  width: 100%;
  min-width: 0;
  accent-color: var(--focus);
}

.message-audio-duration {
  font-size: 0.74rem;
  white-space: nowrap;
  opacity: 0.78;
}

.message-audio-failure {
  grid-column: 1 / -1;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--danger);
}

.message-audio-failure[hidden] {
  display: none !important;
}
