/* ============================================
   DichThuat PWA — Style
   Dark theme, mobile-first, native-like
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0F172A;
  --bg-surface: #1E293B;
  --bg-elevated: #334155;
  --text: #F8FAFC;
  --text-muted: #94A3B8;
  --text-dim: #64748B;
  --primary: #2563EB;
  --accent-a: #3B82F6;
  --accent-b: #10B981;
  --recording: #EF4444;
  --warning: #F59E0B;
  --border: #334155;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
}

/* --- App Shell --- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  max-width: 100vw;
  overflow: hidden;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.screen {
  display: flex;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

/* --- Tab Bar --- */
.tab-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 56px;
  min-height: 56px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  height: 100%;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 10px;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.2s;
  min-width: 48px;
  min-height: 48px;
}

.tab-item .tab-icon {
  font-size: 22px;
  line-height: 1;
}

.tab-item.active {
  color: var(--primary);
}

.tab-item:active {
  opacity: 0.7;
}

/* ============================================
   SCREEN: Doi Thoai (Face-to-Face)
   ============================================ */
.face-to-face {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.half-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.half-top {
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.15) 0%, rgba(59, 130, 246, 0.05) 100%);
  border-bottom: 2px solid var(--accent-a);
  transform: rotate(180deg);
}

.half-bottom {
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.05) 0%, rgba(16, 185, 129, 0.15) 100%);
}

.half-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.half-top .half-label {
  color: var(--accent-a);
}

.half-bottom .half-label {
  color: var(--accent-b);
}

.half-text-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}

.text-original {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  max-width: 100%;
  word-break: break-word;
}

.text-translated {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  max-width: 100%;
  word-break: break-word;
}

.half-top .text-translated {
  color: var(--accent-a);
}

.half-bottom .text-translated {
  color: var(--accent-b);
}

.half-speak-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 220px;
  height: 48px;
  border-radius: 24px;
  border: 2px solid;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 8px;
}

.half-top .half-speak-btn {
  border-color: var(--accent-a);
}

.half-bottom .half-speak-btn {
  border-color: var(--accent-b);
}

.half-speak-btn:active,
.half-speak-btn.recording {
  transform: scale(0.95);
}

.half-top .half-speak-btn.recording {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--recording);
  animation: pulse-a 1.2s infinite;
}

.half-bottom .half-speak-btn.recording {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--recording);
  animation: pulse-b 1.2s infinite;
}

/* ============================================
   SCREEN: Tai Nghe (Headset)
   ============================================ */
.headset-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.headset-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  gap: 12px;
}

.direction-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 16px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  min-height: 48px;
}

.direction-toggle:active {
  background: var(--bg-elevated);
}

.direction-arrow {
  color: var(--primary);
  font-weight: 700;
}

/* Chat history */
.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
  padding: 32px;
}

.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.4;
  animation: fadeSlideIn 0.3s ease;
}

.chat-bubble.original {
  align-self: flex-start;
  background: var(--bg-surface);
  color: var(--text-muted);
  border-bottom-left-radius: 4px;
}

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

.chat-bubble .bubble-lang {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.6;
  margin-bottom: 2px;
}

.chat-bubble.translated .bubble-lang {
  text-align: right;
}

/* Edit bar (shown when edit-before-translate is on) */
.edit-bar {
  display: none;
  padding: 8px 16px;
  gap: 8px;
  align-items: center;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}

.edit-bar.active {
  display: flex;
}

.edit-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
}

.edit-input:focus {
  border-color: var(--primary);
}

.edit-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 48px;
}

/* Push-to-talk area */
.ptt-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  gap: 12px;
}

.ptt-button {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--primary);
  border: 4px solid rgba(37, 99, 235, 0.3);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.15s;
  box-shadow: 0 4px 24px rgba(37, 99, 235, 0.3);
}

.ptt-button .ptt-icon {
  font-size: 32px;
  line-height: 1;
}

.ptt-button:active,
.ptt-button.recording {
  transform: scale(0.92);
  background: var(--recording);
  border-color: rgba(239, 68, 68, 0.3);
  box-shadow: 0 4px 32px rgba(239, 68, 68, 0.4);
  animation: pulse-rec 1.2s infinite;
}

.ptt-status {
  font-size: 12px;
  color: var(--text-dim);
  height: 18px;
}

.ptt-status.active {
  color: var(--recording);
  font-weight: 500;
}

/* Quick phrases bar */
.quick-phrases-bar {
  display: flex;
  gap: 8px;
  padding: 4px 16px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.quick-phrases-bar::-webkit-scrollbar {
  display: none;
}

.quick-phrase-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 36px;
  display: flex;
  align-items: center;
}

.quick-phrase-chip:active {
  background: var(--primary);
  color: var(--text);
  border-color: var(--primary);
}

/* ============================================
   SCREEN: Cau Mau (Phrases)
   ============================================ */
.phrases-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.screen-header {
  padding: 16px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.phrases-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.phrase-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-surface);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
  min-height: 48px;
}

.phrase-card:active {
  background: var(--bg-elevated);
}

.phrase-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.phrase-original {
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
}

.phrase-sub {
  font-size: 12px;
  color: var(--text-dim);
}

.phrase-play-icon {
  font-size: 20px;
  color: var(--primary);
  margin-left: 12px;
}

/* ============================================
   SCREEN: Cai Dat (Settings)
   ============================================ */
.settings-screen {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 24px;
  -webkit-overflow-scrolling: touch;
}

.settings-group {
  margin-top: 24px;
}

.settings-group-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 8px;
  padding-left: 4px;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-surface);
  border-radius: 12px;
  margin-bottom: 2px;
  min-height: 48px;
}

.setting-item:first-of-type {
  border-radius: 12px 12px 4px 4px;
}

.setting-item:last-of-type {
  border-radius: 4px 4px 12px 12px;
  margin-bottom: 0;
}

.setting-item:only-of-type {
  border-radius: 12px;
}

.setting-label {
  font-size: 15px;
  color: var(--text);
}

.setting-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Text input */
.setting-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  margin-top: 8px;
}

.setting-input:focus {
  border-color: var(--primary);
}

.setting-input-group {
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  background: var(--bg-surface);
  border-radius: 12px;
  margin-bottom: 2px;
}

/* Dropdown select */
.setting-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  min-width: 120px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394A3B8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.setting-select:focus {
  border-color: var(--primary);
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-elevated);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  bottom: 3px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s;
}

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

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* Range slider */
.setting-range-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.setting-range {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  outline: none;
}

.setting-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}

.setting-range::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
}

.range-value {
  font-size: 14px;
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
}

/* Danger button */
.btn-danger {
  width: 100%;
  padding: 14px;
  background: transparent;
  border: 1px solid var(--recording);
  border-radius: 12px;
  color: var(--recording);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 48px;
}

.btn-danger:active {
  background: rgba(239, 68, 68, 0.1);
}

/* ============================================
   Animations
   ============================================ */
@keyframes pulse-a {
  0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
  70% { box-shadow: 0 0 0 12px rgba(59, 130, 246, 0); }
  100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}

@keyframes pulse-b {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  70% { box-shadow: 0 0 0 12px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes pulse-rec {
  0% { box-shadow: 0 4px 32px rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 4px 48px rgba(239, 68, 68, 0.6); }
  100% { box-shadow: 0 4px 32px rgba(239, 68, 68, 0.4); }
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-in {
  animation: fadeIn 0.3s ease;
}

/* ============================================
   Utilities
   ============================================ */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 3px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: 2px;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Loading indicator */
.loading-dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
  100% { content: ''; }
}

/* STT / Translated live display */
.stt-display,
.translated-display {
  padding: 4px 16px;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  min-height: 20px;
}

.translated-display {
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
}

/* Edit overlay */
.edit-overlay {
  display: flex;
  padding: 8px 16px;
  gap: 8px;
  align-items: center;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}

/* Swap language button */
.setting-swap-row {
  display: flex;
  justify-content: center;
  width: 100%;
}

.btn-swap {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-swap:active {
  background: var(--primary);
  color: var(--text);
}

/* History list in settings */
.history-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item {
  padding: 10px 14px;
  background: var(--bg-surface);
  border-radius: 8px;
  cursor: pointer;
}

.history-item:active {
  background: var(--bg-elevated);
}

.history-src {
  font-size: 13px;
  color: var(--text-muted);
}

.history-tgt {
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
}

.history-time {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

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

/* Chat bubble styles for headset mode */
.chat-src {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.chat-tgt {
  font-size: 16px;
  color: var(--text);
  font-weight: 500;
}

/* Phrase card layout fix */
.phrase-categories {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.phrase-cat-btn {
  padding: 6px 12px;
  border-radius: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.phrase-cat-btn.active {
  background: var(--primary);
  color: var(--text);
  border-color: var(--primary);
}

.phrase-vi {
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
}

.phrase-zh {
  font-size: 14px;
  color: var(--accent-a);
}

.phrase-en {
  font-size: 13px;
  color: var(--text-dim);
}
