:root {
  --brand: #06be8f;
  --brand-hover: #05a980;
  --brand-active: #049870;
  --teal: #007d84;
  --teal-hover: #006a70;
  --teal-active: #00575c;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;

  --success-bg: #dcfce7;
  --success-text: #166534;
  --error-bg: #fee2e2;
  --error-text: #991b1b;

  --radius: 8px;
  --transition: 0.2s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111827;
    --surface-muted: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #1e293b;

    --success-bg: #052e1a;
    --success-text: #6ee7b7;
    --error-bg: #3f1414;
    --error-text: #fca5a5;

    /* teal escuro tem contraste insuficiente sobre fundo escuro */
    --teal: #0d9488;
    --teal-hover: #0f766e;
    --teal-active: #115e59;
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  /* espaço para o banner de instalação não cobrir o conteúdo */
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

body.has-install-banner .page {
  padding-bottom: calc(140px + env(safe-area-inset-bottom));
}

.container {
  width: 100%;
  max-width: 480px;
}

/* ============ HEADER ============ */

.header {
  text-align: center;
  margin-bottom: 28px;
}

.logo {
  height: 32px;
  width: auto;
  margin-bottom: 16px;
}

.title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 4px;
}

.subtitle {
  font-size: 15px;
  color: var(--muted);
}

/* ============ FORM ============ */

.main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.label {
  font-size: 13px;
  font-weight: 500;
}

.input {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* 16px evita o zoom automático do iOS Safari ao focar */
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background-color: var(--surface);
  min-height: 48px;
  transition: border-color var(--transition);
}

.input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(6, 190, 143, 0.15);
}

.input-readonly {
  background-color: var(--surface-muted);
  color: var(--muted);
}

.input-error {
  border-color: #ef4444;
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

/* ============ BOTÕES ============ */

.btn {
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
  width: 100%;
  min-height: 48px;
}

.btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--brand);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) { background-color: var(--brand-hover); }
.btn-primary:active:not(:disabled) { background-color: var(--brand-active); }

.btn-secondary {
  background-color: var(--teal);
  color: #ffffff;
}

.btn-secondary:hover:not(:disabled) { background-color: var(--teal-hover); }
.btn-secondary:active:not(:disabled) { background-color: var(--teal-active); }

.btn-outline {
  background-color: transparent;
  color: var(--teal);
  border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--teal);
  background-color: var(--surface-muted);
}

.btn-sm {
  min-height: 40px;
  padding: 8px 16px;
  font-size: 14px;
  width: auto;
}

.btn-link {
  background: none;
  border: none;
  padding: 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-link:hover { color: var(--text); }

.btn-link:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============ RESULTADO ============ */

.result-section {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-product {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}

.result-actions {
  display: flex;
  gap: 8px;
}

/* ============ MENSAGEM ============ */

.message {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  text-align: center;
}

.message-success {
  background-color: var(--success-bg);
  color: var(--success-text);
}

.message-error {
  background-color: var(--error-bg);
  color: var(--error-text);
}

/* ============ HISTÓRICO ============ */

.history {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.history-title {
  font-size: 14px;
  font-weight: 600;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.history-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-copy {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--teal);
  cursor: pointer;
  min-height: 36px;
  transition: background-color var(--transition);
}

.history-copy:hover { background-color: var(--surface-muted); }

.history-copy:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ============ RODAPÉ ============ */

.disclaimer {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.footer {
  margin-top: 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.footer-links {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  justify-content: center;
}

.footer-links a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer-links a:hover { color: var(--text); }

/* ============ BANNER DE INSTALAÇÃO ============ */

.install-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background-color: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.install-banner.visible { transform: translateY(0); }

.install-content {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.install-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  flex-shrink: 0;
}

.install-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.install-title { font-size: 14px; }

.install-description {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* ícone de compartilhar do iOS, inline na instrução */
.ios-share-icon {
  display: inline-block;
  vertical-align: -2px;
  width: 13px;
  height: 13px;
  margin: 0 1px;
  fill: currentColor;
}

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

.install-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 12px;
  min-height: 44px;
}

.install-close:hover { color: var(--text); }

.install-close:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

/* modo iOS: só instrução, sem botão de instalar */
.install-banner.ios-mode .install-actions #installBtn { display: none; }

/* ============ PÁGINA DE DOCUMENTO ============ */

.page-doc {
  align-items: flex-start;
  padding-top: 40px;
}

.container-doc { max-width: 680px; }

.doc {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  line-height: 1.65;
  font-size: 15px;
}

.doc h1 {
  font-size: 24px;
  margin-bottom: 4px;
}

.doc h2 {
  font-size: 17px;
  margin-top: 28px;
  margin-bottom: 8px;
}

.doc p { margin-bottom: 12px; }

.doc ul {
  margin: 0 0 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.doc code {
  background-color: var(--surface-muted);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.doc a { color: var(--teal); }

.doc-meta {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 20px;
}

/* ============ UTILITÁRIOS ============ */

.hidden { display: none !important; }

@media (max-width: 480px) {
  .result-actions { flex-direction: column; }

  /* Em telas estreitas o banner empilha: texto em cima, ação em largura
     total embaixo. Antes o botão era espremido pelo texto e, no iOS
     (que não tem botão), a instrução sumia — deixando o banner sem ação. */
  .install-banner {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px 16px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .install-content { align-items: flex-start; }

  .install-actions {
    width: 100%;
    gap: 8px;
  }

  .install-actions .btn { flex: 1; }

  /* o "×" sobe para o canto do banner, liberando a linha para a ação */
  .install-close {
    position: absolute;
    top: 6px;
    right: 8px;
    padding: 6px 10px;
    min-height: 36px;
  }

  /* sem botão de instalar (iOS), a instrução é a própria ação:
     ganha destaque em vez de virar legenda apagada */
  .install-banner.ios-mode .install-description {
    font-size: 13px;
    color: var(--text);
  }

  /* esconde só o botão de instalar. O "×" vive no mesmo container e já
     está posicionado no canto pela regra .install-close acima — esconder
     .install-actions inteiro levava o botão de fechar junto. */
  .install-banner.ios-mode #installBtn { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
