:root {
  --bg: #eff1f7;
  --card: #ffffff;
  --ink: #141826;
  --muted: #616779;
  --primary: #3730a3;
  --accent: #ef4444;
  --user-bubble: #f3f4f6;
  --customer-bubble: #fef9c3;
  --agent-bubble: #eef2ff;
  --radius-xl: 32px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "DM Sans", sans-serif;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(circle, rgba(55, 48, 163, 0.1) 1px, transparent 1px);
  background-size: 18px 18px;
}

.page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.phone-card {
  width: 100%;
  max-width: 420px;
  min-height: 82vh;
  background: var(--card);
  border-radius: var(--radius-xl);
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.08);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.top-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.top-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  align-items: start;
}

.top-bar-tts .toggle-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.top-bar-spacer {
  min-height: 1px;
}

.tts-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
  line-height: 1;
}

.top-bar .segmented {
  width: 100%;
  min-width: 0;
}

.segmented {
  background: #f8f9fc;
  border-radius: 999px;
  padding: 3px;
  display: flex;
  gap: 4px;
  align-items: stretch;
  min-width: 0;
}

.segmented button {
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  height: 34px;
  flex: 1 1 0;
  min-width: 0;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.segmented button.active {
  background: white;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06), inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.inline-warning {
  margin: 0;
  font-size: 12px;
  color: #b91c1c;
}

.hidden {
  display: none !important;
}

.content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-header {
  padding: 4px 4px 0;
}

.card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
}

.end-session {
  flex-shrink: 0;
  border: 1px solid rgba(55, 48, 163, 0.35);
  background: white;
  color: var(--primary);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.end-session:hover {
  background: #eef2ff;
}

.exchange-label {
  margin: 8px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.exchange-dots {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 0 2px 4px;
}

.exchange-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d1d5db;
  flex-shrink: 0;
}

.exchange-dot.filled {
  background: var(--primary);
}

.session-summary {
  margin: 0 4px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #ecfdf5;
  color: #065f46;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.history {
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bubble {
  max-width: 82%;
  border-radius: 16px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.bubble-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
  letter-spacing: 0.02em;
}

.bubble.assistant.speaking-tts .bubble-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bubble.assistant.speaking-tts .bubble-label::after {
  content: "";
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.9;
  background-color: var(--muted);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='11 5 6 9 2 9 2 15 6 15 11 19 11 5'/%3E%3Cpath d='M15.54 8.46a5 5 0 0 1 0 7.07'/%3E%3Cpath d='M19.07 4.93a10 10 0 0 1 0 14.14'/%3E%3C/svg%3E")
    center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='11 5 6 9 2 9 2 15 6 15 11 19 11 5'/%3E%3Cpath d='M15.54 8.46a5 5 0 0 1 0 7.07'/%3E%3Cpath d='M19.07 4.93a10 10 0 0 1 0 14.14'/%3E%3C/svg%3E")
    center / contain no-repeat;
}

.bubble.customer {
  align-self: flex-start;
  background: var(--customer-bubble);
}

.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--agent-bubble);
}

.bottom-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding-top: 6px;
}

.speak-hint {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  min-height: 16px;
}

.speak-button {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.speak-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(55, 48, 163, 0.35);
}

.speak-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
  transform: none;
}

.speak-button.recording {
  background: var(--accent);
  animation: pulse 1.1s infinite;
}

.speak-button.loading {
  background: #4f46e5;
}

.speak-button.playing {
  background: #059669;
}

.new-session-button {
  border: none;
  background: #e0e7ff;
  color: var(--primary);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 999px;
  cursor: pointer;
}

.new-session-button:hover {
  background: #c7d2fe;
}

.toast {
  margin: 0;
  font-size: 13px;
  color: #b91c1c;
  text-align: center;
  min-height: 18px;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  }
  70% {
    box-shadow: 0 0 0 20px rgba(239, 68, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

.pin-lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(20, 24, 38, 0.72);
  backdrop-filter: blur(6px);
}

.pin-lock-overlay.hidden {
  display: none;
}

.pin-lock-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border-radius: 20px;
  padding: 24px 22px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
}

.pin-lock-title {
  margin: 0 0 8px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
}

.pin-lock-hint {
  margin: 0 0 18px;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

.pin-lock-code {
  font-size: 0.8em;
  font-family: ui-monospace, monospace;
  color: var(--primary);
}

.pin-lock-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pin-lock-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.35rem;
  letter-spacing: 0.35em;
  text-align: center;
  font-family: ui-monospace, monospace;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  color: var(--ink);
}

.pin-lock-input:focus {
  outline: none;
  border-color: var(--primary);
}

.pin-lock-error {
  margin: 0;
  font-size: 0.85rem;
  color: var(--accent);
  text-align: center;
}

.pin-lock-error.hidden {
  display: none;
}

.pin-lock-submit {
  margin-top: 4px;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.pin-lock-submit:hover {
  filter: brightness(1.05);
}

@media (min-width: 421px) {
  .phone-card {
    max-width: 480px;
    min-height: 86vh;
    padding: 18px;
  }
}
