/* ==========================================================================
   RESPONSIVE DESIGN & MOBILE OPTIMIZATIONS - TVSI WIDGET
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Medium Devices (Tablets: <= 992px)
   -------------------------------------------------------------------------- */
@media (max-width: 992px) {
  .action-cards-grid {
    grid-template-columns: 1fr;
    max-width: 600px;
    margin: 0 auto;
    gap: 16px;
  }

  .action-card {
    padding: 18px 20px;
  }

  .modal-container {
    width: 96vw;
    height: 92vh;
  }

  .pdf-layout-split,
  .video-layout-split {
    height: calc(92vh - 85px);
  }

  .pdf-sidebar,
  .video-playlist-sidebar {
    width: 340px;
  }
}

/* --------------------------------------------------------------------------
   2. Mobile Devices & Small Tablets (<= 768px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  body {
    padding: 12px 10px;
    justify-content: flex-start;
    min-height: 100dvh;
  }

  .tvsi-widget-wrapper {
    margin: 10px auto;
  }

  .action-cards-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    width: 100%;
  }

  .action-card {
    padding: 16px 18px;
    gap: 14px;
    border-radius: var(--radius-md);
  }

  .card-icon-box {
    width: 48px;
    height: 48px;
    border-radius: 10px;
  }

  .card-icon-box svg {
    width: 26px;
    height: 26px;
  }

  .card-main-title {
    font-size: 1.05rem; /* ~16.8px */
    line-height: 1.35;
  }

  .card-sub-title {
    font-size: 0.9rem; /* ~14.4px */
    line-height: 1.4;
  }

  .card-badge-tap {
    top: -10px;
    right: 12px;
    font-size: 11px;
    padding: 3px 10px;
  }

  /* --- Mobile Full-Screen Modal Window --- */
  .modal-overlay {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }

  .modal-container {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    box-shadow: none;
    transform: translateY(100%);
  }

  .modal-overlay.active .modal-container {
    transform: translateY(0);
  }

  .modal-header {
    padding: 12px 16px;
    gap: 12px;
    border-bottom: 1.5px solid var(--border-light);
  }

  .modal-title-wrap {
    gap: 12px;
    min-width: 0;
    flex: 1;
  }

  .modal-icon-badge {
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  .modal-icon-badge svg {
    width: 22px;
    height: 22px;
  }

  .modal-title {
    font-size: 1.15rem; /* ~18.4px */
    line-height: 1.25;
  }

  .modal-subtitle {
    font-size: 0.82rem; /* ~13px */
    margin-top: 2px;
    line-height: 1.35;
    white-space: normal;
    color: #64748b;
  }

  .modal-close-btn {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
  }

  .modal-close-btn svg {
    width: 20px;
    height: 20px;
  }

  /* --- Mobile PDF Layout (App-like List vs Reader switcher) --- */
  .pdf-layout-split {
    position: relative;
    width: 100%;
    height: calc(100dvh - 65px);
    min-height: 0;
    flex-direction: row;
  }

  /* When NOT active: Show List View */
  .pdf-layout-split .pdf-sidebar {
    width: 100%;
    height: 100%;
    border-right: none;
    display: flex;
    flex-direction: column;
  }

  .pdf-layout-split .pdf-viewer-pane {
    display: none;
  }

  /* When mobile-view-active: Show Reader View */
  .pdf-layout-split.mobile-view-active .pdf-sidebar {
    display: none;
  }

  .pdf-layout-split.mobile-view-active .pdf-viewer-pane {
    display: flex;
    width: 100%;
    height: 100%;
    flex-direction: column;
  }

  .pdf-mobile-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 800;
    cursor: pointer;
    flex-shrink: 0;
  }

  .pdf-mobile-back-btn svg {
    width: 16px;
    height: 16px;
  }

  .pdf-mobile-back-btn:active {
    background: rgba(255, 255, 255, 0.35);
  }

  .pdf-mobile-notice {
    display: block;
    background: #0f172a;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    color: #e2e8f0;
    font-size: 13px;
    line-height: 1.4;
  }

  .pdf-mobile-mini-btn {
    display: inline-flex;
    align-items: center;
    background: #2563eb;
    color: #ffffff;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    text-decoration: none;
  }

  .pdf-sidebar-header {
    padding: 14px 16px;
    gap: 10px;
  }

  .pdf-search-input {
    padding: 11px 16px 11px 44px;
    font-size: 0.95rem;
  }

  .pdf-batch-download-btn {
    padding: 11px 16px;
    font-size: 0.95rem;
  }

  .pdf-items-list {
    padding: 12px 14px;
    gap: 10px;
  }

  .pdf-item {
    padding: 14px;
    gap: 12px;
    border-radius: 12px;
  }

  .pdf-item-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
  }

  .pdf-item-icon svg {
    width: 20px;
    height: 20px;
  }

  .pdf-item-title {
    font-size: 1rem; /* ~16px */
    line-height: 1.4;
    margin-bottom: 6px;
  }

  .pdf-item-meta {
    font-size: 0.85rem;
  }

  .pdf-quick-download {
    padding: 8px;
  }

  .pdf-quick-download svg {
    width: 20px;
    height: 20px;
  }

  /* PDF Viewer Toolbar on Mobile */
  .pdf-viewer-toolbar {
    padding: 10px 12px;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .pdf-current-title {
    display: none; /* Ẩn bớt trên mobile toolbar để nhường chỗ cho các nút điều khiển */
  }

  .pdf-viewer-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  .pdf-view-toggle-group {
    padding: 2px;
  }

  .pdf-view-toggle-group .pdf-tool-btn {
    padding: 6px 10px;
    font-size: 0.85rem;
  }

  .pdf-tool-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
    gap: 6px;
  }

  .pdf-tool-btn svg {
    width: 15px;
    height: 15px;
  }

  .pdf-document-preview-card {
    padding: 20px 16px;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    max-width: 100%;
    min-height: 100%;
  }

  .pdf-preview-header-meta h3,
  .pdf-preview-title {
    font-size: 1.25rem; /* ~20px */
    margin-bottom: 8px;
    line-height: 1.35;
  }

  .pdf-preview-header-meta p,
  .pdf-preview-desc {
    font-size: 0.95rem; /* ~15.2px */
    line-height: 1.55;
  }

  .pdf-steps-heading {
    font-size: 1rem;
    margin-bottom: 6px;
  }

  .pdf-step-box {
    padding: 14px 16px;
    margin-bottom: 10px;
  }

  .pdf-step-title {
    font-size: 1rem;
    margin-bottom: 6px;
  }

  .pdf-step-title .step-num,
  .pdf-step-title span:first-child {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  .pdf-step-desc {
    font-size: 0.925rem;
    padding-left: 0;
    margin-top: 6px;
    line-height: 1.55;
  }

  .pdf-preview-download-box {
    padding: 16px;
    margin-top: 10px;
  }

  .pdf-preview-download-note {
    font-size: 14px;
    margin-bottom: 10px;
  }

  .pdf-large-download-btn {
    font-size: 0.95rem;
    padding: 12px 16px;
    width: 100%;
  }

  /* --- Mobile Video Layout (YouTube Mobile Theater style) --- */
  .video-layout-split {
    flex-direction: column;
    width: 100%;
    height: calc(100dvh - 65px);
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .video-player-stage {
    flex: 0 0 auto;
    width: 100%;
    position: sticky;
    top: 0;
    z-index: 20;
    background: #000000;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  }

  .video-player-wrapper {
    width: 100%;
    height: auto;
    aspect-ratio: 16/9;
    max-height: 38vh;
    background: #000000;
  }

  .main-video-element {
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: contain;
  }

  .video-stage-info {
    padding: 12px 16px;
    background: #0f172a;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .video-playing-title {
    font-size: 1.05rem; /* ~16.8px */
    font-weight: 800;
    line-height: 1.35;
    margin: 0;
  }

  .video-playlist-sidebar {
    flex: 1 0 auto;
    width: 100%;
    border-left: none;
    border-top: 2px solid var(--border-light);
    background: #ffffff;
  }

  .video-playlist-header {
    padding: 12px 16px;
    position: sticky;
    top: 0;
    background: #ffffff;
    z-index: 10;
    border-bottom: 1px solid var(--border-light);
  }

  .playlist-header-title {
    font-size: 0.95rem;
  }

  .playlist-count-badge {
    font-size: 12px;
    padding: 2px 10px;
  }

  .video-items-list {
    padding: 10px 14px 28px;
    gap: 10px;
    overflow-y: visible;
  }

  .video-item {
    padding: 10px 12px;
    gap: 12px;
    border-radius: 12px;
  }

  .video-item-thumb {
    width: 92px;
    height: 58px;
    border-radius: 6px;
  }

  .video-thumb-play-icon {
    width: 22px;
    height: 22px;
  }

  .video-thumb-play-icon svg {
    width: 10px;
    height: 10px;
  }

  .thumb-corner-logo {
    height: 12px;
    top: 3px;
    left: 3px;
    padding: 1px 3px;
  }

  .video-item-title {
    font-size: 0.95rem; /* ~15.2px */
    font-weight: 700;
    line-height: 1.35;
  }
}

/* --------------------------------------------------------------------------
   3. Extra Small Devices (<= 400px)
   -------------------------------------------------------------------------- */
@media (max-width: 400px) {
  .card-main-title {
    font-size: 0.975rem;
  }

  .card-sub-title {
    font-size: 0.85rem;
  }

  .card-icon-box {
    width: 42px;
    height: 42px;
  }

  .card-icon-box svg {
    width: 22px;
    height: 22px;
  }

  .pdf-view-toggle-group .pdf-tool-btn {
    padding: 5px 8px;
    font-size: 0.8rem;
  }

  .pdf-tool-btn {
    padding: 5px 10px;
    font-size: 0.8rem;
  }
}
