/* Atividade — Segmentação da panorâmica
   Tokens herdados do SegPan v2 para manter a identidade entre as ferramentas. */

:root {
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 13px;
  --text-lg: 15px;
  --btn-height: 30px;

  --paper: #0b0d10;
  --surface: #14171c;
  --surface-2: #1b1f26;
  --surface-3: #232831;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --line: rgba(255, 255, 255, 0.06);
  --line-2: rgba(255, 255, 255, 0.12);

  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --accent-soft: rgba(56, 189, 248, 0.12);
  --accent-line: rgba(56, 189, 248, 0.45);

  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;

  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

/* Precisa vir antes das regras de layout: display explícito (.app{display:flex})
   vence o [hidden] do user-agent, e a tela ficaria montada atrás do login. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--paper);
  color: var(--ink);
  font: var(--text-base)/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ── Entrada ─────────────────────────────────────────────────────────────── */

.login-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #16202b, var(--paper));
  z-index: 60;
}

.login-box {
  width: min(420px, 92vw);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-box h1 { margin: 0; font-size: 19px; font-weight: 650; }
.login-box .sub { margin: -10px 0 4px; color: var(--muted); font-size: var(--text-sm); }
.login-box label { display: flex; flex-direction: column; gap: 5px; font-size: var(--text-sm); color: var(--muted); }
.login-box .opt { color: var(--muted-2); }

input[type="text"], input[type="search"], input[type="password"] {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--ink);
  outline: none;
}
input[type="text"]:focus, input[type="search"]:focus {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button.primary {
  background: var(--accent-strong);
  border: 1px solid var(--accent-strong);
  color: #04121b;
  font-weight: 650;
  border-radius: var(--radius-sm);
  height: var(--btn-height);
  padding: 0 14px;
}
button.primary:hover { filter: brightness(1.1); }
button.primary:disabled { opacity: .5; cursor: not-allowed; filter: none; }

button.ghost {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  height: var(--btn-height);
  padding: 0 12px;
  color: var(--ink);
}
button.ghost:hover { background: var(--surface-3); }
button.ghost.sm { height: 26px; font-size: var(--text-sm); padding: 0 8px; }

.erro { color: var(--danger); font-size: var(--text-sm); margin: 0; min-height: 18px; }

/* ── Estrutura geral ─────────────────────────────────────────────────────── */

.app { height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .35);
  flex: none;
  flex-wrap: wrap;
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; font-size: var(--text-base); }
.brand strong { font-weight: 650; white-space: nowrap; letter-spacing: -.01em; }
.brand .chip { font-variant-numeric: tabular-nums; }

.chip {
  background: var(--surface-3);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: var(--text-xs);
  color: var(--muted);
  white-space: nowrap;
}

.tools { display: flex; align-items: center; gap: 10px; flex: 1; flex-wrap: wrap; }

/* Separador entre blocos: substitui o espaçamento solto que fazia a barra
   parecer uma fileira única de 12 controles sem hierarquia. */
.sep { width: 1px; height: 20px; background: var(--line-2); flex: none; }

.tool {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  height: var(--btn-height);
  padding: 0 11px;
  color: var(--muted);
  font-size: var(--text-sm);
  white-space: nowrap;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.tool:hover { background: var(--surface-3); color: var(--ink); }
.tool.ativo {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}

/* Grupo colado: as bordas internas somem e o conjunto lê como um controle só */
.segmentado { display: flex; }
.segmentado > * { border-radius: 0; margin-left: -1px; }
.segmentado > *:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.segmentado > *:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.segmentado > .ativo { position: relative; z-index: 1; }

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  width: var(--btn-height);
  height: var(--btn-height);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  transition: background .12s ease, color .12s ease;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn.ativo { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Tamanho do pincel: fica na barra porque é o controle mais usado, mas com
   um ponto que mostra o calibre em vez de só um número solto. */
.tamanho {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--btn-height);
  padding: 0 10px 0 8px;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
}
.tamanho .ponto { width: 20px; height: 20px; display: grid; place-items: center; flex: none; }
.tamanho .ponto i { display: block; background: var(--muted); border-radius: 50%; }
.tamanho input[type="range"] { width: 84px; accent-color: var(--accent); }
.tamanho output {
  font-size: var(--text-xs); color: var(--muted);
  font-variant-numeric: tabular-nums; min-width: 42px; text-align: right;
}

/* Menu suspenso de ajustes da imagem */
.menu { position: relative; }
.popover {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  z-index: 30;
  width: 258px;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.popover .slider { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; }
.popover .slider span { grid-column: 1; font-size: var(--text-xs); color: var(--muted); }
.popover .slider output {
  grid-column: 2; font-size: var(--text-xs); color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}
.popover .slider input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
.popover button { align-self: flex-start; }

/* Usado no painel do professor */
.check { display: flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--muted); white-space: nowrap; }
.check input { accent-color: var(--accent); }

/* Larguras reservadas: "Salvar rascunho" -> "Salvando..." e "—" -> "salvo 14:32"
   mudam de tamanho durante o envio. Sem min-width, a topbar (flex-wrap) muda de
   numero de linhas, a altura do cabecalho muda e a imagem inteira pula. */
.acoes { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.acoes #btnSalvar { min-width: 142px; }
.acoes #btnEntregar { min-width: 104px; }
.salvo {
  font-size: var(--text-xs);
  color: var(--muted-2);
  white-space: nowrap;
  min-width: 96px;
  text-align: right;
}

.corpo { flex: 1; display: flex; min-height: 0; }

/* ── Lista de estruturas ─────────────────────────────────────────────────── */

.lateral {
  width: 292px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.lateral-topo { padding: 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.lateral-topo input { width: 100%; }

.progresso { display: flex; align-items: center; gap: 8px; font-size: var(--text-xs); color: var(--muted); }
.barra { flex: 1; height: 5px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.barra i { display: block; height: 100%; width: 0; background: var(--ok); transition: width .2s ease; }

.lista { flex: 1; overflow-y: auto; padding: 6px; }

.regiao-titulo {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted-2);
  padding: 10px 8px 4px;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
}
.item:hover { background: var(--surface-2); }
.item.ativo { background: var(--accent-soft); border-color: var(--accent-line); }
.item.feito .rotulo { color: var(--ink); }
.item .rotulo { flex: 1; font-size: var(--text-sm); color: var(--muted); line-height: 1.3; }
.item .n { width: 20px; text-align: right; font-size: var(--text-xs); color: var(--muted-2); font-variant-numeric: tabular-nums; }
.item .cor { width: 12px; height: 12px; border-radius: 3px; flex: none; border: 1px solid rgba(0,0,0,.4); }
.item .marca { font-size: 11px; color: var(--ok); width: 12px; }
.item .olho { opacity: 0; background: none; border: none; color: var(--muted-2); padding: 0 2px; font-size: 12px; }
.item:hover .olho, .item .olho.off { opacity: 1; }
.item .olho.off { color: var(--warn); }

.lateral-rodape { padding: 8px; border-top: 1px solid var(--line); display: flex; gap: 6px; }
.lateral-rodape button { flex: 1; }

/* ── Palco ───────────────────────────────────────────────────────────────── */

.palco { flex: 1; position: relative; min-width: 0; background: #06080a; overflow: hidden; }

.viewport { position: absolute; inset: 0; overflow: hidden; cursor: crosshair; }
.viewport.modo-mover { cursor: grab; }
.viewport.movendo { cursor: grabbing; }

.wrap { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.wrap canvas { position: absolute; top: 0; left: 0; display: block; image-rendering: auto; }
#cvImg { filter: brightness(1) contrast(1); }
#cvMask { pointer-events: none; opacity: .55; }
#cvMask.oculto { display: none; }

.cursor-pincel {
  position: fixed;
  border: 1.5px solid rgba(255, 255, 255, .9);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  mix-blend-mode: difference;
  display: none;
  z-index: 5;
}

.rodape-palco {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 12px;
  background: linear-gradient(transparent, rgba(6, 8, 10, .92) 40%);
  font-size: var(--text-xs);
  color: var(--muted);
  pointer-events: none;
}
.rodape-palco .atual { font-size: var(--text-base); color: var(--ink); font-weight: 600; }
.rodape-palco .dica { flex: 1; color: var(--muted-2); }

.carregando {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 8, 10, .8);
  color: var(--muted);
  font-size: var(--text-sm);
}
.carregando[hidden] { display: none; }

/* ── Toast ───────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: var(--text-sm);
  box-shadow: var(--shadow);
  z-index: 80;
  max-width: 70vw;
}
.toast.ok { border-color: rgba(34, 197, 94, .5); }
.toast.erro { border-color: rgba(239, 68, 68, .55); }
.toast[hidden] { display: none; }

/* ── Painel do professor ─────────────────────────────────────────────────── */

.prof { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.prof .topbar { justify-content: space-between; }
.prof-corpo { flex: 1; overflow-y: auto; padding: 18px; }
.prof-abas { display: flex; gap: 6px; padding: 0 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
.prof-abas button {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 9px 12px; color: var(--muted); font-size: var(--text-sm);
}
.prof-abas button.ativo { color: var(--accent); border-bottom-color: var(--accent); }

.cards { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 16px; min-width: 130px;
}
.card b { display: block; font-size: 22px; font-weight: 650; }
.card span { font-size: var(--text-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted-2); font-weight: 600; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em; }
tbody tr:hover { background: var(--surface); }
td select { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 4px 6px; max-width: 220px; }

.tag { font-size: var(--text-xs); padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--muted); }
.tag.entregue { color: var(--ok); border-color: rgba(34, 197, 94, .45); }
.tag.em_andamento { color: var(--warn); border-color: rgba(245, 158, 11, .45); }

.editor-estruturas { display: flex; flex-direction: column; gap: 4px; max-width: 720px; }
.editor-linha { display: flex; align-items: center; gap: 8px; }
.editor-linha .n { width: 26px; text-align: right; color: var(--muted-2); font-size: var(--text-xs); }
.editor-linha input { flex: 1; }
.editor-linha select { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 6px; }

.aviso {
  background: rgba(245, 158, 11, .08);
  border: 1px solid rgba(245, 158, 11, .35);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: var(--text-sm);
  color: #fbd38d;
  margin-bottom: 14px;
}

.preview { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--line); margin-top: 12px; }
