/**
 * TubtimX Softphone - Modern UI Styles
 * SIP.js 0.21.2
 */

:root {
  /* Primary Colors */
  --primary-color: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #818cf8;
  
  /* Status Colors */
  --success-color: #10b981;
  --danger-color: #ef4444;
  --warning-color: #f59e0b;
  --info-color: #3b82f6;
  
  /* Neutral Colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border-color: #e5e7eb;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  
  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  
  /* Transitions */
  --transition-fast: 150ms ease-in-out;
  --transition-base: 200ms ease-in-out;
  --transition-slow: 300ms ease-in-out;
}

/* ==================== Base Styles ==================== */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-secondary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==================== Container ==================== */

.softphone-container {
  max-width: 400px;
  margin: 0 auto;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  min-height: 100vh;
  position: relative;
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
}

/* ==================== Top Indicators ==================== */

.top-indicators {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 100;
}

/* Presence Status Dot */
.presence-status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  transition: all var(--transition-base);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
  cursor: help;
}

.presence-status-dot.presence-available {
  background: #10b981; /* Green */
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3);
}

.presence-status-dot.presence-away {
  background: #f59e0b; /* Yellow/Orange */
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3);
}

.presence-status-dot.presence-busy {
  background: #ef4444; /* Red */
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3);
}

.presence-status-dot.presence-offline {
  background: #6b7280; /* Gray */
  box-shadow: 0 0 0 3px rgba(107, 114, 128, 0.3);
}

/* Connection Status Dot */
.connection-status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  transition: all var(--transition-base);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
  cursor: help;
}

.connection-status-dot.status-online {
  background: var(--success-color);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3);
  animation: pulse-online 2s infinite;
}

.connection-status-dot.status-offline {
  background: var(--text-muted);
  box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.3);
}

@keyframes pulse-online {
  0%, 100% {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.2);
  }
}

/* Settings Icon */
.settings-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: all var(--transition-base);
  box-shadow: var(--shadow-sm);
}

.settings-icon i {
  font-size: 12px;
  color: var(--text-secondary);
  transition: all var(--transition-base);
}

.settings-icon:hover {
  background: var(--primary-light);
  border-color: var(--primary-color);
  transform: scale(1.1) rotate(45deg);
  box-shadow: var(--shadow-md);
}

.settings-icon:hover i {
  color: white;
}

.settings-icon.active {
  background: var(--primary-color);
  border-color: var(--primary-dark);
  animation: spin 0.5s ease-in-out;
}

.settings-icon.active i {
  color: white;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(180deg); }
}

/* Presence Menu Dropdown */
.presence-menu {
  position: absolute;
  top: 2.5rem;
  right: 0.75rem;
  min-width: 150px;
  z-index: 1000;
  background: white;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.5rem 0;
  animation: slideDown 0.2s ease-out;
}

.presence-menu .dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
}

.presence-menu .dropdown-item:hover {
  background: rgba(var(--v-theme-primary), 0.08);
  color: var(--primary-color);
}

.presence-menu .dropdown-item i {
  font-size: 10px;
}

.presence-menu .dropdown-divider {
  height: 0;
  margin: 0.5rem 0;
  overflow: hidden;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

/* Dark Mode - Presence Menu */
@media (prefers-color-scheme: dark) {
  .presence-menu {
    background: var(--bg-secondary);
    border-color: rgba(255, 255, 255, 0.1);
  }
  
  .presence-menu .dropdown-item {
    color: var(--text-primary);
  }
  
  .presence-menu .dropdown-item:hover {
    background: rgba(var(--v-theme-primary), 0.15);
  }
  
  .presence-menu .dropdown-divider {
    border-top-color: rgba(255, 255, 255, 0.1);
  }
}

/* ==================== Presence Button ==================== */

.presence-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition-base);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.presence-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.presence-available {
  background: var(--success-color);
  color: white;
}

.presence-away {
  background: var(--warning-color);
  color: white;
}

.presence-busy {
  background: var(--danger-color);
  color: white;
}

.presence-offline {
  background: var(--text-secondary);
  color: white;
}

/* ==================== Connection Status ==================== */

.connection-status {
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border-color);
  transition: all var(--transition-base);
}

.connection-status.status-connected {
  background: linear-gradient(to right, #d1fae5 0%, #a7f3d0 100%);
  color: #065f46;
}

.connection-status.status-connecting {
  background: linear-gradient(to right, #fef3c7 0%, #fde68a 100%);
  color: #92400e;
}

.connection-status.status-disconnected {
  background: linear-gradient(to right, #f3f4f6 0%, #e5e7eb 100%);
  color: var(--text-secondary);
}

.connection-status.status-error {
  background: linear-gradient(to right, #fee2e2 0%, #fecaca 100%);
  color: #991b1b;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  animation: pulse 2s ease-in-out infinite;
}

.status-connected .status-indicator {
  background: #10b981;
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
}

.status-connecting .status-indicator {
  background: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2);
}

.status-disconnected .status-indicator {
  background: #9ca3af;
  animation: none;
}

.status-error .status-indicator {
  background: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.2);
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* ==================== Settings Panel ==================== */

.settings-panel {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  animation: slideDown 0.3s ease-out;
}

.settings-panel h6 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.settings-panel .text-muted {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.settings-panel strong {
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 500;
}

/* ==================== Call Panel ==================== */

.call-panel {
  padding: 1.5rem;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* ==================== Dialer ==================== */

.dialer {
  text-align: center;
}

.dialer .form-control {
  font-size: 1.5rem;
  font-weight: 500;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  transition: all var(--transition-base);
  padding: 0.75rem;
  letter-spacing: 0.05em;
}

.dialer .form-control:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
  outline: none;
}

/* ==================== Dialpad ==================== */

.dialpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin: 1rem 0;
  padding: 0 1.5rem;
}

.dialpad-btn {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
  border: 2px solid var(--border-color);
  border-radius: 50%; /* วงกลม */
  width: 100%;
  max-width: 85px;
  aspect-ratio: 1; /* สี่เหลี่ยมจัตุรัส */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
  padding: 0;
  position: relative;
  margin: 0 auto;
}

.dialpad-btn .digit {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 2px;
}

.dialpad-btn .letters {
  font-size: 0.625rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1;
}

.dialpad-btn:hover {
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary-color) 100%);
  border-color: var(--primary-color);
  transform: translateY(-2px) scale(1.05);
  box-shadow: var(--shadow-md);
}

.dialpad-btn:hover .digit {
  color: white;
}

.dialpad-btn:hover .letters {
  color: rgba(255, 255, 255, 0.8);
}

.dialpad-btn:active {
  transform: translateY(0) scale(0.98);
  box-shadow: var(--shadow-sm);
}

.dialpad-small {
  gap: 0.75rem;
  padding: 0 1rem;
}

.dialpad-btn-small {
  width: 100%;
  max-width: 70px;
  aspect-ratio: 1;
}

.dialpad-btn-small .digit {
  font-size: 1.5rem;
}

.dialpad-btn-small .letters {
  font-size: 0.5rem;
}

/* ==================== Call States ==================== */

.call-active {
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.call-active h5 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.call-active .text-muted {
  font-size: 1rem;
  color: var(--text-secondary);
}

.call-active .text-primary {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--primary-color);
}

/* ==================== Animations ==================== */

.calling-animation, .ringing-animation {
  animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

.calling-animation i {
  color: var(--primary-color);
  filter: drop-shadow(0 4px 6px rgba(79, 70, 229, 0.3));
}

.ringing-animation i {
  color: var(--success-color);
  filter: drop-shadow(0 4px 6px rgba(16, 185, 129, 0.3));
  animation: ring 1s ease-in-out infinite;
}

@keyframes ring {
  0%, 100% {
    transform: rotate(-15deg);
  }
  50% {
    transform: rotate(15deg);
  }
}

/* ==================== Call Controls ==================== */

.call-controls {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
}

.call-control-btn {
  width: 64px !important;
  height: 64px !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 1.5rem !important;
  transition: all var(--transition-base) !important;
  border: 2px solid var(--border-color) !important;
  background: white !important;
  box-shadow: var(--shadow-md) !important;
  padding: 0 !important;
}

.call-control-btn i {
  font-size: 1.5rem;
}

.call-control-btn:hover {
  transform: translateY(-3px) scale(1.05) !important;
  box-shadow: var(--shadow-lg) !important;
  border-color: var(--primary-color) !important;
}

.call-control-btn:active {
  transform: translateY(0) scale(0.98) !important;
  box-shadow: var(--shadow-sm) !important;
}

.call-control-btn.active {
  background: var(--primary-color) !important;
  color: white !important;
  border-color: var(--primary-color) !important;
}

.call-control-btn.active:hover {
  background: var(--primary-dark) !important;
}

/* ==================== Buttons ==================== */

.btn-success, .btn-danger, .btn-primary, .btn-secondary {
  border-radius: var(--radius-lg);
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  font-size: 1rem;
  transition: all var(--transition-base);
  border: none;
  box-shadow: var(--shadow-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-success {
  background: linear-gradient(135deg, var(--success-color) 0%, #059669 100%);
}

.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger-color) 0%, #dc2626 100%);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-lg {
  padding: 1rem 2rem;
  font-size: 1.125rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ==================== DTMF Keypad ==================== */

.dtmf-keypad {
  animation: slideDown 0.3s ease-out;
}

/* ==================== Call Statistics ==================== */

.call-stats {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 1rem;
}

.call-stats strong {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.call-stats .text-muted {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

/* ==================== Debug Log ==================== */

.debug-log {
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-color);
  max-height: 200px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
}

.log-messages {
  max-height: 150px;
  overflow-y: auto;
}

.log-item {
  padding: 0.25rem 0;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.log-item:last-child {
  border-bottom: none;
}

/* ==================== Audio Elements ==================== */

audio {
  display: none;
}

/* ==================== Scrollbar ==================== */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ==================== Footer ==================== */

.softphone-footer {
  margin-top: auto;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  text-align: center;
}

.footer-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 500;
  transition: all var(--transition-base);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.footer-link:hover {
  color: var(--primary-color);
  text-decoration: none;
}

.footer-link::before {
  content: '💙';
  font-size: 0.875rem;
}

/* Dark Mode - Footer */
@media (prefers-color-scheme: dark) {
  .softphone-footer {
    background: rgba(0, 0, 0, 0.2);
    border-top-color: rgba(255, 255, 255, 0.1);
  }
  
  .footer-link {
    color: rgba(255, 255, 255, 0.6);
  }
  
  .footer-link:hover {
    color: var(--primary-light);
  }
}

/* ==================== Responsive ==================== */

@media (max-width: 480px) {
  .softphone-container {
    border-radius: 0;
    max-width: 100%;
  }
  
  .dialpad {
    gap: 0.75rem;
    padding: 0 1rem;
  }
  
  .dialpad-btn {
    max-width: 70px;
  }
  
  .dialpad-btn .digit {
    font-size: 1.5rem;
  }
  
  .dialpad-btn .letters {
    font-size: 0.5rem;
  }
  
  .dialpad-btn-small {
    max-width: 60px;
  }
  
  .dialpad-btn-small .digit {
    font-size: 1.25rem;
  }
  
  .call-control-btn {
    width: 56px !important;
    height: 56px !important;
    font-size: 1.25rem !important;
  }
  
  .call-control-btn i {
    font-size: 1.25rem;
  }
}

/* ==================== Loading States ==================== */

.loading {
  position: relative;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--primary-light);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ==================== Badges ==================== */

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-md);
  letter-spacing: 0.025em;
}

/* ==================== Dropdown ==================== */

.dropdown-menu {
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  padding: 0.5rem;
}

.dropdown-item {
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  transition: all var(--transition-fast);
  font-size: 0.875rem;
}

.dropdown-item:hover {
  background: var(--bg-secondary);
  color: var(--primary-color);
}

.dropdown-item i {
  margin-right: 0.5rem;
  width: 16px;
  text-align: center;
}

/* ==================== Toast Notifications ==================== */

.toast-notification {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: white;
  padding: 1rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  border-left: 4px solid var(--primary-color);
  animation: slideInRight 0.3s ease-out;
  z-index: 9999;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ==================== Call Quality Indicator ==================== */

.call-quality {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
}

.quality-bars {
  display: flex;
  gap: 2px;
  align-items: flex-end;
}

.quality-bar {
  width: 4px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: all var(--transition-base);
}

.quality-bar.active {
  background: var(--success-color);
}

.quality-bar:nth-child(1) { height: 8px; }
.quality-bar:nth-child(2) { height: 12px; }
.quality-bar:nth-child(3) { height: 16px; }
.quality-bar:nth-child(4) { height: 20px; }
.quality-bar:nth-child(5) { height: 24px; }

/* ==================== Dark Mode Support (Optional) ==================== */

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --bg-tertiary: #0f172a;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;
    --border-color: #374151;
  }
  
  .dialpad-btn {
    background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
    color: var(--text-primary);
  }
  
  .call-controls .btn {
    background: #374151;
    border-color: #4b5563;
    color: var(--text-primary);
  }
}
