/* ==========================================================================
   ChessKingdom Theory Mobile — Mobile-first responsive overrides
   Design System: Inter font, 12px radius, #f8fafc background
   Touch targets: min 44px (WCAG), preferred 48px
   Breakpoints: 768px (tablet), 480px (phone)
   ========================================================================== */

/* ---------- 0. TEMPLATE FIX: Sidebar margin + padding override ---------- */
/* sidebar-modern.css has html.sidebar-collapsed .content-body { margin-left: 72px !important }
   which wins over the media query due to higher specificity. Must match that specificity here. */
@media (max-width: 991px) {
  html.sidebar-collapsed .content-body,
  html.sidebar-left-collapsed .content-body,
  html .content-body {
    margin-left: 0 !important;
    width: 100% !important;
  }
}

/* Template .content-body has padding: 20px which eats 40px from viewport.
   Remove it on mobile for theory views so they can use full width. */
@media (max-width: 768px) {
  body.view-theoriescourse .content-body,
  body.view-theory .content-body,
  body.view-theoriespractice .content-body,
  body.view-theoriescourses .content-body,
  body.view-theories .content-body,
  body.view-theoriestopics .content-body,
  body.view-theoriespractices .content-body,
  body.view-theory_courses .content-body {
    padding: 0 !important;
  }
}

/* ---------- 1. COURSE LIST (theoriescourses) — TABLET ---------- */

@media (max-width: 768px) {
  /* Page padding tighter */
  .tc-page { padding: 16px 12px; }

  /* Header: stack title + count */
  .tc-header { flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 14px; }
  .tc-title { font-size: 18px; gap: 8px; }
  .tc-title i { font-size: 18px; }

  /* Filter bar: compact */
  .tc-filter-bar { padding: 12px; border-radius: 12px; }
  .tc-filter-section { margin-bottom: 10px; }
  .tc-filter-label { font-size: 11px; margin-bottom: 6px; }

  /* Difficulty + Theme: horizontal scroll
     NOTE: !important needed because inline <style> in template defines .tc-filter-row
     with flex-wrap:wrap AFTER this external CSS loads */
  .tc-filter-row {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    padding-bottom: 4px;
    margin: 0 -4px;
  }
  .tc-filter-row::-webkit-scrollbar { display: none; }

  .tc-diff-btn {
    flex-shrink: 0;
    scroll-snap-align: start;
    padding: 8px 12px;
    min-height: 40px;
    font-size: 12px;
  }

  .tc-theme-chip {
    flex-shrink: 0;
    scroll-snap-align: start;
    padding: 7px 14px;
    font-size: 12px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  /* Search full width */
  .tc-search-row { flex-direction: column; gap: 8px; }
  .tc-search-box { min-width: 100%; }
  .tc-search-box input { padding: 10px 12px 10px 36px; font-size: 14px; min-height: 44px; }
  .tc-clear-btn { min-height: 40px; justify-content: center; width: 100%; }

  /* Card grid: 1 column */
  .tc-grid { grid-template-columns: 1fr !important; gap: 14px; }

  /* Card: compact image */
  .tc-card-img { height: 140px; }
  .tc-card-placeholder { height: 140px; }
  .tc-card-placeholder i { font-size: 36px; }
  .tc-card-body { padding: 12px 14px; }
  .tc-card-title { font-size: 15px; }
  .tc-card-desc { font-size: 13px; margin-bottom: 8px; }

  /* Meta pills: horizontal scroll */
  .tc-card-meta {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
  }
  .tc-card-meta::-webkit-scrollbar { display: none; }
  .tc-meta-pill { flex-shrink: 0; white-space: nowrap; }

  /* Progress */
  .tc-progress-label { font-size: 11px; width: 50px; }
  .tc-progress-value { font-size: 11px; width: 48px; }

  /* Footer: stack */
  .tc-card-footer { flex-direction: column !important; gap: 10px; padding: 12px 14px; align-items: stretch; }
  .tc-footer-stats { justify-content: center; gap: 16px; }
  .tc-open-btn {
    width: 100% !important;
    justify-content: center;
    padding: 12px 16px !important;
    font-size: 14px;
    min-height: 48px;
    border-radius: 10px;
  }

  /* Pagination compact */
  .tc-pagination { flex-direction: column; gap: 10px; }
}

/* ---------- 2. COURSE LIST — PHONE ---------- */

@media (max-width: 480px) {
  .tc-page { padding: 12px 8px; }
  .tc-title { font-size: 16px; }
  .tc-filter-bar { padding: 10px; }

  /* Difficulty: show stars only (hide label text) */
  .tc-diff-btn { padding: 8px 10px; font-size: 11px; }

  .tc-card-img { height: 120px; }
  .tc-card-placeholder { height: 120px; }
  .tc-card-body { padding: 10px 12px; }
  .tc-card-title { font-size: 14px; }
}


/* ==========================================================================
   3. STUDY VIEWER — MOBILE (theoriescourse + theory)
   ========================================================================== */

@media (max-width: 768px) {

  /* --- Page container --- */
  .ck-theories-viewer-shell.ck-financial-page {
    padding: 8px 0 0;
    background: #f8fafc;
  }

  /* --- Header: stack title + chip vertically --- */
  .ck-theories-viewer-shell .ck-financial-header {
    padding: 0 12px;
    margin-bottom: 8px;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .ck-theories-viewer-shell .ck-financial-title {
    font-size: 16px;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100vw - 40px);
  }

  .ck-theories-viewer-shell .ck-financial-chip {
    font-size: 11px;
    padding: 3px 8px;
  }

  /* --- Toolbar: horizontal scroll --- */
  .ck-theories-viewer-shell .ck-financial-toolbar {
    margin: 0 8px 8px;
    padding: 8px 10px;
    border-radius: 10px;
  }

  .ck-theories-viewer-actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
  }
  .ck-theories-viewer-actions::-webkit-scrollbar { display: none; }

  .ck-theories-btn {
    flex-shrink: 0;
    padding: 8px 10px;
    font-size: 12px;
    min-height: 40px;
    white-space: nowrap;
  }

  /* --- Study App: remove outer padding, prevent overflow --- */
  .ck-study-app {
    gap: 0;
    overflow-x: hidden;
    max-width: 100%;
  }

  /* Prevent body/content horizontal scroll */
  .ck-theories-viewer-shell {
    overflow-x: hidden;
    max-width: 100%;
  }

  /* --- Top: compact header + tabs --- */
  .ck-study-top {
    padding: 8px 12px;
    gap: 8px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 0;
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .ck-study-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
  }

  .ck-study-meta {
    display: none;
  }

  /* --- Breadcrumb: compact on mobile --- */
  .ck-study-breadcrumb {
    padding: 6px 12px;
    border-radius: 0;
    font-size: 12px;
    background: var(--ck-warm-bg, #fdf0de);
    border-bottom: 1px solid var(--ck-warm-border, #eacda0);
  }

  .ck-breadcrumb-item:not(:last-child)::after {
    margin: 0 5px;
  }

  .ck-study-top-actions {
    width: 100%;
    gap: 8px;
    justify-content: flex-start;
  }

  /* Mode tabs: compact, take remaining space */
  .ck-study-tabs {
    padding: 3px;
    gap: 4px;
    flex: 1;
    min-width: 0;
  }

  .ck-study-tab-btn {
    padding: 6px 12px;
    font-size: 12px;
    min-height: 36px;
  }

  /* Menu toggle: larger touch target */
  .ck-study-menu-toggle {
    min-width: 44px;
    min-height: 44px;
    padding: 0 10px;
    border-radius: 10px;
  }

  .ck-study-menu-toggle-icon { font-size: 18px; }

  /* --- Picker: FULL SCREEN OVERLAY --- */
  .ck-study-picker-wrap,
  .ck-study-app.ck-study-app--legacy [data-study-role="picker-wrap"] {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    z-index: 9999 !important;
    padding: 56px 12px 12px !important;
    animation: ckMobilePickerSlideUp 0.25s ease-out;
    background: #fff;
  }

  /* Close button area for picker (added via JS) */
  .ck-mobile-picker-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
  }

  .ck-mobile-picker-title {
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
  }

  .ck-mobile-picker-close {
    width: 44px;
    height: 44px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    color: #475569;
    font-size: 20px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .ck-mobile-picker-close:active {
    background: #e2e8f0;
  }

  @keyframes ckMobilePickerSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  /* Picker items: larger touch targets */
  .ck-study-item-btn {
    padding: 12px;
    min-height: 48px;
    border-radius: 10px;
  }

  .ck-study-item-title { font-size: 13px; }

  .ck-toc-toggle {
    min-height: 44px;
    padding: 8px 10px;
  }

  .ck-toc-label { font-size: 14px; }

  /* --- Layout: single column --- */
  .ck-study-layout {
    grid-template-columns: 1fr !important;
    gap: 0;
  }

  /* --- Main panel: no border on mobile --- */
  .ck-study-main {
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 8px;
    gap: 8px;
    overflow: hidden; /* clip chessboard coordinate labels */
  }

  .ck-study-panel {
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
  }

  /* --- Board: FULL WIDTH --- */
  .ck-study-board-wrap {
    width: 100% !important;
    max-width: 100vw;
    border-radius: 0;
  }

  .ck-study-app.ck-study-app--legacy .ck-study-board-wrap {
    width: 100% !important;
  }

  /* --- Controls: large touch targets --- */
  .ck-study-controls {
    justify-content: center;
    gap: 6px;
    padding: 6px 4px;
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    margin: 0 4px;
  }

  .ck-study-control-btn {
    min-width: 48px;
    min-height: 48px;
    border-radius: 10px;
    font-size: 14px;
  }

  .ck-study-control-btn[data-study-control="first"],
  .ck-study-control-btn[data-study-control="prev"],
  .ck-study-control-btn[data-study-control="play"],
  .ck-study-control-btn[data-study-control="next"],
  .ck-study-control-btn[data-study-control="last"] {
    width: 48px;
    min-width: 48px;
    font-size: 20px;
  }

  .ck-study-control-btn[data-study-control="theory-prev"],
  .ck-study-control-btn[data-study-control="theory-next"] {
    width: 48px;
    min-width: 48px;
    font-size: 20px;
    margin-left: 0;
  }

  /* Practice mode buttons: full width */
  .ck-study-app.is-practice-mode .ck-study-controls {
    flex-wrap: wrap;
  }

  .ck-study-app.is-practice-mode .ck-study-control-btn[data-study-control="puzzle-answer"],
  .ck-study-app.is-practice-mode .ck-study-control-btn[data-study-control="puzzle-retry"],
  .ck-study-app.is-practice-mode .ck-study-control-btn[data-study-control="puzzle-next"],
  .ck-study-app.is-practice-mode .ck-study-control-btn[data-study-control="puzzle-auto-next"] {
    flex: 1;
    min-width: 0;
    padding: 10px 8px;
    font-size: 13px;
    border-radius: 10px;
  }

  /* --- Mobile Tab Bar (injected via JS) --- */
  .ck-mobile-tab-bar {
    display: flex;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    margin: 8px;
    padding: 4px;
    gap: 4px;
    position: sticky;
    bottom: 0;
    z-index: 40;
  }

  .ck-mobile-tab {
    flex: 1;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #64748b;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 600;
    padding: 10px 6px;
    min-height: 44px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    transition: all 0.15s ease;
  }

  .ck-mobile-tab i {
    font-size: 16px;
  }

  .ck-mobile-tab.is-active {
    background: var(--ck-primary-soft, #e8f2ff);
    color: var(--ck-primary, #0f4f8c);
  }

  .ck-mobile-tab:active {
    transform: scale(0.96);
  }

  /* --- Content sections controlled by mobile tabs --- */
  .ck-study-app.ck-mobile-active .ck-study-content,
  .ck-study-app.ck-mobile-active .ck-study-right,
  .ck-study-app.ck-mobile-active .ck-study-games {
    display: none;
  }

  .ck-study-app.ck-mobile-active .ck-study-content.ck-mobile-visible,
  .ck-study-app.ck-mobile-active .ck-study-right.ck-mobile-visible,
  .ck-study-app.ck-mobile-active .ck-study-games.ck-mobile-visible {
    display: block;
  }

  /* Content panel when visible on mobile */
  .ck-study-content.ck-mobile-visible {
    max-height: none;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px;
    margin: 0 8px 8px;
    background: #fff;
  }

  /* Right panel (move tree / practice) when visible on mobile */
  .ck-study-right.ck-mobile-visible {
    margin: 0 8px 8px;
    border-radius: 12px;
    padding: 12px;
    border: 1px solid #e2e8f0;
    background: #fff;
  }

  /* Games panel when visible on mobile */
  .ck-study-games.ck-mobile-visible {
    margin: 0 8px 8px;
    border-radius: 12px;
    padding: 12px;
    border: 1px solid #e2e8f0;
    background: #fff;
  }

  /* Move tree: taller on mobile */
  .ck-mobile-visible .ck-move-tree {
    max-height: 50vh;
  }

  /* Games grid: more compact */
  .ck-game-list {
    grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
    gap: 6px;
  }

  .ck-game-item {
    padding: 8px 0;
    font-size: 12px;
    min-height: 40px;
  }

  /* --- Practice section mobile --- */
  .ck-practice-question {
    font-size: 14px;
    padding: 12px;
    border-radius: 12px;
  }

  .ck-practice-notice {
    font-size: 13px;
    padding: 10px 12px;
    border-radius: 12px;
  }

  /* Practice controls in right panel */
  .ck-practice-controls-host .ck-study-controls {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* --- Status text --- */
  .ck-study-status {
    padding: 0 4px;
    font-size: 12px;
  }

  /* --- Section titles --- */
  .ck-study-section-title {
    font-size: 14px;
    padding: 0;
  }

  /* --- Bottom safe area for iOS --- */
  .ck-mobile-tab-bar {
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }
}

/* ---------- 4. STUDY VIEWER — PHONE ---------- */

@media (max-width: 480px) {

  .ck-theories-viewer-shell.ck-financial-page {
    padding: 4px 0 0;
  }

  .ck-theories-viewer-shell .ck-financial-header {
    padding: 0 8px;
  }

  .ck-theories-viewer-shell .ck-financial-title {
    font-size: 14px;
    max-width: calc(100vw - 100px);
  }

  .ck-theories-viewer-shell .ck-financial-toolbar {
    margin: 0 6px 6px;
    padding: 6px 8px;
  }

  .ck-theories-btn {
    padding: 6px 8px;
    font-size: 11px;
  }

  /* Top bar ultra compact */
  .ck-study-top { padding: 6px 8px; gap: 6px; }
  .ck-study-title { font-size: 13px; max-width: calc(100vw - 60px); }
  .ck-study-tab-btn { padding: 5px 10px; font-size: 11px; min-height: 32px; }
  .ck-study-breadcrumb { padding: 5px 8px; font-size: 11px; }
  .ck-breadcrumb-item:not(:last-child)::after { margin: 0 4px; }

  /* Board edge-to-edge */
  .ck-study-main { padding: 4px 0; }

  /* Controls tighter */
  .ck-study-controls { margin: 0 2px; gap: 4px; padding: 4px; }

  .ck-study-control-btn,
  .ck-study-control-btn[data-study-control="first"],
  .ck-study-control-btn[data-study-control="prev"],
  .ck-study-control-btn[data-study-control="play"],
  .ck-study-control-btn[data-study-control="next"],
  .ck-study-control-btn[data-study-control="last"] {
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    font-size: 18px;
  }

  /* Mobile tabs smaller */
  .ck-mobile-tab-bar { margin: 4px 6px; padding: 3px; }
  .ck-mobile-tab { font-size: 11px; padding: 8px 4px; min-height: 40px; }
  .ck-mobile-tab i { font-size: 15px; }

  /* Content panels */
  .ck-study-content.ck-mobile-visible,
  .ck-study-right.ck-mobile-visible,
  .ck-study-games.ck-mobile-visible {
    margin: 0 6px 6px;
    padding: 10px;
    border-radius: 10px;
  }

  /* Picker items */
  .ck-study-item-btn { padding: 10px; }
}


/* ==========================================================================
   5. LANDSCAPE PHONE — Board + controls side by side
   ========================================================================== */

@media (max-height: 500px) and (orientation: landscape) {
  .ck-study-main {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto 1fr;
    gap: 8px;
    padding: 8px;
  }

  .ck-study-board-wrap {
    width: min(80vh, 350px) !important;
    max-width: 80vh !important;
    grid-row: 1 / 3;
  }

  .ck-study-controls {
    grid-column: 2;
    grid-row: 1;
    margin: 0;
    flex-direction: row;
    flex-wrap: wrap;
    align-content: start;
  }

  .ck-study-status {
    grid-column: 2;
    grid-row: 2;
  }

  /* Picker: side panel in landscape */
  .ck-study-picker-wrap,
  .ck-study-app.ck-study-app--legacy [data-study-role="picker-wrap"] {
    width: 60% !important;
    left: auto !important;
    right: 0 !important;
    animation: ckMobilePickerSlideRight 0.2s ease-out;
  }

  .ck-mobile-picker-header { width: 60%; left: auto; right: 0; }
}

@keyframes ckMobilePickerSlideRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}


/* ==========================================================================
   6. DARK OVERLAY backdrop for picker on mobile
   ========================================================================== */

@media (max-width: 768px) {
  .ck-mobile-picker-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 9998;
    animation: ckFadeIn 0.15s ease;
  }

  @keyframes ckFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
}


/* ==========================================================================
   7. TOUCH FEEDBACK — Active states for buttons on mobile
   ========================================================================== */

@media (hover: none) and (pointer: coarse) {
  .ck-study-control-btn:active {
    background: #e5e0d9;
    transform: scale(0.94);
    transition: transform 0.08s ease;
  }

  .ck-study-item-btn:active {
    background: #eae5de;
    transform: scale(0.98);
  }

  .ck-study-tab-btn:active {
    transform: scale(0.95);
  }

  .ck-study-menu-toggle:active {
    background: #e5e0d9;
    transform: scale(0.94);
  }

  .tc-open-btn:active {
    background: #1d4ed8;
    transform: scale(0.97);
  }

  .tc-diff-btn:active,
  .tc-theme-chip:active {
    transform: scale(0.95);
  }

  .ck-game-item:active {
    background: #e5e0d9;
    transform: scale(0.94);
  }

  .ck-mobile-tab:active {
    transform: scale(0.93);
  }

  .ck-mobile-picker-close:active {
    background: #e5e0d9;
    transform: scale(0.92);
  }
}


/* ==========================================================================
   8. SCROLLBAR HIDE utility for horizontal scroll areas
   ========================================================================== */

@media (max-width: 768px) {
  .ck-mobile-hscroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .ck-mobile-hscroll::-webkit-scrollbar { display: none; }
}


/* ==========================================================================
   9. HIDE ELEMENTS on mobile that are desktop-only
   ========================================================================== */

@media (max-width: 768px) {
  /* Hide the right sidebar by default when mobile tabs are active */
  .ck-study-app.ck-mobile-active .ck-study-right {
    border: none;
    padding: 0;
    background: transparent;
    margin: 0;
  }

  /* Ensure the board wrap doesn't have weird styles from desktop */
  .ck-study-board-wrap {
    background: transparent;
  }
}


/* ==========================================================================
   10. COURSE DETAIL META — Mobile compact
   ========================================================================== */

@media (max-width: 768px) {
  /* Course detail meta line: wrap and compact */
  .ck-study-meta {
    display: none; /* hidden on mobile - too much info */
  }

  /* Show condensed meta as pills instead if we add them */
  .ck-mobile-meta-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 12px 8px;
  }

  .ck-mobile-meta-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
  }

  .ck-mobile-meta-pill .stars {
    color: #f59e0b;
    letter-spacing: 0.5px;
  }
}

/* Desktop: hide mobile-only elements */
@media (min-width: 769px) {
  .ck-mobile-tab-bar { display: none !important; }
  .ck-mobile-picker-header { display: none !important; }
  .ck-mobile-picker-backdrop { display: none !important; }
  .ck-mobile-meta-pills { display: none !important; }
  .ck-mobile-only { display: none !important; }
}

/* ========================================================================
   Section 11: Admin-style list views (theories, theoriestopics,
               theoriespractices, theory_courses)
   ======================================================================== */

/* --- Tablet / Mobile (≤768px) --- */
@media (max-width: 768px) {
  .schedule-list-container {
    padding: 12px;
    overflow-x: hidden;
  }

  .page-title-row { flex-direction: column; align-items: flex-start; }
  .page-title { font-size: 18px; }

  /* --- Toolbar: stacked --- */
  .toolbar-row {
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
    gap: 10px;
  }
  .toolbar-left,
  .toolbar-right {
    width: 100%;
    flex-wrap: wrap;
  }
  .toolbar-left { gap: 8px; }
  .toolbar-right { gap: 8px; }

  .filter-tab {
    flex: 1;
    justify-content: center;
    min-height: 44px;
    padding: 8px 12px;
  }

  .toolbar-action-btn {
    flex: 1;
    justify-content: center;
    min-height: 44px;
  }

  /* --- Search: full width --- */
  .search-filter-bar {
    flex-direction: column;
    padding: 10px;
    gap: 10px;
  }

  .search-box {
    max-width: 100% !important;
    width: 100%;
  }
  .search-box input {
    font-size: 16px; /* iOS zoom prevention */
    min-height: 44px;
  }

  /* --- TABLE → CARD CONVERSION --- */
  .table-responsive {
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    overflow: visible;
  }

  .schedule-table {
    display: block;
    min-width: 0 !important;
    background: transparent;
  }

  .schedule-table thead { display: none !important; }

  .schedule-table tbody {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .schedule-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    padding: 14px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  }

  .schedule-table tbody tr:hover { background: #f8fafc; }
  .schedule-table tbody tr.trashed { background: #fff5f5; border-color: #fecaca; }
  .schedule-table tbody tr:not(:last-child) td { border-bottom: none; }

  /* Reset all cells */
  .schedule-table tbody td {
    padding: 0;
    border: none;
    text-align: left;
  }

  /* Hide ordering column (drag handle) — !important to override Bootstrap d-sm-table-cell */
  .schedule-table td.order,
  .schedule-table td:first-child {
    display: none !important;
  }

  /* Hide checkbox column */
  .schedule-table td:nth-child(2) {
    display: none !important;
  }

  /* Hide ID column (last) */
  .schedule-table td:last-child {
    display: none !important;
  }

  /* Title column: first row, takes most width */
  .schedule-table td:nth-child(4) {
    order: -1;
    flex: 1 1 calc(100% - 60px);
    min-width: 0;
    font-size: 14px;
  }
  .schedule-table td:nth-child(4) a {
    font-size: 14px !important;
    font-weight: 600 !important;
    color: #1e293b !important;
    line-height: 1.4;
    display: block;
    word-break: break-word;
  }

  /* Status + action: inline next to title */
  .schedule-table td:nth-child(3) {
    order: 0;
    flex-shrink: 0;
    width: auto;
    min-width: auto;
  }

  .schedule-table td:nth-child(3) .ck-status-action {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .schedule-table td:nth-child(3) .ck-action-3dot {
    min-width: 36px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Secondary columns: flow as tags below */
  .schedule-table td:nth-child(n+5):not(:last-child) {
    order: 1;
    font-size: 12px;
    color: #64748b;
  }
  .schedule-table td:nth-child(n+5):not(:last-child) a {
    font-size: 12px !important;
    color: #3b82f6 !important;
  }

  /* Action menu: bottom sheet */
  .schedule-table .ck-action-dropdown { position: relative; }
  .schedule-table .ck-action-menu {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
    max-height: 60vh;
    overflow-y: auto;
    z-index: 1000;
    padding: 8px;
    background: #fff;
  }
  .schedule-table .ck-action-menu::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    margin: 4px auto 8px;
  }
  .schedule-table .ck-menu-item {
    min-height: 48px;
    font-size: 15px;
    border-radius: 10px;
  }

  /* --- Pagination: stacked --- */
  .pagination-footer {
    flex-direction: column;
    gap: 12px;
    text-align: center;
    padding: 16px 12px;
  }
  .pagination-controls { margin-left: 0; justify-content: center; }
  .pagination-info { text-align: center; font-size: 13px; }
  .pagination-limit { justify-content: center; }

  /* Prevent horizontal body overflow */
  .content-body { overflow-x: hidden; }
  aside.sidebar-right { display: none !important; }

  /* Top action dropdown: bottom sheet */
  .action-dropdown-wrapper { position: static; }
  .action-dropdown-menu {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    border-radius: 16px 16px 0 0;
    max-height: 60vh;
    overflow-y: auto;
    z-index: 1000;
    margin-top: 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
    padding: 8px;
  }
  .action-dropdown-menu::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    margin: 4px auto 8px;
  }
  .action-dropdown-item {
    min-height: 48px;
    font-size: 15px;
    border-radius: 10px;
  }
}

/* --- Small phone (≤480px) --- */
@media (max-width: 480px) {
  .schedule-list-container { padding: 8px; }
  .page-title { font-size: 16px; }

  .toolbar-row { padding: 10px; }
  .filter-tab { font-size: 12px; padding: 6px 10px; }
  .toolbar-action-btn { font-size: 12px; padding: 6px 10px; }

  .schedule-table tbody tr { padding: 12px; gap: 4px 8px; }

  .schedule-table td:nth-child(4) a {
    font-size: 13px !important;
  }
  .schedule-table td:nth-child(n+5):not(:last-child) {
    font-size: 11px;
  }

  .pagination-controls .pagination li a,
  .pagination-controls .pagination li span {
    padding: 6px 10px;
    min-width: 32px;
    height: 32px;
    font-size: 12px;
  }

  .pagination-info { font-size: 12px; }
  .pagination-limit select { font-size: 12px; padding: 6px 8px; }
}

/* ==========================================================================
   12. DARK MODE — Touch feedback & mobile overrides
   ========================================================================== */

@media (hover: none) and (pointer: coarse) {
  html[data-theme="dark"] .ck-study-control-btn:active {
    background: #2a3446;
  }
  html[data-theme="dark"] .ck-study-item-btn:active {
    background: #252d3e;
  }
  html[data-theme="dark"] .ck-study-menu-toggle:active {
    background: #2a3446;
  }
  html[data-theme="dark"] .ck-game-item:active {
    background: #2a3446;
  }
  html[data-theme="dark"] .ck-mobile-picker-close:active {
    background: #2a3446;
  }
}

html[data-theme="dark"] .ck-mobile-meta-pill {
  background: #1e2536;
  color: #94a3b8;
  border-color: #303a50;
}

html[data-theme="dark"] .ck-mobile-tab {
  color: #8899a8;
}

html[data-theme="dark"] .ck-mobile-tab.is-active {
  color: #5b9cf5;
  border-color: #5b9cf5;
}
