/* Phone layout. Layout only: colours stay with the theme. Loaded last so these rules win at phone width.
   Account list = cards, not a sideways table. Account window = full screen, one-line header, a section picker
   instead of 16 tabs, and sub-tabs as one swipeable row instead of wrapping onto several. */

/* Sections in the account window never shrink to nothing when the page is taller than the screen (all sizes). */
.panel-body > * { flex-shrink: 0; }
.army-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }

.tb-more, .tab-select, .filters > .fleet-filter-toggle { display: none; }
.fleet-filter-controls { display: contents; }

@media (max-width: 700px) {
    /* Top of the page */
    .topbar { gap: 8px; }
    .topbar select { min-height: 36px; padding: 4px 8px; }
    .shell:has(.fleet-list) .site-foot { flex-wrap: wrap; gap: 8px 18px; }

    /* Account tools: the everyday ones, the rest behind More */
    .toolbar { gap: 6px; padding: 8px; }
    .toolbar .tb-sep { display: none; }
    .toolbar:not(.open) .tb-extra { display: none; }
    .fleet-toolbar .tb { flex: 1 1 calc((100% - 12px) / 3); min-width: 0; min-height: 44px; justify-content: center; white-space: normal; }
    .fleet-toolbar :is(.tb-add,.tb-more) { flex: 1 1 calc((100% - 6px) / 2); }
    .fleet-toolbar .tb-more { display: inline-flex; }
    .fleet-toolbar:not(.has-selection) .tb-selection { display: none; }
    .fleet-toolbar .tb-more[aria-expanded="true"], .fleet-filter-toggle[aria-expanded="true"] { border-color: var(--accent); color: var(--text); }

    /* Account list as cards */
    .list-card { padding: 12px; border-radius: 12px; }
    .fleet-list .list-head { margin-bottom: 8px; }
    .fleet-selection-count.none-selected { display: none; }
    .fleet-list .filters { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
    .fleet-list .filters input[type=search], .fleet-filter-controls select { width: 100%; min-width: 0; min-height: 44px; font-size: 16px; } /* Prevent zoom on focus. */
    .filters > .fleet-filter-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding-inline: 10px; }
    .filter-count { border-radius: 12px; padding-inline: 6px; background: var(--surface-2); font-variant-numeric: tabular-nums; }
    .fleet-filter-controls { display: none; }
    .fleet-filter-controls.is-open { display: grid; grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
    .fleet-filter-summary { display: none; }
    .list-card .table-wrap { max-height: none; min-height: 0; overflow: visible; border: 0; background: none; }
    table.fleet, table.fleet tbody { display: block; width: 100%; }
    table.fleet thead { display: none; }
    table.fleet tr { position: relative; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 6px; padding: 10px 9px 10px 11px;
        margin: 0 0 6px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; }
    table.fleet tr.picked { border-color: var(--accent); background: var(--surface-2); }
    table.fleet tr.picked td, table.fleet tr.opening td { box-shadow: none; }
    table.fleet td { display: flex; flex-direction: column; gap: 2px; padding: 0; border: 0; min-width: 0; text-align: left; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
    table.fleet th.num, table.fleet td.num { text-align: left; }
    table.fleet td::before { content: attr(data-label); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
    table.fleet td.cb { position: absolute; top: 0; right: 0; width: 44px; height: 44px; align-items: center; justify-content: center; }
    table.fleet td.cb::before, table.fleet td.col-account::before { content: none; }
    table.fleet td.cb .fleet-row-select { display: grid; place-items: center; width: 100%; height: 100%; cursor: pointer; }
    table.fleet td.cb input { width: 22px; height: 22px; margin: 0; }
    table.fleet td.col-account { grid-column: 1 / -1; padding-right: 36px; min-height: 24px; justify-content: center; font-size: 16px; }
    table.fleet td.col-account .acct b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    table.fleet td:is(.col-igg, .col-kingdom, .col-location) { display: none; }
    table.fleet td .chip { align-self: flex-start; max-width: 100%; white-space: normal; }
    .fleet-pagination { flex-wrap: wrap; gap: 8px; }
    .fleet-pagination .row { width: 100%; flex-wrap: wrap; justify-content: space-between; }
    .fleet-pagination .row :is(button,select) { min-height: 44px; }

    /* Account window: the whole screen */
    .overlay:has(> .modal.panel) { padding: 0; }
    .modal.panel { width: 100%; max-width: none; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; padding-bottom: env(safe-area-inset-bottom); }
    .panel-head { position: relative; flex-wrap: nowrap; flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 12px 8px; }
    .panel-head .who { padding-right: 52px; min-width: 0; }
    .panel-head .who > div { min-width: 0; }
    .panel-head h2 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .panel-head .avatar { width: 34px; height: 34px; flex: none; }
    .panel .panel-head .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 0; padding: 0; }
    .panel .panel-head .actions > .btn { min-height: 44px; min-width: 0; justify-content: center; white-space: normal; }
    .panel-head .actions > .pager { display: none; }
    .panel-head .actions > .btn.icon:last-child { position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; }

    /* One section picker instead of a strip of 16 tabs */
    .modal.panel > .tab-bar { padding: 6px 12px; border-bottom: 1px solid var(--border); }
    .tab-bar > .tabs, .tab-bar > .tab-nudge { display: none; }
    .tab-select { display: block; width: 100%; min-height: 44px; padding: 8px 12px; font: inherit; font-size: 16px; font-weight: 600;
        color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
    .panel-body { padding: 10px 12px 14px; overscroll-behavior: contain; }
    .panel .panel-action-feedback { block-size: 2.5em; padding-block: 2px; }

    /* Overview: the most useful rows before resources. */
    .panel-body > .strip5 > div { padding: 7px 9px; }
    .panel-body > .strip5 b { font-size: 15px; overflow-wrap: anywhere; }
    .panel-body > .res-strip { order: 1; margin-bottom: 0; }
    .panel-body > .overview-disclosure { order: 2; }
    .overview-primary .btn, .overview-disclosure > summary { min-height: 44px; }
    .overview-disclosure > summary { align-content: center; }

    /* Sub-tabs: one row you can swipe, never three rows */
    .panel .subtabs {
        flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; overscroll-behavior-inline: contain;
        max-width: 100%; margin-inline: 0; padding: 3px; scroll-padding-inline: 3px; }
    .panel .subtabs > button { flex: none; min-height: 44px; }
    .panel .protect-live { gap: 4px; margin-bottom: 0; }
    .panel .protect-live .pl { padding: 4px 7px; }

    /* Keep native touch heights without turning short settings into page-wide fields. */
    :is(.panel, .global-settings, .rally-join-dialog) .form-grid {
        --settings-control-height: 44px;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 158px), 210px));
        gap: 10px 14px;
    }
    :is(.panel, .global-settings, .rally-join-dialog) .form-grid > label { overflow-wrap: anywhere; font-size: 14px; }
    :is(.panel, .global-settings, .rally-join-dialog) .form-grid > label > :where(input:not([type=checkbox]):not([type=radio]), select) { max-width: min(100%, 210px); font-size: 16px; }
    :is(.panel, .global-settings, .rally-join-dialog) .form-grid > label > input[type=number] { width: min(100%, 128px); }
    .panel .check, .panel .switch { min-height: 44px; align-items: center; }
    .panel .check input[type=checkbox] { margin-top: 0; }
    .panel :is(.automation-save,.settings-save) { flex-wrap: wrap; bottom: -14px; padding: 8px 0; }
    .panel :is(.automation-save,.settings-save) .btn { min-height: 44px; }
    .panel .settings-grid > div { min-width: 0; }
    .panel .shield-action-dialog .shield-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .panel .shield-action-dialog .shield-grid .tile { min-height: 44px; }

    /* Other dialogs fill the screen too */
    .overlay:has(> .modal:not(.panel)) { padding: 0; align-items: stretch; }
    .overlay > .modal:not(.panel) { width: 100%; max-width: none; min-height: 100dvh; max-height: 100dvh; border-radius: 0; overflow-y: auto; }
}

@media (min-width: 375px) and (max-width: 700px) {
    .panel .form-grid.shield-renewal-grid { grid-template-columns: minmax(0, 145px) minmax(0, 190px); gap: 10px; }
    .panel .shield-renewal-grid .shield-fallback { grid-column: 1 / -1; }
}

@media (min-width: 460px) and (max-width: 700px) {
    .panel .panel-head .actions { grid-template-columns: auto minmax(0,1fr) auto auto; }
    .panel .panel-head .actions > .btn { padding-inline: 12px; }
    .fleet-toolbar .tb { flex-basis: auto; }
}

@media (max-width: 360px) {
    table.fleet td { font-size: 12px; }
    table.fleet td::before { font-size: 10px; }
}
