/* Grid items must shrink to their track even with long account or portal names. */
.hub-command-shell > *,
.hub-stage > *,
.hub-hero-card > *,
.hub-user-badge > *,
.hub-status-panel,
.dashboard-layout > *,
.settings-content > *,
.stack-form > * {
  min-width: 0;
}

.hub-user-badge > div { display: grid; gap: 2px; }
.hub-user-badge strong { overflow-wrap: anywhere; }
:is(a, button, summary):focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

@media (max-width: 900px) {
  html, body { overflow-x: clip; }
  html { scroll-padding-top: 130px; }
  .site-shell { min-height: 100dvh; }
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
    margin-bottom: 16px;
    background: #19120e;
    backdrop-filter: none;
    box-shadow: 0 4px 16px rgb(0 0 0 / 15%);
  }
  .brand { font-size: 15px; }
  .brand .brand-mark { width: 34px; height: 34px; flex: 0 0 34px; }
  .brand span:last-child { display: block; overflow-wrap: anywhere; line-height: 1.2; }
  .top-actions { grid-column: 2; grid-row: 1; }
  .user-menu summary { min-height: 44px; min-width: 44px; padding: 5px; justify-content: center; }
  .user-menu summary span:last-child { display: none; }
  .user-menu-panel {
    right: 0;
    width: min(260px, calc(100vw - 28px));
    max-height: calc(100dvh - 90px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .user-menu-panel :is(a, button), .login-chip { min-height: 44px; }
  .main-nav {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    overflow: visible;
  }
  .main-nav a { min-height: 44px; padding: 8px 4px; justify-content: center; font-size: 14px; border-radius: 6px; }
  .main-nav svg { display: block; width: 16px; height: 16px; }
  .hub-command-shell, .hub-hero-card, .hub-dashboard-grid, .hub-tool-grid { grid-template-columns: minmax(0, 1fr); }
  .hub-rail, .hub-breadcrumb { display: none; }
  .hub-stage { gap: 24px; }
  .hub-hero-card { order: 1; min-height: 0; padding: 24px; gap: 22px; }
  .hub-hero-copy h1 { font-size: 42px; line-height: 1.08; overflow-wrap: anywhere; }
  .hub-lead { font-size: 16px; line-height: 1.6; margin-bottom: 20px; }
  .hub-chip { margin-bottom: 12px; font-size: 13px; max-width: 100%; }
  .hub-status-panel { max-width: none; padding: 14px 0 0; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: none; backdrop-filter: none; gap: 12px; }
  .hub-section { order: 2; gap: 8px; }
  .hub-section-note { display: none; }
  .hub-quick-grid { order: 3; }
  .hub-dashboard-grid { order: 4; }
  .hub-tool-card { min-height: 180px; grid-template-columns: minmax(100px, 0.4fr) minmax(0, 1fr); }
  .hub-tool-media { min-height: 100%; }
  .hub-tool-content { padding: 18px; align-content: center; gap: 8px; }
  .hub-tool-content strong { font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
  .hub-tool-content em { width: auto; font-size: 14px; }
  .hub-section-head h2 { font-size: 24px; }
  .hub-section-head a { display: inline-flex; align-items: center; min-height: 44px; }
  .hub-section-head { align-items: center; }
  .side-panel, .account-settings .side-panel { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; overflow: visible; }
  .side-panel .eyebrow { display: none; }
  .side-panel a, .account-settings .side-panel a { display: inline-flex; align-items: center; min-height: 44px; padding: 8px 12px; font-size: 14px; }
  .panel h1 { font-size: 30px; line-height: 1.15; }
  .admin-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .admin-stat-card { padding: 14px; min-width: 0; }
  .admin-stat-card span { font-size: 26px; }
  .admin-stat-card small, .log-row { overflow-wrap: anywhere; }
  .app-admin-form { padding: 14px; }
  .app-admin-form .app-form-preview { min-height: 100px; }
  input, select, textarea { min-width: 0; font-size: 16px; }
  .stack-form :is(button, .primary-action, .secondary-action) { min-height: 44px; white-space: normal; }
  .site-footer { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .has-reveal [data-lab-reveal] { opacity: 1; transform: none; transition: none; }
}

@media (max-width: 560px) {
  .site-shell { padding-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right)); }
  .topbar, .site-footer { width: 100vw; margin-left: calc(50% - 50vw); margin-right: calc(50% - 50vw); }
  .hub-hero-card { padding: 20px; gap: 20px; }
  .hub-hero-copy h1 { font-size: 36px; margin-bottom: 12px; }
  .hub-hero-copy .style-kicker { margin-bottom: 10px; font-size: 11px; }
  .hub-hero-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .hub-hero-actions a { padding: 10px 8px; min-height: 44px; font-size: 14px; text-align: center; }
  .hub-user-badge { grid-template-columns: 32px minmax(0, 1fr); gap: 10px; }
  .hub-user-badge strong { font-size: 14px; }
  .hub-user-badge small { font-size: 12px; }
  .hub-status-numbers strong { font-size: 20px; }
  .hub-status-numbers small { font-size: 11px; }
  .hub-tool-card { min-height: 170px; grid-template-columns: 88px minmax(0, 1fr); }
  .hub-tool-content { padding: 14px; }
  .hub-tool-content strong { font-size: 20px; }
  .hub-tool-content small { font-size: 13px; }
  .hub-tool-content .tool-status { width: fit-content; max-width: 100%; white-space: normal; font-size: 11px; }
  .hub-quick-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .hub-quick-action { min-height: 76px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; box-shadow: none; background: none; padding: 12px 0; gap: 4px 12px; }
  .hub-quick-action > span { grid-row: 1 / 3; }
  .hub-quick-action strong { font-size: 15px; }
  .hub-section-head { display: flex; gap: 12px; }
  .hub-connection-row { grid-template-columns: 40px minmax(0, 1fr); gap: 4px 10px; }
  .hub-connection-cover { width: 40px; height: 40px; grid-row: 1 / 3; }
  .hub-connection-row .tool-status { justify-self: start; }
  .hub-panel { padding: 16px; }
  .panel { padding: 16px; }
  .app-admin-form { border: 0; border-top: 1px solid var(--line); border-radius: 0; background: none; padding: 18px 0; }
  .admin-user-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 12px; }
  .admin-user-row > label:first-of-type { grid-column: 1 / -1; }
  .admin-user-row button { grid-column: 1 / -1; }
  .form-card.auth-workspace-card h1 { font-size: 34px; line-height: 1.12; }
  .auth-workspace-lead { font-size: 16px; }
  .auth-workspace-page { padding: 24px 4px 36px; }
  .auth-workspace-form { margin-top: 24px; gap: 18px; }
  .auth-workspace-form > label input { min-height: 50px; padding: 12px; }
  .auth-forgot-joke summary { min-height: 44px; display: inline-flex; align-items: center; }
  .auth-divider { margin: 24px 0; }
  .site-footer { padding-inline: 18px; gap: 16px; }
}

@media (hover: none) {
  .hub-tool-card.is-not-connected:hover :is(.hub-tool-media, .hub-tool-content) { opacity: 1; }
  .hub-tool-card.is-not-connected:hover .tool-hover-label { opacity: 0; }
  .hub-tool-card:hover, .hub-tool-card:hover .hub-tool-media, .hub-quick-action:hover { transform: none; }
}

@media (max-width: 900px) and (max-height: 500px) {
  .topbar { position: relative; }
  html { scroll-padding-top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .has-reveal [data-lab-reveal] { opacity: 1; transform: none; transition: none; }
}
