/**
 * Live Translator UI Styles
 */

:root {
  --primary-color: #4285f4;
  --user-bubble-bg: #4285f4;
  --agent-bubble-bg: #f1f3f4;
  --user-text-color: #ffffff;
  --agent-text-color: #202124;
  --bg-color: #ffffff;
  --border-color: #e0e0e0;
  --input-bg: #f8f9fa;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-color);
  color: #202124;
  line-height: 1.6;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: linear-gradient(135deg, #e53935 0%, #d81b60 100%);
  color: white;
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
  display: inline;
}

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

.subtitle {
  font-size: 0.875rem;
  opacity: 0.9;
  margin-left: 0.75rem;
}

.github-link {
  color: inherit;
  opacity: 0.7;
  margin-left: 0.5rem;
  vertical-align: text-bottom;
  display: inline-block;
  line-height: 0;
}

.github-link:hover {
  opacity: 1;
}

.subtitle[hidden] + .github-link {
  display: none;
}


.language-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

.custom-select {
  position: relative;
}

.custom-select-trigger {
  padding: 0.4rem 1.5rem 0.4rem 0.6rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--input-bg);
  color: #202124;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  appearance: none;
}

.custom-select-trigger::after {
  content: '▾';
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  pointer-events: none;
  color: #5f6368;
}

.custom-select-trigger:hover {
  background: #e8eaed;
}

.custom-select-dropdown {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  min-width: 260px;
  max-height: 400px;
  overflow-y: auto;
  background: #2d2d2d;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 1000;
  margin-bottom: 4px;
}

.custom-select-dropdown.open {
  display: block;
}

.custom-select-option {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  color: #e0e0e0;
  cursor: pointer;
  white-space: nowrap;
}

.custom-select-option:hover {
  background: rgba(66, 133, 244, 0.3);
  color: white;
}

.custom-select-option.selected {
  background: rgba(66, 133, 244, 0.2);
  color: #8ab4f8;
}

.custom-select-divider {
  border-top: 1px solid #4e4e4e;
  margin: 0.25rem 0;
}

.custom-select-dropdown::-webkit-scrollbar { width: 8px; }
.custom-select-dropdown::-webkit-scrollbar-track { background: #2d2d2d; }
.custom-select-dropdown::-webkit-scrollbar-thumb { background: #555; border-radius: 4px; }

.lang-swap-btn {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: #5f6368;
  font-size: 1.1rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}

.lang-swap-btn:hover {
  background: #e8eaed;
  color: #202124;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.toggle-console-btn {
  padding: 0.3rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toggle-console-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.toggle-console-btn.active {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.6);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #34a853;
}

.status-indicator.connecting {
  background-color: #fbbc04;
}

.status-indicator.disconnected {
  background-color: #ea4335;
}

/* Main Layout */
.main-layout {
  flex: 1;
  display: flex;
  max-width: 1800px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
  gap: 0;
}

.container {
  flex: 2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border-color);
}

/* Messages Area */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: linear-gradient(to bottom, #f8f9fa 0%, #ffffff 100%);
}

#messages::-webkit-scrollbar {
  width: 8px;
}

#messages::-webkit-scrollbar-track {
  background: transparent;
}

#messages::-webkit-scrollbar-thumb {
  background: #dadce0;
  border-radius: 4px;
}

/* Message Bubbles */
.message {
  display: flex;
  margin-bottom: 0.5rem;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  justify-content: flex-end;
}

.message.agent {
  justify-content: flex-start;
}

.bubble {
  max-width: 70%;
  padding: 0.75rem 1rem;
  border-radius: 1.25rem;
  word-wrap: break-word;
  box-shadow: var(--shadow);
  position: relative;
}

.message.user .bubble {
  background-color: var(--user-bubble-bg);
  color: var(--user-text-color);
  border-bottom-right-radius: 0.25rem;
}

.message.agent .bubble {
  background-color: var(--agent-bubble-bg);
  color: var(--agent-text-color);
  border-bottom-left-radius: 0.25rem;
}

.bubble-text {
  margin: 0;
  line-height: 1.5;
}

.message.transcription .bubble-text {
  font-size: 1.5rem;
}


/* Transcription styling */
.message.transcription.user .bubble {
  opacity: 0.9;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.message.transcription.user .bubble::before {
  display: none;
}

/* Typing indicator */
.typing-indicator {
  display: inline-block;
  margin-left: 0.25rem;
  color: #5f6368;
}

.typing-indicator::after {
  content: '...';
  animation: ellipsis 1.5s infinite;
}

@keyframes ellipsis {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

/* Input Form */
.input-container {
  border-top: 1px solid var(--border-color);
  background-color: white;
  padding: 1.5rem 2rem;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

#messageForm {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.input-wrapper {
  flex: 1;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
}

#message {
  flex: 1;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 1.5rem;
  font-size: 1rem;
  font-family: inherit;
  background-color: var(--input-bg);
  transition: all 0.2s ease;
  outline: none;
}

#message:focus {
  border-color: var(--primary-color);
  background-color: white;
  box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1);
}

/* Buttons */
button {
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: 1.5rem;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  white-space: nowrap;
}

#sendButton {
  background-color: var(--primary-color);
  color: white;
}

#sendButton:hover:not(:disabled) {
  background-color: #3367d6;
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

#sendButton:disabled {
  background-color: #dadce0;
  color: #80868b;
  cursor: not-allowed;
  opacity: 0.6;
}

#startAudioButton {
  background-color: #e53935;
  color: white;
}

#startAudioButton:hover:not(:disabled) {
  background-color: #c62828;
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

#startAudioButton:disabled {
  background-color: #dadce0;
  color: #80868b;
  cursor: not-allowed;
  opacity: 0.6;
}

#startAudioButton.ptt-mode {
  background-color: var(--primary-color);
  user-select: none;
  -webkit-user-select: none;
}

#startAudioButton.ptt-mode:hover:not(:disabled) {
  background-color: #3367d6;
}

#startAudioButton.ptt-active {
  background-color: #e53935;
  transform: scale(1.05);
  box-shadow: 0 0 0 4px rgba(229, 57, 53, 0.25);
}

/* PTT toggle switch */
.ptt-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  flex: 1;
  justify-content: flex-end;
  pointer-events: none;
}

.ptt-toggle input,
.ptt-slider,
.ptt-label {
  pointer-events: auto;
}

.ptt-toggle input {
  display: none;
}

.ptt-slider {
  position: relative;
  width: 36px;
  height: 20px;
  background: #dadce0;
  border-radius: 10px;
  transition: background 0.2s ease;
}

.ptt-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.ptt-toggle input:checked + .ptt-slider {
  background: var(--primary-color);
}

.ptt-toggle input:checked + .ptt-slider::after {
  transform: translateX(16px);
}

.ptt-label {
  font-size: 0.8rem;
  color: #5f6368;
  white-space: nowrap;
}

.ptt-toggle:has(input:disabled) {
  opacity: 0.4;
  pointer-events: none;
}

/* System Messages */
.system-message {
  text-align: center;
  color: #5f6368;
  font-size: 0.875rem;
  padding: 0.5rem;
  margin: 1rem 0;
  font-style: italic;
}


/* Responsive */
@media (max-width: 768px) {
  header { padding: 1rem 1.5rem; }
  h1 { font-size: 1.25rem; }
  .main-layout { flex-direction: column; }
  .container { border-right: none; }
  #messages { padding: 1rem; }
  .bubble { max-width: 85%; }
  .input-container { padding: 1rem; }
  .input-wrapper { width: 100%; flex-direction: column; }
  button { width: 100%; }
}

/* Glossary modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-overlay.hidden { display: none; }

.loading-modal {
  width: auto;
  min-width: 260px;
}

.loading-body {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem 2rem;
}

.loading-body p {
  margin: 0;
  font-size: 0.95rem;
  color: var(--agent-text-color);
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

.modal {
  background: var(--bg-color);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: min(680px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #5f6368;
  padding: 0 0.25rem;
  width: auto;
}
.modal-close:hover { color: #202124; }
.modal-body {
  padding: 1rem 1.25rem 1.25rem;
  overflow-y: auto;
}
.modal-hint {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: #5f6368;
  line-height: 1.5;
}
.modal-hint code {
  background: var(--input-bg);
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.glossary-current {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-bottom: 1rem;
  overflow: hidden;
}
.glossary-current-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.6rem 0.85rem;
  background: var(--input-bg);
  font-size: 0.85rem;
  color: #5f6368;
  border-bottom: 1px solid var(--border-color);
}
.glossary-list {
  max-height: 260px;
  overflow-y: auto;
}
.glossary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.glossary-table thead th {
  position: sticky;
  top: 0;
  background: var(--input-bg);
  text-align: left;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #5f6368;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
}
.glossary-table tbody td {
  padding: 0.45rem 0.85rem;
  color: var(--agent-text-color);
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
  word-break: break-word;
}
.glossary-table tbody tr:last-child td { border-bottom: none; }
.glossary-empty {
  padding: 1rem;
  text-align: center;
  color: #9aa0a6;
  font-size: 0.9rem;
}
.glossary-status { font-size: 0.8rem; color: #5f6368; }
.glossary-status.ok { color: #137333; }
.glossary-status.error { color: #c5221f; }

.glossary-upload {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.glossary-upload input[type="file"] {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.85rem;
}
.file-label {
  font-size: 0.85rem;
  color: #5f6368;
}
.glossary-upload button {
  width: auto;
  padding: 0.5rem 1rem;
  background: var(--primary-color);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
}
.glossary-upload button:hover { filter: brightness(0.95); }
.glossary-upload button.glossary-reset {
  background: var(--input-bg);
  color: var(--agent-text-color);
  border: 1px solid var(--border-color);
}

/* Audio settings modal */
.audio-setting {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 1rem;
}

.audio-setting label {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--agent-text-color);
}

.audio-setting select {
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.875rem;
  background: var(--bg-color);
  color: var(--agent-text-color);
  width: 100%;
  cursor: pointer;
}

.audio-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.audio-actions button {
  padding: 0.5rem 1rem;
  background: var(--primary-color);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
}

.audio-actions button:hover { filter: brightness(0.95); }

.model-name {
  font-size: 0.85rem;
  color: var(--agent-text-color);
  font-family: monospace;
}

/* Voice Replication section */
.vr-section {
  border-top: 1px solid var(--border-color);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
}

.vr-section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--agent-text-color);
  user-select: none;
  padding: 0.25rem 0;
}

.vr-section-header:hover { color: var(--primary-color); }

.vr-chevron {
  font-size: 0.6rem;
  transition: transform 0.2s ease;
  display: inline-block;
}

.vr-section.open .vr-chevron {
  transform: rotate(90deg);
}

.vr-section-body {
  display: none;
  margin-top: 0.75rem;
}

.vr-section.open .vr-section-body {
  display: block;
}

.vr-consent-phrase {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--primary-color);
  background: var(--input-bg);
  border-radius: 0 6px 6px 0;
  font-size: 0.85rem;
  font-style: italic;
  color: #5f6368;
  line-height: 1.5;
}

.vr-recording-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.vr-recording-row label {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--agent-text-color);
  min-width: 100px;
}

.vr-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  justify-content: flex-end;
}

.vr-controls button {
  width: auto;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  background: var(--input-bg);
  color: var(--agent-text-color);
  border: 1px solid var(--border-color);
}

.vr-controls button:hover:not(:disabled) { filter: brightness(0.95); }

.vr-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.vr-controls button.recording {
  background: #e53935;
  color: white;
  border-color: #e53935;
  animation: vr-pulse 1.5s ease-in-out infinite;
}

@keyframes vr-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.vr-controls button.vr-clear {
  color: #c5221f;
  border-color: #c5221f33;
}

.vr-duration {
  font-size: 0.78rem;
  color: #5f6368;
  font-variant-numeric: tabular-nums;
  min-width: 3rem;
  text-align: center;
}

.vr-status {
  font-size: 0.8rem;
  color: #5f6368;
  margin-top: 0.25rem;
}

.vr-status.ok { color: #137333; }
.vr-status.error { color: #c5221f; }
