/* ═══════════════════════════════════════════════
   REUSABLE COMPONENTS
   Adapted from Stitch Design System (Academic Precision)
   ═══════════════════════════════════════════════ */

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  line-height: 1.2;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  user-select: none;
  white-space: nowrap;
  min-height: 44px;
  min-width: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--gradient-primary);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(41, 118, 199, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(41, 118, 199, 0.48);
  transform: translateY(-1px);
}

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

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
}
.btn-outline:hover {
  background: var(--color-primary-dim);
}

.btn-danger {
  background: var(--color-error);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(244, 63, 94, 0.3);
}
.btn-danger:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

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

.btn-xs { padding: 4px 8px; font-size: 11px; min-height: 28px; border-radius: var(--radius-sm); }
.btn-sm { padding: 6px 12px; font-size: var(--fs-sm); min-height: 36px; }
.btn-lg { padding: 12px 18px; font-size: var(--fs-base); min-height: 48px; }
.btn-block { width: 100%; }
.btn-icon { padding: var(--sp-2); min-height: auto; }

.btn:disabled, .btn.loading {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.btn .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ── Cards ── */
.card {
  background: var(--color-card-bg);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-card);
  transition: transform var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out), border-color var(--duration-fast) ease;
}
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-elevated);
  border-color: var(--color-primary);
  cursor: pointer;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-4);
}

@media (max-width: 600px) {
  .card-grid {
    grid-template-columns: 1fr;
    gap: var(--sp-3);
  }
}

@media (min-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--sp-5);
  }
}

/* ── Input Fields ── */
.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.input-label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--color-text-secondary);
}
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.input-field, .select-field, .textarea-field {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-input-bg);
  border: 1.5px solid var(--color-input-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: var(--fs-base);
  font-family: inherit;
  transition: border-color var(--duration-fast) var(--ease-in-out), box-shadow var(--duration-fast) var(--ease-in-out);
  outline: none;
}
.input-field:focus, .select-field:focus, .textarea-field:focus {
  border-color: var(--color-input-focus);
  box-shadow: 0 0 0 3px var(--color-primary-dim);
}
.input-field::placeholder { color: var(--color-text-tertiary); }
.input-icon-right {
  position: absolute;
  right: var(--sp-3);
  color: var(--color-text-tertiary);
  cursor: pointer;
  font-size: 20px;
}
[dir="rtl"] .input-icon-right {
  right: auto;
  left: var(--sp-3);
}

/* ── Badges & Chips ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px var(--sp-2);
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1.3;
}
.badge-primary { background: var(--color-primary-dim); color: var(--color-primary); border: 1px solid rgba(41, 118, 199, 0.2); }
.badge-success { background: rgba(16, 185, 129, 0.15); color: var(--color-success); border: 1px solid rgba(16, 185, 129, 0.25); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--color-warning); border: 1px solid rgba(245, 158, 11, 0.25); }
.badge-error { background: rgba(244, 63, 94, 0.15); color: var(--color-error); border: 1px solid rgba(244, 63, 94, 0.25); }
.badge-secondary { background: var(--color-surface-variant); color: var(--color-text-secondary); border: 1px solid var(--color-border); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 6px var(--sp-4);
  background: var(--color-surface-variant);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  user-select: none;
}
.chip.chip-sm { padding: 4px 10px; font-size: 11px; }
.chip:hover { background: var(--color-surface-hover); color: var(--color-text); border-color: var(--color-border-focus); }
.chip.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(41, 118, 199, 0.35);
}

/* ── Avatars ── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--gradient-primary);
  color: white;
  font-weight: var(--fw-bold);
  overflow: hidden;
  user-select: none;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 34px; height: 34px; font-size: var(--fs-xs); }
.avatar-md { width: 44px; height: 44px; font-size: var(--fs-base); }
.avatar-lg { width: 56px; height: 56px; font-size: var(--fs-lg); }
.avatar-xl { width: 96px; height: 96px; font-size: var(--fs-2xl); }

/* ── Toasts ── */
.toast-container {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: var(--z-toast);
  pointer-events: none;
  max-width: 90vw;
  width: 380px;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  color: var(--color-text);
  font-size: var(--fs-sm);
  pointer-events: auto;
  animation: slideUp var(--duration-fast) var(--ease-out);
}
.toast.success { border-inline-start: 4px solid var(--color-success); }
.toast.error { border-inline-start: 4px solid var(--color-error); }
.toast.warning { border-inline-start: 4px solid var(--color-warning); }
.toast.info { border-inline-start: 4px solid var(--color-primary); }

/* ── Modals & Dialogs (Glassmorphic) ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  z-index: var(--z-modal-overlay);
  animation: fadeIn var(--duration-fast) var(--ease-out);
}
.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--sp-6);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
  animation: scaleIn var(--duration-fast) var(--ease-out);
}
@media (max-width: 640px) {
  .modal {
    padding: var(--sp-4);
    border-radius: var(--radius-lg);
    max-height: 88vh;
  }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}
.modal-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  color: var(--color-text);
}
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
  flex-wrap: wrap;
}

/* ── Skeletons / Shimmer ── */
.skeleton {
  background: linear-gradient(90deg, var(--color-skeleton-base) 25%, var(--color-skeleton-shine) 50%, var(--color-skeleton-base) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
.skeleton-card { height: 120px; border-radius: var(--radius-lg); }

/* ── Floating Action Buttons (FAB Cluster) ── */
.fab-cluster {
  position: fixed;
  right: 18px;
  bottom: 86px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: var(--z-fab);
  align-items: center;
}
[dir="rtl"] .fab-cluster {
  right: auto;
  left: 18px;
}

.fab {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.fab:hover { transform: scale(1.08); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); }
.fab:active { transform: scale(0.94); }

.fab-summarizer {
  background: var(--gradient-primary);
}
.fab-chat {
  background: linear-gradient(135deg, #10b981, #059669);
}

/* ── Floating AI Chat Sheet ── */
.chat-sheet-overlay {
  position: fixed;
  bottom: 84px;
  right: 16px;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: 530px;
  max-height: calc(100vh - 120px);
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  animation: scaleIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
[dir="rtl"] .chat-sheet-overlay {
  right: auto;
  left: 16px;
}

.chat-sheet-container {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.chat-sheet-header {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--color-divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-surface-variant);
}

.chat-sheet-quick-prompts {
  display: flex;
  gap: 6px;
  padding: var(--sp-2) var(--sp-3);
  overflow-x: auto;
  border-bottom: 1px solid var(--color-divider);
  scrollbar-width: none;
}
.chat-sheet-quick-prompts::-webkit-scrollbar { display: none; }

.chat-sheet-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
}

.chat-sheet-input-area {
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--color-divider);
  display: flex;
  gap: var(--sp-2);
  background: var(--color-surface);
}

/* Typing Dots Animation */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 16px;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-tertiary);
  animation: typingPulse 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ── Drawer Items ── */
.drawer-section-title {
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: var(--sp-3) var(--sp-4) var(--sp-1);
}
.drawer-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  margin: 2px var(--sp-2);
  color: var(--color-text-secondary);
  font-weight: var(--fw-medium);
  transition: all var(--duration-fast) var(--ease-in-out);
  cursor: pointer;
}
.drawer-item:hover { background: var(--color-surface-hover); color: var(--color-text); }
.drawer-item.active {
  background: var(--color-primary-dim);
  color: var(--color-primary);
  font-weight: var(--fw-semibold);
}
.drawer-item .drawer-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.search-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: var(--color-input-bg);
  border: 1.5px solid var(--color-input-border);
  border-radius: var(--radius-full);
  transition: border-color var(--duration-fast) var(--ease-in-out), box-shadow var(--duration-fast) ease;
}
.search-bar:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-dim);
}
.search-bar .material-icons-round { color: var(--color-text-tertiary); font-size: 20px; }
.search-bar input { flex: 1; font-size: var(--fs-sm); min-height: 32px; border:none; background:transparent; outline:none; color:var(--color-text); }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal-overlay);
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-primary-dim);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--color-divider);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-item {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--color-text-tertiary);
  white-space: nowrap;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--duration-fast) var(--ease-in-out);
}
.tab-item:hover { color: var(--color-text); }
.tab-item.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: var(--fw-semibold);
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--color-surface-variant);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--gradient-primary);
  border-radius: var(--radius-full);
  transition: width var(--duration-normal) var(--ease-out);
}

/* ── Empty State Component (Full-width in Grids) ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--sp-10) var(--sp-6);
  background: var(--color-card-bg);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  width: 100%;
  max-width: 620px;
  margin: var(--sp-6) auto;
  grid-column: 1 / -1;
  gap: var(--sp-2);
}
.empty-state .material-icons-round {
  font-size: 56px;
  color: var(--color-primary);
  opacity: 0.88;
  margin-bottom: var(--sp-2);
}
.empty-state h3 {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  color: var(--color-text);
}
.empty-state p {
  font-size: var(--fs-sm);
  color: var(--color-text-secondary);
  max-width: 440px;
  line-height: var(--lh-normal);
  margin-bottom: var(--sp-4);
}

