:root {
  --ink: #0e1a24;
  --ink-soft: #3a4a58;
  --paper: #f3efe6;
  --panel: rgba(255, 252, 246, 0.92);
  --bot: #ffffff;
  --user: #1a4d63;
  --accent: #d97706;
  --accent-deep: #b45309;
  --line: rgba(14, 26, 36, 0.08);
  --shadow: 0 24px 60px rgba(14, 26, 36, 0.18);
  --radius: 18px;
  --font: "Outfit", system-ui, sans-serif;
  --display: "Source Serif 4", Georgia, serif;
  --vv-height: 100dvh;
  --vv-offset: 0px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  position: fixed;
  inset: 0;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(217, 119, 6, 0.28), transparent 55%),
    radial-gradient(ellipse 70% 45% at 100% 0%, rgba(26, 77, 99, 0.35), transparent 50%),
    linear-gradient(165deg, #1a4d63 0%, #0e1a24 42%, #243b4a 100%);
  pointer-events: none;
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.12;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 20%, transparent 75%);
}

.shell {
  position: fixed;
  top: var(--vv-offset);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(480px, 100%);
  height: var(--vv-height);
  max-height: var(--vv-height);
  margin: 0;
  background: var(--panel);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.shell-head {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  min-width: 0;
}

@media (min-width: 640px) {
  .shell {
    top: 50%;
    transform: translate(-50%, -50%);
    height: min(860px, calc(100dvh - 48px));
    max-height: min(860px, calc(100dvh - 48px));
    border-radius: 28px;
    border: 1px solid rgba(255, 255, 255, 0.2);
  }
}

.brand-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 252, 246, 0.98), rgba(255, 252, 246, 0.85));
  animation: slideDown 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
  flex-shrink: 0;
  transition: padding 0.2s ease;
}

.brand-text {
  min-width: 0;
  flex: 1 1 auto;
}

body.keyboard-open .brand-bar {
  padding: 8px 16px;
}

body.keyboard-open .brand-mark,
body.keyboard-open .status-line,
body.keyboard-open .install-app-btn,
body.keyboard-open .auth-btn,
body.keyboard-open .history-btn,
body.keyboard-open .auth-notice {
  display: none !important;
}

body.keyboard-open .brand-text h1 {
  font-size: 1.15rem;
}

.brand-mark {
  width: 44px;
  height: 44px;
  color: var(--accent);
  flex-shrink: 0;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

.brand-text h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--ink);
}

.status-line {
  margin: 4px 0 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-weight: 500;
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #16a34a;
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5);
  animation: pulse 2s ease-out infinite;
}

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  animation: riseIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
  flex-shrink: 0;
}

.msg strong {
  font-weight: 650;
}

.msg.bot {
  align-self: flex-start;
  background: var(--bot);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: 0 8px 20px rgba(14, 26, 36, 0.05);
}

.msg a {
  color: inherit;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg.bot a {
  color: var(--user);
}

.msg-images {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.msg-images img {
  display: block;
  width: 100%;
  max-width: 280px;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.msg.user a {
  color: #fde68a;
}

.typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 4px 20px 10px;
  flex-shrink: 0;
}

.typing.hidden {
  display: none;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-soft);
  opacity: 0.45;
  animation: bounce 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 16px 12px;
  animation: riseIn 0.3s ease both;
  flex-shrink: 0;
}

.quick-replies[hidden] {
  display: none;
}

.chip {
  appearance: none;
  border: 1px solid rgba(26, 77, 99, 0.22);
  background: rgba(255, 255, 255, 0.85);
  color: var(--user);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, border-color 0.15s;
}

.chip:hover {
  background: #fff;
  border-color: var(--accent);
  transform: translateY(-1px);
}

.chip:active {
  transform: translateY(0);
}

.chip-whatsapp {
  border: none;
  background: linear-gradient(145deg, #25d366, #128c7e);
  color: #fff;
  box-shadow: 0 4px 14px rgba(37, 211, 102, 0.45);
  font-weight: 700;
  animation: waPulse 1.6s ease-in-out infinite;
}

.chip-whatsapp:hover {
  background: linear-gradient(145deg, #2fe574, #16a085);
  border-color: transparent;
  color: #fff;
  transform: translateY(-2px) scale(1.03);
}

@keyframes waPulse {
  0%,
  100% {
    box-shadow: 0 4px 14px rgba(37, 211, 102, 0.4);
  }
  50% {
    box-shadow: 0 6px 22px rgba(37, 211, 102, 0.7);
  }
}

.composer {
  display: flex;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: rgba(255, 252, 246, 0.98);
  flex-shrink: 0;
}

.composer[hidden],
body.composer-hidden .composer {
  display: none !important;
}

@media (max-width: 639px) {
  body.composer-hidden .quick-replies {
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
}

body.keyboard-open .composer {
  padding-bottom: 12px;
}

.composer input {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.composer input:focus {
  border-color: rgba(26, 77, 99, 0.45);
  box-shadow: 0 0 0 3px rgba(26, 77, 99, 0.12);
}

.composer button {
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: transform 0.15s, filter 0.15s;
}

.composer button:hover {
  filter: brightness(1.05);
}

.composer button:active {
  transform: scale(0.96);
}

.composer button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.composer button svg {
  width: 22px;
  height: 22px;
}

/* Formulário de cubagem (igual ao site de cotação) */
.cubagem-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: rgba(255, 252, 246, 0.98);
  flex-shrink: 0;
}

.cubagem-form[hidden] {
  display: none !important;
}

.cubagem-form-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
}

.cubagem-form-title {
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
}

.cubagem-form-hint {
  font-size: 0.78rem;
  color: var(--muted, #6b7280);
}

.cubagem-header {
  display: grid;
  grid-template-columns: 52px 1fr 1fr 1fr 36px;
  gap: 6px;
  padding: 0 2px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.cubagem-form[data-mode="same"] .cubagem-header {
  grid-template-columns: 1fr 1fr 1fr;
}

.cubagem-form[data-mode="same"] .cubagem-col-qtd,
.cubagem-form[data-mode="same"] .cubagem-col-actions {
  display: none;
}

.cubagem-linhas {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cubagem-row {
  display: grid;
  grid-template-columns: 52px 1fr 1fr 1fr 36px;
  gap: 6px;
  align-items: center;
}

.cubagem-form[data-mode="same"] .cubagem-row {
  grid-template-columns: 1fr 1fr 1fr;
}

.cubagem-row input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 11px 8px;
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  outline: none;
  text-align: center;
}

.cubagem-row input:focus {
  border-color: rgba(26, 77, 99, 0.45);
  box-shadow: 0 0 0 3px rgba(26, 77, 99, 0.12);
}

.cubagem-row .cubagem-qtd {
  text-align: center;
}

.cubagem-remove-btn {
  width: 36px;
  height: 42px;
  border: 1px solid rgba(185, 28, 28, 0.2);
  background: rgba(254, 242, 242, 0.9);
  color: #b91c1c;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.cubagem-remove-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.cubagem-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.cubagem-add-btn {
  appearance: none;
  border: 1px dashed rgba(26, 77, 99, 0.35);
  background: transparent;
  color: var(--user);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
}

.cubagem-add-btn[hidden] {
  display: none !important;
}

.cubagem-submit-btn {
  appearance: none;
  border: none;
  margin-left: auto;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fff;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 12px;
  cursor: pointer;
}

.cubagem-submit-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

body.cubagem-open .composer {
  display: none !important;
}

body.cubagem-open .quick-replies {
  display: none !important;
}

/* Modal WhatsApp */
.wa-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
}

.wa-modal[hidden] {
  display: none !important;
}

.wa-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 24, 32, 0.55);
  backdrop-filter: blur(2px);
}

.wa-modal-card {
  position: relative;
  width: min(100%, 380px);
  background: #fffaf3;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 20px 18px;
  box-shadow: 0 18px 48px rgba(12, 24, 32, 0.28);
  animation: riseIn 0.22s ease;
}

.wa-modal-card h2 {
  margin: 0 0 8px;
  font-family: var(--font);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}

.wa-modal-card p {
  margin: 0 0 18px;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--muted, #5b6b75);
}

.wa-modal-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.wa-modal-secondary {
  appearance: none;
  border: 1px solid rgba(26, 77, 99, 0.22);
  background: transparent;
  color: var(--user);
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 11px 14px;
  border-radius: 12px;
  cursor: pointer;
}

.wa-modal-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: linear-gradient(145deg, #1fa855, #128c45);
  color: #fff;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 11px 16px;
  border-radius: 12px;
}

@media (max-width: 639px) {
  .cubagem-header {
    font-size: 0.65rem;
  }

  .cubagem-row {
    grid-template-columns: 44px 1fr 1fr 1fr 34px;
  }

  .cubagem-form[data-mode="same"] .cubagem-row,
  .cubagem-form[data-mode="same"] .cubagem-header {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-4px);
    opacity: 0.9;
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.45);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(22, 163, 74, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0);
  }
}

/* Botão Instalar aplicativo */
.install-app-btn {
  appearance: none;
  flex-shrink: 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  min-width: 40px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgba(26, 77, 99, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--user);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.15;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

html.show-install-btn .install-app-btn {
  display: inline-flex;
}

html.pwa-standalone .install-app-btn,
.install-app-btn[hidden] {
  display: none !important;
}

.install-app-btn:hover {
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(14, 26, 36, 0.08);
}

.install-app-btn:focus-visible {
  outline: none;
  border-color: rgba(26, 77, 99, 0.55);
  box-shadow: 0 0 0 3px rgba(26, 77, 99, 0.16);
}

.install-app-btn:active {
  transform: scale(0.97);
}

.install-app-btn-icon {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  color: var(--accent-deep);
}

.install-app-btn-icon svg {
  width: 100%;
  height: 100%;
}

.install-app-btn-label {
  max-width: 7.2rem;
}

@media (max-width: 380px) {
  .install-app-btn {
    padding: 8px;
  }

  .install-app-btn-label {
    display: none;
  }
}

/* Modais de instalação (iOS / Android) */
.install-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
}

.install-modal[hidden] {
  display: none !important;
}

.install-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 24, 32, 0.55);
  backdrop-filter: blur(2px);
}

.install-modal-card {
  position: relative;
  width: min(100%, 400px);
  max-height: min(92dvh, 640px);
  overflow: auto;
  background: #fffaf3;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 20px 18px;
  box-shadow: 0 18px 48px rgba(12, 24, 32, 0.28);
  animation: riseIn 0.22s ease;
}

.install-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

.install-modal-close:hover,
.install-modal-close:focus-visible {
  background: rgba(14, 26, 36, 0.06);
  color: var(--ink);
  outline: none;
}

.install-modal-close svg {
  width: 18px;
  height: 18px;
}

.install-modal-icon {
  width: 56px;
  height: 56px;
  margin: 0 0 12px;
  color: var(--user);
}

.install-modal-icon.android {
  color: #3ddc84;
}

.install-modal-icon svg {
  width: 100%;
  height: 100%;
}

.install-modal-card h2 {
  margin: 0 0 8px;
  padding-right: 28px;
  font-family: var(--font);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
}

.install-modal-lead {
  margin: 0 0 16px;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--muted, #5b6b75);
}

.install-steps,
.ios-install-steps {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.install-steps li,
.ios-install-steps li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.install-step-num,
.ios-step-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(26, 77, 99, 0.1);
  color: var(--user);
  font-size: 0.85rem;
  font-weight: 700;
}

.install-steps strong,
.ios-install-steps strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 2px;
}

.install-steps p,
.ios-install-steps p {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.4;
  color: var(--muted, #5b6b75);
}

.install-steps em {
  font-style: normal;
  font-weight: 700;
  color: var(--user);
}

.ios-share-badge,
.ios-dots-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0 2px;
  padding: 3px 8px 3px 6px;
  border-radius: 8px;
  background: rgba(26, 77, 99, 0.1);
  color: var(--user);
  font-weight: 700;
  font-size: 0.82rem;
  vertical-align: middle;
}

.ios-dots-badge {
  min-width: 28px;
  justify-content: center;
  padding: 2px 10px 6px;
  font-size: 1.25rem;
  line-height: 1;
  letter-spacing: 0.02em;
}

.ios-share-badge svg {
  width: 16px;
  height: 16px;
}

.install-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.install-modal-primary {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border: none;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fff;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 11px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.15s;
}

.install-modal-primary:hover {
  filter: brightness(1.05);
}

.install-modal-primary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.35);
}

.install-modal-primary:active {
  transform: scale(0.98);
}

/* Auth opcional (ambiente de teste) */
.auth-btn {
  appearance: none;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  min-width: 40px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgba(26, 77, 99, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--user);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.15;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.auth-btn.is-logged {
  border-color: rgba(22, 163, 74, 0.35);
  background: rgba(220, 252, 231, 0.9);
  color: #166534;
}

.auth-btn.is-logged.is-incomplete {
  border-color: #c2410c;
  background: #fff7ed;
  color: #9a3412;
}

.auth-btn:hover {
  background: #fff;
  border-color: var(--accent);
}

.auth-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(26, 77, 99, 0.16);
}

.auth-btn-icon {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
}

.auth-btn-icon svg {
  width: 100%;
  height: 100%;
}

@media (max-width: 380px) {
  .auth-btn-label {
    display: none;
  }
}

.auth-notice {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(254, 243, 199, 0.95), rgba(255, 251, 235, 0.9));
  flex-shrink: 0;
}

.auth-notice[hidden] {
  display: none !important;
}

.auth-notice-warn {
  background: #fff7ed;
}

.auth-notice-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 180px;
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--ink-soft);
}

.auth-notice-text strong {
  color: var(--ink);
  font-size: 0.84rem;
}

.auth-notice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.auth-notice-primary,
.auth-notice-dismiss {
  appearance: none;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 650;
  padding: 8px 12px;
  cursor: pointer;
}

.auth-notice-primary {
  border: none;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fff;
}

.auth-notice-dismiss {
  border: 1px solid rgba(26, 77, 99, 0.2);
  background: transparent;
  color: var(--user);
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-modal[hidden] {
  display: none !important;
}

.auth-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 24, 32, 0.55);
  backdrop-filter: blur(2px);
}

.auth-modal-card {
  position: relative;
  width: min(100%, 420px);
  max-height: min(92dvh, 720px);
  overflow: auto;
  background: #fffaf3;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 20px 18px;
  box-shadow: 0 18px 48px rgba(12, 24, 32, 0.28);
  animation: riseIn 0.22s ease;
}

.auth-account-card {
  width: min(100%, 440px);
}

.auth-modal-card h2 {
  margin: 0 0 8px;
  padding-right: 28px;
  font-family: var(--font);
  font-size: 1.2rem;
  font-weight: 700;
}

.auth-modal-lead {
  margin: 0 0 16px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--muted, #5b6b75);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.auth-form input {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  outline: none;
}

.auth-form input:focus {
  border-color: rgba(26, 77, 99, 0.45);
  box-shadow: 0 0 0 3px rgba(26, 77, 99, 0.12);
}

.auth-form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(254, 242, 242, 0.95);
  color: #b91c1c;
  font-size: 0.85rem;
}

.auth-form-error[hidden] {
  display: none !important;
}

.auth-form-ok {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #ecfdf3;
  color: #166534;
  font-size: 0.85rem;
}

.auth-form-ok[hidden] {
  display: none !important;
}

.auth-switch {
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.86rem;
  color: var(--ink-soft);
}

.auth-link {
  appearance: none;
  border: none;
  background: none;
  color: var(--user);
  font-family: var(--font);
  font-size: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}

.auth-secondary-btn {
  appearance: none;
  width: 100%;
  border: 1px solid rgba(26, 77, 99, 0.22);
  background: #fff;
  color: var(--user);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 650;
  padding: 12px 16px;
  border-radius: 12px;
  cursor: pointer;
}

.auth-section-title {
  margin: 14px 0 8px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
}

.auth-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.85);
}

.auth-item strong {
  font-size: 0.9rem;
  color: var(--ink);
}

.auth-item span {
  font-size: 0.8rem;
  color: var(--ink-soft);
  line-height: 1.35;
}

.auth-item-meta {
  font-size: 0.75rem !important;
  color: var(--muted, #6b7280) !important;
}

.auth-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted, #6b7280);
}

.brand-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.history-btn {
  appearance: none;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  min-width: 40px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgba(26, 77, 99, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--user);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.15;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.history-btn[hidden] {
  display: none !important;
}

.history-btn:hover {
  background: #fff;
  border-color: var(--accent);
}

.history-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(26, 77, 99, 0.16);
}

.history-btn-icon {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
}

.history-btn-icon svg {
  width: 100%;
  height: 100%;
}

@media (max-width: 420px) {
  .history-btn-label,
  .auth-btn-label {
    display: none;
  }
}

.auth-account-info {
  display: grid;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.85);
}

.auth-account-label {
  display: block;
  margin-bottom: 2px;
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--muted, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.auth-account-info strong {
  font-size: 0.95rem;
  color: var(--ink);
  word-break: break-word;
}

.history-panel-card {
  width: min(100%, 520px);
  max-height: min(92dvh, 820px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-panel-card > .auth-modal-lead {
  flex-shrink: 0;
}

.history-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 0 12px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(26, 77, 99, 0.06);
  flex-shrink: 0;
}

.history-tab {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font);
  font-size: 0.86rem;
  font-weight: 650;
  cursor: pointer;
}

.history-tab.is-active {
  background: #fff;
  color: var(--user);
  box-shadow: 0 1px 4px rgba(12, 24, 32, 0.08);
}

.history-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.history-search input,
.history-filters select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  outline: none;
}

.history-search input:focus,
.history-filters select:focus {
  border-color: rgba(26, 77, 99, 0.45);
  box-shadow: 0 0 0 3px rgba(26, 77, 99, 0.12);
}

.history-filters {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
}

.history-filters[hidden] {
  display: none !important;
}

.history-result-meta {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted, #6b7280);
  flex-shrink: 0;
}

.history-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 2px;
}

.history-group-title {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 0 8px;
  padding: 6px 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: linear-gradient(180deg, #fffaf3 70%, rgba(255, 250, 243, 0));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-group-title span {
  font-weight: 650;
  color: var(--muted, #6b7280);
}

.history-group-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  appearance: none;
  width: 100%;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  color: inherit;
  font-family: var(--font);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
}

button.history-item:hover,
button.history-item:focus-visible {
  border-color: rgba(26, 77, 99, 0.35);
  background: #fff;
  outline: none;
}

.history-protocol-item {
  cursor: default;
}

.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-item-top strong {
  font-size: 0.92rem;
  color: var(--ink);
}

.history-protocol-number {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.history-item-badge {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(26, 77, 99, 0.08);
  color: var(--user);
  font-size: 0.7rem;
  font-weight: 700;
}

.history-item-preview,
.history-protocol-summary {
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--ink-soft);
}

.history-protocol-summary {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item-meta {
  font-size: 0.74rem;
  color: var(--muted, #6b7280);
}

.history-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.history-mini-btn {
  appearance: none;
  border: 1px solid rgba(26, 77, 99, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--user);
  font-family: var(--font);
  font-size: 0.74rem;
  font-weight: 650;
  padding: 7px 10px;
  cursor: pointer;
}

.history-mini-btn-primary {
  border-color: transparent;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fff;
}

.history-protocol-details {
  display: grid;
  gap: 8px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.history-protocol-details[hidden] {
  display: none !important;
}

.history-protocol-details div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-protocol-details span {
  font-size: 0.7rem;
  font-weight: 650;
  color: var(--muted, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.history-protocol-details strong {
  font-size: 0.86rem;
  font-weight: 650;
  color: var(--ink);
  word-break: break-word;
}

.history-view-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(219, 234, 254, 0.95), rgba(239, 246, 255, 0.9));
  flex-shrink: 0;
}

.history-view-banner[hidden] {
  display: none !important;
}

.history-view-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 160px;
}

.history-view-banner-text strong {
  font-size: 0.84rem;
  color: var(--ink);
}

.history-view-banner-text span {
  font-size: 0.76rem;
  color: var(--ink-soft);
  line-height: 1.3;
}

.history-view-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.history-view-btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fff;
  font-family: var(--font);
  font-size: 0.76rem;
  font-weight: 650;
  cursor: pointer;
}

.history-view-btn-ghost {
  border: 1px solid rgba(26, 77, 99, 0.2);
  background: transparent;
  color: var(--user);
}

body.history-viewing .composer,
body.history-viewing .quick-replies,
body.history-viewing .cubagem-form {
  display: none !important;
}
