/* Phone-only layout/navigation tweaks (<= 720px)
   Remove the `<link href="./src/styles/phone.css">` from `index.html` to revert. */

.mobile-menu-only {
  display: none;
}

@media (max-width: 720px) {
  html,
  body {
    overflow-x: hidden;
  }

  body {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-top: 12px;
    padding-bottom: 16px;
  }

  .app {
    width: calc(100vw - 24px);
    margin: 0 auto;
    border-radius: 16px;
    max-height: none;
  }

  *,
  *::before,
  *::after {
    box-sizing: border-box;
    max-width: 100%;
  }

  .mobile-menu-only {
    display: block;
  }

  /* Move primary navigation into the ... menu */
  .header-actions .view-toggle,
  .header-actions #quickJumpDropdown {
    display: none;
  }

  /* Keep the ... menu inline with the confidence toggle (same row / same height). */
  .header-actions {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 8px;
  }

  .header-menu {
    position: relative;
    top: auto;
    right: auto;
    z-index: 2;
  }

  .header-row {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .header-main h1 {
    font-size: 22px;
    margin-bottom: 2px;
  }

  .header-main .subtitle {
    display: none;
  }

  /* Hide "maximize" controls on phone */
  .section-max-btn,
  .today-maximize-btn {
    display: none !important;
  }

  .top-row .summary-card {
    padding: 12px;
  }

  .top-row .summary-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 10px;
  }

  .top-row .focus-card {
    padding: 12px;
  }

  /* Keep subjects after stats */
  #layoutRow .main-area {
    order: 2;
  }

  /* Hide Today's focus by default on phone */
  #layoutRow {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  /* Mode routing (index.html?mode=...) */
  body[data-mode="board"] #layoutRow {
    display: flex !important;
  }

  body[data-mode="board"] #layoutRow .main-area {
    display: block !important;
    width: 100%;
  }

  body[data-mode="board"] #layoutRow .today-sidebar,
  body[data-mode="board"] #scheduleView {
    display: none !important;
  }

  body[data-mode="subjects"] .summary-card,
  body[data-mode="subjects"] .focus-card,
  body[data-mode="subjects"] #scheduleView,
  body[data-mode="subjects"] #layoutRow .today-sidebar {
    display: none !important;
  }

  body[data-mode="subjects"] .top-row {
    display: none !important;
  }

  /* Subject paging (single subject per screen) */
  body[data-mode="subjects"] .subject-nav-btn,
  body[data-mode="subjects"] .subject-nav-label {
    display: inline-flex;
  }

  body[data-mode="subjects"] #subjectBackBtn {
    display: none;
  }

  .subject-nav-btn,
  .subject-nav-label {
    display: none;
  }

  body[data-mode="subjects"] .table-wrapper {
    overflow: hidden;
  }

  body[data-mode="subjects"] .subject-scroll {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
  }

  body[data-mode="subjects"] .section-heading {
    min-width: 0;
    width: 100%;
    flex-wrap: wrap;
    position: sticky;
    top: 8px;
    background: var(--surface-soft);
    z-index: 3;
    padding-bottom: 6px;
  }

  body[data-mode="subjects"] .section-subtitle {
    display: none;
  }

  body[data-mode="subjects"] .section-actions {
    position: static;
    right: auto;
    top: auto;
    padding-left: 0;
    background: transparent;
  }

  body[data-mode="subjects"] .subject-table {
    display: flex;
    flex-direction: row;
    width: 100%;
    gap: 0;
    background: transparent;
    transform: translateX(calc(var(--subject-page, 0) * -100%));
    transition: transform 0.22s ease;
    will-change: transform;
  }

  body[data-mode="subjects"] .subject-column {
    min-width: 100%;
    max-width: 100%;
  }

  .subject-nav-btn {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid #dfe4f0;
    background: #ffffff;
    color: var(--accent-ink);
    cursor: pointer;
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 18px;
    font-weight: 800;
  }

  .subject-nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .subject-nav-label {
    height: 34px;
    min-width: 56px;
    border-radius: 10px;
    border: 1px solid #dfe4f0;
    background: #ffffff;
    color: var(--ink-muted);
    font-weight: 800;
    font-size: 12px;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.06);
  }

  body[data-mode="today"] .summary-card,
  body[data-mode="today"] .focus-card,
  body[data-mode="today"] #scheduleView,
  body[data-mode="today"] #layoutRow .main-area {
    display: none !important;
  }

  body[data-mode="today"] .top-row {
    display: none !important;
  }

  body[data-mode="today"] #layoutRow .today-sidebar {
    display: block !important;
  }

  body[data-mode="today"] #todayDropZone {
    display: none !important;
  }

  body[data-mode="today"].today-picker-open #layoutRow .today-sidebar {
    display: none !important;
  }

  body[data-mode="today"].today-picker-open #layoutRow .main-area {
    display: block !important;
  }

  body[data-mode="today"].today-picker-open #layoutRow {
    gap: 10px;
  }

  /* In picker mode, behave like Subjects paging UI */
  body[data-mode="today"].today-picker-open .subject-nav-btn,
  body[data-mode="today"].today-picker-open .subject-nav-label {
    display: inline-flex;
  }

  body[data-mode="today"].today-picker-open #subjectBackBtn {
    display: inline-flex;
  }

  body[data-mode="today"].today-picker-open .table-wrapper {
    overflow: hidden;
  }

  body[data-mode="today"].today-picker-open .subject-scroll {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
  }

  body[data-mode="today"].today-picker-open .section-heading {
    min-width: 0;
    width: 100%;
    flex-wrap: wrap;
    position: sticky;
    top: 8px;
    background: #f8fafc;
    z-index: 3;
  }

  body[data-mode="today"].today-picker-open .section-subtitle {
    display: none;
  }

  body[data-mode="today"].today-picker-open .section-actions {
    position: static;
    right: auto;
    top: auto;
    padding-left: 0;
    background: transparent;
  }

  body[data-mode="today"].today-picker-open .subject-table {
    display: flex;
    flex-direction: row;
    width: 100%;
    gap: 0;
    background: transparent;
    transform: translateX(calc(var(--subject-page, 0) * -100%));
    transition: transform 0.22s ease;
    will-change: transform;
  }

  body[data-mode="today"].today-picker-open .subject-column {
    min-width: 100%;
    max-width: 100%;
  }

  body[data-mode="today"].today-picker-open .chip-btn.chip-btn-primary {
    white-space: nowrap;
  }

  body[data-mode="today"] .today-header {
    align-items: center;
  }

  body[data-mode="today"] #todayPickerBackBtn {
    padding: 10px 12px;
  }

  body[data-mode="today"].today-picker-open .file-row.in-today {
    background: #dcfce7;
    border-color: #22c55e;
  }

  body[data-mode="today"] #layoutRow .today-sidebar .today-section {
    width: 100%;
  }

  body[data-mode="schedule"] .summary-card,
  body[data-mode="schedule"] .focus-card,
  body[data-mode="schedule"] #layoutRow {
    display: none !important;
  }

  body[data-mode="schedule"] .schedule-subtitle {
    display: none;
  }

  body[data-mode="schedule"] .schedule-grid {
    grid-template-columns: 1fr;
  }

  body[data-mode="schedule"] .schedule-focus-chip {
    max-width: 100%;
  }

  body[data-mode="today"] .today-actions {
    min-width: 0;
    max-width: none;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

/* Phone-only: stack focus + daily stats vertically. */
@media (max-width: 720px) and (hover: none) and (pointer: coarse) {
  /* Reorder top row: Focus first, stats second */
  .top-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .top-row .focus-card {
    order: 0;
  }

  .top-row .summary-card {
    order: 1;
  }
}
