/* Layout for desktop, iPad and iPhone. Loaded after styles.css and overrides it.
   Breakpoints: >1100 desktop (sidebar) · 701-1100 tablet (top bar) · <=700 phone (top bar + menu sheet). */

/* ---------- All sizes ---------- */
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }
.btn, .nav button { min-height: 40px; touch-action: manipulation; }
.btn:focus-visible, .nav button:focus-visible, .field :is(input, select, textarea):focus-visible {
  outline: 2px solid var(--purple2); outline-offset: 1px;
}

/* Main area sits at the top (styles.css centres it vertically, which leaves a big gap
   above short pages) and can never be stretched wider than the screen by wide content. */
.main { margin: 0 auto; min-width: 0; }

/* The builder only ever has one column; the empty 290px sidebar column was wasted space. */
#builder .grid { grid-template-columns: minmax(0, 1fr); max-width: 1180px; }

/* Flight legs: flexible widths so the row never spills out of its card. */
.leg {
  grid-template-columns: minmax(130px, .9fr) minmax(100px, .7fr) minmax(0, 1.2fr) minmax(0, 1.2fr) minmax(190px, 1.4fr) minmax(140px, 1fr);
}

/* Option header: buttons wrap instead of overflowing. */
.optionhead { flex-wrap: wrap; gap: 8px; }
.optionhead > :last-child { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.optionhead .badge, .optionhead [class*="pill"], .optionhead small { white-space: nowrap; align-self: center; }

/* Wide tables scroll inside their panel rather than stretching the page. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Top bar + menu (hidden on desktop). */
.topbar, .menu-sheet { display: none; }

/* ---------- Tablet & phone ---------- */
@media (max-width: 1100px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }

  .topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 20;
    background: #151419; color: #fff;
    padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  }
  .topbar .logo { background: #fff; border-radius: 8px; padding: 5px 10px; display: flex; flex: none; }
  .topbar .logo img { height: 30px; width: auto; display: block; }
  .topbar .current { flex: 1; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .menu-btn {
    flex: none; display: flex; align-items: center; gap: 8px;
    background: var(--purple); color: #fff; border: 0; border-radius: 9px;
    padding: 10px 14px; min-height: 44px; font-weight: 650; cursor: pointer;
  }

  .menu-sheet {
    position: fixed; inset: 0; z-index: 30; background: rgba(12, 10, 16, .55);
  }
  .menu-sheet.open { display: block; }
  .menu-sheet .sheet {
    position: absolute; top: 0; right: 0; bottom: 0; width: min(340px, 88vw);
    background: #151419; padding: calc(16px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto; box-shadow: -10px 0 40px #0006;
  }
  .menu-sheet .sheet-head { display: flex; justify-content: space-between; align-items: center; color: #fff; margin: 0 4px 12px; }
  .menu-sheet .close-menu { background: transparent; color: #fff; border: 1px solid #ffffff33; border-radius: 9px; min-height: 44px; padding: 0 14px; cursor: pointer; }
  .menu-sheet .nav { display: block; overflow: visible; }
  .menu-sheet .nav button { display: block; width: 100%; white-space: normal; font-size: 16px; padding: 14px; min-height: 50px; }

  .main { padding: 20px max(20px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); }
  .fields.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .leg { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- Phone ---------- */
@media (max-width: 700px) {
  /* 16px stops iOS zooming into a field when you tap it. */
  .field input, .field select, .field textarea, input, select, textarea { font-size: 16px; }
  .field input, .field select { min-height: 44px; }

  .topbar .logo img { height: 26px; }
  .main { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .top h1 { font-size: 24px; }
  .top { flex-direction: column; align-items: stretch; }

  .fields, .fields.four { grid-template-columns: minmax(0, 1fr); }
  /* Legs: two per row (Date/ETD, From/To, ETA/Flight time) rather than one long column. */
  .leg { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .leg + .leg, .legs .leg { padding-top: 12px; border-top: 1px solid var(--line); }

  .panel { padding: 14px; border-radius: 10px; }
  .optionhead > :last-child .btn { flex: 1 1 auto; }

  /* Main quote actions stick to the bottom of the screen, 2x2, thumb-reachable. */
  #builder .top .actions {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    background: #fffffff2; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
    padding: 10px max(14px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  #builder .top .actions .btn { min-height: 46px; }
  #builder { padding-bottom: 130px; }

  /* Other views' action rows go full width. */
  .saved .top .actions, .saved .top > .btn { width: 100%; }
  .saved .top .actions .btn { flex: 1 1 auto; }

  .preview { padding: 0; }
  .paper { border-radius: 0; min-height: 100%; }
  .quote-table th, .quote-table td { padding: 10px 8px; }
}
