/* Phone layout for every page, app-like: bottom tab bar, section strip, card tables, touch-sized
   controls. Colours come from each page's own theme variables (dashboard light, management dark). */
.lionel-tabs, .lionel-subnav { display: none; }

@media (max-width: 680px) {
  /* Navigation: the full menu gives way to a section strip on top and tabs at the bottom. */
  nav.lionel-nav { display: none; }
  .lionel-subnav {
    display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
    padding: 10px 12px; position: sticky; top: 0; z-index: 40;
    background: var(--paper); border-bottom: 1px solid var(--rule);
  }
  .lionel-subnav::-webkit-scrollbar { display: none; }
  .lionel-subnav a {
    flex: none; padding: 8px 14px; border: 1px solid var(--rule); border-radius: 999px;
    color: var(--muted); text-decoration: none; font-size: 13px; white-space: nowrap;
  }
  .lionel-subnav a[aria-current=page] {
    color: var(--surface); background: var(--blue, var(--green)); border-color: transparent; font-weight: 650;
  }
  .lionel-tabs {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--rule);
    box-shadow: 0 -6px 18px rgba(0, 0, 0, .12);
  }
  .lionel-tabs a {
    display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 48px;
    justify-content: center; color: var(--muted); text-decoration: none; font-size: 10px; font-weight: 600;
    -webkit-tap-highlight-color: transparent;
  }
  .lionel-tabs a[aria-current=page] { color: var(--blue, var(--green)); }
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

  /* Touch: 44px targets; 16px inputs stop iOS zooming into a field. */
  button, .button, select, summary { min-height: 44px; }
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px; }
  dialog { width: 100%; max-width: 100%; max-height: 100%; height: 100%; margin: 0; border-radius: 0; }

  /* Tables become cards: the first column is the card title, the rest are labelled fields
     (labels come from mobile.mjs). A table marked data-mobile="scroll" keeps scrolling sideways. */
  /* Card lists scroll with the page: no inner scroll box (dashboard.css caps it at 620px). */
  .table-wrap:not(:has(table[data-mobile=scroll])) { overflow: visible; max-height: none; border: 0; background: transparent; }
  /* dashboard.css gives tables min-width: 760px for sideways scrolling on desktop; cards must not. */
  :is(main, dialog) table:not([data-mobile=scroll]), :is(main, dialog) table:not([data-mobile=scroll]) > tbody { display: block; width: 100%; min-width: 0; }
  :is(main, dialog) table:not([data-mobile=scroll]) > tbody { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
  :is(main, dialog) table:not([data-mobile=scroll]) > thead tr { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
  /* Header cells hide, except those holding sort buttons, which stay as a row of chips. */
  :is(main, dialog) table:not([data-mobile=scroll]) > thead th { display: none; }
  :is(main, dialog) table:not([data-mobile=scroll]) > thead th:has(button) { display: block; padding: 0; background: none; border: 0; }
  :is(main, dialog) table:not([data-mobile=scroll]) > tbody > tr {
    display: block; background: var(--surface); border: 1px solid var(--rule); border-radius: 14px;
    padding: 4px 14px; box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
  }
  /* The label is pinned in a left gutter and the value flows beside it as ordinary content, so
     cells holding several elements (a value plus notes) cannot widen the card. */
  :is(main, dialog) table:not([data-mobile=scroll]) > tbody > tr > td {
    display: block; position: relative; min-height: 38px; padding: 9px 0 9px 36%;
    border-bottom: 1px solid var(--rule); font-size: 13px; text-align: left;
    overflow-wrap: anywhere; word-break: break-word; max-width: 100%; white-space: normal;
  }
  :is(main, dialog) table:not([data-mobile=scroll]) > tbody > tr > td::before {
    content: attr(data-label); position: absolute; left: 0; top: 11px; width: calc(36% - 10px);
    color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    overflow-wrap: anywhere;
  }
  :is(main, dialog) table:not([data-mobile=scroll]) > tbody > tr > td * { max-width: 100%; white-space: normal; }
  :is(main, dialog) table:not([data-mobile=scroll]) > tbody > tr > td:first-child { padding: 12px 0 10px; font-size: 15px; font-weight: 700; }
  :is(main, dialog) table:not([data-mobile=scroll]) > tbody > tr > td:first-child::before { content: none; }
  :is(main, dialog) table:not([data-mobile=scroll]) > tbody > tr > td:last-child { border-bottom: 0; }
  :is(main, dialog) table:not([data-mobile=scroll]) > tbody > tr > td:empty { display: none; }
  :is(main, dialog) table:not([data-mobile=scroll]) td .actions { gap: 6px; }
  :is(main, dialog) table:not([data-mobile=scroll]) td .actions button { flex: 1 1 auto; }
  /* Highlighted rows (positive EV) keep their tint as a card accent. */
  :is(main, dialog) table:not([data-mobile=scroll]) > tbody > tr.positive-ev { border-left: 4px solid var(--green); }
}
