.tarvi-pwa-notices {
  position: fixed;
  z-index: 80;
  left: max(12px, env(safe-area-inset-left, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  top: 0;
  max-height: min(35dvh, 280px);
  display: grid;
  gap: 8px;
  pointer-events: none;
  overflow-y: auto;
}

.tarvi-pwa-banner {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid rgba(145, 167, 214, 0.3);
  border-radius: 16px;
  background: rgba(8, 16, 31, 0.96);
  color: #f5f6f8;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.tarvi-pwa-banner[hidden] {
  display: none;
}

.tarvi-pwa-banner p {
  margin: 0;
  flex: 1 1 180px;
  font-size: 13px;
  line-height: 1.35;
}

.tarvi-pwa-banner button {
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid rgba(145, 167, 214, 0.3);
  background: #101a2d;
  color: #f5f6f8;
  font-size: 13px;
}

.tarvi-pwa-banner button.tarvi-pwa-primary {
  border-color: transparent;
  background: linear-gradient(135deg, #00d4b4 0%, #2962ff 52%, #9c4dff 100%);
  color: #fff;
}

.tarvi-pwa-file-proxy {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#tarvi-pwa-keyboard-probe {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
  --tarvi-keyboard-inset: env(keyboard-inset-bottom, 0px);
}

@media (min-width: 721px) {
  .tarvi-pwa-notices {
    left: auto;
    width: min(420px, calc(100vw - 24px));
    top: 0;
  }
}

@media (max-width: 720px) {
  body .app-shell {
    height: 100dvh;
    padding-bottom: calc(63px + env(safe-area-inset-bottom, 0px));
  }

  body .workspace {
    bottom: calc(63px + env(safe-area-inset-bottom, 0px));
  }

  body .mobile-nav {
    height: calc(63px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  body .composer {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }

  body .composer-tool,
  body .send-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  body .composer-input-wrap textarea {
    font-size: 16px;
  }

  body.tarvi-pwa-keyboard .mobile-nav {
    display: none;
  }

  body.tarvi-pwa-keyboard .app-shell {
    padding-bottom: env(keyboard-inset-bottom, 0px);
  }

  body.tarvi-pwa-keyboard .workspace {
    bottom: env(keyboard-inset-bottom, 0px);
  }

  body.tarvi-pwa-keyboard .composer {
    padding-bottom: max(12px, env(keyboard-inset-bottom, 0px));
  }

  body.tarvi-pwa-keyboard .tarvi-pwa-notices {
    top: 0;
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  body .app-shell {
    height: 100dvh;
    grid-template-columns: 76px minmax(240px, 320px) minmax(0, 1fr);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  body .nav-rail {
    display: flex;
  }

  body .mobile-nav {
    display: none;
  }

  body .composer-tool,
  body .send-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
}

html.tarvi-pwa-standalone .prototype-banner {
  display: none;
}

html.tarvi-pwa-standalone body .app-shell {
  height: 100dvh;
}

/* A landscape phone can leave less than one chat row above the IME. Keep the
   composer usable there; the full conversation returns when the IME closes. */
@media (max-width: 900px) and (max-height: 320px) {
  body.tarvi-pwa-keyboard .prototype-banner,
  body.tarvi-pwa-keyboard .nav-rail,
  body.tarvi-pwa-keyboard .list-panel,
  body.tarvi-pwa-keyboard .conversation-header,
  body.tarvi-pwa-keyboard .connection-strip,
  body.tarvi-pwa-keyboard .demo-scene-bar,
  body.tarvi-pwa-keyboard .messages,
  body.tarvi-pwa-keyboard .mobile-nav {
    display: none !important;
  }

  body.tarvi-pwa-keyboard .app-shell {
    display: block;
    height: 100dvh;
    padding: 0;
  }

  body.tarvi-pwa-keyboard .workspace {
    position: fixed;
    inset: 0;
    width: 100%;
    height: auto !important;
    transform: none;
  }

  body.tarvi-pwa-keyboard .composer {
    grid-template-columns: 44px 44px minmax(0, 1fr) 44px 44px !important;
    grid-template-rows: minmax(0, 1fr);
    gap: 6px;
    min-height: 0;
    height: 100%;
    padding: 4px 8px;
    align-items: center;
  }

  body.tarvi-pwa-keyboard .composer > [data-action="attach"] { grid-row: 1; grid-column: 1; }
  body.tarvi-pwa-keyboard .composer > .voice-record-button { grid-row: 1; grid-column: 2; }
  body.tarvi-pwa-keyboard .composer > .composer-input-wrap { grid-row: 1; grid-column: 3; }
  body.tarvi-pwa-keyboard .composer > .send-button { grid-row: 1; grid-column: 4; }
  body.tarvi-pwa-keyboard .composer > #quietSendToggleWrap { grid-row: 1; grid-column: 5; }

  body.tarvi-pwa-keyboard .composer-input-wrap {
    height: 44px;
    overflow-y: auto;
    padding: 4px 8px;
  }

  body.tarvi-pwa-keyboard.chats-real-v1 #messageInput {
    max-height: 32px;
    overflow-y: auto;
  }
}

/* Reserve notice space in the layout instead of intercepting page controls.
   Stacked notices scroll within the strip; the composer remains outside it. */
body .app-shell {
  padding-top: var(--tarvi-pwa-notice-space, 0px);
}
body.chats-login-only .app-shell {
  padding-top: calc(24px + var(--tarvi-pwa-notice-space, 0px));
}
/* styles.css has ID-specific full-height mobile rules, and the incoming-alert
   stylesheet owns a separate normal-flow row. The measured bottom composes both
   rows. Keep this narrow layout invariant above those competing declarations. */
@media (max-width: 720px), (min-width: 721px) and (max-width: 1024px) and (max-height: 500px) {
  body #workspace {
    top: var(--tarvi-pwa-notice-bottom, 0px) !important;
    height: calc(100dvh - var(--tarvi-pwa-notice-bottom, 0px) - 63px - env(safe-area-inset-bottom, 0px)) !important;
    min-height: 0;
  }
  body.chats-real-v1 #workspace.mobile-open {
    height: calc(100dvh - var(--tarvi-pwa-notice-bottom, 0px)) !important;
  }
}

/* The real conversation details drawer is also fixed, outside the grid row. */
body.chats-real-v1 .details-panel.chats-real-details.open {
  top: var(--tarvi-pwa-notice-bottom, 30px) !important;
}
