/* Shared responsive overrides for the PBD Tuning Control Center.
   Loaded on every page AFTER that page's own inline <style> block, so these rules win
   ties on identical selectors without needing !important. Desktop layout is untouched --
   everything here is scoped inside a max-width media query.

   Wide data tables (Tunes in Progress, New Tunes, Master Mod List, Customer Database,
   the pipeline report, Customer Detail) use stacked cards on mobile: add class="mobile-cards"
   to the <table> and data-label="..." to every <td> (matching its header text), and the
   rules below turn each row into a bordered card with the first column as a dark title bar
   and every other column shown as a labeled line. No horizontal or nested vertical scroll. */

/* Desktop-default look for the auto-injected account menu: identical to the old flat
   "email  Sign out" row (trigger hidden, panel always visible as a plain row). The
   media query below turns the trigger into a small icon button and the panel into a
   dropdown on mobile. */
.user-menu { display: flex; align-items: center; gap: 10px; position: relative; }
.user-menu-btn { display: none; }
.user-menu-panel { display: flex; align-items: center; gap: 10px; }

@media (max-width: 760px) {

  html { -webkit-text-size-adjust: 100%; }

  body { font-size: 16px; }

  /* --- Top navigation ---
     Title and the compact user controls (bell + account menu) share one row, same as
     desktop -- only the nav links drop to their own full-width row below. Saves both
     vertical and horizontal space instead of stacking everything into three rows. */
  .topnav {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    gap: 8px;
  }
  .topnav-title { order: 1; }
  .topnav-title .title-text {
    font-size: 14px;
    padding-left: 8px;
  }
  .topnav-title .version { display: none; }
  .topnav-title img { height: 28px; }
  /* Uniform grid of equal-size cells, text centered, regardless of label length --
     transparent (no button chrome), just evenly-sized plain links in neat rows.
     flex-basis 100% forces this onto its own full-width row below title+user. */
  .topnav-links {
    order: 3;
    flex: 1 1 100%;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
  .topnav-links a {
    font-size: 12.5px;
    padding: 9px 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 38px;
    background: transparent;
    border: none;
    border-radius: 6px;
    box-sizing: border-box;
  }
  .topnav-links a.active {
    background: rgba(165, 40, 60, 0.35);
  }
  /* With 7 links in a 3-column grid the last one would sit alone in its row --
     span it full width instead so the last row still reads as a clean, even line. */
  .topnav-links a:last-child:nth-child(3n+1) {
    grid-column: 1 / -1;
  }
  .topnav-user {
    order: 2;
    width: auto;
    justify-content: flex-end;
    font-size: 14px;
    gap: 8px;
  }
  .topnav-user span#pbdAuthEmail {
    max-width: 38vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topnav-user button {
    font-size: 14px;
    padding: 7px 14px;
  }

  /* --- Page layout --- */
  .page-wrap {
    padding: 0.85rem;
    max-width: 100%;
  }
  h1 { font-size: 19px; }

  /* --- Filter bars / toolbars --- */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px;
    gap: 8px;
  }
  .filter-field { width: 100%; }
  .filter-field input,
  .filter-field select {
    min-width: 0;
    width: 100%;
    font-size: 16px; /* prevents iOS auto-zoom on focus */
    padding: 8px;
  }
  .filter-clear { align-self: stretch; text-align: center; padding: 9px 12px; }

  /* --- Cards / sections --- */
  .card-header, .section-header {
    padding: 13px 15px;
  }
  .card-header h1, .card-header h2, .section-header h2 {
    font-size: 18px;
  }
  .card-body, .section-body {
    padding: 14px 15px 16px;
  }
  .field-row { gap: 14px; }
  .field { min-width: 46%; }

  /* --- Forms --- */
  .edit-form {
    grid-template-columns: 1fr !important;
  }
  .edit-form input, .edit-form select {
    font-size: 16px;
  }
  .edit-actions { flex-wrap: wrap; }

  /* --- Buttons: comfortable tap targets --- */
  .btn, .filter-clear, .copy-btn, .back-link {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .mark-btn, .escalate-btn {
    width: 100%;
    padding: 10px 0;
    font-size: 14.5px;
  }
  .action-cell { width: 100%; }

  /* --- Tables without the cards treatment yet: scroll sideways as a fallback --- */
  .card-body, .section-body {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table {
    table-layout: auto !important;
    min-width: 640px;
    font-size: 14.5px;
  }
  th, td {
    padding: 9px 10px;
    white-space: nowrap;
  }
  /* Customer/note cells tend to hold longer free text -- let those wrap so the scroll
     width stays reasonable instead of one column stretching the whole table out. */
  td .customer-cell, td .problem-note, td .escalation-note {
    white-space: normal;
  }

  /* --- Tables with the cards treatment: table.mobile-cards + data-label on every <td> ---
     Each row becomes a bordered card; the first column is a dark title bar, every other
     column shows as "LABEL   value" using the data-label attribute. Higher specificity
     (class selector) than the plain `table` rules above, so no min-width/scroll applies. */
  table.mobile-cards, table.mobile-cards tbody, table.mobile-cards tr {
    display: block;
    width: 100%;
    min-width: 0;
  }
  table.mobile-cards thead { display: none; }
  table.mobile-cards tr {
    border: 1px solid #d3d3d3;
    border-radius: 10px;
    margin-bottom: 12px;
    background: #ffffff;
    overflow: hidden;
  }
  table.mobile-cards td {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 9px 14px;
    border: none;
    border-bottom: 1px solid #f0f0f0;
    white-space: normal;
    font-size: 14.5px;
  }
  table.mobile-cards tr td:last-child { border-bottom: none; }
  table.mobile-cards td::before {
    content: attr(data-label);
    flex: 0 0 92px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: #8a8a8a;
  }
  table.mobile-cards td:first-child {
    background: #101010;
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    padding: 13px 14px;
  }
  table.mobile-cards td:first-child::before { display: none; }
  table.mobile-cards td:first-child a { color: #ffffff; }

  /* --- Compact account menu (email + sign out combined into a dropdown) ---
     Auto-injected by notifications.js around every page's #pbdAuthEmail + sign-out
     button, so no per-page HTML changes are needed. Base rule below (outside this
     media query) keeps desktop looking exactly like the old flat row. */
  .user-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    background: transparent;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    color: #f0f0f0;
    padding: 6px 10px;
    cursor: pointer;
  }
  .user-menu-panel {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #1c1c1c;
    border: 1px solid #2e2e2e;
    border-radius: 8px;
    padding: 12px 14px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    min-width: 170px;
    z-index: 30;
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  }
  .user-menu-panel.open { display: flex; }
  .user-menu-panel span#pbdAuthEmail {
    max-width: none;
    white-space: normal;
    word-break: break-all;
    font-size: 13px;
  }
  .user-menu-panel button { width: 100%; }

  /* --- Login / forgot-password / reset-password centered cards --- */
  .login-card {
    max-width: 92vw;
    padding: 26px 20px;
  }
  .ff input { font-size: 16px; } /* prevents iOS auto-zoom on focus */

  /* --- Escalation list cards (customer-detail.html) --- */
  .escalation-top { flex-direction: column; align-items: stretch; }
  .escalation-order { margin-left: 0; margin-top: 2px; }

  /* --- Home page (index.html) --- */
  .home-wrap { padding: 1.5rem 1rem; }
  .home-header h1 { font-size: 22px; }
  .btn-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .big-btn { padding: 16px 12px; border-radius: 12px; }
  .big-btn .icon { font-size: 24px; margin-bottom: 6px; }
  .big-btn .label { font-size: 14px; margin-bottom: 4px; }
  .big-btn .desc { font-size: 11px; line-height: 1.35; }
}

@media (max-width: 420px) {
  .topnav-title .title-text { display: none; }
}
