:root {
  --bg: #0b1220;
  --card-bg: #131b2e;
  --card-border: #1f2a44;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #22c55e;
  --accent-dark: #16a34a;
  --danger: #ef4444;
  --input-bg: #0f172a;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 40px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  background: linear-gradient(135deg, #0f172a, #131b2e);
  border-bottom: 1px solid var(--card-border);
}

.topbar .logo { width: 44px; height: 44px; border-radius: 10px; }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar > div { min-width: 0; }
.subtitle { margin: 2px 0 0; overflow-wrap: anywhere; font-size: 13px; color: var(--text-dim); }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  color: var(--text);
}

form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-wide { grid-column: 1 / -1; }
.field label { font-size: 12.5px; color: var(--text-dim); }

.field input {
  background: #d7f2df;
  border: 1px solid #a9e0b8;
  border-radius: 8px;
  color: #111111;
  padding: 10px 12px;
  font-size: 16px;
  width: 100%;
  min-width: 0;
}

.field select {
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
  width: 100%;
  min-width: 0;
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent-dark);
}

.toggle-field {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #334155;
  border-radius: 999px;
  transition: .2s;
}
.slider::before {
  position: absolute; content: "";
  height: 20px; width: 20px; left: 3px; bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: .2s;
}
.switch input:checked + .slider { background-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.btn-primary, .btn-secondary {
  grid-column: 1 / -1;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #06210f;
}
.btn-primary:active { background: var(--accent-dark); }

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}
.btn-secondary {
  grid-column: unset;
  flex: 1 1 150px;
  background: #1e293b;
  color: var(--text);
  border: 1px solid var(--card-border);
}
.btn-secondary:active { background: #273449; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  padding: 10px 8px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--card-border);
  font-weight: 600;
}
tbody td {
  padding: 9px 8px;
  border-bottom: 1px solid #1a2338;
  white-space: nowrap;
}
tbody td:first-child { color: var(--text-dim); white-space: normal; }

.margin-viz { margin-top: 20px; }
.margin-label { font-size: 13.5px; margin-bottom: 10px; }
.margin-label.positive { color: var(--accent); }
.margin-label.negative { color: var(--danger); }

.margin-bar {
  height: 14px;
  background: #0f172a;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 6px;
}
.margin-segment { height: 100%; border-radius: 8px; }
.margin-segment.informado { background: #38bdf8; }
.margin-segment.maximo { background: var(--accent); }

.margin-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
}
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}
.dot.informado { background: #38bdf8; }
.dot.maximo { background: var(--accent); }

footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 20px;
}

@media (max-width: 520px) {
  form { grid-template-columns: minmax(0, 1fr); }
}

.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.thumbs:empty { display: none; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--input-bg); cursor: pointer; border: 3px solid transparent; opacity: .6; }
.thumb.sel { border-color: var(--accent); opacity: 1; }
.thumb:focus-visible { outline: 2px solid #38bdf8; outline-offset: 2px; }
.ordem {
  position: absolute; left: 4px; bottom: 4px; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; background: var(--accent); color: #06210f;
  font-size: 13px; font-weight: 700; line-height: 22px; text-align: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.remover {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px; border: none; border-radius: 50%;
  background: rgba(15, 23, 42, .8); color: #fff; font-size: 16px; line-height: 1; cursor: pointer;
}
.lista-docs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lista-docs:empty { display: none; }
.lista-docs li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--input-bg); border: 1px solid var(--card-border); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; color: var(--text);
}
.lista-docs .nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.lista-docs .aviso { flex: none; font-size: 11.5px; }
.lista-docs .aviso.entra { color: var(--accent); }
.lista-docs .aviso.so-lista { color: #f59e0b; }
.lista-docs .remover { position: static; flex: none; }
.email-field { margin-top: 20px; }
.status { margin: 12px 0 0; font-size: 13.5px; color: var(--text-dim); }
.status.erro { color: var(--danger); }
.status.ok { color: var(--accent); }
.status a { color: inherit; }
button:disabled { opacity: .55; cursor: progress; }

.anexos { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--card-border); display: flex; flex-direction: column; gap: 16px; }
.anexos h3 { margin: 0; font-size: 15px; }
.dica { margin: 0; font-size: 12.5px; color: var(--text-dim); }
.rotulo { font-size: 12.5px; color: var(--text-dim); }
.anexos { position: relative; }
.field input.oculto { position: absolute; width: 1px; height: 1px; min-width: 0; padding: 0; border: 0; opacity: 0; overflow: hidden; pointer-events: none; }
.field .btn-arquivo {
  display: block; text-align: center; cursor: pointer;
  background: #1e293b; color: var(--text); border: 1px dashed #3b4b6b;
  border-radius: 10px; padding: 12px; font-size: 15px; font-weight: 600;
}
.field .btn-arquivo:active { background: #273449; }
.contagem { margin: 0; font-size: 13px; color: var(--text-dim); }
.contagem.tem { color: var(--accent); }
.contagem.alerta { color: #f59e0b; }
.dlg {
  border: 1px solid var(--card-border); border-radius: var(--radius);
  background: var(--card-bg); color: var(--text);
  width: min(92vw, 420px); padding: 20px;
}
.dlg::backdrop { background: rgba(2, 6, 23, .7); }
.dlg h3 { margin: 0 0 6px; font-size: 16px; }
.dlg input {
  width: 100%; margin: 14px 0; background: #d7f2df; border: 1px solid #a9e0b8;
  border-radius: 8px; color: #111; padding: 10px 12px; font-size: 16px;
}
.dlg-acoes { display: flex; gap: 10px; }
.dlg-acoes button { flex: 1; grid-column: unset; }

.pronto { display: flex; gap: 10px; margin-top: 12px; }
.pronto[hidden] { display: none; }
.btn-pronto {
  flex: 1; text-align: center; text-decoration: none; cursor: pointer;
  background: var(--accent); color: #06210f; border: none; border-radius: 10px;
  padding: 14px; font-size: 15px; font-weight: 600; font-family: inherit;
}
.btn-pronto:active { background: var(--accent-dark); }
