/* ==========================================================================
   Thready — UI Components
   Buttons, Cards, Forms, Modals, Toasts, Badges, Dropdowns, Tooltips
   ========================================================================== */

/* ==========================================================================
   Global SVG size constraint
   ========================================================================== */
/* Global SVG size constraint — prevent uncontrolled SVG inflation */
svg {
  width: 1em;
  height: 1em;
}
svg[width] {
  width: attr(width);
  height: attr(height);
}
.pricing-card__feature svg { width: 18px; height: 18px; flex-shrink: 0; }
.feature-card__icon svg { width: 24px; height: 24px; }
.step__number svg { width: 24px; height: 24px; }
.quick-action__icon svg { width: 24px; height: 24px; }
.btn svg { width: 16px; height: 16px; }
.btn--lg svg { width: 18px; height: 18px; }
.activity-item__dot svg { width: 14px; height: 14px; }
.settings-nav__item svg { width: 18px; height: 18px; }
.topbar__menu-btn svg { width: 24px; height: 24px; }
.sidebar-nav__link svg { width: 20px; height: 20px; }
.mobile-bottom-nav__icon svg { width: 22px; height: 22px; }
.threads-connection svg { width: 32px; height: 32px; }
.empty-state__icon svg { width: 80px; height: 80px; }
.hero__badge__dot { width: 6px; height: 6px; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  font-family: var(--font-heading);
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--duration-base) var(--ease-out);
  white-space: nowrap;
  user-select: none;
  position: relative;
  overflow: hidden;
}
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* Sizes */
.btn--sm { height: 32px; padding: 0 var(--space-md); font-size: var(--text-sm); border-radius: var(--radius-sm); }
.btn--sm svg { width: 15px; height: 15px; }
.btn--md { height: 40px; padding: 0 var(--space-lg); font-size: var(--text-sm); }
.btn--lg { height: 48px; padding: 0 var(--space-xl); font-size: var(--text-base); }

/* Primary */
.btn--primary {
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
  color: #fff;
  border-color: var(--color-primary-light);
  box-shadow: 0 2px 8px rgba(108, 92, 231, .3);
}
.btn--primary:hover {
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-accent-dark));
  border-color: var(--color-primary-light);
  box-shadow: var(--shadow-glow-primary);
  transform: translateY(-1px);
}
.btn--primary:active { transform: translateY(0); box-shadow: none; }

/* Accent */
.btn--accent {
  background: var(--color-accent);
  color: var(--color-bg);
  border-color: var(--color-accent);
  font-weight: 700;
}
.btn--accent:hover {
  background: var(--color-accent-light);
  border-color: var(--color-accent-light);
  box-shadow: var(--shadow-glow-accent);
  transform: translateY(-1px);
}

/* Secondary */
.btn--secondary {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn--secondary:hover {
  background: var(--color-bg-elevated);
  border-color: var(--color-primary);
  color: var(--color-primary-light);
}

/* Ghost */
.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
}
.btn--ghost:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text);
}

/* Danger */
.btn--danger {
  background: transparent;
  color: var(--color-error);
  border-color: rgba(255,107,107,.3);
}
.btn--danger:hover {
  background: rgba(255,107,107,.1);
  border-color: var(--color-error);
}

/* Icon-only */
.btn--icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
}
.btn--icon.btn--sm { width: 32px; height: 32px; }
.btn--icon.btn--lg { width: 48px; height: 48px; }

/* Loading */
.btn.is-loading { pointer-events: none; opacity: .7; }
.btn.is-loading::after {
  content: '';
  width: 16px; height: 16px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Button Group */
.btn-group {
  display: flex;
  gap: 0;
}
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.btn-group .btn:last-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.btn-group .btn + .btn { border-left: 1px solid rgba(255,255,255,.1); }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: all var(--duration-base) var(--ease-out);
}
.card:hover {
  border-color: var(--color-primary-alpha-20);
}
.card--interactive:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}
.card__title {
  font-size: var(--text-lg);
  font-weight: 600;
}
.card__body { }
.card__footer {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border);
}

/* ==========================================================================
   Forms
   ========================================================================== */
.form-group {
  margin-bottom: var(--space-lg);
}
.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-sm);
}
.form-label--required::after {
  content: ' *';
  color: var(--color-error);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px var(--space-md);
  font-size: var(--text-base);
  color: var(--color-text);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--color-text-muted);
}
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-alpha-10);
}
.form-input.is-error,
.form-textarea.is-error {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px rgba(255,107,107,.1);
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
  line-height: var(--leading-relaxed);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239494A8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  cursor: pointer;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}
.form-error {
  font-size: var(--text-xs);
  color: var(--color-error);
  margin-top: var(--space-xs);
}

.form-checkbox,
.form-radio {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-size: var(--text-sm);
}
.form-checkbox input,
.form-radio input {
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

/* File Upload / Drop Zone */
.dropzone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  text-align: center;
  cursor: pointer;
  transition: all var(--duration-base);
  color: var(--color-text-muted);
}
.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-alpha-10);
  color: var(--color-primary-light);
}
.dropzone__icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-md);
  opacity: .5;
}
.dropzone__text {
  font-size: var(--text-sm);
}
.dropzone__hint {
  font-size: var(--text-xs);
  margin-top: var(--space-xs);
  color: var(--color-text-muted);
}

/* ==========================================================================
   Badges / Status
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.badge--draft { background: rgba(92,92,114,.2); color: var(--color-text-muted); }
.badge--scheduled { background: var(--color-primary-alpha-20); color: var(--color-primary-light); }
.badge--publishing { background: rgba(253,203,110,.15); color: var(--color-warning); }
.badge--published { background: rgba(0,184,148,.15); color: var(--color-success); }
.badge--failed { background: rgba(255,107,107,.15); color: var(--color-error); }

.badge--sm { padding: 1px 6px; font-size: 10px; }
.badge--dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ==========================================================================
   Modal
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: var(--z-modal-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-base), visibility var(--duration-base);
}
.modal-backdrop.is-active {
  opacity: 1;
  visibility: visible;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(.95);
  width: min(90vw, 520px);
  max-height: 85vh;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transition: all var(--duration-slow) var(--ease-out);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal.is-active {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}
.modal--lg { width: min(90vw, 720px); }
.modal--sm { width: min(90vw, 400px); }

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--color-border);
}
.modal__title {
  font-size: var(--text-lg);
  font-weight: 600;
}
.modal__close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: all var(--duration-fast);
}
.modal__close:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text);
}

.modal__body {
  padding: var(--space-xl);
  overflow-y: auto;
  flex: 1;
}
.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  border-top: 1px solid var(--color-border);
}

/* ==========================================================================
   Toast / Notifications
   ========================================================================== */
.toast-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  min-width: 320px;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  transform: translateX(120%);
  opacity: 0;
  transition: all var(--duration-slow) var(--ease-out);
}
.toast.is-visible {
  transform: translateX(0);
  opacity: 1;
}
.toast.is-leaving {
  transform: translateX(120%);
  opacity: 0;
}

.toast__icon {
  width: 20px; height: 20px;
  flex-shrink: 0;
  margin-top: 2px;
}
.toast__content { flex: 1; }
.toast__title {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: 2px;
}
.toast__message {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}
.toast__close {
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted);
  flex-shrink: 0;
  cursor: pointer;
}

.toast--success { border-left: 3px solid var(--color-success); }
.toast--success .toast__icon { color: var(--color-success); }
.toast--error { border-left: 3px solid var(--color-error); }
.toast--error .toast__icon { color: var(--color-error); }
.toast--warning { border-left: 3px solid var(--color-warning); }
.toast--warning .toast__icon { color: var(--color-warning); }
.toast--info { border-left: 3px solid var(--color-info); }
.toast--info .toast__icon { color: var(--color-info); }

/* ==========================================================================
   Dropdown / Action Menu
   ========================================================================== */
.dropdown {
  position: relative;
  display: inline-flex;
}
.dropdown__menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 180px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-xs) 0;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--duration-fast) var(--ease-out);
  z-index: var(--z-tooltip);
}
.dropdown.is-open .dropdown__menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.dropdown__item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  transition: all var(--duration-fast);
  cursor: pointer;
}
.dropdown__item:hover {
  background: var(--color-bg-hover);
  color: var(--color-text);
}
.dropdown__item--danger { color: var(--color-error); }
.dropdown__item--danger:hover {
  background: rgba(255,107,107,.08);
  color: var(--color-error);
}
.dropdown__item svg { width: 16px; height: 16px; }
.dropdown__divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-xs) 0;
}

/* ==========================================================================
   Tabs
   ========================================================================== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
}
.tab {
  padding: var(--space-md) var(--space-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--duration-fast);
  margin-bottom: -1px;
}
.tab:hover { color: var(--color-text-secondary); }
.tab.is-active {
  color: var(--color-primary-light);
  border-bottom-color: var(--color-primary);
}

/* ==========================================================================
   Avatar
   ========================================================================== */
.avatar {
  width: 36px; height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-bg-elevated);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary-light);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar--lg { width: 48px; height: 48px; font-size: var(--text-lg); }
.avatar--xl { width: 64px; height: 64px; font-size: var(--text-2xl); }

/* ==========================================================================
   Toggle / Switch
   ========================================================================== */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle__track {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  border-radius: var(--radius-full);
  transition: background var(--duration-fast);
}
.toggle__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--color-text);
  border-radius: 50%;
  transition: transform var(--duration-base) var(--ease-out);
}
.toggle input:checked ~ .toggle__track { background: var(--color-primary); }
.toggle input:checked ~ .toggle__thumb { transform: translateX(20px); }

/* ==========================================================================
   Tooltip
   ========================================================================== */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 10px;
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-fast);
  z-index: var(--z-tooltip);
}
[data-tooltip]:hover::after { opacity: 1; }

/* ==========================================================================
   Progress Bar
   ========================================================================== */
.progress {
  height: 6px;
  background: var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out);
}
.progress__bar--success { background: var(--color-success); }
.progress__bar--warning { background: var(--color-warning); }
.progress__bar--error { background: var(--color-error); }

/* ==========================================================================
   Divider
   ========================================================================== */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-lg) 0;
}
.divider--with-text {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.divider--with-text::before,
.divider--with-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

/* ==========================================================================
   Character Counter
   ========================================================================== */
.char-counter {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  text-align: right;
}
.char-counter.is-warn { color: var(--color-warning); }
.char-counter.is-over { color: var(--color-error); font-weight: 600; }

/* ==========================================================================
   Empty State
   ========================================================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--color-text-muted);
}
.empty-state__icon {
  width: 80px;
  height: 80px;
  margin-bottom: var(--space-lg);
  opacity: .3;
}
.empty-state__title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-sm);
}
.empty-state__desc {
  font-size: var(--text-sm);
  max-width: 360px;
  margin-bottom: var(--space-xl);
  line-height: var(--leading-relaxed);
}

/* ==========================================================================
   Notification Dot
   ========================================================================== */
.notif-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--color-error);
  position: absolute;
  top: -2px; right: -2px;
}

/* ==========================================================================
   Media Preview Thumbnails
   ========================================================================== */
.media-grid {
  display: grid;
  gap: var(--space-sm);
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
}
.media-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-bg-elevated);
}
.media-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.media-thumb__remove {
  position: absolute;
  top: 4px; right: 4px;
  width: 20px; height: 20px;
  background: rgba(0,0,0,.7);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--duration-fast);
}
.media-thumb:hover .media-thumb__remove { opacity: 1; }

@media (max-width: 767px) {
  .toast-container {
    top: auto;
    bottom: calc(72px + var(--space-md));
    right: var(--space-md);
    left: var(--space-md);
  }
  .toast { min-width: auto; width: 100%; }
}
