/* ==================== RESET & VARIABLES ==================== */

:root {
  --bg-primary: #0f172a;
  --bg-panel: #1e293b;
  --bg-elevated: #334155;
  --border: #334155;
  --border-focus: #3b82f6;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-green: #22c55e;
  --accent-green-hover: #16a34a;
  --accent-red: #ef4444;
  --accent-red-hover: #dc2626;
  --accent-blue: #3b82f6;
  --accent-orange: #f97316;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ==================== SPLASH SCREEN ==================== */

.splash-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 9999;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.splash-screen.fade-out {
  opacity: 0;
  visibility: hidden;
}

.splash-logo {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  animation: splash-bounce 1s ease-in-out infinite alternate;
}

@keyframes splash-bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-6px); }
}

.splash-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.15em;
}

.splash-spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--bg-elevated);
  border-top-color: var(--accent-green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-top: 0.5rem;
}

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

/* ==================== TOAST NOTIFICATIONS ==================== */

.toast-container {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

.toast {
  pointer-events: auto;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.4;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  animation: toast-in 0.3s ease-out;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.toast.toast-error {
  background: #451a1a;
  border: 1px solid var(--accent-red);
  color: #fca5a5;
}

.toast.toast-warning {
  background: #451f1a;
  border: 1px solid var(--accent-orange);
  color: #fdba74;
}

.toast.toast-info {
  background: #1a2744;
  border: 1px solid var(--accent-blue);
  color: #93c5fd;
}

.toast.toast-success {
  background: #1a3a1a;
  border: 1px solid var(--accent-green);
  color: #86efac;
}

.toast-icon {
  font-size: 1rem;
  flex-shrink: 0;
  line-height: 1.4;
}

.toast-body {
  flex: 1;
}

.toast-title {
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.toast-message {
  opacity: 0.85;
  font-size: 0.8rem;
}

.toast.fade-out {
  animation: toast-out 0.3s ease-in forwards;
}

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

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

/* ==================== LANDING PAGE ==================== */

#landingView {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.landing-container {
  text-align: center;
  max-width: 600px;
}

.hero-headline {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.hero-subheadline {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-bottom: 3rem;
}

.landing-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin-bottom: 1rem;
}

/* Slot machine */
.brand-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-transform: lowercase;
  margin-bottom: 1.5rem;
}

.brand-tagline {
  font-weight: 400;
  letter-spacing: 0.02em;
  font-style: italic;
}

.slot-display {
  color: var(--accent-green);
  font-weight: 800;
  transition: opacity 80ms;
}

/* Landing CTA */
.landing-cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.cta-note {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ==================== APP NAV ==================== */

.app-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

.app-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.nav-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}

.btn-link:hover {
  color: var(--text-primary);
}

/* ==================== STATUS BAR ==================== */

.status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.dot.connected {
  background: var(--accent-green);
  box-shadow: 0 0 6px var(--accent-green);
}

.dot.disconnected {
  background: var(--accent-red);
}

/* ==================== CALL SETUP ==================== */

.call-setup {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.phone-input-wrapper {
  display: flex;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-panel);
  transition: border-color 0.2s;
}

.phone-input-wrapper:focus-within {
  border-color: var(--border-focus);
}

.phone-prefix {
  display: flex;
  align-items: center;
  padding: 0.75rem 0.75rem;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: 600;
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

.phone-input-wrapper input {
  flex: 1;
  padding: 0.75rem;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 1rem;
  outline: none;
}

/* Language row */
.lang-row {
  display: flex;
  align-items: end;
  gap: 0.5rem;
}

.lang-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.lang-group label,
.voice-row label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lang-group select,
.voice-row select {
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
  width: 100%;
}

.lang-group select:focus,
.voice-row select:focus {
  border-color: var(--border-focus);
}

.swap-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 1.2rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}

.swap-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* Voice row */
.voice-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* Call button */
.btn {
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

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

.btn:not(:disabled):active {
  transform: scale(0.98);
}

.btn-start-call {
  width: 100%;
  padding: 0.9rem;
  background: var(--accent-green);
  color: #fff;
  font-size: 1.1rem;
  margin-top: 0.25rem;
}

.btn-start-call:not(:disabled):hover {
  background: var(--accent-green-hover);
}

/* ==================== IN-CALL CONTROLS ==================== */

.in-call-controls {
  text-align: center;
  margin-bottom: 1rem;
}

.call-status {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  min-height: 1.2em;
}

.call-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.btn-end-call {
  flex: 1;
  max-width: 200px;
  padding: 0.75rem 1.5rem;
  background: var(--accent-red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-end-call:hover {
  background: var(--accent-red-hover);
}

.btn-icon {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 1.3rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn-icon.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

/* ==================== MIC STATUS ==================== */

.mic-status {
  text-align: center;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--accent-green);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.mic-status[hidden] { display: none; }

.mic-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ==================== CONVERSATION ==================== */

.conversation-panel {
  background: var(--bg-panel);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 350px;
  max-height: 60vh;
}

.conversation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.conversation-header h2 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.conversation-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* Chat bubbles */
.chat-msg {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.chat-msg.incoming { align-self: flex-start; }
.chat-msg.outgoing { align-self: flex-end; }

.chat-msg .speaker {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 0.2rem;
}

.chat-msg.incoming .speaker { color: var(--accent-orange); }
.chat-msg.outgoing .speaker { color: var(--accent-green); text-align: right; }

.chat-msg .original {
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.4;
}

.chat-msg.incoming .original {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-msg.outgoing .original {
  background: #1e3a5f;
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

.chat-msg .translation {
  padding: 0.25rem 0.65rem;
  font-size: 0.8rem;
  line-height: 1.3;
  font-style: italic;
}

.chat-msg.incoming .translation { color: #93c5fd; }
.chat-msg.outgoing .translation { color: #86efac; text-align: right; }

/* Interim bubble */
.chat-msg.interim { opacity: 0.5; }

.chat-msg.interim .interim-text {
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.4;
  border: 1px dashed var(--border);
  color: var(--text-muted);
}

/* ==================== CALL HISTORY ==================== */

.history-panel {
  background: var(--bg-panel);
  border-radius: var(--radius);
  margin-top: 1rem;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.history-header:hover {
  background: var(--bg-elevated);
  border-radius: var(--radius) var(--radius) 0 0;
}

.history-header h2 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.history-toggle {
  font-size: 0.6rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.history-panel.open .history-toggle {
  transform: rotate(180deg);
}

.history-list {
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
}

.history-panel.open .history-list {
  padding: 0.5rem;
  max-height: 300px;
  overflow-y: auto;
}

.empty-history {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1.5rem 0;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

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

.history-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.history-phone {
  color: var(--text-primary);
  font-weight: 500;
}

.history-langs {
  color: var(--text-muted);
  font-size: 0.7rem;
}

.history-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.history-duration {
  font-weight: 600;
  color: var(--text-secondary);
}

.history-status {
  font-size: 0.7rem;
}

.history-item.success .history-status { color: var(--accent-green); }
.history-item.failed .history-status { color: var(--accent-red); }

/* ==================== KEYPAD OVERLAY ==================== */

.keypad-overlay {
  position: fixed;
  bottom: 0;
  left: 50%;
  width: 100%;
  max-width: 480px;
  transform: translate(-50%, 100%);
  background: var(--bg-panel);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
  padding: 1rem;
  z-index: 100;
  transition: transform 0.3s ease-out;
}

.keypad-overlay.visible {
  transform: translate(-50%, 0);
}

.keypad-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  max-width: 280px;
  margin: 0 auto;
}

.key {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 1.2rem;
  font-weight: 600;
  padding: 0.7rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
}

.key span {
  font-size: 0.5rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.15em;
}

.key:hover { background: #475569; }
.key:active { background: var(--accent-blue); transform: scale(0.95); }

.dtmf-status {
  text-align: center;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  min-height: 1em;
}

/* ==================== FEEDBACK MODAL ==================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--bg-panel);
  border-radius: 16px;
  padding: 1.5rem;
  width: 90%;
  max-width: 360px;
  text-align: center;
}

.modal h3 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.star-rating {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.star {
  background: none;
  border: none;
  font-size: 2rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, transform 0.1s;
}

.star:hover,
.star.active {
  color: #fbbf24;
  transform: scale(1.15);
}

.modal textarea {
  width: 100%;
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
  resize: none;
  outline: none;
  margin-bottom: 1rem;
}

.modal textarea:focus {
  border-color: var(--border-focus);
}

.modal-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: center;
}

.btn-submit-feedback {
  padding: 0.6rem 1.5rem;
  background: var(--accent-green);
  color: #fff;
}

.btn-submit-feedback:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ==================== SCROLLBAR ==================== */

.conversation-content::-webkit-scrollbar { width: 3px; }
.conversation-content::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 2px; }

/* ==================== RESPONSIVE ==================== */

@media (max-width: 640px) {
  .hero-headline { font-size: 1.8rem; }
  .hero-subheadline { font-size: 1.4rem; }
  .slot-wrapper { min-width: 100px; }
  .app-container { padding: 0 0.75rem 1.5rem; }
  .conversation-panel { max-height: 50vh; }
}
