/* public/css/responsive.css - 關鍵影格動畫與響應式斷點（1080px / 960px / 720px / 480px / reduced-motion） */
/* =========================================================
   動畫、行動端預設控制與響應式設計
   ========================================================= */
@keyframes sweepBar {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(320%); }
}

.inbox-back-btn {
  display: none;
}

.user-menu-mobile-tools {
  display: none;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--cyan-hair);
}

.hud-btn,
.side-nav-btn,
.quick-tab-btn,
.subnav-btn,
.rail-item,
.cal-cell,
.inbox-conv-item,
.user-chip {
  touch-action: manipulation;
}

/* =========================================================
   平板斷點（<= 1080px）：還原自然整頁捲動與單欄主區
   ========================================================= */
@media (max-width: 1080px) {
  html, body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .cool-shell,
  .cool-main-wrap,
  .hud-stage,
  .view-dashboard,
  .view-course,
  .view-calendar,
  .view-inbox,
  .cool-layout,
  .cool-dashboard-main,
  .courses-grid,
  .cool-right-rail,
  .rail-section,
  .rail-list,
  .rail-item,
  .course-workspace,
  .course-tab-content,
  .cal-workspace,
  .cal-main-area,
  .cal-side-panel,
  .cal-grid,
  .cal-weekday,
  .cal-cell,
  .inbox-workspace,
  .inbox-list-pane,
  .inbox-thread-pane,
  .inbox-thread-wrap,
  .inbox-messages,
  .inbox-conv-item,
  .login-layout,
  .login-terminal {
    height: auto;
    min-width: 0;
    max-width: 100%;
    overflow: visible;
  }

  .hud-stage,
  .cool-main-wrap {
    width: 100%;
  }

  .cal-weekday,
  .cal-cell,
  .cal-cell-events,
  .cal-event-pill {
    min-width: 0;
  }

  .cal-cell {
    overflow: hidden;
  }

  /* 平板左側導航列維持固定高度並可獨立捲動，避免隨頁面拉長而滾出視野 */
  .cool-sidebar {
    width: 76px;
    height: 100dvh;
    position: sticky;
    top: 0;
    align-self: flex-start;
    overflow-y: auto;
  }

  .cool-topbar {
    padding: 10px 18px;
  }

  .hud-stage {
    padding: 16px 18px 24px;
  }

  /* 首頁儀表板：主欄單欄 + 右側資訊欄於平板雙欄並排 */
  .cool-layout,
  .login-layout,
  .course-workspace,
  .cal-workspace,
  .inbox-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .cool-layout {
    gap: 18px;
  }

  .courses-grid {
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    padding-right: 0;
  }

  .cool-right-rail {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding-right: 0;
  }

  #panel-announcements {
    grid-column: 1 / -1;
  }

  .rail-list {
    max-height: 300px;
    overflow-x: hidden;
  }

  /* 登入代理視窗高度適配平板 */
  .terminal-frame-wrap iframe {
    min-height: 520px;
    height: 65vh;
  }

  /* 深入課程工作區：COURSE MENU 改為橫向可滑動頁籤列 */
  .course-workspace {
    gap: 14px;
  }

  .course-subnav {
    max-height: none;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
  }

  .course-subnav .hud-header-line {
    display: none;
  }

  .subnav-btn {
    width: auto;
    flex-shrink: 0;
    white-space: nowrap;
    padding: 8px 14px;
  }

  .course-tab-content {
    padding-right: 0;
  }

  /* 行事曆：月曆下方並排顯示當日詳情與課程篩選 */
  .cal-workspace {
    gap: 14px;
  }

  .cal-main-area {
    padding-right: 0;
  }

  .cal-side-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding-right: 0;
  }

  .cal-cell {
    min-height: 92px;
  }

  /* 收件匣：平板上下堆疊並保留內部捲動上限 */
  .inbox-workspace {
    gap: 14px;
  }

  .inbox-list-pane {
    max-height: 320px;
    overflow-y: auto;
  }

  .inbox-messages {
    max-height: 460px;
    overflow-y: auto;
  }
}

/* =========================================================
   中型平板頂部遙測列精簡（<= 960px）
   ========================================================= */
@media (max-width: 960px) {
  .topbar-right .telemetry-pair:first-child,
  .topbar-right .telemetry-divider:nth-child(2),
  .topbar-right .telemetry-pair:nth-child(5),
  .topbar-right .telemetry-divider:nth-child(4) {
    display: none;
  }
}

/* =========================================================
   手機與小平板斷點（<= 720px）：底部全息導航列與單手觸控排版
   ========================================================= */
@media (max-width: 720px) {
  .cool-shell {
    flex-direction: column;
    min-height: 100dvh;
  }

  /* 固定底部 5 鍵導航列（對齊 iOS/Android 安全區） */
  .cool-sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: auto;
    z-index: 45;
    flex-direction: row;
    align-items: stretch;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    gap: 0;
    background: rgba(0, 4, 8, 0.96);
    backdrop-filter: blur(8px);
    border-right: 0;
    border-top: 1px solid var(--cyan-line);
    overflow: visible;
  }

  .sidebar-brand,
  .sidebar-footer {
    display: none;
  }

  .sidebar-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    width: 100%;
    gap: 2px;
  }

  .side-nav-btn {
    width: 100%;
    min-height: 48px;
    padding: 6px 2px;
    gap: 3px;
    font-size: 0.65rem;
    border: 0;
    justify-content: center;
  }

  .side-nav-btn svg {
    width: 19px;
    height: 19px;
  }

  .side-nav-btn span {
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .side-nav-btn.active {
    border: 0;
    box-shadow: inset 0 2px 0 var(--cyan), var(--cyan-glow);
  }

  #btn-open-command span {
    font-size: 0.62rem;
  }

  /* 行動端輔助工具收斂進右上角帳號選單 */
  .user-menu-mobile-tools {
    display: flex;
  }

  .user-menu {
    max-width: calc(100vw - 24px);
  }

  /* 頂部狀態列吸頂精簡化 */
  .cool-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    padding: 8px 12px;
    gap: 8px;
    flex-wrap: nowrap;
  }

  .topbar-left {
    gap: 8px;
    min-width: 0;
  }

  .brand-title {
    font-size: 0.84rem;
    white-space: nowrap;
  }

  .conn-badge {
    padding: 3px 7px;
    font-size: 0.6rem;
    letter-spacing: 0.04em;
  }

  .topbar-right {
    gap: 8px;
    flex-shrink: 0;
  }

  .telemetry-pair,
  .telemetry-divider {
    display: none;
  }

  .user-chip {
    padding: 4px 8px 4px 5px;
    gap: 5px;
  }

  .user-name {
    display: none;
  }

  /* 主舞台為底部導航列保留安全空間 */
  .hud-stage {
    padding: 12px 12px calc(76px + env(safe-area-inset-bottom));
  }

  /* 側滑課程抽屜 */
  .course-drawer {
    left: 0;
    z-index: 60;
  }

  .course-drawer-panel {
    width: min(320px, 86vw);
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  }

  /* 避免 iOS Safari 聚焦表單時自動放大畫面 */
  .hud-input,
  .hud-select,
  .hud-textarea,
  .cmd-input {
    font-size: 16px;
  }

  /* 登入頁面 */
  .boot-card {
    padding: 20px;
  }

  .login-brief {
    padding: 16px;
  }

  .login-title {
    font-size: 1.18rem;
  }

  .terminal-bar {
    gap: 8px;
  }

  .terminal-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .terminal-frame-wrap iframe {
    min-height: 440px;
    height: 58dvh;
  }

  /* 首頁儀表板 */
  .dash-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .dash-title-wrap {
    min-width: 0;
  }

  .dash-title {
    font-size: 1.3rem;
  }

  .telemetry-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stat-chip {
    justify-content: space-between;
    padding: 6px 10px;
  }

  .course-toolbar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
    gap: 8px;
  }

  .toolbar-left {
    width: 100%;
    justify-content: space-between;
  }

  .toolbar-left .hud-select {
    flex: 1;
    min-width: 0;
  }

  #filter-search {
    width: 100%;
  }

  .courses-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
  }

  .quick-tab-btn {
    min-height: 38px;
    font-size: 0.75rem;
  }

  .cool-right-rail {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .rail-section {
    padding: 12px;
  }

  .rail-list {
    max-height: 340px;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .rail-item .item-title,
  .inbox-conv-item .item-title {
    overflow-wrap: anywhere;
  }

  .rail-item .item-sub,
  .inbox-conv-item .item-sub {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* 深入課程工作區 */
  .course-topbar {
    padding: 10px 12px;
    gap: 10px;
  }

  .course-topbar-left {
    width: 100%;
    align-items: flex-start;
    gap: 8px;
  }

  .course-topbar-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .course-view-title {
    font-size: 1.05rem;
    line-height: 1.35;
  }

  .module-toolbar,
  .file-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .file-search-input {
    width: 100%;
    flex-basis: 100%;
  }

  .module-card {
    padding: 10px 12px;
  }

  .module-item {
    flex-wrap: wrap;
    gap: 6px 8px;
    padding: 10px;
  }

  .module-item-hint {
    width: 100%;
    font-size: 0.7rem;
  }

  .course-row-card {
    padding: 12px 14px;
  }

  .file-row {
    padding: 10px 12px;
  }

  .grade-table {
    min-width: 500px;
  }

  /* 行事曆：精簡月曆色帶與單欄當日詳情 */
  .cal-topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .cal-nav-group,
  .cal-mode-group {
    width: 100%;
    justify-content: space-between;
  }

  .cal-month-title {
    width: 100%;
    margin: 2px 0 0;
    text-align: center;
    font-size: 0.98rem;
  }

  .cal-grid {
    width: 100%;
    table-layout: fixed;
  }

  .cal-weekday {
    padding: 6px 1px;
    font-size: 0.6rem;
    letter-spacing: 0.02em;
  }

  .cal-cell {
    min-height: 58px;
    padding: 4px 2px;
    gap: 3px;
  }

  .cal-cell-head {
    min-width: 0;
    gap: 2px;
  }

  .cal-day-num {
    font-size: 0.7rem;
  }

  .cal-day-badge {
    font-size: 0.54rem;
    padding: 0 2px;
    flex-shrink: 0;
  }

  .cal-cell-events {
    width: 100%;
    min-width: 0;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 2px;
  }

  .cal-event-pill {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: 5px;
    padding: 0;
    font-size: 0;
    line-height: 0;
    color: transparent;
    border-left-width: 3px;
  }

  .cal-more {
    display: none;
  }

  .cal-side-panel {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  /* 收件匣：Master-Detail 切換模式 */
  .inbox-topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .inbox-scope-group {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .inbox-scope-group .hud-btn {
    flex-shrink: 0;
    white-space: nowrap;
  }

  .inbox-actions-group {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  #inbox-course-filter,
  .addressbook-anchor {
    grid-column: 1 / -1;
    width: 100%;
  }

  .inbox-search-combo {
    width: 100%;
  }

  #inbox-search {
    flex: 1;
    min-width: 0;
  }

  .inbox-list-pane {
    max-height: none;
    overflow: visible;
  }

  .inbox-thread-pane {
    display: none;
  }

  .inbox-workspace.is-thread-open .inbox-list-pane {
    display: none;
  }

  .inbox-workspace.is-thread-open .inbox-thread-pane {
    display: flex;
  }

  .inbox-back-btn {
    display: inline-flex;
    margin-bottom: 6px;
  }

  .inbox-thread-head {
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
  }

  .inbox-thread-subject,
  .inbox-thread-head .modal-meta {
    overflow-wrap: anywhere;
  }

  .inbox-thread-tools {
    justify-content: flex-start;
  }

  .inbox-messages {
    max-height: none;
    padding: 12px;
  }

  .inbox-reply-box {
    padding: 10px 12px 12px;
  }

  .inbox-reply-actions {
    flex-wrap: wrap;
  }

  .addressbook-menu {
    max-width: calc(100vw - 24px);
  }

  /* 共用 Modal、文件解析引擎與作業繳交 */
  .hud-modal {
    padding: 8px;
  }

  .hud-modal-dialog {
    max-height: 94dvh;
  }

  .modal-xl {
    height: 92dvh;
  }

  .modal-cmd {
    margin-top: 3vh;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 12px 14px;
  }

  .modal-header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .modal-footer {
    flex-wrap: wrap;
  }

  .doc-stage {
    height: min(62dvh, 480px);
    padding: 8px;
  }

  .doc-pdf-page-wrap {
    padding: 6px;
    max-width: 100%;
  }

  .doc-pdf-canvas {
    max-width: 100%;
    height: auto !important;
  }

  .doc-sheet-search {
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  .doc-cool-video-iframe {
    height: 50vh;
  }

  .assign-status-box,
  .assign-submit-box {
    padding: 12px;
  }

  .assign-dropzone {
    padding: 16px 12px;
  }

  .assign-inline-comment,
  .assign-file-row {
    flex-direction: column;
    align-items: stretch;
  }

  .assign-file-actions {
    justify-content: flex-end;
  }
}

/* =========================================================
   小手機斷點（<= 480px）：單欄課程網格與超窄寬度收斂
   ========================================================= */
@media (max-width: 480px) {
  .courses-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .brand-title {
    font-size: 0.78rem;
  }

  .brand-title .accent {
    display: none;
  }

  .recipient-input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .compose-discard-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* =========================================================
   PWA Standalone 模式安全區適配（iOS 動態島／瀏海與橫向邊距）
   ========================================================= */
@media (display-mode: standalone) {
  .cool-topbar {
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-left: calc(24px + env(safe-area-inset-left));
    padding-right: calc(24px + env(safe-area-inset-right));
  }
}

@media (display-mode: standalone) and (min-width: 721px) {
  .cool-sidebar {
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-left: calc(6px + env(safe-area-inset-left));
  }
}

@media (display-mode: standalone) and (max-width: 720px) {
  .cool-topbar {
    padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 8px calc(12px + env(safe-area-inset-left));
  }
}
