/* ─────────────────────────────────────────────────────────────
   Mobile overrides — max-width: 768px only.
   Zero impact on desktop. All additive.
   ───────────────────────────────────────────────────────────── */

/* ─── Desktop: hide mobile-only elements ─────────────────────── */
@media (min-width: 769px) {
  .mob-tab-bar          { display: none !important; }
  .mob-fab-wrap         { display: none !important; }
  #mob-formation-select { display: none !important; }
  #mob-menu-btn         { display: none !important; }
  .bench-node--empty    { display: none !important; }
}

/* ─── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Pitch scaling — players use %, so they adapt automatically */
  :root {
    --pitch-w: min(400px, 92vw);
    --pitch-h: calc(var(--pitch-w) * 1.45);
  }

  /* Body */
  body {
    height: 100dvh;
    overflow: hidden; /* default; formation/squad override below */
  }

  /* App shell */
  #app-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
    /* Reset desktop fixed-card padding; topbar is still fixed */
    padding-left: 0;
    padding-right: 0;
    padding-top: var(--topbar-h);
  }

  #main-area {
    flex: none;
    overflow: visible;
    flex-direction: column;
  }

  /* ─── Formation select in topbar ─── */
  #mob-formation-select {
    -webkit-appearance: none;
    appearance: none;
    background-color: rgba(255,255,255,0.12);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%23ffffff' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    border: 1px solid rgba(255,255,255,0.20);
    border-radius: 6px;
    padding: 6px 26px 6px 10px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    cursor: pointer;
  }

  /* ─── Pitch fills viewport below topbar ─── */
  /* position:fixed bypasses the auto-height ancestor chain that breaks iOS Safari */
  .pitch-container {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
  }

  /* Always hidden on mobile */
  .pitch-actions { display: none !important; }

  /* Stack pitch and bench vertically on mobile */
  .pitch-row {
    flex-direction: column;
    align-items: center;
  }

  .pitch-bench {
    position: static;
    flex-direction: row;
    justify-content: center;
    gap: 12px;
    padding: 16px 0 4px;
    transform: none;
  }

  /* ─── Squad tab: sidebar fills viewport ─── */
  .sidebar {
    /* Reset desktop fixed card */
    position: static;
    left: auto;
    top: auto;
    bottom: auto;
    border-radius: 0;
    box-shadow: none;
    border: none;
    border-top: 1px solid var(--border);
    /* Mobile layout */
    display: none;
    width: 100%;
    min-width: 0;
    min-height: calc(100dvh - var(--topbar-h));
    overflow-y: auto;
  }

  /* Hide the card header on mobile (mobile has its own roster screen) */
  .spillere-card-header { display: none; }

  /* pitch-center fills available height and centers the pitch within it */
  .pitch-container .pitch-center {
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .right-panel {
    /* Reset desktop fixed card */
    position: static;
    right: auto;
    top: auto;
    bottom: auto;
    border-radius: 0;
    box-shadow: none;
    border: none;
    border-top: 1px solid var(--border);
    /* Mobile layout */
    display: none;
    width: 100%;
    padding: 24px 20px 80px; /* bottom padding clears tab bar */
    overflow-y: visible;
  }


  /* ─── Prevent iOS zoom on input focus ─────────────────────── */
  .player-input,
  .pitch-popover-input {
    font-size: 16px;
  }

  /* ─── Mobile bottom-sheet player picker ────────────────────── */
  .mob-picker-sheet {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }

  .mob-picker-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
  }

  .mob-picker-panel {
    position: relative;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    height: 95dvh;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
  }

  .mob-picker-panel--open {
    transform: translateY(0);
  }

  .mob-picker-drag-zone {
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 14px 0 10px;
    touch-action: none;
    cursor: grab;
  }

  .mob-picker-drag-zone:active {
    cursor: grabbing;
  }

  .mob-picker-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    pointer-events: none;
  }

  .mob-picker-search-wrap {
    padding: 8px 16px 12px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
  }

  .mob-picker-search {
    width: 100%;
    box-sizing: border-box;
    font-size: 16px;
    font-family: 'DM Sans', sans-serif;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    -webkit-appearance: none;
    appearance: none;
  }

  .mob-picker-list {
    list-style: none;
    margin: 0;
    padding: 0 0 calc(env(safe-area-inset-bottom, 0px) + 8px);
    overflow-y: auto;
    flex: 1;
  }

  .mob-picker-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-picker-item:active {
    background: var(--bg);
  }

  .mob-picker-item-name {
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
  }

  .mob-picker-item--clear {
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-faint);
    justify-content: center;
  }

  /* ─── Topbar: show Menu button, hide desktop-only elements ─── */
  #topbar-trup-btn,
  #topbar-user-btn,
  #cloud-account-btn         { display: none; }
  .app-topbar-companion-wrap { display: none !important; }
  #mob-menu-btn              { display: inline-flex; }

  /* Hide export button below pitch — accessible via Menu instead */
  .export-below-pitch { display: none !important; }

  /* ─── Empty bench nodes: dark stroke so they're visible on light bg ─── */
  .bench-node--empty .shirt-body,
  .bench-node--empty .shirt-sleeve-left,
  .bench-node--empty .shirt-sleeve-right { fill: rgba(0,0,0,0.04); }
  .bench-node--empty .shirt-outline      { stroke: rgba(0,0,0,0.22); }

  /* ─── Mobile sheet group filter ─────────────────────────── */
  .mob-sheet-group-filter {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 10px 16px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .mob-sheet-group-filter::-webkit-scrollbar { display: none; }

  .mob-sheet-group-pill {
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: 100px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-faint);
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
    opacity: 0.4;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 120ms ease, background 120ms ease, color 120ms ease, border-color 120ms ease;
  }

  .mob-sheet-group-pill--active                      { opacity: 1; }
  .mob-sheet-group-pill--active[data-group-idx="0"]  { background: #e6f4ea; color: #2a7a38; border-color: #b7dfc0; }
  .mob-sheet-group-pill--active[data-group-idx="1"]  { background: #fce8e6; color: #c0392b; border-color: #f5b8b3; }
  .mob-sheet-group-pill--active[data-group-idx="2"]  { background: #e8e8e8; color: #1a1a1a; border-color: #c8c8c8; }
  .mob-sheet-group-pill--active[data-group-idx="3"]  { background: #ffffff; color: #555;    border-color: #ddd;    }
  .mob-sheet-group-pill--active[data-group-idx="4"]  { background: #e3f0fc; color: #1a6fc4; border-color: #b0d4f5; }
  .mob-sheet-group-pill--active[data-group-idx="5"]  { background: #f0eaff; color: #6b2fa0; border-color: #d4b8f5; }
  .mob-sheet-group-pill--active[data-group-idx="6"]  { background: #fef9e3; color: #b07c0a; border-color: #f0e0a0; }

  /* ─── Mobile menu sheet ──────────────────────────────────── */
  .mob-menu-list {
    padding: 8px 0 calc(env(safe-area-inset-bottom, 0px) + 16px);
  }

  .mob-menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    list-style: none;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-menu-item:last-child { border-bottom: none; }

  .mob-menu-item:active { background: var(--bg); }

  /* ─── Mobile menu footer ───────────────────────────────────── */
  .mob-menu-footer {
    margin-top: auto;
    padding: 16px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
    border-top: 1px solid var(--border);
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-faint);
    line-height: 1.5;
  }

  .mob-menu-footer-link {
    color: var(--text-muted);
    text-decoration: underline;
    text-underline-offset: 2px;
  }

  /* ─── Roster screen mobile overrides ──────────────────────── */

  /* Editor panel height: auto up to 90dvh, not forced full-height */
  .roster-editor-mob-panel {
    height: auto;
    max-height: 90dvh;
  }

  /* Prevent iOS zoom on roster inputs */
  .roster-edit-input,
  .roster-edit-select,
  .roster-edit-textarea {
    font-size: 16px;
  }

  /* Mobile editor bottom sheet */
  .roster-editor-mob-header {
    padding: 4px 16px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  .roster-edit-form--mob {
    overflow-y: auto;
    flex: 1;
    padding: 16px 16px;
    gap: 14px;
  }

  .roster-editor-mob-footer {
    padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
  }

  .roster-delete-btn--full {
    width: 100%;
    padding: 10px;
    text-align: center;
    border: 1px solid rgba(192,57,43,0.25);
    border-radius: 8px;
    background: rgba(192,57,43,0.06);
  }

  .roster-save-btn--full {
    width: 100%;
    padding: 13px;
    font-size: 15px;
    border-radius: 10px;
  }

  /* Hide desktop "Trup" button in sidebar on mobile (accessed via tab bar) */
  .sidebar-trup-btn { display: none; }

  /* ─── Groups editor modal ──────────────────────────────────── */
  .paste-modal.groups-editor-modal { width: 96vw; max-height: 88dvh; }
  /* Collapse to 3-column grid on mobile: handle | name+import | del */
  .groups-editor-header,
  .groups-editor-row {
    grid-template-columns: 32px 1fr 32px;
    grid-template-rows: auto auto;
    row-gap: 6px;
    padding: 10px 10px;
  }
  /* Handle stays col 1 row 1, spans vertically */
  .groups-editor-handle { grid-column: 1; grid-row: 1 / 3; }
  /* Name: col 2 row 1 */
  .groups-editor-name-input { grid-column: 2; grid-row: 1; width: 100%; }
  /* Import: col 2 row 2 */
  .groups-editor-import-input { grid-column: 2; grid-row: 2; width: 100%; }
  /* Farve + Spillere + Del: hide on mobile header, shown inline in rows */
  .groups-editor-farve-wrap { display: none; }
  .groups-editor-count { display: none; }
  /* Delete: col 3 row 1, spans */
  .groups-editor-del { grid-column: 3; grid-row: 1 / 3; }
  /* Hide extra header cells */
  .groups-editor-header-cell:nth-child(n+3) { display: none; }
  .groups-editor-footer { flex-wrap: wrap; }

  /* ─── Mobile squad screen ─────────────────────────────────── */
  .roster-mob-add-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  .roster-mob-backup-btn {
    align-self: flex-start;
    margin: 6px 16px 0;
    font-size: 12px;
    padding: 6px 12px;
  }

  .trup-mob-pills {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px 16px;
    flex-shrink: 0;
    scrollbar-width: none;
  }
  .trup-mob-pills::-webkit-scrollbar { display: none; }

  .trup-mob-pill {
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: 100px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-faint);
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
  }

  .trup-mob-pill--active {
    background: var(--text);
    color: var(--surface);
    border-color: var(--text);
  }
}
