* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: clamp(14px, 2.5vw, 15px);
  line-height: 1.5;
  max-width: 900px;
  margin: 0 auto;
  padding: clamp(0.75rem, 3vw, 1.5rem);
  padding-left: max(clamp(0.75rem, 3vw, 1.5rem), env(safe-area-inset-left));
  padding-right: max(clamp(0.75rem, 3vw, 1.5rem), env(safe-area-inset-right));
  color: #1a1a1a;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: hidden;
}

.split {
  display: flex;
  gap: clamp(1rem, 3vw, 1.5rem);
  align-items: stretch;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: hidden;
}

.chat-panel .status { order: 0; }
.chat-panel .transcript-wrapper { order: 1; flex: 1; min-height: 0; }
.chat-panel .listening { order: 2; }
.chat-panel .actions { order: 3; flex-shrink: 0; }

h1 {
  font-size: clamp(1.5rem, 5vw, 2.25rem);
  margin: 0 0 clamp(0.5rem, 2vw, 1rem);
  text-align: center;
}

.status {
  padding: 0.5rem 0.75rem;
  background: #f5f5f5;
  border-radius: 6px;
  font-size: 0.85rem;
  color: #555;
}

.status.error {
  background: #fef2f2;
  color: #b91c1c;
}

.transcript-wrapper {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: hidden;
}

.transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  background: #fafafa;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin: 0 auto;
  width: 100%;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 #f1f5f9;
}

.transcript::-webkit-scrollbar {
  width: 8px;
}

.transcript::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}

.transcript::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 4px;
}

.transcript::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}

.transcript .agent {
  color: #0f766e;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.transcript .text {
  margin-bottom: 0.75rem;
}

.transcript .word {
  transition: background 0.1s ease;
}

.transcript .word.active {
  background: #ccfbf1;
  border-radius: 2px;
}

.transcript .agent-msg .text,
.transcript .user-msg .text {
  margin-bottom: 0.75rem;
}

.transcript .user-msg .agent {
  color: #0f766e;
}

.transcript .agent-msg .agent {
  color: #ea580c;
}

.transcript .user-live {
  opacity: 0.7;
  font-style: italic;
}

.listening {
  flex-shrink: 0;
  padding: 0.75rem;
  background: #ccfbf1;
  border: 1px solid #0d9488;
  border-radius: 6px;
  font-weight: 500;
  color: #0f766e;
}

@keyframes pulse {
  50% { opacity: 0.7; }
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.actions-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: stretch;
}

.settings-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem;
  font-size: 1.25rem;
  background: #f5f5f5;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  color: #374151;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.settings-btn:hover {
  background: #e5e7eb;
  border-color: #d1d5db;
  color: #0d9488;
}

.actions .contact-input,
.actions select.contact-input {
  flex: 1 1 120px;
  min-width: 0;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  font-size: clamp(0.9rem, 2vw, 0.95rem);
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  touch-action: manipulation;
}

.actions select.contact-input {
  background: #fff;
  cursor: pointer;
}

.actions .contact-input::placeholder {
  color: #9ca3af;
}

.actions .contact-input:focus,
.actions select.contact-input:focus {
  outline: none;
  border-color: #0d9488;
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.2);
}

.actions button {
  flex: 1 1 auto;
  min-width: 120px;
  min-height: 44px;
  padding: 0.6rem 1.2rem;
  font-size: clamp(0.9rem, 2vw, 1rem);
  background: #0d9488;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
}

.actions button:hover {
  background: #0f766e;
}

.actions .end-call {
  background: #dc2626;
}

.actions .end-call:hover {
  background: #b91c1c;
}

.actions .secondary,
.appointments .secondary {
  background: #475569;
}

.actions .secondary:hover,
.appointments .secondary:hover {
  background: #334155;
}

.appointments {
  flex: 0 0 min(320px, 100%);
  min-width: 0;
  border: 1px solid #eee;
  border-radius: 6px;
  background: #fafafa;
  padding: clamp(0.6rem, 2vw, 0.9rem);
  display: flex;
  flex-direction: column;
}

.appointments-header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}


.appointments-header .tabs {
  display: flex;
  gap: 0.25rem;
}

.appointments-header .tabs .tab {
  flex: 1 1 0;
  min-width: 0;
}

.appointments-header .header-actions {
  display: flex;
  width: 100%;
  padding-top: 0.25rem;
  border-top: 1px solid #e5e7eb;
}

.appointments-header .header-actions button {
  flex: 1;
  width: 100%;
}

.appointments-header .tab {
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
  background: transparent;
  color: #6b7280;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  cursor: pointer;
}

.appointments-header .tab:hover {
  background: #f1f5f9;
  color: #374151;
}

.appointments-header .tab.active {
  background: #0d9488;
  color: white;
  border-color: #0d9488;
}

.appointments .panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.appointments h2 {
  margin: 0;
  font-size: 0.95rem;
  color: #374151;
}

.appointments-header button {
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  background: #0d9488;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.appointments-header button:hover {
  background: #0f766e;
}

.appointments-header button.secondary {
  background: #475569;
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
}

.appointments-header button.secondary:hover {
  background: #334155;
}

.appointments .secondary {
  font-size: 0.85rem;
  padding: 0.45rem 0.7rem;
}

.appointments-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.appointment-row {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
}

.appointment-head {
  font-weight: 600;
  color: #0f766e;
  margin-bottom: 0.2rem;
}

.appointment-contact {
  font-size: 0.85rem;
  color: #374151;
  margin-bottom: 0.2rem;
}

.appointment-summary {
  font-size: 0.82rem;
  color: #6b7280;
}

.appointment-empty {
  font-size: 0.82rem;
  color: #6b7280;
}

.transcripts-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.transcript-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  cursor: pointer;
}

.transcript-row-main {
  flex: 1;
  min-width: 0;
}

.transcript-full-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1rem;
  background: #f5f5f5;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  color: #374151;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.transcript-full-btn:hover {
  background: #e5e7eb;
  border-color: #0d9488;
  color: #0d9488;
}

.transcript-row:hover {
  border-color: #0d9488;
}

.transcript-row.expanded {
  border-color: #0d9488;
}

.transcript-row .transcript-head {
  font-weight: 600;
  color: #0f766e;
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
}

.transcript-row .transcript-meta {
  font-size: 0.82rem;
  color: #6b7280;
  margin-bottom: 0.25rem;
}

.transcript-row .transcript-preview {
  font-size: 0.82rem;
  color: #6b7280;
  max-height: 2.4em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.transcript-row .transcript-body {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #e5e7eb;
  font-size: 0.85rem;
}

.transcript-row .transcript-body .agent-msg,
.transcript-row .transcript-body .user-msg {
  margin-bottom: 0.5rem;
}

.transcript-row .transcript-body .agent {
  color: #ea580c;
  font-weight: 500;
}

.transcript-row .transcript-body .user-msg .agent {
  color: #0f766e;
}

.transcript-empty {
  font-size: 0.82rem;
  color: #6b7280;
}

/* Transcript modal */
.transcript-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.transcript-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.transcript-modal-content {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  max-height: 80vh;
  width: 100%;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.transcript-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e5e7eb;
}

.transcript-modal-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #0f766e;
}

.transcript-modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  background: #f5f5f5;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  color: #374151;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.transcript-modal-close:hover {
  background: #e5e7eb;
  border-color: #0d9488;
  color: #0d9488;
}

.transcript-modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  background: #fafafa;
  font-size: 0.9rem;
  line-height: 1.5;
}

.transcript-modal-body .agent-msg,
.transcript-modal-body .user-msg {
  margin-bottom: 0.75rem;
}

.transcript-modal-body .agent {
  font-weight: 500;
}

.transcript-modal-body .agent-msg .agent {
  color: #ea580c;
}

.transcript-modal-body .user-msg .agent {
  color: #0f766e;
}

@media (max-width: 640px) {
  .split {
    flex-direction: column;
    gap: 1rem;
  }

  .chat-panel {
    flex: 1 1 auto;
    min-height: 180px;
  }

  .actions {
    flex-direction: column;
    gap: 0.5rem;
  }

  .actions .contact-input,
  .actions select.contact-input {
    flex: 1 1 auto;
    width: 100%;
  }

  .actions button {
    width: 100%;
    min-width: 0;
  }

  .appointments {
    flex: 1 1 auto;
    min-height: 200px;
    min-width: 0;
  }

  .appointments-header .tab {
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
  }

  .appointments-header .secondary {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  .actions .contact-input,
  .actions select.contact-input {
    flex: 1 1 140px;
  }
}

