#accessDialog { width: min(640px, calc(100vw - 24px)); max-height: 85dvh; overflow: auto; padding: 24px; }
#accessDialog h2 { margin: 0; font-size: 21px; }
#accessDialog .dialog-title { justify-content: space-between; gap: 16px; }
#accessDialog h3 { margin: 24px 0 12px; }
#accessDialog p { line-height: 1.6; }
#accessDialog button { padding: 9px 14px; border-radius: 8px; cursor: pointer; }
#accessDialog button:not(.primary) { background: var(--panel2); border: 1px solid var(--line); }
#accessDialog button:hover { filter: brightness(1.15); }
#accessDialog button:disabled { opacity: .5; cursor: wait; }
#accessDialog input { width: 100px; margin: 0 12px; }
#usageForm { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin: 20px 0; padding: 0; }
#usageForm[hidden], #adminPanel[hidden] { display: none; }
.access-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 0; border-bottom: 1px solid #303540; }
.access-row span { flex: 1 1 180px; overflow-wrap: anywhere; }
.access-note { font-size: 12px; color: #a6b0c0; margin-top: 24px; }
#accessError { color: #ffa5a5; }
.auth-card > .secondary { margin-top: 12px; width: 100%; padding: 12px; }
.auth-card label + label { margin-top: 16px; }
.auth-screen { overflow-y: auto; }
@media (max-height: 720px) { .auth-screen { align-items: start; } }
@media (max-width: 480px) { #accessDialog { padding: 20px; } #accessDialog h2 { font-size: 19px; } }

/* Keep all controls reachable on narrow phones and short landscape viewports. */
header .model { flex: 1 1 0; min-width: 0; max-width: 430px; }
header .model span { min-width: 0; }
header .icon, header .logout { flex-shrink: 0; }
header .logout { white-space: nowrap; }
main, aside { min-height: 0; }
main { grid-template-columns: minmax(0, 1fr); }
#modelSelect { width: 100%; min-width: 0; border: 0; background: var(--panel); color: var(--text); padding: 6px 0; font: inherit; text-overflow: ellipsis; }
select { max-width: 100%; min-width: 0; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px; font: inherit; }
#manageAccounts[hidden] { display: none; }
#managementPage { width: min(1100px, calc(100vw - 20px)); height: calc(100dvh - 20px); max-height: calc(100dvh - 20px); padding: 20px; overflow: auto; }
.management-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
#managementPage h2 { margin: 0; }
#managementPage button { padding: 9px 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; }
#managementPage button:disabled { opacity: .45; }
#managementPage form { padding: 12px 0; }
#managementPage .managed-user { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.managed-user strong { flex: 1 1 160px; overflow-wrap: anywhere; }
#managementPage label.grant { display: flex; flex-direction: row; align-items: center; overflow-wrap: anywhere; font-weight: normal; }
#managementPage .grant input { width: 18px; flex: 0 0 18px; }
#roleModels { max-height: 40dvh; overflow: auto; margin-bottom: 16px; }
#managementError { color: #ffa5a5; }
dialog { max-height: calc(100dvh - 24px); overflow-y: auto; }
#accessDialog { max-height: calc(100dvh - 24px); overflow-wrap: anywhere; }
.auth-screen { height: 100dvh; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
@media (max-width: 1000px) and (max-height: 600px), (max-width: 760px) {
  .shell { display: block; }
  .mobile { display: grid; }
  aside { position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(280px, 86vw);
    height: 100dvh; transform: translateX(-102%); overflow-y: auto; }
  aside.open { transform: none; }
  .backdrop { position: fixed; z-index: 20; inset: 0; background: #0009; }
  .backdrop:not([hidden]) { display: block; }
  main { width: 100%; height: 100dvh; min-width: 0; overflow: hidden;
    grid-template-rows: auto minmax(0, 1fr) auto; }
  header { min-height: 58px; gap: 4px; padding: 6px max(6px, env(safe-area-inset-right)) 6px max(6px, env(safe-area-inset-left)); }
  header .model { padding-inline: 4px; gap: 6px; }
  header .logout { margin-left: 0; padding-inline: 7px; }
  header .icon { width: 32px; }
  .empty { padding: 20px 16px; }
  .prompts { grid-template-columns: minmax(0, 1fr); }
  footer { width: calc(100% - 20px); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .composer small, footer > p { display: none; }
  .composer > div { justify-content: flex-end; }
  .composer textarea { max-height: min(180px, 25dvh); }
}
@media (max-height: 500px) {
  .auth-screen { align-items: start; padding-top: 12px; }
  .auth-card { padding: 20px; }
  .auth-mark { display: none; }
  #accessDialog { padding: 16px; }
  #accessDialog h3 { margin-top: 16px; }
}
