:root {
  --bg: #071927;
  --bg-soft: #0b2135;
  --panel: #102b45;
  --panel-2: #17344f;
  --text: #f6fbff;
  --muted: #a9bfd3;
  --line: rgba(255,255,255,.12);
  --brand: #24539b;
  --brand-2: #0ab6d6;
  --danger: #ef476f;
  --shadow: 0 24px 70px rgba(0,0,0,.28);
}

:root[data-theme='light'] {
  --bg: #f5f8fc;
  --bg-soft: #ffffff;
  --panel: #ffffff;
  --panel-2: #eef4fb;
  --text: #111827;
  --muted: #64748b;
  --line: rgba(17,24,39,.12);
  --brand: #173b73;
  --brand-2: #0aa6d3;
  --shadow: 0 22px 60px rgba(15, 23, 42, .10);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: radial-gradient(circle at top left, rgba(10,182,214,.18), transparent 28%), var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button, .button-like {
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: white;
  font-weight: 800;
  padding: 13px 18px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
button:disabled { opacity: .55; cursor: not-allowed; }
button.secondary, .button-like.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.danger, .danger-mini { color: #ffc7d5 !important; }
.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 36px;
  box-shadow: var(--shadow);
}
.login-logo { width: 190px; margin-bottom: 24px; }
.login-card h1 { font-size: 46px; margin: 0 0 8px; }
.login-card p { color: var(--muted); line-height: 1.5; margin-bottom: 28px; }

.app { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar {
  background: rgba(5, 18, 31, .72);
  border-right: 1px solid var(--line);
  padding: 26px 20px;
  display: flex;
  flex-direction: column;
  gap: 34px;
  position: sticky;
  top: 0;
  height: 100vh;
}
:root[data-theme='light'] .sidebar { background: #ffffff; }
.logo-wrap img { width: 190px; max-height: 62px; object-fit: contain; object-position: left; }
nav { display: grid; gap: 8px; }
.nav-btn {
  justify-content: flex-start;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}
.nav-btn.active, .nav-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.sidebar-bottom { margin-top: auto; display: grid; gap: 10px; }

.main { padding: 34px; max-width: 1800px; width: 100%; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.topbar h1 { margin: 0; font-size: 42px; letter-spacing: -.03em; }
.topbar p { margin: 8px 0 0; color: var(--muted); font-size: 18px; }
.sync-pill {
  display: inline-flex;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel);
  font-size: 14px;
  font-weight: 700;
}
.cards-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 20px; }
.metric-card, .summary-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.metric-card span, .summary-card span { display: block; color: var(--muted); font-weight: 800; margin-bottom: 8px; }
.metric-card strong, .summary-card strong { font-size: 42px; line-height: 1; }
.panel {
  background: color-mix(in srgb, var(--panel) 95%, transparent);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 26px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 16px; font-size: 28px; }
.panel-subtitle, .hint { color: var(--muted); line-height: 1.5; }
.hint { font-size: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1.35fr; gap: 20px; align-items: start; }
.grid-scan { display: grid; grid-template-columns: 420px minmax(0, 1fr); gap: 20px; align-items: start; }
.narrow-panel { max-width: 900px; }
.stack-form { display: grid; gap: 12px; }
label { color: var(--muted); font-weight: 900; font-size: 14px; }
input, select, textarea {
  width: 100%;
  background: color-mix(in srgb, var(--bg) 68%, transparent);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 14px;
  padding: 13px 14px;
  outline: none;
}
textarea { resize: vertical; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field-row:has(> div:nth-child(3)) { grid-template-columns: repeat(3, minmax(0,1fr)); }
.advanced-box { border: 1px solid var(--line); border-radius: 18px; padding: 14px; background: rgba(255,255,255,.03); }
.advanced-box summary { cursor: pointer; font-weight: 900; color: var(--text); }
.advanced-fields { margin-top: 12px; }
.checkline { display: flex; gap: 10px; align-items: center; color: var(--text); }
.checkline input { width: auto; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.list { display: grid; gap: 12px; }
.item {
  background: color-mix(in srgb, var(--bg) 45%, transparent);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}
.item-header { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.item strong { display: block; font-size: 18px; }
.item small { display: block; color: var(--muted); margin-top: 5px; }
.item p { color: var(--muted); margin: 8px 0 0; line-height: 1.45; }
.item .tiny { font-size: 12px; opacity: .8; }
.item-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.item-actions button, .item-actions .button-like { padding: 10px 12px; border-radius: 12px; }
.result-header { display: flex; justify-content: space-between; align-items: start; gap: 20px; margin-bottom: 16px; }
.report-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-bottom: 16px; }
.summary-card { padding: 16px; box-shadow: none; }
.summary-card strong { font-size: 30px; }
.map { min-height: 620px; border-radius: 22px; overflow: hidden; border: 1px solid var(--line); background: #dfe5ec; }
.map-message { height: 620px; display: grid; place-items: center; color: #0f172a; text-align: center; padding: 24px; }
.legend { display: flex; gap: 22px; color: var(--muted); font-weight: 800; margin-top: 14px; flex-wrap: wrap; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; }
.green { background: #00b894; }
.yellow { background: #f6c54f; }
.red { background: #ef476f; }
.gray { background: #8b98a8; }
.status-box {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel-2) 70%, transparent);
  border-radius: 16px;
  padding: 14px;
  margin-top: 14px;
  color: var(--text);
  line-height: 1.5;
}
.panel-title-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2, .grid-scan, .cards-grid, .summary-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
}

/* V3.1: separa claramente ajuste do grid, resultado e histórico */
.preview-help {
  background: color-mix(in srgb, var(--panel-2) 70%, transparent);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  min-height: 104px;
}
.preview-help strong { display: block; font-size: 16px; margin-bottom: 8px; color: var(--text); }
.preview-help span { display: block; color: var(--muted); line-height: 1.45; font-weight: 650; }
#scanView.preview-mode .result-panel { outline: 2px solid color-mix(in srgb, var(--brand-2) 36%, transparent); outline-offset: 3px; }
#scanView.preview-mode #map { min-height: 680px; }
#scanView.result-mode .result-panel, #scanView.history-mode .result-panel { grid-column: 1 / -1; }
#scanView.result-mode .scan-config-panel, #scanView.history-mode .scan-config-panel { display: none; }
#scanView.result-mode #map, #scanView.history-mode #map { min-height: 700px; }
#scanView.history-mode .result-header::after {
  content: 'Histórico: somente leitura';
  display: inline-flex;
  align-items: center;
  align-self: start;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}
#scanView.history-mode .result-header { align-items: flex-start; }
@media (max-width: 1100px) {
  #scanView.result-mode .result-panel, #scanView.history-mode .result-panel { grid-column: auto; }
}


.client-editing { border-color: color-mix(in srgb, var(--brand-2) 45%, var(--line)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 18%, transparent); }
.form-note { color: var(--muted); font-size: 13px; font-weight: 700; }
.move-help { margin-top: 10px; color: var(--muted); font-size: 13px; font-weight: 700; }
#scanView.preview-mode #map { min-height: 720px; }
#scanView.result-mode #map, #scanView.history-mode #map { min-height: 760px; }
