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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow-x: hidden;
}

a {
  color: var(--text-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  font-size: var(--fs-base);
  color: var(--text-primary);
}

input, textarea, select {
  font-family: inherit;
  font-size: var(--fs-base);
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  outline: none;
  transition: border-color var(--transition-fast);
  width: 100%;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--border-focus);
}

input::placeholder, textarea::placeholder {
  color: var(--text-placeholder);
}

img {
  max-width: 100%;
  display: block;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  transition: all var(--transition-fast);
  white-space: nowrap;
  line-height: 1.4;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  animation: jelly 0.4s ease;
}

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

.btn-secondary:hover {
  background: var(--bg-active);
}

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

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

.btn-danger {
  color: var(--text-danger);
}

.btn-danger:hover {
  background: rgba(235, 87, 87, 0.08);
}

.btn-sm {
  padding: 4px 10px;
  font-size: var(--fs-xs);
}

.btn-icon {
  padding: 6px;
  border-radius: var(--radius-md);
}

.btn-icon:hover {
  background: var(--bg-hover);
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-default);
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-sm {
  width: 14px;
  height: 14px;
}

.spinner-lg {
  width: 32px;
  height: 32px;
}

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

.spinner-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

/* Skeleton */
.skeleton {
  background: var(--bg-skeleton);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--bg-skeleton-shine), transparent);
  animation: skeleton-shimmer 1.5s infinite;
}

@keyframes skeleton-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  width: 80%;
}

.skeleton-text-sm {
  height: 10px;
  width: 50%;
}

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

.skeleton-card {
  height: 80px;
  margin-bottom: 8px;
}

/* Avatar */
.avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
  flex-shrink: 0;
  overflow: hidden;
}

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

.avatar-sm {
  width: 22px;
  height: 22px;
  font-size: 10px;
}

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

/* Online indicator */
.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--online-green);
  border: 2px solid var(--bg-primary);
}

.offline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-placeholder);
  border: 2px solid var(--bg-primary);
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
}

.badge-blue { background: var(--bg-tag-blue); color: var(--text-primary); }
.badge-green { background: var(--bg-tag-green); color: var(--text-primary); }
.badge-yellow { background: var(--bg-tag-yellow); color: var(--text-primary); }
.badge-red { background: var(--bg-tag-red); color: var(--text-primary); }
.badge-purple { background: var(--bg-tag-purple); color: var(--text-primary); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

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

.modal {
  background: var(--bg-modal);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform var(--transition-normal);
}

.modal-overlay.active .modal {
  transform: scale(1);
  animation: jelly 0.4s ease;
}

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

.modal-header h3 {
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-default);
}

/* Form */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

/* Dropdown */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  padding: 4px;
  z-index: var(--z-dropdown);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all var(--transition-fast);
}

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

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  color: var(--text-primary);
  width: 100%;
  text-align: left;
  cursor: pointer;
}

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

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

.dropdown-divider {
  height: 1px;
  background: var(--border-default);
  margin: 4px 0;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text-primary);
  color: var(--text-inverse);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s ease;
  max-width: 320px;
}

.toast.toast-error {
  background: var(--text-danger);
}

.toast.toast-success {
  background: var(--text-success);
}

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

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-state-icon {
  font-size: 40px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  margin-bottom: 8px;
}

.empty-state-text {
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  max-width: 300px;
}

/* Utility */
.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hidden {
  display: none !important;
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-accent { color: var(--accent); }

/* Jelly animation */
@keyframes jelly {
  0% { transform: scale(1); }
  20% { transform: scale(1.04, 0.96); }
  40% { transform: scale(0.97, 1.03); }
  60% { transform: scale(1.02, 0.98); }
  80% { transform: scale(0.99, 1.01); }
  100% { transform: scale(1); }
}

@keyframes jelly-sm {
  0% { transform: scale(1); }
  25% { transform: scale(1.06, 0.94); }
  50% { transform: scale(0.96, 1.04); }
  75% { transform: scale(1.02, 0.98); }
  100% { transform: scale(1); }
}

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pop-in {
  0% { opacity: 0; transform: scale(0.9); }
  60% { transform: scale(1.02); }
  100% { opacity: 1; transform: scale(1); }
}

.animate-in {
  animation: fade-in-up 0.25s ease forwards;
}

.animate-pop {
  animation: pop-in 0.3s ease forwards;
}

/* Confirm dialog */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: calc(var(--z-modal) + 10);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
}

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

.confirm-overlay.active .confirm-dialog {
  animation: jelly 0.4s ease;
}

.confirm-dialog {
  background: var(--bg-modal);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  width: 90%;
  max-width: 360px;
  padding: 24px;
  text-align: center;
  transform: scale(0.95);
  transition: transform var(--transition-fast);
}

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

.confirm-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border-radius: var(--radius-full);
  background: var(--bg-tag-red);
  display: flex;
  align-items: center;
  justify-content: center;
}

.confirm-title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  margin-bottom: 8px;
}

.confirm-text {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: var(--lh-normal);
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.confirm-actions .btn {
  flex: 1;
  justify-content: center;
  padding: 8px 16px;
}

.btn-danger-fill {
  background: var(--text-danger);
  color: #ffffff;
}

.btn-danger-fill:hover {
  background: #d44040;
}

/* Inline file preview */
.inline-preview {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-top: 8px;
  max-width: 400px;
}

.inline-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-default);
}

.inline-preview-title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-preview-body {
  max-height: 400px;
  overflow: auto;
}

.inline-preview-body img {
  width: 100%;
  display: block;
}

.inline-preview-body iframe {
  width: 100%;
  height: 360px;
  border: none;
}

.inline-preview-body .preview-unavailable {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--fs-sm);
}

/* Members popup */
.members-panel {
  background: var(--bg-modal);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 90%;
  max-width: 340px;
  max-height: 70vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: jelly 0.4s ease;
}

.members-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-default);
}

.members-panel-list {
  overflow-y: auto;
  padding: 8px;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}

.member-item:hover {
  background: var(--bg-hover);
}

.member-info {
  flex: 1;
  min-width: 0;
}

.member-name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}

.member-role {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  text-transform: capitalize;
}

.member-status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
}

/* Nav item badge accent */
.nav-item-badge {
  background: var(--accent) !important;
}

/* Send button accent */
.chat-send-btn {
  background: var(--accent) !important;
  color: #ffffff !important;
}

.chat-send-btn:hover {
  background: var(--accent-hover) !important;
}
