/* Shared tablet and touch adaptations, loaded after page-specific styles. */
:root { --touch-target: 44px; }
html { scroll-padding-top: 90px; scroll-padding-bottom: 24px; }

button, a, input, select, textarea, summary { -webkit-tap-highlight-color: rgba(0, 117, 222, .14); }
button, a, summary { touch-action: manipulation; }
:is(button, a, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid #0075de;
    outline-offset: 3px;
}
.dashboard-menu-toggle { display: none; }
.table-responsive, .dashboard-table-wrap, .batch-table-wrap {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

@media (max-width: 1100px), (any-pointer: coarse) {
    .btn-notion, .btn-notion.btn-sm, .dashboard-btn, .dashboard-settings-tab,
    .tab-notion, .media-more summary, .dashboard-modal-close, .btn-close {
        min-height: var(--touch-target);
        min-width: var(--touch-target);
        box-sizing: border-box;
    }
    .btn-notion, .btn-notion.btn-sm { padding: 10px 12px; }
    .input-notion, .input-sm, .dashboard-input, .dashboard-select,
    .dashboard-textarea, .form-control, .form-select, textarea, [contenteditable="true"] {
        font-size: 16px !important;
        line-height: 1.5;
    }
    input.input-notion, input.input-sm, select.input-sm, .dashboard-input,
    .dashboard-select, .form-control, .form-select { min-height: var(--touch-target); }
    textarea, .dashboard-textarea { min-height: 100px; }
    .form-check, .radio-pill, .checkbox-pill { min-height: var(--touch-target); align-content: center; }
    .form-check label { padding: 10px 4px; }
    .choice-chip label { min-height: 44px; box-sizing: border-box; }
    .choice-chip input:focus-visible + label { outline: 3px solid #0075de; outline-offset: 3px; }
    .student-chip button { min-height: 36px; min-width: 36px; font-size: 18px; }
    .record-checkbox { width: 28px; height: 28px; }
    .multi-select-checkbox { width: 44px; height: 44px; display: grid; place-items: center; }
    .record-card .actions-compact { flex-wrap: wrap; overflow: visible; gap: 6px; }
    .record-card [onclick].badge-notion { min-height: 36px; padding: 8px 12px; }
    .filter-suggestion-item, .tag-suggestion-item, .tags-suggestion-item, .student-suggestion-item {
        min-height: var(--touch-target);
        padding: 12px !important;
        box-sizing: border-box;
    }
    .filter-suggestions, .tag-suggestions, .tags-suggestions, .student-suggestions {
        max-height: min(320px, 40dvh);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .tag-item .remove-tag { min-width: 36px; min-height: 36px; font-size: 16px; }
    .media-file-row { gap: 12px; padding: 12px 0; }
    .media-file-row button { min-width: 44px; min-height: 44px; }
    .media-file-name { font-size: 15px; }
    .media-file-info small { font-size: 13px; }
    .flatpickr-calendar .flatpickr-day { min-height: 40px; line-height: 40px; }
    .flatpickr-calendar .flatpickr-prev-month, .flatpickr-calendar .flatpickr-next-month { padding: 12px; }
    .service-option:hover, .dashboard-settings-card:hover { transform: none; }
    .modal-dialog { margin: 16px auto; width: calc(100% - 32px); }
    .modal-content { max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); }
    .modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
    .modal-footer { gap: 8px; flex-wrap: wrap; }
    .dashboard-modal { max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); }
    .record-media-player.video-js .vjs-control-bar { overflow-x: auto; }
}

@media (max-width: 1100px), (max-width: 1400px) and (any-pointer: coarse) {
    .container-notion { padding: 24px 20px; }
    .nav-notion {
        height: auto;
        min-height: 60px;
        gap: 8px;
        flex-wrap: wrap;
        padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
    }
    .nav-notion .brand { min-height: 44px; }
    .tabs-notion { gap: 20px; overflow-x: auto; align-items: center; }
    .tabs-notion > * { flex-shrink: 0; white-space: nowrap; }
    #index-main-content > .d-flex, #batch-operations > .card-notion,
    #batch-operations > .card-notion > .d-flex, .record-action-footer,
    .record-action-footer > .d-flex { flex-wrap: wrap; gap: 12px; }
    .container-notion > .mb-5.d-flex { align-items: flex-start !important; flex-wrap: wrap; gap: 16px; }
    .record-detail-title { font-size: 28px; overflow-wrap: anywhere; }
    .record-meta-grid { gap: 8px 12px; }
    .grid-notion { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
    .dashboard-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
    .dashboard-sidebar {
        position: static;
        height: auto;
        padding: 12px 20px;
        border-right: 0;
        border-bottom: 1px solid var(--dashboard-border);
    }
    .dashboard-sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
    .dashboard-sidebar .dashboard-brand { margin-bottom: 0; font-size: 18px; }
    .dashboard-sidebar .dashboard-brand small { display: none; }
    .dashboard-menu-toggle { display: inline-flex; }
    .dashboard-sidebar .dashboard-nav { margin-top: 12px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
    .dashboard-sidebar .dashboard-nav[hidden] { display: none; }
    .dashboard-nav a { min-height: 44px; padding: 10px; }
    .dashboard-main { padding: 24px 20px; }
    .dashboard-topbar { gap: 16px; flex-wrap: wrap; }
    .dashboard-title { font-size: 28px; }
    .dashboard-grid, .dashboard-grid[style] { grid-template-columns: minmax(0, 1fr) !important; }
    .dashboard-stats, .dashboard-stats-analytics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-analytics-grid, .dashboard-dual-panels { grid-template-columns: minmax(0, 1fr); }
    .dashboard-filter-field { min-width: min(220px, 100%); flex: 1 1 220px; }
    .dashboard-settings-grid { grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
    .dashboard-login { min-height: 100dvh; padding: 20px; box-sizing: border-box; }
    .dashboard-login-card { width: 100%; max-width: 480px; box-sizing: border-box; }
    .export-layout { grid-template-columns: minmax(0, 1fr); }
    .export-queue { max-height: 240px; }
    .process-container { padding: 24px 20px; }

    /* Each course becomes a labeled form instead of a wide spreadsheet. */
    .batch-table-wrap { overflow: visible; border: 0; }
    .batch-table { display: block; min-width: 0; width: 100%; }
    .batch-table thead { display: none; }
    .batch-table tbody { display: grid; gap: 16px; }
    .batch-table tbody tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 16px;
        padding: 20px;
        border: 1px solid rgba(0,0,0,.12);
        border-radius: 12px;
        background: #fff;
    }
    .batch-table tbody td { display: block; width: auto; padding: 0; border: 0; min-width: 0; }
    .batch-table tbody td::before { content: attr(data-label); display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--warm-gray-500); }
    .batch-table td.col-idx { grid-column: 1 / -1; text-align: left; }
    .batch-table td.col-idx::before, .batch-table td.col-action::before { display: none; }
    .batch-table td.col-url, .batch-table td.col-notes { grid-column: 1 / -1; }
    .batch-table td.col-action { justify-self: end; grid-column: 1 / -1; }
    .batch-table td.is-inactive { display: none; }
    .batch-table #batch-tbody tr .row-num::before { content: '课程 ' counter(row-counter); font-size: 16px; color: var(--notion-black); }
    .batch-table .row-error-msg, .batch-table .row-success-msg { font-size: 14px; white-space: normal; overflow-wrap: anywhere; }
    .batch-table .row-success-msg a { display: inline-flex; align-items: center; min-height: 44px; }
    .batch-table .audio-file-wrap > .btn-notion { height: auto !important; font-size: 14px !important; }
    .batch-toolbar { gap: 12px; }
}

@media (max-width: 600px) {
    .container-notion, .dashboard-main { padding: 16px 12px; }
    .nav-notion .brand { flex-basis: 100%; }
    .nav-notion > div[style*="flex-grow"] { display: none; }
    .nav-notion > .btn-notion { flex: 1; }
    .record-meta-grid { grid-template-columns: minmax(0, 1fr); }
    .dashboard-sidebar { padding: 12px; }
    .dashboard-sidebar .dashboard-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-title, .record-detail-title { font-size: 24px; }
    .dashboard-card, .dashboard-form-card, .dashboard-filter-bar { padding: 16px; }
    .dashboard-stat-value { font-size: 28px; }
    .dashboard-settings-tabs { width: 100%; box-sizing: border-box; }
    .dashboard-settings-tab { flex: 1 1 auto; justify-content: center; }
    .batch-table tbody tr { grid-template-columns: minmax(0, 1fr); padding: 16px; }
    .batch-table tbody td { grid-column: 1; }
    .batch-toolbar #btn-submit { flex: 1; }
    .progress-row { flex-wrap: wrap; }
    .upload-area-dashed { padding: 24px 16px; }
    .modal-dialog { margin: 8px; width: calc(100% - 16px); }
    .modal-content { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); }
    .modal-body.p-5 { padding: 20px !important; }
    #analysis-result-editor { min-height: 240px !important; overflow-wrap: anywhere; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0s !important; animation-duration: 0s !important; }
}
