/* Oficina ORA/OTCA — identidade visual institucional */

/*
 * Identidade visual do Observatório Regional Amazônico.
 * Os tokens abaixo vêm do sistema de design do painel oficial
 * (dev.dashboard.oraotca.org): laranja como primária, verde-limão como
 * secundária, superfícies em teal escuro e neutros frios.
 *
 * Onde uma cor da marca não alcança contraste suficiente como texto, usamos o
 * degrau mais escuro da mesma escala — a família permanece, a leitura melhora.
 */
:root {
  /* Escala primária (laranja ORA) */
  --primary-100: #FFE6D0;
  --primary-200: #FFC89B;
  --primary-300: #FA9C51;
  --primary-400: #F4842A;   /* laranja da marca — preenchimentos e destaques */
  --primary-500: #BC621A;
  --primary-600: #9F5214;   /* degrau legível para texto e botões */
  --primary-700: #7E3E0F;

  /* Escala secundária (verde-limão ORA) */
  --secondary-100: #F4FAD5;
  --secondary-200: #DCEC87;
  --secondary-300: #CEE362;
  --secondary-400: #BFD83E;
  --secondary-600: #7B8C22;
  --secondary-700: #63711A;

  /* Superfícies da marca (teal escuro) */
  --brand-surface: #12414F;
  --brand-surface-dark: #0C313C;
  --brand-surface-darker: #08222B;

  /* Neutros */
  --neutral-100: #FFFFFF;
  --neutral-200: #F1F1F4;
  --neutral-300: #D9DBE1;
  --neutral-400: #A1A4B3;
  --neutral-500: #82889F;
  --neutral-700: #5F6376;
  --neutral-900: #393C47;
  --neutral-1000: #26282F;

  /* Papéis na interface */
  --bg: var(--neutral-200);
  --ink: var(--neutral-1000);
  --ink-soft: var(--neutral-700);
  --ink-faint: #63687C;      /* neutral-600 escurecido para passar AA no fundo */
  --primary: var(--brand-surface);
  --primary-dark: var(--brand-surface-dark);
  --accent: var(--primary-400);
  --accent-text: var(--primary-600);
  --accent-wash: #FFF4EA;
  --ocre: var(--primary-400);
  --ocre-deep: var(--primary-600);
  --card: var(--neutral-100);
  --border: var(--neutral-300);

  --danger: #CB1649;
  --ok: #06850B;

  --radius: 12px;
  --radius-sm: 8px;
  /* Sombras do painel oficial: cartões flutuam, não são delimitados por traço. */
  --shadow: 0 0 8px 0 rgb(184 188 210 / 50%);
  --shadow-lift: 0 4px 12.6px 0 rgb(0 0 0 / 25%);

  --font-title: 'Open Sans', system-ui, -apple-system, sans-serif;
  --font-body: 'Open Sans', system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, monospace;

  --maxw: 720px;
  --tap: 48px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-title);
  font-weight: 700;
  line-height: 1.5;
  margin: 0;
}

/* ---------- Cabeçalho e progresso ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(238, 243, 242, .95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 16px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 30px;
  height: 30px;
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.brand-title {
  font-family: var(--font-title);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--brand-surface);
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-sub {
  font-size: 10px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-faint);
  line-height: 1.3;
  /* Uma linha só: em telas estreitas o resto é cortado, sem empurrar o layout. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 380px) {
  .brand-logo { width: 26px; height: 26px; }
  .brand-title { font-size: 12.5px; }
  /* O subtítulo é contexto, não instrução: sai antes do título e do seletor. */
  .brand-sub { display: none; }
  .lang-btn { min-width: 40px; padding: 0 6px; font-size: 11px; }
}

/* Seletor de idioma — três siglas curtas, sempre visíveis no topo. */
.lang-switch {
  display: flex;
  gap: 2px;
  flex: none;
  background: var(--neutral-300);
  border-radius: 999px;
  padding: 3px;
}

.lang-btn {
  /* 44px de altura: são os alvos mais estreitos da tela e precisam ser tocáveis. */
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.lang-btn[aria-pressed="true"] {
  background: var(--card);
  color: var(--brand-surface);
  box-shadow: 0 1px 2px rgb(38 40 47 / 18%);
}

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

.progress {
  margin-top: 10px;
}

.progress-track {
  display: flex;
  gap: 4px;
}

.progress-seg {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  transition: background .3s ease;
}

.progress-seg.done { background: var(--primary-400); }
.progress-seg.current { background: var(--brand-surface); }

.progress-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 7px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .01em;
  text-transform: uppercase;
  color: var(--ink-faint);
  gap: 2px;
}

.progress-labels span {
  flex: 1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-labels span.current { color: var(--primary); font-weight: 600; }

/* ---------- Layout ---------- */

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 16px 140px;
}

.step-head { margin-bottom: 18px; }

.step-eyebrow {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent-text);
  margin-bottom: 6px;
}

.step-title { font-size: 26px; margin-bottom: 10px; }

.step-instruction {
  color: var(--ink-soft);
  font-size: 15.5px;
  margin: 0;
}

.welcome {
  background: var(--accent-wash);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 15.5px;
  color: var(--ink);
  margin-bottom: 22px;
}

.card {
  background: var(--card);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card-num {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 11px;
  color: var(--accent-text);
  letter-spacing: .06em;
  margin-bottom: 4px;
}

.card-title { font-size: 18px; margin-bottom: 4px; }

.card-hint {
  color: var(--ink-soft);
  font-size: 14.5px;
  margin: 0 0 14px;
}

/* ---------- Campos ---------- */

.field { margin-bottom: 16px; }

label, .label {
  display: block;
  font-weight: 600;
  font-size: 14.5px;
  margin-bottom: 6px;
  color: var(--ink);
}

.label-req {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ocre-deep);
  margin-left: 6px;
}

input[type="text"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}

textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.5;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(21, 94, 99, .14);
}

input::placeholder, textarea::placeholder { color: var(--ink-faint); }

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%234A6B70' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}

.field-error {
  color: var(--danger);
  font-size: 13.5px;
  margin-top: 6px;
  font-weight: 500;
}

input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); }

/* ---------- Pílulas de avaliação ---------- */

.pills {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

@media (min-width: 560px) {
  .pills { grid-template-columns: repeat(4, 1fr); }
}

.pill {
  min-height: var(--tap);
  padding: 11px 10px;
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 500;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s ease;
  text-align: center;
}

.pill:hover { border-color: var(--primary-400); }

.pill[aria-pressed="true"] {
  background: var(--brand-surface);
  border-color: var(--brand-surface);
  color: #fff;
  font-weight: 700;
}

.pill:focus-visible,
.btn:focus-visible,
.btn-add:focus-visible,
.icon-btn:focus-visible,
details.helpbox summary:focus-visible,
.pill-group:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* O anel do campo de texto precisa ser percebido, não apenas sugerido. */
input:focus-visible, select:focus-visible, textarea:focus-visible {
  box-shadow: 0 0 0 3px rgba(21, 94, 99, .38);
}

.pill-group.invalid .pill { border-color: var(--danger); }

/* Escala menor para frequência/importância dentro das fichas */
.pills.compact { grid-template-columns: repeat(2, 1fr); gap: 6px; }
.pills.compact .pill { font-size: 13.5px; min-height: 44px; padding: 9px 8px; }

@media (min-width: 560px) {
  .pills.compact.freq { grid-template-columns: repeat(4, 1fr); }
  .pills.compact.imp { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Caixa recolhível ---------- */

details.helpbox {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}

details.helpbox summary {
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14.5px;
  color: var(--primary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
}

details.helpbox summary::-webkit-details-marker { display: none; }

details.helpbox summary::before {
  content: '+';
  font-family: var(--font-mono);
  font-size: 17px;
  color: var(--accent-text);
  width: 16px;
}

details.helpbox[open] summary::before { content: '−'; }

details.helpbox ul {
  margin: 0;
  padding: 0 18px 16px 34px;
  color: var(--ink-soft);
  font-size: 14.5px;
}

details.helpbox li { margin-bottom: 8px; }

/* ---------- Fichas dinâmicas ---------- */

.repeat-card {
  background: var(--card);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  position: relative;
}

.repeat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.repeat-label {
  font-family: var(--font-body);
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--accent-text);
  font-weight: 500;
}

.repeat-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 15px;
  transition: all .15s ease;
  font-family: var(--font-body);
}

.icon-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--accent-wash);
}

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

.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: #FBEEEA; }

.drag-handle {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Em telas de toque não há cursor para indicar arraste; as setas são o caminho principal. */
@media (hover: none) {
  .drag-handle { cursor: default; }
}

.drag-handle:active { cursor: grabbing; }

.repeat-card.dragging {
  opacity: .9;
  box-shadow: var(--shadow-lift);
  border-color: var(--primary);
  position: relative;
  z-index: 5;
}

.repeat-card.drop-target { border-color: var(--accent); border-style: dashed; }

.btn-add {
  width: 100%;
  min-height: var(--tap);
  padding: 13px;
  background: transparent;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  color: var(--primary);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
  margin-bottom: 20px;
}

.btn-add:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-wash); }
.btn-add:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Destaques ---------- */

.highlight-card {
  background: linear-gradient(180deg, var(--accent-wash) 0%, var(--card) 100%);
  border: 1.5px solid var(--primary-400);
  border-radius: var(--radius);
  padding: 18px;
  margin: 22px 0 14px;
  box-shadow: var(--shadow);
}

.highlight-card .card-title { color: var(--primary-dark); }

.recap {
  background: var(--accent-wash);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: 14.5px;
}

.recap h4 {
  font-size: 12.5px;
  font-family: var(--font-body);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 8px;
}

.recap ul { margin: 0; padding-left: 18px; color: var(--ink-soft); }
.recap li { margin-bottom: 5px; }

/* ---------- Barra de navegação inferior ---------- */

.actionbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: rgba(238, 243, 242, .96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}

.actionbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  min-height: var(--tap);
  padding: 13px 22px;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all .15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  flex: 1;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--ink-soft);
}

.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

.btn-finish { background: var(--primary-600); }
.btn-finish:hover { background: var(--primary-700); }

/* ---------- Indicador de salvamento ---------- */

/*
 * O texto "sem conexão — tentando de novo" não cabe ao lado dos botões em telas
 * estreitas, então o indicador ocupa a própria linha, acima deles.
 */
.savestate {
  font-family: var(--font-body);
  font-size: 11.5px;
  letter-spacing: .03em;
  color: var(--ink-faint);
  order: -1;
  flex-basis: 100%;
  text-align: center;
  min-height: 14px;
  transition: color .2s ease;
}

.savestate.saving { color: var(--accent-text); }
.savestate.saved { color: var(--ok); }
.savestate.error, .savestate.pending { color: var(--ocre-deep); }
.savestate.rejected { color: var(--danger); font-weight: 600; }

.offline-banner {
  background: var(--ocre);
  color: #fff;
  padding: 9px 16px;
  font-size: 13.5px;
  text-align: center;
  display: none;
}

.offline-banner.show { display: block; }

/* ---------- Tela de agradecimento ---------- */

.thanks {
  text-align: center;
  padding: 48px 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.thanks-mark {
  width: 60px;
  height: 60px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: var(--accent-wash);
  border: 2px solid var(--accent);
  display: grid;
  place-items: center;
  color: var(--primary);
  font-size: 28px;
}

.thanks h2 { font-size: 28px; margin-bottom: 12px; color: var(--primary); }
.thanks p { color: var(--ink-soft); margin: 0 0 8px; font-size: 16px; }

.thanks-meta {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--ink-faint);
  margin-top: 20px;
}

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

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