/* ============================================
   VOXLY DESIGN SYSTEM - COMPONENT LIBRARY
   ============================================
   Reusable UI components for Voxly messaging app
   ============================================ */

/* --------------------------------------------
   BUTTONS
   -------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  font-family: var(--font-family-body);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-tight);
  border-radius: var(--radius-lg);
  border: none;
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
  user-select: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-primary-500), 0 0 0 4px var(--color-primary-100);
}

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

/* Button Variants */
.btn-primary {
  background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-700));
  color: var(--color-neutral-0);
  box-shadow: var(--shadow-primary);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--color-primary-700), var(--color-primary-800));
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg), var(--shadow-primary);
}

.btn-secondary {
  background: var(--surface-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-tertiary);
  border-color: var(--border-secondary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-secondary);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--color-error-600);
  color: var(--color-neutral-0);
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-error-700);
}

/* Button Sizes */
.btn-sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-xs);
  border-radius: var(--radius-md);
}

.btn-lg {
  padding: var(--space-4) var(--space-6);
  font-size: var(--font-size-base);
  border-radius: var(--radius-xl);
}

.btn-icon {
  padding: var(--space-2);
  border-radius: var(--radius-lg);
  aspect-ratio: 1;
}

/* --------------------------------------------
   INPUTS
   -------------------------------------------- */
.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-family-body);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-lg);
  transition: all var(--transition-base);
}

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

.input:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px var(--color-primary-100);
}

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

.input-error {
  border-color: var(--color-error-500);
}

.input-error:focus {
  border-color: var(--color-error-500);
  box-shadow: 0 0 0 3px var(--color-error-100);
}

/* Input with Icon */
.input-wrapper {
  position: relative;
}

.input-icon {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.input-with-icon {
  padding-left: var(--space-10);
}

/* --------------------------------------------
   CARDS
   -------------------------------------------- */
.card {
  background: var(--surface-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  overflow: hidden;
  transition: all var(--transition-base);
}

.card-hover:hover {
  border-color: var(--border-secondary);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-primary);
}

.card-body {
  padding: var(--space-5);
}

.card-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-primary);
}

/* --------------------------------------------
   AVATARS
   -------------------------------------------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-700));
  color: var(--color-neutral-0);
  font-weight: var(--font-weight-semibold);
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-xs {
  width: 24px;
  height: 24px;
  font-size: var(--font-size-xs);
}

.avatar-sm {
  width: 32px;
  height: 32px;
  font-size: var(--font-size-sm);
}

.avatar-md {
  width: 40px;
  height: 40px;
  font-size: var(--font-size-base);
}

.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: var(--font-size-lg);
}

.avatar-xl {
  width: 80px;
  height: 80px;
  font-size: var(--font-size-xl);
}

.avatar-status {
  position: relative;
}

.avatar-status::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 25%;
  height: 25%;
  border-radius: var(--radius-full);
  border: 2px solid var(--surface-primary);
}

.avatar-status-online::after {
  background: var(--color-online);
}

.avatar-status-away::after {
  background: var(--color-away);
}

.avatar-status-busy::after {
  background: var(--color-busy);
}

.avatar-status-offline::after {
  background: var(--color-offline);
}

/* --------------------------------------------
   BADGES
   -------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  border-radius: var(--radius-full);
  line-height: 1;
}

.badge-primary {
  background: var(--color-primary-100);
  color: var(--color-primary-700);
}

.badge-success {
  background: var(--color-success-100);
  color: var(--color-success-700);
}

.badge-warning {
  background: var(--color-warning-100);
  color: var(--color-warning-700);
}

.badge-error {
  background: var(--color-error-100);
  color: var(--color-error-700);
}

.badge-neutral {
  background: var(--surface-tertiary);
  color: var(--text-secondary);
}

/* --------------------------------------------
   TOGGLES
   -------------------------------------------- */
.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--surface-tertiary);
  border-radius: var(--radius-full);
  transition: all var(--transition-base);
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--color-neutral-0);
  border-radius: var(--radius-full);
  transition: all var(--transition-base);
  box-shadow: var(--shadow-sm);
}

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

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

.toggle-input:focus-visible + .toggle-slider {
  box-shadow: 0 0 0 2px var(--color-primary-500), 0 0 0 4px var(--color-primary-100);
}

/* --------------------------------------------
   TABS
   -------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--surface-secondary);
  border-radius: var(--radius-lg);
}

.tab {
  padding: var(--space-2) var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  border: none;
  background: transparent;
}

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

.tab-active {
  background: var(--surface-primary);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* --------------------------------------------
   MODALS
   -------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface-primary);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-2xl);
  max-width: 90vw;
  max-height: 90vh;
  overflow: hidden;
  transform: scale(0.95);
  transition: all var(--transition-base);
}

.modal-overlay.active .modal {
  transform: scale(1);
}

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

.modal-body {
  padding: var(--space-5);
  overflow-y: auto;
  max-height: calc(90vh - 140px);
}

.modal-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-primary);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* --------------------------------------------
   TOASTS
   -------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  z-index: var(--z-toast);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--surface-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: slideInRight var(--transition-base);
  max-width: 400px;
}

.toast-success {
  border-left: 4px solid var(--color-success-500);
}

.toast-error {
  border-left: 4px solid var(--color-error-500);
}

.toast-warning {
  border-left: 4px solid var(--color-warning-500);
}

.toast-info {
  border-left: 4px solid var(--color-info-500);
}

/* --------------------------------------------
   DROPDOWNS
   -------------------------------------------- */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: var(--space-2);
  min-width: 200px;
  background: var(--surface-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-dropdown);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition-fast);
}

.dropdown.active .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.dropdown-item:hover {
  background: var(--surface-secondary);
}

.dropdown-item-danger {
  color: var(--color-error-600);
}

.dropdown-divider {
  height: 1px;
  margin: var(--space-2) 0;
  background: var(--border-primary);
}

/* --------------------------------------------
   MESSAGE BUBBLES
   -------------------------------------------- */
.message-bubble {
  max-width: 70%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-xl);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-relaxed);
  position: relative;
  word-wrap: break-word;
}

.message-sent {
  background: var(--message-sent-bg);
  color: var(--message-sent-text);
  border-bottom-right-radius: var(--radius-sm);
  margin-left: auto;
}

.message-received {
  background: var(--message-received-bg);
  color: var(--message-received-text);
  border-bottom-left-radius: var(--radius-sm);
}

.message-time {
  font-size: var(--font-size-xs);
  opacity: 0.7;
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* --------------------------------------------
   LIST ITEMS
   -------------------------------------------- */
.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: background var(--transition-fast);
  border-radius: var(--radius-lg);
}

.list-item:hover {
  background: var(--surface-secondary);
}

.list-item-active {
  background: var(--color-primary-50);
}

[data-theme="dark"] .list-item-active {
  background: var(--color-primary-900);
}

.list-item-content {
  flex: 1;
  min-width: 0;
}

.list-item-title {
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-item-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-item-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-1);
}

/* --------------------------------------------
   SKELETON LOADING
   -------------------------------------------- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-secondary) 25%,
    var(--surface-tertiary) 50%,
    var(--surface-secondary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

.skeleton-text {
  height: 1em;
  margin-bottom: var(--space-2);
}

.skeleton-text:last-child {
  width: 80%;
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
}

.skeleton-card {
  height: 120px;
  border-radius: var(--radius-xl);
}

/* --------------------------------------------
   DIVIDERS
   -------------------------------------------- */
.divider {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  color: var(--text-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-primary);
}

/* --------------------------------------------
   EMPTY STATES
   -------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-secondary);
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  margin-bottom: var(--space-6);
  color: var(--text-muted);
}

.empty-state-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.empty-state-description {
  font-size: var(--font-size-sm);
  max-width: 300px;
}

/* --------------------------------------------
   TYPING INDICATOR
   -------------------------------------------- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: var(--radius-full);
  animation: typing 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
  animation-delay: -0.16s;
}

/* --------------------------------------------
   SEARCH BAR
   -------------------------------------------- */
.search-bar {
  position: relative;
  width: 100%;
}

.search-bar input {
  width: 100%;
  padding: var(--space-3) var(--space-4) var(--space-3) var(--space-10);
  background: var(--surface-secondary);
  border: 1px solid transparent;
  border-radius: var(--radius-xl);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  transition: all var(--transition-base);
}

.search-bar input:focus {
  outline: none;
  background: var(--surface-primary);
  border-color: var(--color-primary-500);
}

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

.search-bar-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* --------------------------------------------
   FLOATING ACTION BUTTON
   -------------------------------------------- */
.fab {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + var(--space-4));
  right: var(--space-4);
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-700));
  color: var(--color-neutral-0);
  border: none;
  box-shadow: var(--shadow-lg), var(--shadow-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-base);
  z-index: var(--z-fixed);
}

.fab:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-xl), var(--shadow-primary);
}

.fab:active {
  transform: scale(0.95);
}

/* --------------------------------------------
   STORY RING
   -------------------------------------------- */
.story-ring {
  position: relative;
  padding: 3px;
  border-radius: var(--radius-full);
  background: linear-gradient(45deg, #F59E0B, #EF4444, #8B5CF6);
}

.story-ring img {
  border-radius: var(--radius-full);
  border: 2px solid var(--surface-primary);
}

.story-ring-unseen {
  background: linear-gradient(45deg, #F59E0B, #EF4444, #8B5CF6);
}

.story-ring-seen {
  background: var(--color-neutral-400);
}

/* --------------------------------------------
   CALL CONTROLS
   -------------------------------------------- */
.call-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  padding: var(--space-6);
}

.call-control-btn {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: all var(--transition-base);
}

.call-control-btn-mute {
  background: var(--surface-tertiary);
  color: var(--text-primary);
}

.call-control-btn-end {
  background: var(--color-error-600);
  color: var(--color-neutral-0);
  width: 64px;
  height: 64px;
}

.call-control-btn:hover {
  transform: scale(1.05);
}

.call-control-btn:active {
  transform: scale(0.95);
}