/* =========================================================================
   CR Consultoria - App Mobile PCO
   Mobile-first: design otimizado para 360-420px, escala até tablet
   ========================================================================= */

:root {
  --blue:        #003399;
  --blue-dark:   #001f5c;
  --cyan:        #00ceff;
  --ink:         #172033;
  --text:        #344054;
  --muted:       #667085;
  --line:        #dce5f0;
  --line-strong: #c7d4e4;
  --page:        #f6f8fb;
  --surface:     #ffffff;
  --soft-blue:   #edf6ff;
  --soft-cyan:   #e9fbff;
  --danger:      #c9344f;
  --success:     #087f5b;
  --warning:     #916400;

  /* Cores das 4 carinhas */
  --face-1:      #2bb673;  /* Concordo Inteiramente */
  --face-2:      #8bc63f;  /* Concordo */
  --face-3:      #f7a823;  /* Discordo */
  --face-4:      #e94e4e;  /* Discordo Totalmente */

  --radius-sm:   10px;
  --radius:      16px;
  --radius-lg:   22px;
  --shadow:      0 8px 28px rgba(18, 35, 70, 0.10);
  --shadow-lift: 0 14px 38px rgba(0, 51, 153, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
}

body { font-size: 16px; line-height: 1.5; }

button, input { font-family: inherit; }

a { color: var(--blue); text-decoration: none; }

/* =========================================================================
   Layout shell (mobile-first)
   ========================================================================= */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--surface);
  position: relative;
}

@media (min-width: 481px) {
  body { background: linear-gradient(135deg, #eaf3ff 0%, #d8f1f9 100%); padding: 24px 0; }
  .app-shell { box-shadow: var(--shadow-lift); border-radius: 24px; overflow: hidden; min-height: calc(100vh - 48px); }
}

/* =========================================================================
   Header
   ========================================================================= */

.app-header {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: #fff;
  padding: 28px 22px 22px;
  position: relative;
}

.app-header-brand {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 18px;
}
.app-header-brand .brand-mark {
  width: 38px; height: 38px;
  background: rgba(255,255,255,.18);
  border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 14px; letter-spacing: .5px;
}
.app-header-brand strong { font-size: 15px; font-weight: 700; letter-spacing: .3px; }
.app-header-brand small { display: block; opacity: .8; font-size: 11px; font-weight: 500; }

.app-header h1 {
  margin: 0;
  font-size: 22px; font-weight: 800; line-height: 1.25;
  letter-spacing: -0.2px;
}
.app-header p.lead { margin: 6px 0 0; opacity: .85; font-size: 14px; }

.header-back {
  position: absolute; top: 22px; right: 22px;
  background: rgba(255,255,255,.15); color: #fff;
  border: 0; padding: 8px 14px;
  border-radius: 999px; font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.header-back:active { background: rgba(255,255,255,.28); }

/* =========================================================================
   Content
   ========================================================================= */

.app-content {
  flex: 1;
  padding: 24px 22px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.app-content.compact { padding-top: 18px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.eyebrow {
  display: inline-block;
  background: var(--soft-cyan);
  color: var(--blue);
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.8px;
  padding: 5px 10px; border-radius: 999px;
}

/* =========================================================================
   Login
   ========================================================================= */

.login-hero {
  text-align: center;
  padding: 8px 0 16px;
}
.login-hero .hero-icon {
  width: 72px; height: 72px;
  margin: 0 auto 16px;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--cyan) 0%, var(--blue) 100%);
  display: grid; place-items: center;
  box-shadow: 0 10px 26px rgba(0, 51, 153, 0.28);
}
.login-hero h2 { margin: 0 0 6px; font-size: 22px; color: var(--ink); font-weight: 800; }
.login-hero p { margin: 0; color: var(--muted); font-size: 14px; }

.field {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 16px;
}
.field label {
  font-size: 13px; font-weight: 600; color: var(--ink);
}
.field input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px; /* >=16px evita zoom no iOS */
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
  outline: 0; border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(0, 51, 153, .12);
}
.field .hint { font-size: 12px; color: var(--muted); }

.primary-button {
  width: 100%;
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: #fff;
  border: 0;
  border-radius: 14px;
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0, 51, 153, 0.25);
  transition: transform .1s, box-shadow .15s;
}
.primary-button:active { transform: translateY(1px); box-shadow: 0 4px 12px rgba(0, 51, 153, 0.2); }
.primary-button:disabled { opacity: .55; cursor: not-allowed; }

.ghost-button {
  width: 100%;
  padding: 14px 20px;
  background: transparent;
  color: var(--blue);
  border: 1.5px solid var(--line-strong);
  border-radius: 14px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
}
.ghost-button:active { background: var(--soft-blue); }

.alert {
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 14px;
  display: none;
}
.alert.is-visible { display: block; }
.alert.danger { background: #ffe9ee; color: var(--danger); border: 1px solid #ffc8d4; }
.alert.success { background: #e6f7f1; color: var(--success); border: 1px solid #b6e6d5; }

.login-help {
  margin-top: 18px;
  padding: 16px;
  background: var(--soft-blue);
  border-radius: 14px;
  font-size: 13px;
  color: var(--text);
}
.login-help strong { display: block; color: var(--blue); margin-bottom: 6px; }
.login-help ul { margin: 8px 0 0; padding: 0 0 0 18px; }
.login-help li { margin-bottom: 4px; }
.login-help code {
  background: #fff; padding: 1px 6px; border-radius: 5px;
  font-family: 'SF Mono', Menlo, monospace; font-size: 12px;
  color: var(--blue);
}

/* =========================================================================
   Dashboard - lista de questionários
   ========================================================================= */

.greeting {
  margin-bottom: 4px;
}
.greeting small { color: var(--muted); font-size: 13px; }
.greeting strong { font-size: 20px; color: var(--ink); display: block; font-weight: 800; margin-top: 2px; }
.greeting .sub { font-size: 13px; color: var(--muted); }

/* Greeting dentro do header azul - tudo branco com hierarquia por opacidade */
.app-header .greeting small,
.app-header .greeting .sub {
  color: #ffffff;
  opacity: 0.78;
}
.app-header .greeting strong {
  color: #ffffff;
  opacity: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

/* Brand do header - garantir consistência */
.app-header-brand strong,
.app-header-brand small { color: #ffffff; }
.app-header-brand small { opacity: 0.82; }

.section-title {
  font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.8px;
  margin: 8px 0 4px;
}

.q-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
  transition: transform .12s, box-shadow .15s;
  cursor: pointer;
}
.q-card:active { transform: scale(.99); box-shadow: var(--shadow); }
.q-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.q-card h3 { margin: 0; font-size: 16px; color: var(--ink); font-weight: 700; line-height: 1.35; }
.q-card .q-meta { font-size: 13px; color: var(--muted); margin: 0; }
.q-card .badge {
  font-size: 11px; font-weight: 700;
  padding: 5px 11px; border-radius: 999px;
  background: var(--soft-cyan); color: var(--blue);
  white-space: nowrap;
  letter-spacing: .02em;
  display: inline-flex; align-items: center; gap: 5px;
}
.q-card .badge.warning { background: #fff4d6; color: var(--warning); }
.q-card .badge.success {
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  color: #fff;
  box-shadow: 0 2px 6px rgba(22,163,74,.28);
}
.q-card .badge.success::before {
  content: ""; display: inline-block;
  width: 12px; height: 12px;
  background: rgba(255,255,255,.95);
  border-radius: 999px;
  position: relative;
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>");
  mask-size: cover;
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>");
  -webkit-mask-size: cover;
}

/* Card de questionario ja respondido */
.q-card.is-concluded {
  position: relative;
  background: linear-gradient(180deg, #f6fbf7 0%, #ffffff 100%);
  border-color: #d1f0dc;
  cursor: not-allowed;
}
.q-card.is-concluded::before {
  content: "";
  position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px;
  background: linear-gradient(180deg, #22c55e, #16a34a);
  border-radius: 0 4px 4px 0;
}
.q-card.is-concluded h3 { color: #1f3a2c; }
.q-card.is-concluded .q-meta { color: #5b6d63; }
.q-card.is-concluded .q-card-cta .arrow {
  background: #22c55e;
  opacity: .65;
}
.q-card.is-concluded .q-card-cta span { color: #16a34a; font-weight: 700; }
.q-card.is-concluded:active { transform: none; box-shadow: none; }

.q-card-cta {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 8px; border-top: 1px dashed var(--line);
}
.q-card-cta span { font-size: 13px; color: var(--text); font-weight: 600; }
.q-card-cta .arrow {
  width: 32px; height: 32px;
  background: var(--blue); color: #fff;
  border-radius: 999px;
  display: grid; place-items: center;
  font-size: 18px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 14px;
}

/* =========================================================================
   Pesquisa - fit-to-screen (sem rolagem)
   Estratégia: body.is-survey trava em 100dvh e usa flex column.
   Faces-grid cresce/encolhe pra preencher o espaço disponível.
   ========================================================================= */

body.is-survey {
  height: 100vh; height: 100dvh;
  overflow: hidden;
}
body.is-survey .app-shell {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  max-width: 480px;
}

@media (min-width: 481px) {
  body.is-survey { padding: 0; background: var(--page); }
  body.is-survey .app-shell { border-radius: 0; box-shadow: none; }
}

.survey-header {
  flex: 0 0 auto;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: #fff;
  padding: 14px 18px 12px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
}
.survey-header-top {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 600;
  margin-bottom: 8px;
}
.survey-header-top .count { opacity: .95; }
.survey-header-top .exit {
  background: transparent; border: 0; color: #fff;
  font-size: 13px; opacity: .85; cursor: pointer;
  padding: 4px 8px;
}
.survey-header-top .exit:active { opacity: 1; }

.progress-bar {
  height: 5px; background: rgba(255,255,255,.22);
  border-radius: 999px; overflow: hidden;
}
.progress-bar .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), #ffffff);
  border-radius: 999px;
  transition: width .35s ease;
}

.survey-category {
  flex: 0 0 auto;
  padding: 14px 20px 0;
}
.survey-category .eyebrow {
  background: var(--soft-cyan); color: var(--blue);
  font-size: 11px; padding: 5px 11px;
}

/* Spacer flexível: absorve sobra vertical SEM esticar os cards */
.survey-spacer { flex: 1 1 auto; min-height: 0; }

.question-block {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 20px 4px;
}
.question-block h2 {
  font-size: clamp(17px, 5vw, 21px);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.35;
  margin: 6px 0 0;
  letter-spacing: -0.1px;
  /* mostra a pergunta inteira, sem cortar */
  overflow-wrap: break-word;
  word-break: break-word;
}
.question-block .question-instruction {
  display: none; /* economizado: as carinhas já comunicam isso */
}

/* =========================================================================
   4 carinhas - cards quadrados, tamanho confortável (não esticam)
   ========================================================================= */

.faces-grid {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 20px 4px;
}

.face-option {
  appearance: none;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px 8px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .12s, border-color .15s, background .15s;
  /* proporção próxima de 1:1 (quadrado), sem esticar */
  aspect-ratio: 1 / 0.95;
  min-width: 0;
  text-align: center;
}
.face-option .face-svg {
  width: clamp(40px, 13vw, 56px);
  height: clamp(40px, 13vw, 56px);
  flex: 0 0 auto;
  transition: transform .15s;
}
.face-option .face-label {
  font-size: clamp(12px, 3.4vw, 14px);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}
.face-option:active { transform: scale(.97); }
.face-option:hover { border-color: var(--line-strong); }
.face-option.is-selected {
  background: #f5fbff;
}
.face-option.is-selected .face-svg { transform: scale(1.08); }

.face-option[data-value="4"].is-selected { border-color: var(--face-1); }
.face-option[data-value="3"].is-selected { border-color: var(--face-2); }
.face-option[data-value="2"].is-selected { border-color: var(--face-3); }
.face-option[data-value="1"].is-selected { border-color: var(--face-4); }

.face-option[data-value="4"] .face-label { color: var(--face-1); }
.face-option[data-value="3"] .face-label { color: #5e9c1f; }
.face-option[data-value="2"] .face-label { color: #c97e08; }
.face-option[data-value="1"] .face-label { color: var(--face-4); }

/* Navegação - rodapé fixo no flex column, com safe-area iOS */
.survey-nav {
  flex: 0 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 10px 18px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex; gap: 8px;
}
.survey-nav .primary-button,
.survey-nav .ghost-button {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 15px;
}
.survey-nav .primary-button { flex: 2; }
.survey-nav .ghost-button { flex: 1; }

/* Viewports curtos (ex.: 360x640, iPhone SE) - encolhe pergunta e padding */
@media (max-height: 700px) {
  .survey-header { padding: 10px 18px 8px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .survey-header-top { font-size: 12px; margin-bottom: 6px; }
  .survey-category { padding: 10px 20px 0; }
  .question-block { padding: 8px 20px 2px; }
  .question-block h2 { font-size: clamp(15px, 4.4vw, 18px); line-height: 1.3; }
  .faces-grid { gap: 8px; padding: 8px 20px 2px; }
  .face-option { aspect-ratio: 1 / 0.92; padding: 10px 6px; gap: 6px; }
  .face-option .face-svg { width: clamp(36px, 11vw, 48px); height: clamp(36px, 11vw, 48px); }
  .face-option .face-label { font-size: 12px; }
  .survey-nav { padding: 8px 18px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .survey-nav .primary-button,
  .survey-nav .ghost-button { padding: 11px 14px; font-size: 14px; }
}

/* Viewports muito curtos - encolhe mais ainda */
@media (max-height: 600px) {
  .question-block h2 { font-size: 15px; }
  .face-option { aspect-ratio: 1 / 0.85; padding: 8px 4px; gap: 4px; }
  .face-option .face-svg { width: 34px; height: 34px; }
  .face-option .face-label { font-size: 11px; }
}

/* Landscape em celulares - vira 4 carinhas em linha */
@media (max-height: 480px) and (orientation: landscape) {
  .survey-header { padding: 6px 16px 6px; }
  .survey-header-top { font-size: 11px; margin-bottom: 4px; }
  .survey-category { padding: 4px 16px 0; }
  .question-block { padding: 4px 16px 0; }
  .question-block h2 { font-size: 14px; }
  .faces-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 6px 14px 4px;
  }
  .face-option { aspect-ratio: 1 / 1; padding: 6px 4px; gap: 4px; }
  .face-option .face-svg { width: clamp(28px, 10vh, 38px); height: clamp(28px, 10vh, 38px); }
  .face-option .face-label { font-size: 10px; }
  .survey-nav { padding: 6px 16px; }
}

/* =========================================================================
   Concluído (obrigado)
   ========================================================================= */

.thanks-screen {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 40px 28px;
  gap: 18px;
}
.thanks-icon {
  width: 110px; height: 110px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--face-1) 0%, #1f9d5e 100%);
  display: grid; place-items: center;
  box-shadow: 0 18px 38px rgba(43, 182, 115, 0.32);
  animation: pop .45s ease-out;
}
@keyframes pop {
  0%   { transform: scale(.4); opacity: 0; }
  60%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}
.thanks-screen h2 {
  font-size: 26px; font-weight: 800;
  color: var(--ink); margin: 0;
  letter-spacing: -0.2px;
}
.thanks-screen p {
  font-size: 15px; color: var(--text); margin: 0;
  max-width: 320px; line-height: 1.6;
}
.thanks-screen .protocolo {
  margin-top: 4px;
  font-size: 12px; color: var(--muted);
  background: var(--page);
  padding: 8px 14px;
  border-radius: 999px;
  font-family: 'SF Mono', Menlo, monospace;
}
.thanks-screen .resumo-stats {
  display: flex; gap: 22px;
  margin-top: 6px;
}
.thanks-screen .resumo-stats div {
  text-align: center;
}
.thanks-screen .resumo-stats strong {
  display: block; font-size: 22px; color: var(--blue); font-weight: 800;
}
.thanks-screen .resumo-stats small {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.6px;
}

.thanks-actions {
  width: 100%;
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 18px;
}

/* =========================================================================
   Utilitários
   ========================================================================= */

.is-hidden { display: none !important; }

.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Safe area iOS */
@supports (padding: env(safe-area-inset-bottom)) {
  .survey-nav { padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
  .app-content { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
}

/* Pergunta aberta (textarea) */
.open-answer { padding: 4px 4px 10px; }
.open-answer textarea {
  width: 100%;
  min-height: 140px;
  padding: 14px;
  border: 1.5px solid #cfd9e4;
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  background: #fff;
  color: var(--ink);
  resize: vertical;
}
.open-answer textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
