:root {
  --forest: #263f2b;
  --forest-2: #314b36;
  --moss: #6b8e23;
  --earth: #8b6f4e;
  --paper: #fbfaf4;
  --line: #d7d2c7;
  --danger: #c63d2f;
  --warning: #ff8c00;
  --muted: #666;
  --white: #fff;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: Calibri, Arial, sans-serif;
  background: linear-gradient(135deg, #eef1e7, #d9dfcf);
  color: #222;
}

.app {
  height: 100vh;
  padding: 12px;
  display: grid;
  grid-template-columns: 330px 1fr 420px;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.app.right-panel-hidden {
  grid-template-columns: 330px 1fr 34px;
}

.app.right-panel-hidden .right-panel {
  display: flex;
  min-width: 34px;
  overflow: visible;
  background: transparent;
  box-shadow: none;
}

.app.right-panel-hidden .right-panel > :not(.right-panel-toggle) {
  display: none !important;
}

.scale-control-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
}

.scale-control-row span {
  color: rgba(255, 255, 255, 0.88);
  font-weight: 700;
}

.scale-control-row .btn.compact {
  padding: 8px 9px;
  white-space: nowrap;
}

.scale-control-row input {
  min-width: 0;
}

.app-menu {
  grid-column: 1 / -1;
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: var(--shadow);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.app-logo {
  display: block;
  max-width: 100px;
  max-height: 100px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.app-brand h1 {
  margin: 0;
  color: var(--forest);
  font-size: 24px;
  line-height: 1.05;
}

.app-brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.app-menu-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn.menu-btn {
  padding: 8px 10px;
  color: var(--white);
  background: var(--forest);
  white-space: nowrap;
}

.btn.menu-btn:hover {
  background: var(--forest-2);
}

.btn.menu-btn.danger {
  background: rgba(198, 61, 47, 0.95);
}

/* PAINÉIS */

.panel,
.map-panel {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.left-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: linear-gradient(160deg, var(--forest), var(--forest-2) 55%, #6d5b44);
  color: var(--white);
  overflow-y: auto;
}

.map-panel {
  background: var(--white);
  min-width: 0;
  min-height: 0;
}

.right-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: rgba(255, 255, 255, 0.96);
}

.right-panel-toggle {
  position: absolute;
  z-index: 20;
  left: -16px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 64px;
  border: 1px solid rgba(38, 63, 43, 0.28);
  border-right: 0;
  border-radius: 12px 0 0 12px;
  cursor: pointer;
  color: var(--white);
  background: linear-gradient(160deg, var(--forest), var(--forest-2));
  box-shadow: var(--shadow);
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.right-panel-toggle:hover {
  background: linear-gradient(160deg, #31533a, #3c5d43);
}

.app.right-panel-hidden .right-panel-toggle {
  position: static;
  align-self: stretch;
  width: 34px;
  height: 100%;
  min-height: 100%;
  transform: none;
  border-radius: var(--radius);
  border: 1px solid rgba(38, 63, 43, 0.28);
  box-shadow: var(--shadow);
}

/* MENU ESQUERDO */

.brand {
  padding: 18px 18px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.brand h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0.2px;
}

.brand p {
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  line-height: 1.35;
}

.section {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.section h2 {
  margin: 0 0 9px;
  font-size: 15px;
  font-weight: 700;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.footer {
  padding: 10px;
  display: grid;
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

/* CAMPOS */

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: 14px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 9px 10px;
  cursor: pointer;
  color: var(--white);
  background: rgba(255, 255, 255, 0.14);
  transition: 0.12s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.btn.active,
.btn.run {
  background: var(--moss);
  font-weight: 700;
}

.btn.danger {
  background: rgba(198, 61, 47, 0.9);
}

.btn.secondary {
  background: rgba(0, 0, 0, 0.22);
}

.btn.full {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 5px;
  margin-bottom: 8px;
}

.field label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
}

.field input,
.field select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.12);
  color: var(--white);
  border-radius: 10px;
  padding: 8px;
  outline: none;
}

.field input[readonly] {
  opacity: 0.72;
}

.field option {
  color: #222;
}

.hint {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.75);
}

/* CANVAS */

.map-statusbar {
  height: 58px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
}

.status {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status strong {
  color: var(--forest);
}

#mapCanvas {
  display: block;
  width: 100%;
  height: calc(100% - 58px);
  background: var(--paper);
  cursor: crosshair;
}

/* PAINEL DIREITO */

.right-header {
  padding: 14px 16px;
  background: linear-gradient(140deg, #fff, #f1efe7);
  border-bottom: 1px solid var(--line);
}

.right-header h2 {
  margin: 0;
  font-size: 18px;
  color: var(--forest);
}

.right-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 10px;
  background: #f8f6ef;
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 1px solid var(--line);
  background: var(--white);
  border-radius: 999px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
  color: #222;
}

.tab.active {
  color: var(--white);
  background: var(--forest);
}

.right-body {
  overflow: auto;
  padding: 12px;
  flex: 1;
}

/* CARDS E TABELAS */

.card {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.card h3 {
  margin: 0;
  color: var(--forest);
  font-size: 15px;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.card label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 12px;
}

.card input,
.card select,
.card textarea {
  width: 100%;
  border: 1px solid #d8d6ca;
  border-radius: 9px;
  padding: 7px;
  color: #222;
  background: var(--white);
}

.card input[disabled],
.card input[readonly] {
  background: #f5f5f2;
  color: #666;
}

.small {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.38;
}

.json {
  min-height: 180px;
  width: 100%;
  resize: vertical;
  font-family: Consolas, monospace;
  font-size: 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 8px;
}

/* TABELAS */

.table-wrap {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid #eee;
  background: var(--white);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: var(--white);
}

th,
td {
  border-bottom: 1px solid #eee;
  padding: 7px 6px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f0f2eb;
  color: var(--forest);
  position: sticky;
  top: 0;
  z-index: 1;
}

tr.bad td {
  background: #ffe7e7;
}

tr.warn td {
  background: #fff3df;
}

/* BADGES */

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 11px;
  color: var(--white);
}

.badge.CAPTACAO {
  background: #2674a6;
}

.badge.BOMBA {
  background: #8737a0;
}

.badge.RESERVATORIO {
  background: #4666ad;
}

.badge.BEBEDOURO {
  background: #2f7d4f;
}

.badge.DERIVACAO {
  background: #8b6f4e;
}

.badge.ANTIVACUO {
  background: #008c8c;
}

.badge.REGISTRO {
  background: #5c5c5c;
}

.badge.CAVALETE {
  background: #b56f1d;
}

.badge.ALIVIO {
  background: #d7191c;
}

.badge.ENERGIA {
  background: #c69522;
}

/* SCROLL */

.left-panel::-webkit-scrollbar,
.right-body::-webkit-scrollbar {
  width: 10px;
}

.left-panel::-webkit-scrollbar-thumb,
.right-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 999px;
}

.left-panel::-webkit-scrollbar-track,
.right-body::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.12);
}

/* RESPONSIVO */

@media (max-width: 1200px) {
  .app {
    grid-template-columns: 300px 1fr;
  }

  .app-menu {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-menu-actions {
    justify-content: flex-start;
  }

  .right-panel {
    display: none;
  }
}

@media (max-width: 780px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .app-brand {
    min-width: 0;
  }

  .app-brand h1 {
    font-size: 21px;
  }

  .left-panel,
  .map-panel,
  .right-panel {
    min-height: 400px;
  }

  .right-panel {
    display: flex;
  }

  #mapCanvas {
    height: 500px;
  }
}
.card label.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #2f2f2f;
}

.card label.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.layer-checklist {
  display: grid;
  gap: 7px;
}

.layer-checklist label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.92);
  font-size: 13px;
  cursor: pointer;
}

.layer-checklist input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: var(--moss);
}

/* PRÉVIA PDF */
.pdf-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.58);
}

.pdf-preview-modal.open {
  display: flex;
}

.pdf-preview-window {
  width: 95vw;
  height: 95vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-radius: 14px;
  overflow: hidden;
  background: #e7e7e7;
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.45);
}

.pdf-preview-toolbar {
  min-height: 54px;
  padding: 9px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  border-bottom: 1px solid #cfcfcf;
}

.pdf-preview-toolbar strong {
  color: var(--forest);
  font-size: 16px;
  margin-right: 4px;
}

.pdf-preview-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #333;
  font-weight: 700;
}

.pdf-preview-toolbar input[type="number"] {
  width: 110px;
  padding: 6px 8px;
  border: 1px solid #bbb;
  border-radius: 6px;
}

.pdf-preview-hint {
  color: #666;
  font-size: 12px;
  margin-right: auto;
}

.pdf-preview-body {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: #555;
}

.pdf-preview-viewport {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.pdf-a2-sheet {
  position: relative;
  width: 594mm;
  height: 420mm;
  flex: 0 0 auto;
  transform-origin: center center;
  background: #ffffff;
  box-shadow: 0 0 14px rgba(0,0,0,.35);
  overflow: hidden;
}

.pdf-preview-map-canvas,
.pdf-preview-titleblock-host,
#pdfPreviewDragSurface {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.pdf-preview-map-canvas {
  z-index: 1;
  background: #fff;
}

.pdf-preview-titleblock-host {
  z-index: 2;
  pointer-events: none;
}

#pdfPreviewDragSurface {
  z-index: 3;
  cursor: move;
  background: rgba(0,0,0,0);
}

@media print {
  @page {
    size: A2 landscape;
    margin: 0;
  }

  body > *:not(#pdfPreviewModal) {
    display: none !important;
  }

  #pdfPreviewModal,
  .pdf-preview-modal.open,
  .pdf-preview-window,
  .pdf-preview-body,
  .pdf-preview-viewport {
    display: block !important;
    position: static !important;
    width: 594mm !important;
    height: 420mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: #fff !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  .pdf-preview-toolbar {
    display: none !important;
  }

  .pdf-a2-sheet {
    width: 594mm !important;
    height: 420mm !important;
    transform: none !important;
    box-shadow: none !important;
  }

  #pdfPreviewDragSurface {
    display: none !important;
  }
}


/* PRÉVIA PDF - iframe A2 centralizado, sem rolagem */
.pdf-preview-body {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden !important;
  background: #555;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.pdf-preview-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #555;
  box-shadow: none;
  overflow: hidden;
}

@media print {
  .pdf-preview-modal,
  .pdf-preview-window,
  .pdf-preview-body,
  .pdf-preview-frame {
    display: none !important;
  }
}

.scenario-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.75rem;
}

.scenario-card {
  border: 1px solid rgba(35, 55, 40, 0.18);
  border-radius: 10px;
  padding: 0.65rem;
  background: rgba(255, 255, 255, 0.7);
}

.scenario-card-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}

.scenario-card-header input[type="text"] {
  flex: 1;
  min-width: 0;
}

.scenario-register-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.5rem;
  align-items: center;
}

.scenario-register-grid label {
  font-size: 0.78rem;
  color: #435044;
}

.scenario-register-grid select {
  min-width: 86px;
}

.checkline {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  font-size: 0.9rem;
}

.button-grid.compact {
  grid-template-columns: 1fr;
}

.menu-dropdown {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}

.menu-dropdown .dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 1000;
  min-width: 220px;
  display: none;
  padding: 6px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.menu-dropdown:hover .dropdown-menu,
.menu-dropdown:focus-within .dropdown-menu {
  display: grid;
  gap: 4px;
}

.dropdown-menu button {
  width: 100%;
  border: 0;
  border-radius: 9px;
  padding: 9px 10px;
  background: transparent;
  color: var(--forest);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.dropdown-menu button:hover,
.dropdown-menu button:focus {
  outline: none;
  background: rgba(38, 63, 43, 0.1);
}

.calc-dump-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.42);
}

.calc-dump-modal.hidden {
  display: none;
}

.calc-dump-box {
  width: min(980px, calc(100vw - 40px));
  height: min(720px, calc(100vh - 40px));
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.calc-dump-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid #d9dee7;
  background: #f7f9fc;
}

.calc-dump-header strong {
  display: block;
  font-size: 15px;
}

.calc-dump-header span {
  display: block;
  margin-top: 3px;
  color: #5c6573;
  font-size: 12px;
}

.calc-dump-log {
  flex: 1;
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
  background: #111827;
  color: #e5e7eb;
}

.calc-dump-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #d9dee7;
  background: #f7f9fc;
}

.btn.danger {
  background: #b42318;
  border-color: #b42318;
  color: #fff;
}

.btn.success {
  background: #188038;
  border-color: #188038;
  color: #fff;
}

.btn.small {
  padding: 5px 9px;
  font-size: 12px;
}

.pump-curve-editor-row {
  margin: 8px 0 10px;
}

.pump-curve-modal {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.48);
}

.pump-curve-modal.hidden {
  display: none;
}

.pump-curve-box {
  width: min(1100px, calc(100vw - 36px));
  max-height: min(820px, calc(100vh - 36px));
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.30);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pump-curve-header,
.pump-curve-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #f7f9fc;
  border-bottom: 1px solid #d9dee7;
}

.pump-curve-actions {
  justify-content: flex-end;
  border-top: 1px solid #d9dee7;
  border-bottom: 0;
}

.pump-curve-header strong {
  display: block;
  font-size: 15px;
}

.pump-curve-header span {
  display: block;
  margin-top: 4px;
  color: #5c6573;
  font-size: 12px;
}

.pump-curve-body {
  display: grid;
  grid-template-columns: minmax(420px, 2fr) minmax(290px, 1fr);
  gap: 14px;
  padding: 16px;
  overflow: auto;
}

.pump-curve-chart-wrap {
  min-width: 0;
}

.pump-curve-svg {
  width: 100%;
  min-height: 340px;
  border: 1px solid #d9dee7;
  border-radius: 12px;
  touch-action: none;
  user-select: none;
}

.pump-curve-bg {
  fill: #ffffff;
}

.pump-curve-grid {
  stroke: #e5e9f0;
  stroke-width: 1;
}

.pump-curve-axis {
  stroke: #384152;
  stroke-width: 1.6;
}

.pump-curve-line {
  fill: none;
  stroke: #1f5f99;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pump-curve-node circle {
  fill: #ffffff;
  stroke: #1f5f99;
  stroke-width: 3;
  cursor: grab;
}

.pump-curve-node:active circle {
  cursor: grabbing;
}

.pump-curve-node text,
.pump-curve-axis-text,
.pump-curve-label {
  fill: #384152;
  font-size: 11px;
  font-family: Arial, sans-serif;
}

.pump-curve-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.pump-curve-table th,
.pump-curve-table td {
  padding: 6px;
  border-bottom: 1px solid #e5e9f0;
  text-align: left;
}

.pump-curve-table input {
  width: 100%;
  box-sizing: border-box;
}

@media (max-width: 860px) {
  .pump-curve-body {
    grid-template-columns: 1fr;
  }
}
