/* ===========================================================================
   v7-responsive.css — loads LAST. Two jobs:
     1. On mobile the header keeps EVERY item on ONE single row (never wraps
        onto a second line): brand on the left, the action buttons on the
        right, all scaled down to fit even a 320px screen.
     2. A final responsiveness sweep so no page of the portal can overflow
        sideways, and every grid, table, form, modal and toolbar reflows.
   Desktop is untouched: every rule lives inside a media query.
   ========================================================================= */

/* -------------------------------------------------------------------------
   1. SINGLE-ROW MOBILE HEADER
   ------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .topfix > .header,
  .header.header-wrap,
  .header {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    row-gap: 0 !important;
    gap: 6px !important;
    padding: 8px 10px !important;
    min-width: 0;
  }

  .header .header-left {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center;
    gap: 6px;
    overflow: hidden;
  }

  .header .header-right {
    flex: 0 0 auto !important;
    width: auto !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center;
    justify-content: flex-end !important;
    gap: 4px;
  }

  /* the brand can shrink and truncate — it must never push buttons down */
  .header .header-brand {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
  }
  .header .header-brand .title,
  .header .title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.95rem !important;
    max-width: 40vw;
  }
  .header .brand-logo {
    flex: 0 0 auto;
    height: 30px !important;
    width: auto !important;
  }
  .header .menu-btn {
    flex: 0 0 auto;
    font-size: 1.15rem !important;
    padding: 4px 8px !important;
  }

  /* compact action buttons so the whole row fits */
  .header .header-right .btn,
  .header .header-right .theme-btn,
  .header .header-right .lang-btn {
    flex: 0 0 auto;
    padding: 6px 9px !important;
    font-size: 0.78rem !important;
    white-space: nowrap;
    line-height: 1.1;
  }
  .header .header-right .pill {
    display: none !important; /* the long "Name · Role" chip never fits */
  }
}

@media (max-width: 480px) {
  .header .header-brand .title,
  .header .title {
    max-width: 32vw;
    font-size: 0.85rem !important;
  }
  .header .brand-logo {
    height: 26px !important;
  }
  .header .header-right .btn,
  .header .header-right .theme-btn,
  .header .header-right .lang-btn {
    padding: 5px 7px !important;
    font-size: 0.72rem !important;
  }
  .header .header-right .lang-btn .lang-code {
    display: none;
  } /* keep just the globe */
}

@media (max-width: 360px) {
  .header .header-brand .title,
  .header .title {
    max-width: 26vw;
  }
  .header .header-right .btn-gold {
    font-size: 0.68rem !important;
    padding: 5px 6px !important;
  }
}

/* -------------------------------------------------------------------------
   2. FINAL SITE-WIDE RESPONSIVENESS SWEEP
   ------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .content,
  .main,
  .page,
  .container,
  .wrap {
    max-width: 100%;
    min-width: 0;
  }
  .two-col,
  .split,
  .row-2,
  .flex-row {
    flex-wrap: wrap;
  }
}

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

  /* every layout grid collapses gracefully */
  [class*="grid-"],
  .grid,
  .cards,
  .tiles,
  .stat-cards,
  .summary-grid,
  .dash-grid,
  .qb-grid,
  .rc-grid {
    grid-template-columns: 1fr !important;
  }

  /* tables scroll horizontally instead of breaking the page */
  .table-wrap,
  .table-responsive,
  .scroll-x,
  .card > table,
  .panel > table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table {
    min-width: 0;
  }
  table th,
  table td {
    white-space: nowrap;
  }

  /* forms stack, inputs stay tappable */
  form .row,
  .form-row,
  .filters,
  .filter-bar,
  .toolbar,
  .actions,
  .btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  input,
  select,
  textarea {
    max-width: 100%;
    font-size: 16px; /* stops iOS zooming on focus */
  }
  .btn {
    min-height: 40px;
  }

  /* dialogs, popovers and the AI assistant stay inside the viewport */
  .modal,
  .modal-box,
  .popup,
  .drawer,
  .ai-panel,
  .lang-menu {
    max-width: calc(100vw - 20px) !important;
  }

  /* toolbars on the result sheet / transcript wrap neatly */
  .rs-toolbar,
  .rs-toolbar-actions,
  .tr-toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .rs-toolbar-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}

@media (max-width: 560px) {
  .card,
  .panel,
  .box {
    padding: 12px !important;
    border-radius: 12px;
  }
  h1 {
    font-size: 1.35rem !important;
  }
  h2 {
    font-size: 1.15rem !important;
  }
  h3 {
    font-size: 1rem !important;
  }
  .bhv-upload {
    grid-template-columns: 1fr !important;
  }
  .qb-subjects,
  .qb-chips {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
  }
  .qb-chip {
    white-space: nowrap;
  }
}
