:root {
  --color-bg: #ffffff;
  --color-bg-secondary: #f5f5f7;
  --color-text: #1d1d1f;
  --color-text-muted: #86868b;
  --color-border: #d2d2d7;
  --color-primary: #007aff;
  --color-primary-light: #e3f2ff;
  --color-success: #34c759;
  --color-error: #ff3b30;
  --color-warning: #ff9500;
  --color-user-bubble: #007aff;
  --color-user-text: #ffffff;
  --color-assistant-bubble: #e9e9eb;
  --color-assistant-text: #1d1d1f;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", "PingFang TC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1c1c1e;
    --color-bg-secondary: #2c2c2e;
    --color-text: #f5f5f7;
    --color-text-muted: #98989d;
    --color-border: #38383a;
    --color-primary: #0a84ff;
    --color-primary-light: #1a3a5c;
    --color-assistant-bubble: #3a3a3c;
    --color-assistant-text: #f5f5f7;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  }
}

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

html, body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

header {
  text-align: center;
  padding: 24px 0 16px;
}

header h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

header .subtitle {
  font-size: 14px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--color-bg-secondary);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 16px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-muted);
}

.status-connected .status-dot {
  background: var(--color-success);
}

.status-disconnected .status-dot {
  background: var(--color-text-muted);
}

.status-recording .status-dot {
  background: var(--color-error);
  animation: pulse 1s ease-in-out infinite;
}

.status-error .status-dot {
  background: var(--color-warning);
}

.instructions {
  text-align: center;
  font-size: 14px;
  color: var(--color-text-muted);
  padding: 12px 16px;
  margin-bottom: 12px;
  line-height: 1.6;
}

.instructions-en {
  font-size: 12px;
  opacity: 0.8;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.2); }
}

.conversation {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
}

.message p {
  margin: 0;
}

.message.user {
  align-self: flex-end;
  background: var(--color-user-bubble);
  color: var(--color-user-text);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--color-assistant-bubble);
  color: var(--color-assistant-text);
  border-bottom-left-radius: 4px;
}

.message.system {
  align-self: center;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 13px;
  text-align: center;
  padding: 8px 16px;
}

.message.error {
  align-self: center;
  background: rgba(255, 59, 48, 0.1);
  color: var(--color-error);
  font-size: 13px;
  border: 1px solid var(--color-error);
}

.message.pending {
  opacity: 0.7;
}

.conversation-image {
  margin-top: 12px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-width: 200px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.conversation-image:hover {
  transform: scale(1.02);
}

.conversation-image img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.image-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.9);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.image-lightbox.active {
  opacity: 1;
  visibility: visible;
}

.image-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.image-lightbox.active img {
  transform: scale(1);
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 24px;
  cursor: pointer;
  transition: background 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.voice-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 8px 12px;
  background: rgba(var(--color-primary-rgb, 10, 132, 255), 0.1);
  border-radius: var(--radius-sm);
  transition: opacity 0.3s ease;
}

.voice-loading.fade-out {
  opacity: 0;
}

.voice-loading-waves {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}

.voice-loading-waves span {
  display: block;
  width: 4px;
  height: 8px;
  background: var(--color-primary);
  border-radius: 2px;
  animation: voice-wave 1s ease-in-out infinite;
}

.voice-loading-waves span:nth-child(1) { animation-delay: 0s; }
.voice-loading-waves span:nth-child(2) { animation-delay: 0.1s; }
.voice-loading-waves span:nth-child(3) { animation-delay: 0.2s; }
.voice-loading-waves span:nth-child(4) { animation-delay: 0.3s; }
.voice-loading-waves span:nth-child(5) { animation-delay: 0.4s; }

@keyframes voice-wave {
  0%, 100% {
    height: 8px;
    opacity: 0.5;
  }
  50% {
    height: 20px;
    opacity: 1;
  }
}

.voice-loading-text {
  font-size: 12px;
  color: var(--color-primary);
  font-weight: 500;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 0;
  gap: 16px;
}

.waveform-canvas {
  width: 200px;
  height: 60px;
  border-radius: var(--radius-sm);
  background: var(--color-bg-secondary);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.waveform-canvas.active {
  opacity: 1;
}

.mic-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 32px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--color-primary);
  color: #ffffff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-md);
}

.mic-button:hover:not(:disabled) {
  transform: scale(1.02);
  box-shadow: 0 6px 20px rgba(0, 122, 255, 0.4);
}

.mic-button:active:not(:disabled) {
  transform: scale(0.98);
}

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

.mic-button.recording {
  background: var(--color-error);
  animation: recording-pulse 1.5s ease-in-out infinite;
}

@keyframes recording-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.5); }
  50% { box-shadow: 0 0 0 16px rgba(255, 59, 48, 0); }
}

.mic-icon {
  width: 32px;
  height: 32px;
}

.mic-text {
  font-size: 13px;
}

/* Text input for chat */
.controls-row {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 500px;
}

.text-input-container {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: border-color 0.2s ease;
}

.text-input-container:focus-within {
  border-color: var(--color-primary);
}

.text-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--color-text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  min-width: 0;
}

.text-input::placeholder {
  color: var(--color-text-muted);
}

.text-input:disabled {
  opacity: 0.5;
}

.send-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--color-primary);
  color: #ffffff;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.4);
}

.send-button:active:not(:disabled) {
  transform: scale(0.95);
}

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

.send-icon {
  width: 18px;
  height: 18px;
}

.language-selectors {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 12px 0;
}

.language-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.language-selector select {
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.language-selector select:focus {
  outline: none;
  border-color: var(--color-primary);
}

.test-audio {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 0;
  font-size: 13px;
  color: var(--color-text-muted);
}

.test-btn {
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-secondary);
  color: var(--color-text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.test-btn:hover {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.test-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Chat History Section */
.history-section {
  margin-top: 24px;
  padding: 16px;
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.history-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.history-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-toggle:hover {
  background: var(--color-bg);
}

.chevron-icon {
  width: 18px;
  height: 18px;
  transition: transform 0.2s ease;
}

.history-section.collapsed .chevron-icon {
  transform: rotate(-90deg);
}

.history-content {
  margin-top: 12px;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.history-section.collapsed .history-content {
  display: none;
}

.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.session-item:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.session-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.session-item-date {
  font-size: 12px;
  color: var(--color-text-muted);
}

.session-item-preview {
  font-size: 13px;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.session-item-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.session-item-count {
  font-size: 11px;
  color: var(--color-text-muted);
}

.session-delete-btn {
  padding: 4px 8px;
  font-size: 11px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--color-error);
  cursor: pointer;
  transition: all 0.2s ease;
  opacity: 0;
}

.session-item:hover .session-delete-btn {
  opacity: 1;
}

.session-delete-btn:hover {
  background: rgba(255, 59, 48, 0.1);
}

.load-more-btn {
  width: 100%;
  margin-top: 12px;
  padding: 10px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.load-more-btn:hover {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.history-empty {
  text-align: center;
  padding: 24px;
  color: var(--color-text-muted);
  font-size: 13px;
}

.history-loading {
  text-align: center;
  padding: 16px;
  color: var(--color-text-muted);
  font-size: 13px;
}

/* Session Modal */
.session-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.session-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.session-modal-content {
  position: relative;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  background: var(--color-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.session-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--color-border);
}

.session-modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.close-modal-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--color-bg-secondary);
  color: var(--color-text-muted);
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.close-modal-btn:hover {
  background: var(--color-border);
  color: var(--color-text);
}

.session-modal-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.session-modal-messages .message {
  max-width: 85%;
}

/* System Metrics Monitor */
.metrics-section {
  margin-top: 24px;
  padding: 16px;
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
}

.metrics-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-align: center;
  margin-bottom: 12px;
}

.system-info {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--color-text-muted);
}

.system-info-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.system-info-label {
  font-weight: 500;
  color: var(--color-text);
}

.metrics-charts {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.metric-chart {
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 12px;
  box-shadow: var(--shadow-sm);
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.metric-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
}

.metric-value {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.metric-value.cpu {
  color: var(--color-primary);
}

.metric-value.memory {
  color: var(--color-success);
}

.metric-value.gpu {
  color: var(--color-warning);
}

.metric-value.na {
  color: var(--color-text-muted);
}

.metric-canvas {
  width: 100%;
  height: 80px;
  border-radius: 4px;
  background: var(--color-bg-secondary);
}

footer {
  text-align: center;
  padding: 16px 0;
  font-size: 12px;
  color: var(--color-text-muted);
}

/* Technical Documentation Section */
.tech-docs {
  margin-top: 32px;
  padding: 24px;
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
}

.tech-docs-title {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 24px;
  color: var(--color-text);
}

.tech-section {
  margin-bottom: 24px;
}

.tech-images {
  margin-bottom: 32px;
}

.tech-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 12px;
}

.tech-image-card {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-bg);
  box-shadow: var(--shadow-sm);
  transition: all 0.3s ease;
}

.tech-image-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.tech-image-card img {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 16 / 10;
  object-fit: cover;
}

.tech-image-label {
  display: block;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-bg);
  text-align: center;
}

.tech-image-credit {
  font-size: 11px;
  color: var(--color-text-muted);
  text-align: center;
  font-style: italic;
  margin-top: 8px;
}

.tech-section h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}

.tech-diagram {
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow-x: auto;
}

.tech-diagram pre {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 11px;
  line-height: 1.4;
  color: var(--color-text);
  margin: 0;
  white-space: pre;
}

.tech-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.tech-table th,
.tech-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.tech-table th {
  background: var(--color-bg-secondary);
  font-weight: 600;
  color: var(--color-text);
}

.tech-table td {
  color: var(--color-text);
}

.tech-table tr:last-child td {
  border-bottom: none;
}

.tech-table code {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 11px;
  background: var(--color-bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--color-primary);
}

.tech-table.timeline td:first-child {
  white-space: nowrap;
  color: var(--color-text-muted);
  font-size: 11px;
}

.dev-time {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  text-align: center;
}

.cost-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.cost-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
}

.cost-item:last-child {
  border-bottom: none;
}

.cost-item.total {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 2px solid var(--color-primary);
  border-bottom: none;
}

.cost-label {
  font-size: 13px;
  color: var(--color-text);
}

.cost-value {
  font-size: 14px;
  font-weight: 600;
}

.cost-value.free {
  color: var(--color-success);
}

.cost-item.total .cost-label,
.cost-item.total .cost-value {
  font-size: 15px;
  font-weight: 600;
}

.cost-note {
  margin-top: 12px;
  font-size: 11px;
  color: var(--color-text-muted);
  text-align: center;
  font-style: italic;
}

@media (max-width: 768px) {
  .container {
    padding: 12px;
  }

  header {
    padding: 16px 0 12px;
  }

  header h1 {
    font-size: 24px;
  }

  .message {
    max-width: 90%;
    padding: 10px 14px;
    font-size: 14px;
  }

  .mic-button {
    padding: 16px 28px;
  }

  .mic-icon {
    width: 28px;
    height: 28px;
  }
  
  .tech-diagram pre {
    font-size: 9px;
  }
  
  .tech-table {
    font-size: 11px;
  }
  
  .tech-table th,
  .tech-table td {
    padding: 8px;
  }
}
