:root {
  --bg: #050b12;
  --panel: rgba(9, 22, 34, 0.78);
  --panel-strong: rgba(10, 28, 43, 0.94);
  --line: rgba(127, 229, 255, 0.16);
  --cyan: #65e7ff;
  --cyan-soft: #2aa9c8;
  --violet: #a788ff;
  --mint: #6fffc0;
  --amber: #ffc96b;
  --danger: #ff718b;
  --text: #ecfaff;
  --muted: #8ba8b6;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -10%, rgba(36, 120, 151, 0.2), transparent 42%),
    linear-gradient(145deg, #04090f 0%, #07131d 45%, #090d17 100%);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.glass {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}
.ambient {
  position: fixed;
  width: 36rem;
  height: 36rem;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.12;
  pointer-events: none;
}
.ambient-one { top: -16rem; left: -12rem; background: var(--cyan); }
.ambient-two { right: -18rem; bottom: -18rem; background: var(--violet); }
.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--cyan);
  font-size: 0.67rem;
  font-weight: 750;
  letter-spacing: 0.18em;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.auth-card {
  width: min(100%, 30rem);
  padding: clamp(1.6rem, 5vw, 2.8rem);
  border-radius: 2rem;
  text-align: center;
}
.auth-logo { width: 5.5rem; height: 5.5rem; filter: drop-shadow(0 0 30px rgba(101, 231, 255, 0.3)); }
.auth-card h1 { margin: 0.3rem 0; font-size: clamp(2.6rem, 10vw, 4.2rem); letter-spacing: -0.07em; }
.auth-card > p { color: var(--muted); }
.auth-form { display: grid; gap: 1rem; margin-top: 1.6rem; text-align: left; }
label { display: grid; gap: 0.45rem; color: #bdd2dc; font-size: 0.8rem; }
input, textarea, select {
  width: 100%;
  border: 1px solid rgba(126, 215, 238, 0.18);
  border-radius: 0.9rem;
  outline: none;
  color: var(--text);
  background: rgba(2, 10, 17, 0.72);
  padding: 0.85rem 1rem;
  transition: border-color 160ms, box-shadow 160ms;
}
input:focus, textarea:focus, select:focus {
  border-color: rgba(101, 231, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(101, 231, 255, 0.08);
}
.hint, .voice-hint { color: var(--muted); font-size: 0.72rem; }
.error-text { min-height: 1.1rem; color: var(--danger) !important; }
code { color: #a7edff; word-break: break-all; }

.primary, .secondary, .ghost, .send-button {
  border: 0;
  border-radius: 0.9rem;
  padding: 0.82rem 1.1rem;
  font-weight: 720;
  transition: transform 140ms, filter 140ms, background 140ms;
}
.primary, .send-button {
  color: #031017;
  background: linear-gradient(135deg, var(--cyan), var(--mint));
  box-shadow: 0 10px 30px rgba(78, 213, 239, 0.18);
}
.secondary { color: var(--cyan); background: rgba(101, 231, 255, 0.1); border: 1px solid rgba(101, 231, 255, 0.22); }
.ghost { color: var(--muted); background: transparent; border: 1px solid var(--line); }
.danger { color: var(--danger); }
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px) scale(0.99); }
button:disabled { cursor: not-allowed; filter: grayscale(0.7); opacity: 0.45; }

.app {
  width: min(100%, 62rem);
  min-height: 100vh;
  margin: auto;
  padding: max(0.8rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto minmax(8rem, 1fr) auto auto auto;
  gap: 0.8rem;
}
.topbar { display: grid; grid-template-columns: 10rem 1fr 10rem; align-items: center; }
.top-actions { justify-self: end; display: flex; gap: 0.4rem; }
.top-actions .icon-button { width: 2.3rem; height: 2.3rem; }
.identity { justify-self: center; display: flex; align-items: center; gap: 0.65rem; }
.identity img { width: 2.3rem; height: 2.3rem; }
.identity div { display: grid; }
.identity strong { letter-spacing: 0.02em; }
.identity span { color: var(--muted); font-size: 0.68rem; }
.icon-button, .round-button {
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: rgba(8, 22, 34, 0.64);
}
.stop-button {
  min-width: 3.4rem;
  height: 2.3rem;
  border: 1px solid rgba(255, 113, 139, 0.5);
  border-radius: 999px;
  color: var(--danger);
  background: rgba(255, 113, 139, 0.08);
  font-size: 0.64rem;
  font-weight: 850;
  letter-spacing: 0.09em;
}
.stop-button.engaged {
  color: #fff;
  background: rgba(181, 25, 54, 0.86);
  animation: stop-pulse 1.4s infinite;
}
@keyframes stop-pulse { 50% { box-shadow: 0 0 24px rgba(255, 113, 139, 0.42); } }
.round-button.active { color: var(--cyan); border-color: rgba(101, 231, 255, 0.46); background: rgba(101, 231, 255, 0.1); }

.presence { position: relative; min-height: clamp(13rem, 34vh, 22rem); display: grid; place-items: center; }
#mentor-canvas { width: 100%; height: 100%; position: absolute; inset: 0; }
.state-line {
  z-index: 2;
  align-self: end;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.48rem 0.78rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(4, 13, 21, 0.64);
  backdrop-filter: blur(12px);
  font-size: 0.72rem;
}
.state-line span:last-child { color: var(--muted); }
.state-dot { width: 0.45rem; height: 0.45rem; border-radius: 50%; background: var(--mint); box-shadow: 0 0 12px var(--mint); }

.conversation { overflow-y: auto; min-height: 7rem; max-height: 30vh; padding: 0.2rem 0.3rem; scroll-behavior: smooth; }
.message, .welcome-message {
  max-width: 84%;
  margin: 0.7rem 0;
  padding: 0.85rem 1rem;
  border-radius: 1rem;
  color: #d8eaf2;
  background: rgba(13, 31, 45, 0.58);
  border: 1px solid rgba(120, 219, 245, 0.1);
  line-height: 1.5;
  white-space: pre-wrap;
}
.message.owner { margin-left: auto; color: #effbff; background: rgba(45, 77, 100, 0.48); }
.message-source { margin: 0 0 0.35rem; color: var(--cyan); font-size: 0.61rem; letter-spacing: 0.14em; }
.message p:last-child, .welcome-message p:last-child { margin: 0; }

.plan-card, .progress-card { border-radius: 1.25rem; padding: 1rem; }
.plan-heading, .progress-header { display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.plan-heading h2 { margin: 0; font-size: 1.05rem; }
.risk-badge { padding: 0.38rem 0.6rem; border-radius: 999px; color: var(--mint); background: rgba(111, 255, 192, 0.08); font-size: 0.68rem; }
.risk-badge.risk-2, .risk-badge.risk-3 { color: var(--amber); background: rgba(255, 201, 107, 0.1); }
.plan-content { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; margin-top: 0.85rem; }
.plan-block { padding: 0.7rem; border-radius: 0.8rem; background: rgba(1, 8, 14, 0.42); }
.plan-block h3 { margin: 0 0 0.35rem; color: var(--cyan); font-size: 0.64rem; letter-spacing: 0.11em; }
.plan-block p, .plan-block ul { margin: 0; padding-left: 1rem; color: #bcd1dc; font-size: 0.77rem; line-height: 1.45; }
.plan-hash { color: var(--muted); font-size: 0.68rem; }
.correction-row { display: grid; grid-template-columns: 1fr auto; gap: 0.55rem; }
.plan-actions { display: flex; justify-content: flex-end; gap: 0.7rem; margin-top: 0.75rem; }
.approve { min-width: 7rem; }
.progress-track { height: 0.42rem; overflow: hidden; margin: 0.7rem 0; border-radius: 999px; background: rgba(255,255,255,.07); }
#progress-bar { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--violet), var(--cyan), var(--mint)); transition: width 250ms; }

.composer { border-radius: 1.35rem; padding: 0.55rem; }
.composer textarea { min-height: 3rem; max-height: 10rem; resize: none; border: 0; background: transparent; }
.composer-actions { display: flex; align-items: center; gap: 0.45rem; }
.send-button { margin-left: auto; min-width: 6rem; }
.voice-hint { margin: 0.45rem 0 0 0.3rem; }
.status-footer { display: flex; justify-content: space-between; color: #66818e; font-size: 0.62rem; padding: 0 0.3rem; }

.drawer {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  width: min(92vw, 28rem);
  height: 100vh;
  padding: max(1rem, env(safe-area-inset-top)) 1rem;
  overflow-y: auto;
  background: var(--panel-strong);
  border-left: 1px solid var(--line);
  box-shadow: -30px 0 80px rgba(0,0,0,.4);
  transform: translateX(105%);
  transition: transform 240ms ease;
}
.drawer.open { transform: translateX(0); }
.drawer-header { display: flex; justify-content: space-between; align-items: center; }
.drawer-header h2 { margin: 0; }
.drawer-backdrop { position: fixed; z-index: 15; inset: 0; background: rgba(0,0,0,.58); backdrop-filter: blur(4px); }
.search-field, .settings-section { margin-top: 1.2rem; }
.drawer-list { display: grid; gap: 0.6rem; margin-top: 1rem; }
.history-item, .integration-item {
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: rgba(4, 13, 21, 0.55);
}
.history-item { cursor: pointer; }
.history-item strong, .history-item span { display: block; }
.history-item span { margin-top: 0.25rem; color: var(--muted); font-size: 0.7rem; }
.settings-section { display: grid; gap: 0.8rem; padding: 1rem; border: 1px solid var(--line); border-radius: 1rem; }
.settings-section h3 { margin: 0; }
.runtime-metrics {
  padding: 0.75rem;
  border: 1px solid color-mix(in srgb, var(--cyan) 24%, transparent);
  border-radius: 0.75rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--cyan) 5%, transparent);
  font: 0.72rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.control-status.stopped {
  border-color: rgba(255, 113, 139, 0.58);
  background: rgba(90, 15, 31, 0.22);
}
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.capability-list { display: grid; gap: 0.55rem; max-height: 28rem; overflow: auto; }
.capability-item {
  padding: 0.72rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: rgba(2, 10, 17, 0.42);
}
.capability-item header { display: flex; justify-content: space-between; gap: 0.6rem; }
.capability-item p { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.7rem; }
.capability-state { color: var(--cyan); font-size: 0.61rem; text-align: right; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 0.7rem; }
.section-heading .ghost { padding: 0.48rem 0.68rem; font-size: 0.72rem; }
.device-item, .download-item {
  display: grid;
  gap: 0.35rem;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: rgba(4, 14, 23, 0.58);
}
.device-heading, .download-heading { display: flex; justify-content: space-between; gap: 0.7rem; align-items: center; }
.device-meta, .download-meta { color: var(--muted); font-size: 0.68rem; line-height: 1.45; }
.device-state, .artifact-state {
  color: var(--mint);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.artifact-state.waiting, .device-state.waiting { color: var(--amber); }
.artifact-actions { display: flex; gap: 0.5rem; align-items: center; }
.artifact-actions a { color: var(--cyan); font-size: 0.73rem; }
.checksum { color: #8ba5b7; font: 0.62rem/1.4 ui-monospace, SFMono-Regular, monospace; word-break: break-all; }
.pairing-result {
  padding: 0.9rem;
  border: 1px solid rgba(101, 231, 255, .3);
  border-radius: 0.8rem;
  background: rgba(101, 231, 255, .07);
}
.pairing-code { font: 700 1.35rem/1.2 ui-monospace, SFMono-Regular, monospace; letter-spacing: .22em; color: var(--cyan); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle-row input { width: auto; }
.integration-list { display: grid; gap: 0.5rem; }
.integration-item { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.78rem; }
.integration-state { color: var(--amber); font-size: 0.65rem; }
.update-toast { position: fixed; z-index: 40; right: 1rem; bottom: 1rem; padding: 0.8rem 1rem; border-radius: 0.8rem; background: #123044; box-shadow: var(--shadow); }
.update-toast button { margin-left: 0.5rem; color: var(--cyan); background: transparent; border: 0; }

@media (max-width: 620px) {
  .app { gap: 0.55rem; padding-inline: 0.7rem; }
  .topbar { grid-template-columns: 8rem 1fr 8rem; }
  .presence { min-height: 11rem; }
  .identity span { display: none; }
  .stop-button { min-width: 2.8rem; padding: 0.35rem; }
  .control-grid { grid-template-columns: 1fr; }
  .app { min-height: 100dvh; grid-template-rows: auto minmax(6rem, 24vh) minmax(12rem, 1fr) auto auto auto; }
  .presence { min-height: 7rem; }
  .conversation { max-height: none; min-height: 0; overflow-y: auto; padding-bottom: 0.5rem; }
  .composer { position: sticky; bottom: max(0.35rem, env(safe-area-inset-bottom)); z-index: 8; }
  .plan-content { grid-template-columns: 1fr; }
  .correction-row { grid-template-columns: 1fr; }
  .message, .welcome-message { max-width: 92%; }
  .voice-hint { display: block; min-height: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
  .ambient { display: none; }
}

.activation-progress {
  width: 100%;
  height: .55rem;
  margin: .7rem 0 1rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 75%, transparent);
}
.activation-progress > span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--blue));
  transition: width .25s ease;
}
.activation-domain {
  margin-top: .4rem;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}


/* Fase 3A — experiência compacta de aplicativo */
html, body { min-height: 100%; }
body { overflow: hidden; }
.app {
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  grid-template-rows: auto minmax(4.8rem, 14vh) minmax(0, 1fr) auto auto auto;
  gap: 0.55rem;
}
.presence { min-height: 4.8rem; max-height: 14vh; }
.conversation {
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 0.15rem 0.3rem 0.65rem;
}
.composer { flex: 0 0 auto; }
.composer textarea {
  min-height: 4.6rem;
  max-height: min(28vh, 14rem);
  line-height: 1.42;
  overflow-y: auto;
}
.plan-card {
  max-height: min(58vh, 34rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.progress-card { flex: 0 0 auto; }
.updates-section h4 { margin: 1rem 0 0.35rem; color: var(--cyan); }
.update-entry { padding: 0.78rem; border: 1px solid var(--line); border-radius: 0.8rem; background: rgba(1,8,14,.35); }
.update-entry strong { display: block; }
.update-entry span { display: block; margin-top: .25rem; color: var(--muted); font-size: .74rem; line-height: 1.4; }

@media (min-width: 621px) {
  .app { grid-template-rows: auto minmax(5.5rem, 16vh) minmax(0, 1fr) auto auto auto; }
  .presence { min-height: 5.5rem; max-height: 16vh; }
  .composer textarea { min-height: 4.2rem; }
}

@media (max-width: 620px) {
  body { height: 100dvh; }
  .app {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    padding: max(.4rem, env(safe-area-inset-top)) .55rem max(.35rem, env(safe-area-inset-bottom));
    grid-template-rows: auto minmax(3.6rem, 8vh) minmax(0, 1fr) auto auto auto;
    gap: .38rem;
  }
  .topbar { grid-template-columns: 2.6rem minmax(0, 1fr) auto; gap: .25rem; }
  .identity { justify-self: start; min-width: 0; }
  .identity img { width: 1.85rem; height: 1.85rem; }
  .identity span { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .top-actions { gap: .22rem; }
  .top-actions .icon-button { width: 2rem; height: 2rem; }
  .stop-button { min-width: 2.9rem; height: 2rem; }
  .presence { min-height: 3.6rem; max-height: 8vh; }
  .state-line { padding: .34rem .56rem; font-size: .66rem; gap: .38rem; }
  .message, .welcome-message { max-width: 92%; margin: .4rem 0; padding: .68rem .78rem; line-height: 1.42; }
  .composer { position: static; padding: .42rem; border-radius: 1rem; }
  .composer textarea { min-height: 5.6rem; max-height: 26vh; font-size: 16px; }
  .composer-actions { gap: .3rem; }
  .round-button { width: 2.45rem; height: 2.45rem; }
  .send-button { min-width: 4.8rem; padding: .72rem .82rem; }
  .voice-hint { margin: .32rem .18rem 0; font-size: .66rem; }
  .status-footer { font-size: .56rem; }
  .plan-card { max-height: 52vh; padding: .75rem; }
  .plan-content { grid-template-columns: 1fr; gap: .45rem; }
  .plan-block { padding: .58rem; }
  .plan-block p, .plan-block ul { font-size: .73rem; }
}


/* ============================================================
   FASE 3A-R1 — aplicação móvel estável, conversa como área útil
   ============================================================ */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden !important;
  overscroll-behavior-x: none;
}

body {
  touch-action: pan-y;
}

.app {
  width: 100%;
  max-width: 100vw;
  height: var(--mentor-viewport-height, 100dvh) !important;
  max-height: var(--mentor-viewport-height, 100dvh);
  min-width: 0;
  overflow: hidden !important;
  grid-template-rows: auto minmax(4.4rem, 13vh) minmax(0, 1fr) auto auto !important;
}

.app > * {
  min-width: 0;
}

.topbar {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.top-left-actions,
.top-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.search-glyph {
  display: block;
  width: 0.82rem;
  height: 0.82rem;
  border: 1.8px solid currentColor;
  border-radius: 50%;
  position: relative;
}

.search-glyph::after {
  content: "";
  position: absolute;
  width: 0.48rem;
  height: 1.8px;
  background: currentColor;
  right: -0.38rem;
  bottom: -0.16rem;
  transform: rotate(45deg);
  transform-origin: left center;
  border-radius: 999px;
}

.presence {
  min-height: 0 !important;
  height: auto !important;
  max-height: 13vh !important;
  overflow: hidden;
}

#mentor-canvas {
  max-width: 100%;
  max-height: 100%;
}

.conversation-stage {
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  padding: 0.6rem clamp(0.65rem, 2.5vw, 1.4rem) 1rem;
}

.conversation {
  width: 100%;
  max-width: 100%;
  min-height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0 !important;
}

.conversation .message,
.conversation .welcome-message {
  min-width: 0;
  max-width: min(88%, 58rem);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.conversation p {
  font-size: clamp(0.98rem, 2.7vw, 1.08rem);
  line-height: 1.55;
}

.plan-card,
.progress-card {
  width: 100%;
  max-width: 100%;
  margin: 0.8rem 0 0;
  min-width: 0;
  overflow: hidden;
}

.plan-content {
  min-width: 0;
}

.plan-block,
.plan-block p,
.plan-block li {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.composer {
  width: calc(100% - clamp(0.7rem, 2vw, 1.5rem) * 2);
  max-width: none !important;
  min-width: 0;
  margin: 0 clamp(0.7rem, 2vw, 1.5rem) 0.35rem;
  position: relative !important;
  inset: auto !important;
  transform: none !important;
  z-index: 12;
}

.composer textarea,
.correction-row input,
.search-field input {
  font-size: 16px !important;
  touch-action: auto;
  max-width: 100%;
}

.status-footer {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.history-search-context {
  display: grid;
  gap: 0.22rem;
  margin-top: 0.5rem;
  padding-left: 0.65rem;
  border-left: 2px solid color-mix(in srgb, var(--accent, #5ce8ff) 38%, transparent);
}

.history-search-context small {
  opacity: 0.68;
  line-height: 1.35;
}

.search-hit {
  outline: 2px solid color-mix(in srgb, var(--accent, #5ce8ff) 74%, transparent);
  outline-offset: 4px;
  border-radius: 0.8rem;
  animation: mentor-search-hit 2.8s ease-out;
}

@keyframes mentor-search-hit {
  0%, 30% { background: rgba(88, 230, 255, 0.14); }
  100% { background: transparent; }
}

.clarification-box {
  grid-column: 1 / -1;
  border: 1px solid rgba(92, 232, 255, 0.26);
  border-radius: 0.9rem;
  padding: 0.85rem;
  background: rgba(3, 21, 31, 0.54);
}

.clarification-box strong {
  display: block;
  margin-bottom: 0.45rem;
}

.clarification-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.clarification-options button {
  min-height: 2.5rem;
}

.recovery-section {
  border-color: rgba(92, 232, 255, 0.22);
}

@media (max-width: 760px) {
  .app {
    grid-template-rows: auto minmax(3.8rem, 10vh) minmax(0, 1fr) auto auto !important;
  }

  .topbar {
    padding: 0.5rem 0.55rem !important;
    gap: 0.35rem;
  }

  .top-left-actions,
  .top-actions {
    gap: 0.24rem;
  }

  .topbar .icon-button {
    width: 2.25rem;
    height: 2.25rem;
    flex: 0 0 2.25rem;
  }

  .stop-button {
    min-width: 3.25rem;
    min-height: 2.25rem;
    padding-inline: 0.55rem;
  }

  .identity {
    min-width: 0;
    flex: 1 1 auto;
    justify-content: center;
  }

  .identity img {
    width: 2rem;
    height: 2rem;
  }

  .identity div {
    min-width: 0;
  }

  .identity span {
    display: block;
    max-width: 32vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .presence {
    max-height: 10vh !important;
    min-height: 3.8rem !important;
  }

  .state-line {
    font-size: 0.76rem;
  }

  .conversation-stage {
    padding: 0.55rem 0.65rem 1rem;
  }

  .conversation .message,
  .conversation .welcome-message {
    max-width: 94%;
  }

  .conversation .message.owner {
    max-width: 94%;
  }

  .conversation p {
    font-size: 1rem;
    line-height: 1.52;
  }

  .plan-content {
    grid-template-columns: 1fr !important;
    gap: 0.55rem !important;
  }

  .plan-card {
    padding: 0.85rem !important;
  }

  .plan-heading h2 {
    font-size: 1.08rem;
  }

  .correction-row {
    grid-template-columns: 1fr !important;
  }

  .correction-row input {
    min-height: 3rem;
  }

  .plan-actions {
    position: sticky;
    bottom: 0;
    padding-top: 0.55rem;
    background: linear-gradient(180deg, transparent, rgba(3, 16, 25, 0.96) 34%);
  }

  .composer {
    width: calc(100% - 0.8rem);
    margin: 0 0.4rem max(0.28rem, env(safe-area-inset-bottom));
    padding: 0.62rem !important;
  }

  .composer textarea {
    min-height: 3.15rem !important;
    max-height: min(22dvh, 10rem) !important;
    line-height: 1.42;
  }

  .composer-actions {
    min-width: 0;
  }

  .voice-hint {
    font-size: 0.72rem;
    line-height: 1.25;
  }

  .status-footer {
    padding: 0 0.55rem 0.25rem !important;
    font-size: 0.68rem;
  }

  .drawer {
    width: min(100vw, 34rem) !important;
    max-width: 100vw !important;
    overflow-x: hidden;
  }

  .drawer * {
    max-width: 100%;
  }
}

@media (max-width: 430px) {
  .identity span {
    max-width: 24vw;
  }

  .topbar .icon-button {
    width: 2rem;
    height: 2rem;
    flex-basis: 2rem;
  }

  .topbar {
    padding-inline: 0.38rem !important;
  }

  .stop-button {
    min-width: 3rem;
    padding-inline: 0.4rem;
    font-size: 0.68rem;
  }

  .conversation-stage {
    padding-inline: 0.5rem;
  }
}

/* Rolagem por gesto, sem ocupar largura com barra visual. */
.conversation-stage {
  scrollbar-width: none;
}

.conversation-stage::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* ============================================================
   FASE 3A-R2 — viewport móvel livre, legível e sem conteúdo preso
   A rolagem vertical pertence ao documento/conversa e o zoom do
   navegador continua permitido. O layout nunca depende de 80%.
   ============================================================ */
html,
body {
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  overflow-x: hidden !important;
  overscroll-behavior-x: none;
}

body {
  height: auto !important;
  min-height: 100dvh;
  overflow-y: auto !important;
  touch-action: pan-y pinch-zoom !important;
}

.app {
  width: min(100%, 62rem) !important;
  max-width: 100% !important;
  height: auto !important;
  max-height: none !important;
  min-height: 100dvh !important;
  overflow: visible !important;
  grid-template-rows: auto auto auto auto auto !important;
  align-content: start;
}

.presence {
  min-height: 4.2rem !important;
  height: clamp(4.2rem, 10vh, 6.4rem) !important;
  max-height: none !important;
  overflow: hidden;
}

.conversation-stage {
  width: 100%;
  max-width: 100%;
  min-height: 12rem;
  max-height: none !important;
  overflow: visible !important;
  overscroll-behavior-x: none;
  touch-action: pan-y pinch-zoom !important;
  padding-bottom: 0.35rem;
}

.conversation {
  max-height: none !important;
  overflow: visible !important;
}

.plan-card,
.progress-card {
  max-height: none !important;
  overflow: visible !important;
}

.plan-actions {
  position: sticky;
  bottom: 0;
  z-index: 7;
  padding: 0.6rem 0 0.2rem;
  background: linear-gradient(
    180deg,
    rgba(4, 13, 21, 0),
    rgba(4, 13, 21, 0.92) 35%
  );
}

.composer {
  position: sticky !important;
  bottom: max(0.35rem, env(safe-area-inset-bottom));
  z-index: 12;
  width: calc(100% - 1rem) !important;
  margin: 0 0.5rem !important;
}

@media (max-width: 760px) {
  .app {
    padding:
      max(0.45rem, env(safe-area-inset-top))
      0.55rem
      max(0.65rem, env(safe-area-inset-bottom)) !important;
    gap: 0.5rem !important;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto !important;
    gap: 0.3rem !important;
    align-items: center;
  }

  .top-left-actions,
  .top-actions {
    gap: 0.22rem !important;
  }

  .top-actions .icon-button,
  .top-left-actions .icon-button {
    width: 2.15rem !important;
    height: 2.15rem !important;
  }

  .stop-button {
    min-width: 2.85rem !important;
    height: 2.15rem !important;
    padding-inline: 0.5rem;
  }

  .identity {
    gap: 0.35rem !important;
  }

  .identity img {
    width: 2rem !important;
    height: 2rem !important;
  }

  .identity span {
    max-width: 34vw !important;
  }

  .presence {
    min-height: 3.6rem !important;
    height: clamp(3.6rem, 8vh, 5rem) !important;
  }

  .conversation-stage {
    min-height: 14rem;
    padding: 0.25rem 0.2rem 0.5rem !important;
  }

  .conversation .message,
  .conversation .welcome-message {
    max-width: 94% !important;
    font-size: 1rem;
  }

  .conversation p {
    font-size: 1rem !important;
    line-height: 1.55 !important;
  }

  .plan-card,
  .progress-card {
    padding: 0.75rem !important;
    border-radius: 1rem !important;
  }

  .plan-heading {
    align-items: flex-start !important;
  }

  .plan-content {
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
  }

  .correction-row {
    grid-template-columns: 1fr !important;
  }

  .correction-row input,
  .composer textarea {
    font-size: 16px !important;
  }

  .plan-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem !important;
  }

  .plan-actions button {
    width: 100%;
    min-height: 2.8rem;
  }

  .composer {
    width: 100% !important;
    margin: 0 !important;
    padding: 0.48rem !important;
  }

  .composer textarea {
    min-height: 4.7rem !important;
    max-height: 32vh !important;
  }

  .composer-actions {
    flex-wrap: wrap;
  }

  .send-button {
    min-width: 5.2rem;
  }

  .status-footer {
    padding-bottom: max(0.2rem, env(safe-area-inset-bottom));
  }
}

@media (max-width: 430px) {
  .identity span {
    display: none;
  }

  .top-actions .icon-button,
  .top-left-actions .icon-button {
    width: 2rem !important;
    height: 2rem !important;
  }

  .stop-button {
    min-width: 2.6rem !important;
    font-size: 0.58rem;
  }

  .plan-actions {
    position: sticky;
    bottom: 0;
  }
}

/* ============================================================
   FASE 3A-R3 — experiência móvel real + confirmação de senha segura
   A classe mentor-mobile é aplicada pelo app mesmo quando o navegador
   simula um viewport desktop em um telefone.
   ============================================================ */
html.mentor-mobile {
  font-size: var(--mentor-mobile-font-size, 16px);
  width: 100%;
  max-width: 100%;
  overflow-x: hidden !important;
}

html.mentor-mobile body {
  width: 100%;
  max-width: 100%;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  touch-action: pan-y pinch-zoom !important;
}

html.mentor-mobile .app {
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  height: auto !important;
  max-height: none !important;
  min-height: 100dvh !important;
  margin: 0 !important;
  padding: 0.55rem !important;
  gap: 0.55rem !important;
  overflow: visible !important;
  grid-template-rows: auto auto auto auto auto !important;
  align-content: start !important;
}

html.mentor-mobile .topbar {
  grid-template-columns: auto minmax(0, 1fr) auto !important;
  gap: 0.35rem !important;
}

html.mentor-mobile .identity span {
  display: none !important;
}

html.mentor-mobile .presence {
  min-height: 3.4rem !important;
  height: 4.2rem !important;
  max-height: 4.2rem !important;
}

html.mentor-mobile .conversation-stage,
html.mentor-mobile .conversation,
html.mentor-mobile .plan-card,
html.mentor-mobile .progress-card {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  max-height: none !important;
  overflow: visible !important;
}

html.mentor-mobile .conversation-stage {
  min-height: 0 !important;
  padding: 0.2rem 0 0.4rem !important;
}

html.mentor-mobile .conversation .message,
html.mentor-mobile .conversation .welcome-message {
  width: auto !important;
  max-width: 96% !important;
  font-size: 1rem !important;
  line-height: 1.55 !important;
}

html.mentor-mobile .plan-content,
html.mentor-mobile .correction-row {
  grid-template-columns: 1fr !important;
  gap: 0.55rem !important;
}

html.mentor-mobile .plan-block p,
html.mentor-mobile .plan-block ul,
html.mentor-mobile .plan-block li,
html.mentor-mobile .plan-hash,
html.mentor-mobile .risk-badge,
html.mentor-mobile .status-footer,
html.mentor-mobile .voice-hint {
  font-size: 0.92rem !important;
  line-height: 1.5 !important;
}

html.mentor-mobile .plan-block h3 {
  font-size: 0.78rem !important;
}

html.mentor-mobile .plan-heading h2,
html.mentor-mobile .progress-header {
  font-size: 1.08rem !important;
}

html.mentor-mobile .plan-actions {
  position: sticky !important;
  bottom: 0 !important;
  z-index: 20 !important;
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 0.5rem !important;
  padding: 0.65rem 0 0.25rem !important;
}

html.mentor-mobile .plan-actions button,
html.mentor-mobile .correction-row button,
html.mentor-mobile .send-button {
  min-height: 2.9rem !important;
  font-size: 1rem !important;
}

html.mentor-mobile .correction-row input,
html.mentor-mobile .composer textarea,
html.mentor-mobile input,
html.mentor-mobile select {
  font-size: 16px !important;
}

html.mentor-mobile .composer {
  position: sticky !important;
  bottom: max(0.25rem, env(safe-area-inset-bottom)) !important;
  z-index: 25 !important;
  width: 100% !important;
  margin: 0 !important;
  padding: 0.55rem !important;
}

html.mentor-mobile .composer textarea {
  min-height: 4.5rem !important;
  max-height: 35vh !important;
}

html.mentor-mobile .drawer {
  width: min(100%, 34rem) !important;
  max-width: 100% !important;
}

.secure-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(0, 5, 10, 0.72);
  backdrop-filter: blur(10px);
}

.secure-modal.hidden {
  display: none !important;
}

.secure-modal-card {
  width: min(100%, 30rem);
  padding: 1.15rem;
  border: 1px solid var(--line);
  border-radius: 1.2rem;
}

.secure-modal-card h2 {
  margin: 0.25rem 0 0.45rem;
}

.secure-modal-message {
  color: var(--muted);
  line-height: 1.5;
}

.secure-password-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: center;
}

.secure-password-row input {
  width: 100%;
  font-size: 16px;
}

.secure-eye {
  width: 3rem;
  height: 3rem;
  font-size: 1.15rem;
}

.secure-modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-top: 1rem;
}

.secure-modal-actions button {
  min-height: 2.9rem;
}
