/* styles.css */

:root {
  --bg-primary: #0b0d19;
  --bg-secondary: #11162d;
  --bg-glass: rgba(17, 22, 45, 0.7);
  --border-glass: rgba(255, 255, 255, 0.08);
  
  --primary: #4f46e5;
  --primary-glow: rgba(79, 70, 229, 0.4);
  --secondary: #6366f1;
  
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.3);
  --error: #ef4444;
  --error-glow: rgba(239, 68, 68, 0.3);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --customer-bubble: #1e293b;
  --customer-accent: #06b6d4;
  --staff-bubble: #2d1b4e;
  --staff-accent: #a855f7;
}

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

body {
  font-family: 'Outfit', 'Noto Sans TC', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  position: relative;
  background-image: radial-gradient(circle at 10% 20%, rgba(20, 25, 60, 0.9) 0%, rgba(10, 12, 28, 1) 90.2%);
}

/* Background animated stars */
.stars-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 40px),
    radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 30px);
  background-size: 550px 550px, 350px 350px;
  background-position: 0 0, 40px 60px;
  opacity: 0.15;
  z-index: 0;
  pointer-events: none;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 1.5rem;
  z-index: 1;
  position: relative;
}

/* Header Styling */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-glass);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-icon {
  width: 2.8rem;
  height: 2.8rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  border-radius: 12px;
  box-shadow: 0 4px 15px var(--primary-glow);
  position: relative;
}

.logo-icon::before {
  content: '';
  position: absolute;
  top: 25%;
  left: 25%;
  width: 50%;
  height: 50%;
  border: 2px solid white;
  border-radius: 50%;
}

.logo-text h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(to right, #ffffff, #a5b4fc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 300;
}

.status-panel {
  display: flex;
  gap: 1.5rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.5rem 1.2rem;
  border-radius: 30px;
  border: 1px solid var(--border-glass);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online {
  background-color: var(--success);
  box-shadow: 0 0 10px var(--success-glow);
}

.status-dot.offline {
  background-color: var(--error);
  box-shadow: 0 0 10px var(--error-glow);
}

/* Dashboard Grid Layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  gap: 1.5rem;
  flex: 1;
  min-height: 0; /* Important for scroll nested columns */
}

/* Card Design (Glassmorphism) */
.glass-card {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 20px;
  border: 1px solid var(--border-glass);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.02);
}

.header-title {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.header-title h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-body {
  padding: 1.5rem;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.card-body.scrollable {
  overflow-y: auto;
}

/* Scrollbar styles */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Column 1: Rooms list */
.room-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.room-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 15px;
  padding: 1.2rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.room-card:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(79, 70, 229, 0.3);
  transform: translateY(-2px);
}

.room-card.active {
  background: rgba(79, 70, 229, 0.15);
  border-color: var(--primary);
  box-shadow: 0 4px 20px rgba(79, 70, 229, 0.15);
}

.room-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.room-card-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: white;
}

.room-code-tag {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  font-size: 0.7rem;
  font-family: monospace;
  color: var(--text-secondary);
}

.room-card-devices {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  padding-top: 0.6rem;
  margin-top: 0.6rem;
}

.device-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.device-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
}

.device-badge.customer {
  background: rgba(6, 182, 212, 0.15);
  color: var(--customer-accent);
}

.device-badge.staff {
  background: rgba(168, 85, 247, 0.15);
  color: var(--staff-accent);
}

.device-badge.unpaired {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
}

.btn-pair-device {
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  transition: all 0.2s;
}

.btn-pair-device:hover {
  border-color: var(--primary);
  color: var(--text-secondary);
}

/* Column 2: Chat area */
.conversation-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  padding: 1.5rem;
}

.no-room-selected {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  text-align: center;
  color: var(--text-muted);
  gap: 1rem;
}

.empty-state-icon {
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-glass);
  border-radius: 50%;
  position: relative;
}

.empty-state-icon::before {
  content: '?';
  font-size: 24px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-secondary);
}

.conversation-footer {
  padding: 1.2rem 1.5rem;
  border-top: 1px solid var(--border-glass);
  display: flex;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.01);
  gap: 1rem;
}

/* Chat bubble styling */
.msg-bubble-wrapper {
  display: flex;
  width: 100%;
  margin-bottom: 0.8rem;
}

.msg-bubble-wrapper.customer-msg {
  justify-content: flex-start;
}

.msg-bubble-wrapper.staff-msg {
  justify-content: flex-end;
}

.msg-bubble {
  max-width: 70%;
  border-radius: 16px;
  padding: 1rem 1.2rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  position: relative;
}

.customer-msg .msg-bubble {
  background: var(--customer-bubble);
  border-left: 4px solid var(--customer-accent);
  border-bottom-left-radius: 4px;
}

.staff-msg .msg-bubble {
  background: var(--staff-bubble);
  border-right: 4px solid var(--staff-accent);
  border-bottom-right-radius: 4px;
}

.msg-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
}

.customer-msg .msg-meta {
  color: var(--customer-accent);
}

.staff-msg .msg-meta {
  color: var(--staff-accent);
  flex-direction: row-reverse;
}

.msg-source-text {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 0.6rem;
  color: white;
}

.msg-translated-text {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.4;
  color: #fff;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 0.6rem;
}

/* TTS Speaker Button */
.btn-tts {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  margin-left: 6px;
  vertical-align: middle;
  transition: all 0.25s ease;
  flex-shrink: 0;
}

.btn-tts:hover {
  background: rgba(79, 70, 229, 0.25);
  color: white;
  transform: scale(1.15);
  box-shadow: 0 0 12px var(--primary-glow);
}

.btn-tts.tts-playing {
  background: rgba(79, 70, 229, 0.3);
  color: white;
  animation: tts-pulse 1s ease-in-out infinite;
}

@keyframes tts-pulse {
  0%, 100% { box-shadow: 0 0 0px var(--primary-glow); }
  50% { box-shadow: 0 0 16px var(--primary-glow); }
}

.msg-source-text,
.msg-translated-text {
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

.msg-source-text .btn-tts,
.msg-translated-text .btn-tts {
  margin-top: 2px;
}

.confidence-indicator {
  background: rgba(255, 255, 255, 0.06);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.65rem;
}

/* System notice events */
.system-event {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1rem 0;
}

.system-event-badge {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0.4rem 1.2rem;
  border-radius: 30px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Column 3: Simulator sandbox */
.simulator-section {
  padding-bottom: 1.5rem;
  margin-bottom: 1.5rem;
}

.simulator-section.border-top {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 1.5rem;
}

.section-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

/* Form inputs styling */
.form-group {
  margin-bottom: 1rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--text-secondary);
}

input, select, textarea {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 8px var(--primary-glow);
}

textarea {
  resize: none;
}

/* Quick phrases chips */
.quick-phrases {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.chip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 30px;
  cursor: pointer;
  transition: all 0.2s;
}

.chip:hover {
  background: rgba(79, 70, 229, 0.15);
  border-color: var(--primary);
  color: white;
}

/* Copy Token Box */
.token-result {
  margin-top: 1rem;
  background: rgba(16, 185, 129, 0.05);
  border: 1px solid rgba(16, 185, 129, 0.2);
  padding: 0.8rem;
  border-radius: 10px;
}

.token-result p {
  font-size: 0.75rem;
  color: var(--success);
  margin-bottom: 0.4rem;
}

.token-copy-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.token-copy-wrapper code {
  font-family: monospace;
  font-size: 0.8rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  flex: 1;
  overflow-x: auto;
  color: white;
}

.hidden {
  display: none !important;
}

/* Buttons styling */
.btn {
  font-family: inherit;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
  border: none;
  text-align: center;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: 0.7rem 1.2rem;
  font-size: 0.9rem;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
  box-shadow: 0 4px 25px var(--primary-glow);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  background: #27273a;
  box-shadow: none;
  cursor: not-allowed;
  color: var(--text-muted);
}

.btn-success {
  background: var(--success);
  color: white;
  box-shadow: 0 4px 15px var(--success-glow);
}

.btn-success:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-success:disabled {
  background: #27273a;
  box-shadow: none;
  cursor: not-allowed;
  color: var(--text-muted);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-secondary:disabled {
  background: rgba(255, 255, 255, 0.01);
  border-color: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-outline {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  border-radius: 6px;
}

/* Modals Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal {
  width: 90%;
  max-width: 500px;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 1.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s;
}

.close-btn:hover {
  color: white;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-glass);
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1.2rem;
  line-height: 1.4;
}

/* Skeletons */
.skeleton-loader {
  height: 90px;
  background: linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0.03) 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: 15px;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.btn-qr-code {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  color: var(--success);
  cursor: pointer;
  border-radius: 5px;
  font-size: 0.65rem;
  padding: 0.15rem 0.45rem;
  transition: all 0.2s ease-in-out;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  outline: none;
  font-family: inherit;
}

.btn-qr-code:hover {
  background: rgba(16, 185, 129, 0.25);
  border-color: var(--success);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 0 8px var(--success-glow);
}

.btn-edit-room {
  background: rgba(79, 70, 229, 0.1);
  border: 1px solid rgba(79, 70, 229, 0.25);
  color: #a5b4fc;
  cursor: pointer;
  border-radius: 5px;
  font-size: 0.65rem;
  padding: 0.15rem 0.45rem;
  transition: all 0.2s ease-in-out;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  outline: none;
  font-family: inherit;
}

.btn-edit-room:hover {
  background: rgba(79, 70, 229, 0.25);
  border-color: var(--primary);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 0 8px var(--primary-glow);
}

.btn-delete-room {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #fca5a5;
  cursor: pointer;
  border-radius: 5px;
  font-size: 0.65rem;
  padding: 0.15rem 0.45rem;
  transition: all 0.2s ease-in-out;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  outline: none;
  font-family: inherit;
}

.btn-delete-room:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

/* ==========================================
   RESPONSIVE DESIGN & LAYOUT OPTIMIZATION
   ========================================== */

/* 1. Large Screen Adjustments (up to 1200px) */
@media (max-width: 1200px) {
  .dashboard-grid {
    grid-template-columns: 280px 1fr;
    gap: 1rem;
  }
  
  .simulator-panel {
    grid-column: span 2;
    height: auto;
    max-height: none;
  }
  
  .simulator-panel .card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    overflow: visible;
  }
  
  .simulator-panel .simulator-section.border-top {
    border-top: none;
    border-left: 1px solid var(--border-glass);
    padding-top: 0;
    padding-left: 1.5rem;
  }
}

/* 2. Tablet Screens (up to 992px) */
@media (max-width: 992px) {
  body {
    height: auto;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .app-container {
    height: auto;
    min-height: 100vh;
    padding: 1rem;
    overflow-y: visible;
  }

  .dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    height: auto;
    min-height: 0;
  }

  .rooms-panel {
    height: 400px;
  }

  .conversation-panel {
    height: 600px;
  }

  .simulator-panel {
    height: auto;
  }

  .simulator-panel .card-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
  }

  .simulator-panel .simulator-section.border-top {
    border-left: none;
    border-top: 1px solid var(--border-glass);
    padding-left: 0;
    padding-top: 1.5rem;
  }
  
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    padding-bottom: 1.2rem;
  }
  
  .header-controls {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
  }
  
  .status-panel {
    flex: 1;
    justify-content: space-around;
  }
}

/* 3. Mobile Screens (up to 576px) */
@media (max-width: 576px) {
  .app-container {
    padding: 0.75rem;
  }
  
  .logo-text h1 {
    font-size: 1.25rem;
  }
  
  .status-panel {
    flex-direction: column;
    gap: 0.5rem;
    border-radius: 12px;
    padding: 0.8rem;
  }
  
  .card-header {
    padding: 1rem;
  }
  
  .card-body {
    padding: 1rem;
  }
  
  .btn-qr-code, .btn-edit-room, .btn-edit-room:hover, .btn-delete-room, .btn-delete-room:hover {
    padding: 0.2rem 0.35rem;
    font-size: 0.6rem;
  }
  
  .room-card-header h3 {
    font-size: 0.95rem;
  }
  
  .quick-phrases {
    gap: 0.4rem;
  }
  
  .chip {
    padding: 0.3rem 0.6rem;
    font-size: 0.7rem;
  }
  
  #login-overlay .modal {
    width: 92% !important;
    margin: 10px;
  }
}

/* Logout Button Hover style */
#btn-logout:hover {
  background: rgba(239, 68, 68, 0.35) !important;
  border-color: #ef4444 !important;
  color: white !important;
  transform: translateY(-1px);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
}

