/* ============================================================
   SOChat - style.css
   Global base styles, design tokens, utilities
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-main);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

/* Remove tap flash on mobile for all interactive elements */
button, a, [role="button"], input, textarea, select {
  -webkit-tap-highlight-color: transparent;
}

/* ---- Design Tokens ---- */
:root {
  /* Colors */
  --primary:         #286e34;
  --primary-dark:    #1e5327;
  --secondary:       #c3f2cb;
  --primary-light:   var(--secondary);
  --primary-glow:    rgba(40,110,52,.15);
  --accent:          var(--secondary);
  --success:         #286e34;
  --danger:          #ef4444;
  --warning:         #F8961E;
  --online:          #286e34;
  --online-bg:       rgba(40,110,52,.12);

  /* Surface */
  --bg:              #f0f2f5;
  --sidebar-bg:      #ffffff;
  --chat-bg:         #ebe8df;
  --chat-bg-pattern: #ebe8df;
  --card:            #ffffff;
  --input-bg:        #f5f5f5;
  --bubble-out:      #286e34;
  --bubble-out-text: #ffffff;
  --bubble-in:       #ffffff;
  --bubble-in-text:  #1a1a2e;

  /* Text */
  --text-main:       #1a1a2e;
  --text-sub:        #6b7280;
  --text-muted:      #9ca3af;
  --text-white:      #ffffff;

  /* Borders */
  --border:          #e5e7eb;
  --border-light:    #f3f4f6;

  /* Sizing */
  --sidebar-width:   320px;
  --header-h:        64px;
  --composer-h:      72px;
  --radius-xl:       20px;
  --radius-lg:       14px;
  --radius-md:       10px;
  --radius-sm:       6px;
  --radius-xs:       4px;
  --avatar-md:       42px;
  --avatar-sm:       34px;

  /* Shadows */
  --shadow-sm:       0 1px 4px rgba(0,0,0,.06);
  --shadow-md:       0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:       0 8px 32px rgba(0,0,0,.12);
  --shadow-card:     0 8px 40px rgba(108,99,255,.10);

  /* Transitions */
  --t-fast:          0.15s ease;
  --t-base:          0.2s ease;
  --t-slow:          0.35s ease;
}

/* ---- Dark Mode Overrides ---- */
[data-theme='dark'] {
  --bg:              #0f1113;
  --sidebar-bg:      #1a1d21;
  --chat-bg:         #0b0d0f;
  --chat-bg-pattern: #0b0d0f;
  --card:            #24292e;
  --input-bg:        #2d333b;
  --bubble-in:       #2d333b;
  --bubble-in-text:  #e6edf3;
  --text-main:       #e6edf3;
  --text-sub:        #8b949e;
  --text-muted:      #484f58;
  --border:          #30363d;
  --border-light:    #21262d;
  --shadow-sm:       0 1px 4px rgba(0,0,0,.3);
  --shadow-md:       0 4px 16px rgba(0,0,0,.4);
  --shadow-lg:       0 8px 32px rgba(0,0,0,.5);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 20px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---- Utilities ---- */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-auto { margin-top: auto; }

/* ---- Avatar ---- */
.avatar {
  width: var(--avatar-md);
  height: var(--avatar-md);
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  letter-spacing: .02em;
  color: #fff;
  position: relative;
  user-select: none;
}
.avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.avatar-sm {
  width: var(--avatar-sm);
  height: var(--avatar-sm);
  font-size: .75rem;
}
.avatar-lg {
  width: 60px; height: 60px;
  font-size: 1.1rem;
}
.avatar-xl {
  width: 80px; height: 80px;
  font-size: 1.4rem;
}

/* Online dot on avatar */
.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}
.online-dot {
  position: absolute;
  bottom: 1px; right: 1px;
  width: 11px; height: 11px;
  background: var(--online);
  border-radius: 50%;
  border: 2px solid var(--sidebar-bg);
}
.online-dot::after {
  content: '';
  position: absolute;
  top: -2px; left: -2px;
  width: 11px; height: 11px;
  border-radius: 50%;
  border: 2.5px solid var(--online);
  opacity: 0;
  animation: onlineRipple 2s infinite;
}
@keyframes onlineRipple {
  0%   { transform: scale(1); opacity: .8; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* ---- Badge ---- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  font-size: .68rem;
  font-weight: 700;
  flex-shrink: 0;
  animation: badgePop .2s ease;
}
@keyframes badgePop {
  from { transform: scale(.6); }
  to   { transform: scale(1); }
}

/* ---- Toast ---- */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  background: #1e293b;
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 8px;
  max-width: 320px;
  pointer-events: auto;
  transform: translateY(10px);
  opacity: 0;
  animation: toastIn .25s ease forwards;
}
.toast.toast-success { background: var(--success); }
.toast.toast-error   { background: var(--danger);  }
.toast.toast-warn    { background: var(--warning);  }
.toast.toast-info    { background: #2563eb; }
.toast.toast-hide    { animation: toastOut .25s ease forwards; }
@keyframes toastIn  { to { transform: translateY(0); opacity: 1; } }
@keyframes toastOut { to { transform: translateY(10px); opacity: 0; } }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-base);
}
.modal-overlay.open {
  opacity: 1; pointer-events: all;
}
.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 32px;
  transform: scale(.95) translateY(10px);
  transition: transform var(--t-base);
}
.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}
.modal-header {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title {
  font-size: 1.1rem; font-weight: 700;
  color: var(--text-main);
}
.modal-close {
  background: none; border: none;
  font-size: 1.4rem; cursor: pointer;
  color: var(--text-sub);
  transition: color var(--t-fast);
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--danger); background: #fee2e2; }

/* ---- Loader / Spinner ---- */
.spinner-ring {
  display: inline-block;
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Skeleton ---- */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--border-light) 50%, var(--border) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- Action Sheet (Bottom Drawer) ---- */
.actionsheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(8px);
  z-index: 3000;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-base);
}
.actionsheet-overlay.open { opacity: 1; pointer-events: all; }

.actionsheet {
  background: var(--card);
  border-radius: 24px 24px 0 0;
  width: 100%; max-width: 500px;
  padding: 12px 16px 32px;
  transform: translateY(100%);
  transition: transform var(--t-base) cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.15);
}
.actionsheet-overlay.open .actionsheet { transform: translateY(0); }

.actionsheet-handle {
  width: 40px; height: 5px;
  background: var(--border);
  border-radius: 3px;
  margin: 0 auto 20px;
}

.actionsheet-title {
  font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted);
  margin: 0 8px 12px;
}

.actionsheet-content { display: flex; flex-direction: column; gap: 4px; }

.actionsheet-btn {
  display: flex; align-items: center; gap: 14px;
  width: 100%; border: none; background: none;
  padding: 14px 16px; border-radius: 12px;
  cursor: pointer;
  transition: background var(--t-fast);
  color: var(--text-main);
  font-family: inherit; font-size: 1rem; font-weight: 500;
}
.actionsheet-btn:hover { background: var(--border-light); }
.actionsheet-btn.danger { color: var(--danger); }
.actionsheet-btn.danger:hover { background: #fee2e2; }

.actionsheet-icon { font-size: 1.2rem; min-width: 24px; text-align: center; }