/* ==========================================================================
   COMPONENTS.CSS — Buttons, Cards, Inputs, Modals, Toasts & Media Items
   Standardized based on mtips5s_30_VPS3_UX_UI_Design Curriculum
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Buttons System (Atomic States: Default, Hover, Focus, Active, Disabled)
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 8px 14px;
  font-size: var(--font-size-base);
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  font-family: inherit;
  outline: none;
  user-select: none;
  text-decoration: none;
}

.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

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

/* Primary Button (Telegram Blue Accent) */
.btn-primary {
  background: var(--grad-primary);
  color: #ffffff;
  border: 1px solid var(--tg-blue);
  box-shadow: 0 2px 10px var(--tg-blue-glow);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.12);
  box-shadow: 0 4px 14px var(--tg-blue-glow);
  transform: translateY(-1px);
}

/* Secondary Button (Glass Surface) */
.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
  color: #ffffff;
}

/* Danger Button */
.btn-danger {
  background: rgba(244, 63, 94, 0.12);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.btn-danger:hover:not(:disabled) {
  background: var(--accent-rose);
  color: #ffffff;
  border-color: var(--accent-rose);
  box-shadow: 0 2px 10px rgba(244, 63, 94, 0.35);
}

/* Ghost Button */
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
}

/* Header Action Icon Buttons */
.btn-header-icon {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
  text-decoration: none;
}

.btn-header-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--border-accent);
  transform: translateY(-1px);
}

.btn-header-icon:focus-visible {
  outline: 2px solid var(--border-focus);
}

.btn-header-icon svg {
  width: 17px;
  height: 17px;
}

/* Quick Telegram Button */
.btn-quick-tg {
  background: rgba(36, 161, 222, 0.12);
  border: 1px solid rgba(36, 161, 222, 0.3);
  color: var(--tg-cyan);
  font-size: var(--font-size-xs);
  font-weight: 700;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.btn-quick-tg:hover {
  background: var(--tg-blue);
  color: #ffffff;
  border-color: var(--tg-blue);
  transform: translateY(-1px);
}

/* --------------------------------------------------------------------------
   2. Filter & Search Controls
   -------------------------------------------------------------------------- */
.filter-search-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.filter-pills {
  display: flex;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
  padding-bottom: 2px;
}

.filter-pill {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: var(--font-size-xs);
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  font-family: inherit;
  outline: none;
}

.filter-pill:hover {
  color: var(--text-main);
  border-color: var(--border-strong);
}

.filter-pill.active {
  background: var(--tg-blue);
  color: #ffffff;
  border-color: var(--tg-blue);
  box-shadow: 0 2px 8px var(--tg-blue-glow);
}

.search-input-wrap {
  position: relative;
  width: 150px;
  display: flex;
  align-items: center;
}

.search-input-wrap input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 6px 14px 6px 30px;
  font-size: var(--font-size-xs);
  color: var(--text-main);
  outline: none;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.search-input-wrap input:focus {
  border-color: var(--border-focus);
  background: var(--bg-surface-elevated);
  box-shadow: 0 0 0 3px rgba(36, 161, 222, 0.15);
  width: 175px;
}

.search-input-wrap .search-icon {
  position: absolute;
  left: 10px;
  width: 13px;
  height: 13px;
  color: var(--text-dim);
  pointer-events: none;
}

.search-clear-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2px;
}

.search-clear-btn:hover {
  color: var(--text-main);
}

/* --------------------------------------------------------------------------
   3. Batch Actions Toolbar (Fogg Ability & Trigger Enhancement)
   -------------------------------------------------------------------------- */
.batch-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  box-shadow: var(--shadow-xs);
}

.batch-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.custom-checkbox {
  accent-color: var(--tg-blue);
  width: 17px;
  height: 17px;
  cursor: pointer;
  border-radius: var(--radius-xs);
}

.selected-text {
  color: var(--text-muted);
  font-weight: 600;
  font-size: var(--font-size-xs);
}

.batch-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-batch-action {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all var(--transition-fast);
  outline: none;
  font-family: inherit;
}

.btn-batch-action:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.btn-batch-action:active:not(:disabled) {
  transform: scale(0.96);
}

.btn-batch-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-batch-action.primary {
  background: var(--grad-primary);
  border-color: var(--tg-blue);
  color: #ffffff;
  box-shadow: 0 2px 10px var(--tg-blue-glow);
}

.btn-batch-action.primary:hover:not(:disabled) {
  filter: brightness(1.15);
  box-shadow: 0 4px 14px var(--tg-blue-glow);
}

.btn-batch-action.danger {
  color: #fda4af;
  border-color: rgba(244, 63, 94, 0.3);
  background: rgba(244, 63, 94, 0.08);
}

.btn-batch-action.danger:hover:not(:disabled) {
  background: var(--accent-rose);
  color: #ffffff;
  border-color: var(--accent-rose);
}

/* --------------------------------------------------------------------------
   4. Progress Bar
   -------------------------------------------------------------------------- */
.progress-bar-wrap {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  animation: slideUp var(--transition-base);
}

.progress-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-bottom: var(--space-2);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8, #24a1de, #10b981);
  transition: width 0.3s ease;
  border-radius: var(--radius-pill);
}

.progress-text {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  text-align: center;
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   5. Media Cards & List (Object Component Matrix - Bài 6)
   -------------------------------------------------------------------------- */
.media-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.media-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  transition: all var(--transition-fast);
  cursor: pointer;
  position: relative;
  box-shadow: var(--shadow-xs);
}

.media-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
  transform: translateX(2px);
  box-shadow: var(--shadow-sm);
}

.media-card.selected {
  border-color: var(--tg-blue);
  background: rgba(36, 161, 222, 0.12);
  box-shadow: 0 0 14px rgba(36, 161, 222, 0.15);
}

.card-checkbox-wrapper {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.thumb-wrapper {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
}

.thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-base);
}

.media-card:hover .thumb-img {
  transform: scale(1.05);
}

.play-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-overlay svg {
  width: 24px;
  height: 24px;
  color: #ffffff;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

.duration-tag {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.8);
  color: #ffffff;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  letter-spacing: 0.02em;
}

.media-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.media-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Badges for Media Types */
.type-pill {
  font-size: 9px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.06em;
}

.badge-video {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.badge-image {
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-file {
  background: rgba(139, 92, 246, 0.18);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.35);
}

.media-size {
  font-size: var(--font-size-xs);
  color: var(--text-dim);
  font-weight: 600;
}

.media-title {
  font-size: var(--font-size-base);
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2px;
}

.media-id {
  font-size: 10px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.media-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-icon-action {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
}

.btn-icon-action:hover {
  background: var(--bg-card-hover);
  color: #ffffff;
  border-color: var(--border-focus);
  transform: translateY(-1px);
}

.btn-icon-action:focus-visible {
  outline: 2px solid var(--border-focus);
}

.btn-icon-action svg {
  width: 15px;
  height: 15px;
}

/* --------------------------------------------------------------------------
   6. Empty State (Recognition over Recall - Bài 3)
   -------------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px var(--space-4);
  background: var(--bg-card);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  gap: var(--space-3);
  animation: fadeIn var(--transition-base);
}

.empty-icon-wrap {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(36, 161, 222, 0.12);
  border: 1px solid var(--border-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tg-blue);
  box-shadow: 0 0 16px rgba(36, 161, 222, 0.15);
}

.empty-icon-wrap svg {
  width: 30px;
  height: 30px;
}

.empty-title {
  font-size: var(--font-size-md);
  font-weight: 800;
  color: var(--text-main);
}

.empty-desc {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  max-width: 340px;
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   7. Scanner Hero Card (Tab Quét Kênh)
   -------------------------------------------------------------------------- */
.scanner-card {
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.28), rgba(14, 116, 144, 0.18));
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  box-shadow: var(--shadow-card);
}

.scanner-hero-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.scanner-hero-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--grad-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.4);
}

.scanner-hero-icon svg {
  width: 26px;
  height: 26px;
}

.scanner-hero-text h3 {
  font-size: var(--font-size-lg);
  font-weight: 800;
  color: #ffffff;
}

.scanner-hero-text p {
  font-size: var(--font-size-sm);
  color: #bae6fd;
}

.scanner-features-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.scanner-feat-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-main);
  background: rgba(15, 23, 42, 0.45);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.scanner-feat-item svg {
  width: 15px;
  height: 15px;
  color: var(--accent-emerald);
  flex-shrink: 0;
}

.btn-launch-scanner {
  background: var(--grad-primary);
  border: none;
  color: #ffffff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: all var(--transition-fast);
  box-shadow: 0 4px 18px rgba(2, 132, 199, 0.4);
  font-family: inherit;
  outline: none;
}

.btn-launch-scanner:hover {
  filter: brightness(1.15);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(2, 132, 199, 0.55);
}

.btn-launch-scanner:active {
  transform: scale(0.98);
}

.btn-launch-scanner svg {
  width: 18px;
  height: 18px;
}

/* --------------------------------------------------------------------------
   8. Guide & Settings Cards (Tab Cài Đặt)
   -------------------------------------------------------------------------- */
.guide-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-shadow: var(--shadow-xs);
}

.guide-header {
  font-size: var(--font-size-md);
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.guide-steps {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.step-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.step-number {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(36, 161, 222, 0.15);
  border: 1px solid var(--border-accent);
  color: var(--tg-blue);
  font-size: var(--font-size-xs);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-item b {
  color: var(--text-main);
}

.download-ext-box {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12), rgba(6, 95, 70, 0.16));
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.download-ext-info h4 {
  font-size: var(--font-size-base);
  font-weight: 800;
  color: #34d399;
}

.download-ext-info p {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-download-ext {
  background: var(--grad-emerald);
  border: none;
  color: #ffffff;
  font-size: var(--font-size-xs);
  font-weight: 800;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.3);
}

.btn-download-ext:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.btn-download-ext svg {
  width: 15px;
  height: 15px;
}

/* --------------------------------------------------------------------------
   9. Error Prevention Dialog / Modal (Bài 3 Usability & Safety)
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: modalBackdropFadeIn 0.2s ease-out forwards;
}

.modal-backdrop.active {
  display: flex;
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  overflow: hidden;
  animation: modalScaleIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.modal-header-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-rose);
  flex-shrink: 0;
}

.modal-header-icon svg {
  width: 20px;
  height: 20px;
}

.modal-header h3 {
  font-size: var(--font-size-md);
  font-weight: 800;
  color: var(--text-main);
}

.modal-body {
  padding: var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  line-height: 1.6;
}

.modal-footer {
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface-elevated);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* --------------------------------------------------------------------------
   10. Toast Notification System
   -------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 99999;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

.toast-item {
  background: var(--bg-surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  padding: 11px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--font-size-sm);
  font-weight: 600;
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast-item.hide {
  animation: toastOut 0.25s forwards;
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.toast-success { border-color: rgba(16, 185, 129, 0.45); }
.toast-success .toast-icon { color: var(--accent-emerald); }
.toast-warning { border-color: rgba(245, 158, 11, 0.45); }
.toast-warning .toast-icon { color: var(--accent-amber); }
.toast-error { border-color: rgba(244, 63, 94, 0.45); }
.toast-error .toast-icon { color: var(--accent-rose); }
.toast-info { border-color: var(--border-accent); }
.toast-info .toast-icon { color: var(--tg-blue); }

.spinner-small {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: currentColor;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
