/* Responsive console layout (≤760px). Loaded after console.css.
   Navigation is the sidebar alone: on phones it becomes a drawer opened from the top bar
   (shell.js). There is no bottom tab bar, so sheets, toasts and the save bar anchor to the
   safe-area edge rather than sitting above a second navigation strip. */
.nav-btn, .nav-veil { display: none; }

@media (max-width: 760px) {
  html[data-theme="dark"], html[data-theme="dark"] body { color-scheme: only dark; }
  html[data-theme="light"], html[data-theme="light"] body { color-scheme: only light; }
  body.nav-open { overflow: hidden; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .main, .view, .box, .pad, .grid2 > *, .grid3 > * { min-width: 0; }

  /* Drawer */
  .nav {
    position: fixed; inset: 0 auto 0 0; z-index: 70;
    width: 290px; max-width: 86vw; height: 100%; height: 100dvh;
    padding: max(16px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
    overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
    border-right: 1px solid var(--line); box-shadow: var(--shadow-lg);
    transform: translateX(-102%); transition: transform .24s var(--ease);
  }
  .nav.open { transform: translateX(0); }
  .nav a { min-height: 44px; font-size: 15px; }
  .nav-pref { height: 42px; font-size: 13.5px; }
  .nav-btn { display: inline-flex !important; }
  .nav-collapse { display: none; }
  .nav-veil {
    display: block; position: fixed; inset: 0; z-index: 65; background: var(--scrim);
    opacity: 0; pointer-events: none; transition: opacity .24s var(--ease);
  }
  .nav-veil.on { opacity: 1; pointer-events: auto; }

  /* Top bar */
  .topbar { min-height: 54px; gap: 8px; padding: 8px 12px; }
  .crumb { gap: 6px; }
  .topbar .meta { display: none; }
  .topbar h2 { overflow: hidden; font-size: 15px; text-overflow: ellipsis; }
  .refresh-state { display: none; }
  .refresh-state.stale {
    display: block; position: absolute; left: 12px; right: 12px; top: calc(100% + 8px);
    padding: 8px 12px; border: 1px solid var(--warn-line); border-radius: var(--r-sm);
    box-shadow: var(--shadow-sm); white-space: normal; font-size: 12.5px;
  }
  .topbar-actions { gap: 4px; }
  .topbar button { min-height: 36px; padding: 6px 11px; font-size: 13.5px; }
  .topbar button.icon { width: 36px; padding: 0; }

  .view { padding: 22px 16px calc(40px + env(safe-area-inset-bottom)); }
  .page-heading { margin-bottom: 18px; }
  .page-heading h1 { font-size: 27px; }
  .page-heading p { margin-top: 6px; font-size: 13.5px; }
  .job-banner { width: calc(100% - 32px); margin-top: 12px; padding: 12px; }
  .job-banner .jb-acts { margin-left: 0; }

  /* Overview */
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
  .stat { padding: 13px 14px; border-radius: 12px; }
  .stat .k { font-size: 12.5px; }
  .stat .v { margin: 6px 0 3px; font-size: clamp(23px, 7vw, 28px); }
  .stat-caption { font-size: 11.5px; line-height: 1.45; }
  .stat-credits .v { font-size: clamp(19px, 5.4vw, 24px); }
  .stat-clickable::after { display: none; }
  .health-strip { gap: 6px; margin-bottom: 20px; }
  .health-label { flex-basis: 100%; margin-bottom: 2px; }
  .health-chip { min-height: 34px; }

  /* Cards */
  .box { margin-bottom: 16px; border-radius: 12px; }
  .box > header { gap: 8px; min-height: 0; padding: 12px 14px; }
  .box > header h3 { flex: 1 1 150px; font-size: 15px; line-height: 1.45; }
  .box > header h3 .hint { display: block; flex: 1 1 100%; margin: 2px 0 0; font-size: 12.5px; }
  .box > header .note { font-size: 12.5px; white-space: normal; }
  .box .pad { padding: 16px 14px; }
  .action-menu-list { position: fixed; top: auto; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 60; width: auto; max-height: 65vh; overflow-y: auto; padding: 6px; }
  .action-menu-list button { min-height: 44px; font-size: 14.5px; }

  /* Tables become cards */
  .tbl-wrap { overflow: visible; }
  .acc, .acc.md, .acc.req, .account-box .acc { display: block; width: 100%; min-width: 0; }
  .acc thead { display: none; }
  .acc tbody { display: block; }
  .acc tr {
    display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: min-content;
    align-items: center; gap: 10px 8px; padding: 14px;
    border-bottom: 1px solid var(--line-soft);
  }
  .acc tbody tr:last-child { border-bottom: 0; }
  .acc tbody tr:hover, .acc.zebra tbody tr:nth-child(even), .acc.zebra tbody tr:nth-child(even):hover { background: transparent; }
  .acc td, .acc.md td, .acc.req td {
    display: flex; align-items: center; flex-wrap: wrap; min-width: 0;
    padding: 0; border: 0; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; text-align: left;
  }
  .acc td::before { content: attr(data-l); flex: none; margin-right: 6px; color: var(--ink-3); font-size: 12px; font-weight: 450; white-space: nowrap; }
  .acc td:not([data-l])::before, .acc td.who::before, .acc td.acts::before { content: none; }
  .acc .mark, .acc.md .mark { display: none; }
  .acc tr > td { grid-column: span 4; }
  .acc td[colspan] { grid-column: 1 / -1; justify-content: center; }
  .acc .who { display: block; min-width: 0; max-width: none; }
  .acc .who .nm { font-size: 15px; line-height: 1.4; white-space: normal; overflow-wrap: anywhere; }
  .acc .who .id { margin-top: 3px; white-space: normal; overflow-wrap: anywhere; }
  .acc .num { white-space: normal; }
  .acc .tag { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
  .acc .cred { min-width: 0; }
  .acc .cred .bar { flex: 1 1 100%; min-width: 18px; max-width: none; margin-top: 4px; }
  .acc td.acts { display: flex; justify-content: flex-start; gap: 6px; text-align: left; }
  .acc td.acts button { margin: 0; }

  /* Account pool: the card is the account, so drop the outer card chrome */
  .account-box { overflow: visible; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
  .account-box > header { padding: 0 0 12px; border-bottom: 0; }
  .account-box > .fbar { margin-bottom: 10px; padding: 12px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--surface); }
  .account-box > .batch-bar { margin-bottom: 10px; padding: 12px; border: 0; border-radius: 12px; }
  .account-box .tbl-wrap { border-radius: 0; }
  #accBody tr { margin-bottom: 10px; padding: 15px 14px 13px; border: 1px solid var(--line-soft); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-xs); }
  #accBody tr:last-child { margin-bottom: 0; border-bottom: 1px solid var(--line-soft); }
  #accBody tr > .who { grid-column: 1 / -1; }
  #accBody tr > td:nth-child(3) { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: -2px; }
  #accBody tr > td:nth-child(3)::before { content: none; }
  #accBody tr > td:nth-child(3) .acc-reason { flex: 1 1 100%; max-width: none; margin: 0; order: 3; }
  #accBody tr > td:nth-child(3) .capability-note { margin: 0; }
  #accBody tr > td:nth-child(3) .rate-limits { flex: 1 1 100%; width: 100%; max-width: none; min-width: 0; margin-top: 2px; order: 4; }
  #accBody tr > .cred { grid-column: 1 / 7; }
  #accBody tr > .req-cell { grid-column: 7 / 13; column-gap: 8px; }
  #accBody .req-cell .cell-sub { margin: 0; }
  #accBody tr > td:nth-child(7) { grid-column: 1 / 13; order: 1; color: var(--ink-3); }
  #accBody tr > .usage-cell { grid-column: 1 / 13; order: 2; }
  #accBody tr > .usage-cell::before { align-self: flex-start; }
  #accBody .usage-line { flex-direction: row; flex-wrap: wrap; column-gap: 0; }
  #accBody .usage-sub::before { content: "·"; margin: 0 6px; color: var(--ink-4); }
  #accBody tr > td.acts { order: 3; grid-column: 1 / 13; padding-top: 10px; border-top: 1px solid var(--line-soft); }
  #accBody td.acts button { flex: 1 1 0; min-height: 38px; font-size: 13.5px; }
  #accBody td.acts .row-more { flex: 0 0 44px; width: 44px; }

  #mlBody tr > td:nth-child(1) { grid-column: 1 / 9; }
  #mlBody tr > td:nth-child(2) { grid-column: 9 / 13; justify-content: flex-end; }
  #mlBody tr > td:nth-child(3) { grid-column: 1 / 7; }
  #mlBody tr > td:nth-child(4), #mlBody tr > td:nth-child(5) { grid-column: span 3; }
  #mlBody tr > td:nth-child(6), #mlBody tr > td:nth-child(7) { grid-column: span 6; }
  #mlBody tr > td:nth-child(8) { grid-column: 1 / 13; }
  /* `.acc.md td { display: flex }` outranks `.acc .who`: without this the model ID and its
     display name sit side by side and the ID is cut to an ellipsis on phones. */
  #mdBody tr > .who { display: block; grid-column: 1 / 13; }
  #mdBody tr > .who .nm { font-size: 14px; }
  #mdBody .who .nm .mid { overflow: visible; white-space: normal; overflow-wrap: anywhere; text-overflow: clip; }
  #mdBody tr > td:nth-child(3), #mdBody tr > td:nth-child(4),
  #mdBody tr > td:nth-child(6), #mdBody tr > td:nth-child(7) { grid-column: span 3; }
  #mdBody tr > .efs { grid-column: 1 / 13; order: 2; min-width: 0; gap: 3px; }
  .acc.zebra tr > td.mark + td, .acc.zebra tr > td:first-child { grid-column: 1 / -1; }
  .acc.zebra tr > td { grid-column: span 4; }
  .acc.zebra tr > td:first-child { display: block; font-size: 14px; font-weight: 550; }
  .acc.req .clip, .acc.req .clip.ip, .acc.req .clip.rid { max-width: none; white-space: normal; overflow-wrap: anywhere; }
  #reqBody tr > td:nth-child(1) { grid-column: 1 / 8; }
  #reqBody tr > td:nth-child(2) { grid-column: 8 / 13; justify-content: flex-end; }
  #reqBody tr > td:nth-child(2)::before { content: none; }
  #reqBody tr > td:nth-child(3) { grid-column: 1 / 13; }
  #reqBody tr > td:nth-child(4) { grid-column: 1 / 8; }
  #reqBody tr > td:nth-child(5) { grid-column: 8 / 13; justify-content: flex-end; }
  #reqBody tr > td:nth-child(6) { grid-column: 1 / 13; }
  #reqBody tr > td:nth-child(7), #reqBody tr > td:nth-child(8), #reqBody tr > td:nth-child(9) { grid-column: span 4; }
  #reqBody tr > td:nth-child(10) { grid-column: 1 / 13; }
  .req-wrap { max-height: 70vh; overflow: auto; -webkit-overflow-scrolling: touch; }
  #taskBody tr { padding: 12px 0; }
  #taskBody tr > .who { grid-column: 1 / 9; }
  #taskBody tr > td:nth-child(5) { grid-column: 9 / 13; justify-content: flex-end; }
  #taskBody tr > td:nth-child(5)::before { content: none; }
  #taskBody tr > td:nth-child(3), #taskBody tr > td:nth-child(4) { grid-column: span 6; }
  #taskBody tr > td.acts { grid-column: 1 / 13; }
  #taskBody td.acts:empty { display: none; }
  #pkDetail tr > td:nth-child(2) { grid-column: 1 / 9; order: -2; }
  #pkDetail tr > td:nth-child(7) { grid-column: 9 / 13; justify-content: flex-end; order: -1; }
  #pkDetail tr > td:nth-child(3), #pkDetail tr > td:nth-child(4),
  #pkDetail tr > td:nth-child(5), #pkDetail tr > td:nth-child(6) { grid-column: span 3; }

  /* Filters & segmented controls */
  .fbar { gap: 8px; padding: 12px; }
  .fbar > input, .fbar > select { min-height: 40px; max-width: 100%; font-size: 15px; }
  .fbar > input[type=search] { min-width: 0; flex: 1 1 100%; }
  .fbar > select { flex: 1 1 120px; min-width: 0; }
  .fbar .grow { display: none; }
  .trange { gap: 8px; max-width: 100%; }
  .trange select, .trange input { min-width: 0; min-height: 38px; max-width: 100%; font-size: 14px; }
  .trange .tr-custom { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; max-width: 100%; }
  .trange .tr-custom input { flex: 1 1 150px; }
  .vtabs, .chips { max-width: 100%; flex-wrap: wrap; }
  .vtabs button, .chips .chip { min-height: 34px; }
  .kpis, .kpis.k4, .kpis.k5 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 14px; }
  .kpi { padding: 12px; }
  .kpi .v { font-size: 21px; white-space: normal; overflow-wrap: anywhere; }
  .kpi .k, .kpi .s { white-space: normal; }
  .uschart-hd { padding: 11px 12px; }
  .uschart-hd .lb { flex: 1 1 auto; }
  .uschart-hd .grow { display: none; }
  .uschart-hd .note { flex: 1 1 100%; order: 3; white-space: normal; }
  .uschart-body { padding: 8px 4px 10px; }
  .uschart-body .tk, .uschart-body .tk-avg, .uschart-body .tk-peak { font-size: 13px; }

  /* Forms */
  .config-nav { top: 62px; margin-bottom: 16px; }
  .config-nav-label { display: none; }
  .config-nav-links button { min-height: 34px; }
  .config-section { scroll-margin-top: 122px; }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  label.fld { margin-bottom: 18px; }
  input, select, textarea { min-width: 0; max-width: 100%; min-height: 42px; border-radius: 10px; font-size: 16px; }
  input[type=checkbox], input[type=radio] { min-height: 0; }
  button { min-height: 40px; padding: 8px 14px; font-size: 14px; }
  button.xs, select.xs, .sel-note select { min-height: 36px; font-size: 13.5px; }
  .fld .inline { flex-wrap: wrap; }
  .fld .inline input { flex: 1 1 100%; width: 100%; }
  .switch { gap: 14px; min-height: 48px; padding: 8px 0; }
  .savebar { flex-wrap: wrap; gap: 8px; padding: 12px 0; }
  .savebar.floating { bottom: calc(10px + env(safe-area-inset-bottom)); padding: 12px; }
  .savebar .grow { display: none; }
  .draft-state, .restart-note { flex: 1 1 100%; }
  .savebar #btnCfgReload { margin-left: auto; }
  #cfgPath { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
  .project-keys-wrap { max-width: 100%; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
  .project-keys-wrap table { min-width: 900px; }
  .project-keys-wrap input:not([type=checkbox]) { font-size: 16px; }

  /* Tasks, jobs, logs, credits */
  .qgroup header { padding: 10px 2px 8px; flex-wrap: wrap; }
  .qrow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0 0 8px; padding: 12px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--surface); }
  .qrow .name { flex: 1 1 100%; order: -1; font-size: 14px; }
  .qrow .name .t, .qrow .msg, .qrow .code { white-space: normal; overflow-wrap: anywhere; }
  .qrow .code { flex: 1 1 auto; }
  .qrow .msg { flex: 1 1 100%; }
  .qprog { flex-wrap: wrap; padding: 14px 14px 0; }
  .job-row { align-items: flex-start; flex-wrap: wrap; padding: 13px 14px; }
  .job-row > div { flex: 1 1 200px; }
  #logBox { max-height: 60vh; padding: 12px 14px; font-size: 12px; }
  .req-detail-grid { grid-template-columns: minmax(0, 1fr); }
  .pk-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .pk-expiry-hdr, .pk-expiry-row { grid-template-columns: 54px minmax(0, 1fr) 64px; gap: 8px; }
  .pk-expiry-chart { min-width: 0; padding-right: 0; }
  .exp-row { grid-template-columns: 8px minmax(0, 1fr); gap: 4px 10px; }
  .exp-row .exp-main { grid-column: 2; }
  .comp-row { gap: 8px; }
  .rm-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .rm-row .rm-who { flex-basis: auto; }

  /* Sheets: dialogs and the row menu rise from the bottom */
  .veil.on { align-items: flex-end; padding: 0; }
  .dlg { width: 100%; max-width: 100%; max-height: 92vh; max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom); border-bottom: 0; border-radius: 20px 20px 0 0; animation: sheetIn .24s var(--ease); }
  @keyframes sheetIn { from { transform: translateY(28px); opacity: .6; } to { transform: none; opacity: 1; } }
  .dlg header { padding: 20px 18px 12px; }
  .dlg header h3 { font-size: 21px; }
  .dlg .body { padding: 4px 18px 18px; }
  .dlg-wide .body { padding-top: 14px; }
  .dlg footer { flex-wrap: wrap; gap: 8px; padding: 12px 18px 16px; }
  .dlg footer .grow { flex-basis: 0; }
  #taskVeil footer button:not(.ghost) { flex: 1 1 auto; }
  #keyVeil { align-items: center; padding: 24px 20px; }
  #keyDlg.login-dlg { width: 100%; max-width: 400px; border-radius: 0; padding: 0; animation: dlgIn .18s var(--ease); }
  #keyDlg.login-dlg h3 { font-size: 34px; }
  .row-menu { left: 10px !important; right: 10px; top: auto !important; bottom: calc(10px + env(safe-area-inset-bottom)); width: auto; max-height: 70vh; padding: 6px; border-radius: 16px; box-shadow: var(--shadow-lg); animation: sheetIn .2s var(--ease); }
  .row-menu button { min-height: 46px; font-size: 15px; }
  .vc .ft { gap: 8px; }
  .vc .ft .acts { margin-left: 0; }
  #toasts { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); align-items: stretch; }
  .tst { max-width: 100%; overflow-wrap: anywhere; }

  .box > header h3, .qgroup header .nm, .vc .hd .nm, .vc-acct .nm, .vc .ft code, .vc .meta,
  .pk-card .nm, .pk-legend span, .pk-expiry-legend span, .brand .sub, .nav-foot,
  .dlg header h3, .dlg header .hint, .hint, .note, .state, .page-heading p { min-width: 0; overflow-wrap: anywhere; }
  .qgroup header, .vc .hd, .vc-acct, .pk-card .who { flex-wrap: wrap; }
  .who .nm, .who .id { min-width: 0; white-space: normal; overflow-wrap: anywhere; text-overflow: clip; }
  .tag { max-width: 100%; min-width: 0; }
}

@media (max-width: 400px) {
  .view { padding-left: 12px; padding-right: 12px; }
  .topbar { padding-left: 8px; padding-right: 8px; }
  .job-banner { width: calc(100% - 24px); }
  .box .pad, .box > header { padding-left: 12px; padding-right: 12px; }
  .acc tr { padding: 13px 12px; }
  .kpi .v { font-size: 19px; }
  .sel-note { flex-wrap: wrap; white-space: normal; }
}
@media (max-width: 760px) and (orientation: landscape) {
  .dlg { max-height: 96vh; max-height: 96dvh; }
  #logBox { max-height: 42vh; }
}
