:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #172026;
  --muted: #66747c;
  --line: #d9e1e5;
  --green: #176b52;
  --blue: #245b91;
  --red: #b42318;
  --yellow: #946200;
  --ink: #0f1f2a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; }
button {
  border: 0;
  background: var(--green);
  color: white;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
}
button.secondary { background: var(--blue); }
button.warn { background: var(--yellow); }
button.danger { background: var(--red); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.icon { width: 34px; min-height: 34px; padding: 0; background: transparent; color: var(--text); border: 1px solid var(--line); }
button:disabled { opacity: .55; cursor: not-allowed; }

.hidden { display: none !important; }
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #e9f2ed, #f7f3e8);
}
.login-box {
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 16px 45px rgba(15,31,42,.12);
}
.login-box h1 { margin: 0 0 6px; font-size: 28px; }
.login-box p { margin: 0 0 24px; color: var(--muted); }
label { display: grid; gap: 7px; color: var(--muted); margin-bottom: 14px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--text);
  background: white;
}
textarea { min-height: 120px; resize: vertical; }
small { color: var(--muted); }
.login-credit {
  display: block;
  margin-top: 14px;
  line-height: 1.35;
}

.app { min-height: 100vh; display: grid; grid-template-columns: 230px 1fr; }
.sidebar {
  background: #10251f;
  color: white;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.brand { display: grid; gap: 3px; padding: 8px; }
.brand strong { font-size: 24px; }
.brand span { color: #b8cec4; }
nav { display: grid; gap: 6px; }
nav button {
  text-align: left;
  background: transparent;
  color: #dce8e3;
}
nav button.active, nav button:hover { background: #1f493d; }
.sidebar .ghost { color: #dce8e3; border-color: #34584d; margin-top: auto; }
.main { min-width: 0; }
.credit {
  color: #6f7d84;
  font-size: 12px;
  text-align: center;
  padding: 10px 16px 18px;
}
.topbar {
  height: 78px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 18px;
}
.topbar h2 { margin: 0; }
.search { display: flex; gap: 8px; width: min(560px, 50vw); }
.view { padding: 22px 24px 40px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(4, minmax(160px, 1fr)); }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; font-size: 27px; margin-top: 8px; }
.split { display: grid; grid-template-columns: 1.2fr .8fr; gap: 16px; margin-top: 16px; }
.report-shell {
  display: grid;
  gap: 18px;
}
.report-hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  background: linear-gradient(135deg, #123b31, #1f6d55 58%, #d79b2d);
  color: white;
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 16px 40px rgba(16, 37, 31, .16);
}
.report-hero span {
  display: inline-block;
  color: #d7f0e5;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 10px;
}
.report-hero h1 {
  margin: 0;
  max-width: 760px;
  font-size: 32px;
  line-height: 1.12;
}
.report-hero p {
  color: #e7f4ef;
  margin: 12px 0 0;
  max-width: 720px;
}
.report-stamp {
  min-width: 170px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 8px;
  padding: 16px;
  text-align: right;
  background: rgba(255,255,255,.08);
}
.report-stamp strong { display: block; font-size: 25px; }
.report-stamp small { color: #eef8f4; }
.report-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}
.report-metric {
  border-radius: 8px;
  padding: 16px;
  color: #10251f;
  border: 1px solid var(--line);
  background: white;
}
.report-metric span { display: block; font-size: 12px; color: #52636b; text-transform: uppercase; }
.report-metric strong { display: block; margin-top: 8px; font-size: 25px; }
.report-metric.green { border-top: 5px solid #176b52; }
.report-metric.blue { border-top: 5px solid #245b91; }
.report-metric.amber { border-top: 5px solid #d79b2d; }
.report-metric.red { border-top: 5px solid #b42318; }
.report-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr);
  gap: 16px;
}
.report-panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.report-panel.wide { grid-row: span 2; }
.section-title {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.section-title span {
  width: 9px;
  height: 28px;
  border-radius: 999px;
  background: #d79b2d;
}
.section-title h2 {
  margin: 0;
  font-size: 18px;
}
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.renegation-attachments {
  margin-top: 12px;
  display: grid;
  gap: 12px;
}
.attachment-panel {
  display: grid;
  gap: 12px;
}
.attachment-panel h4 {
  margin: 0;
}
.attachment-panel small {
  white-space: nowrap;
}
.attachment-panel label {
  margin-bottom: 0;
}
.phone-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.wa-link, .wa-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  color: #1fa463;
  background: #e8f6ef;
  text-decoration: none;
}
.wa-link svg, .wa-inline svg {
  width: 16px;
  height: 16px;
}
.paste-box {
  min-height: 140px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fbfcfd;
  color: var(--muted);
  overflow: auto;
}
.paste-box:focus {
  outline: 2px solid rgba(36,91,145,.18);
  border-color: #9bb8d3;
  color: var(--text);
}
.reneg-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.6fr) minmax(150px, .7fr) minmax(160px, .8fr);
  gap: 10px;
  align-items: end;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafcfd;
}
.reneg-row > label {
  margin: 0;
}
.reneg-row input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}
.report-shell table {
  width: 100%;
}
.chart-note {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select, .filters input { width: auto; min-width: 180px; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
th, td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}
th { background: #eef3f1; color: #31433d; font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  background: #e9eef2;
  color: #334;
}
.pill.Media { background: #fff1c2; color: #6c4800; }
.pill.Alta { background: #ffe2bd; color: #824500; }
.pill.Critica, .pill.Maxima { background: #ffe0dc; color: #9a1b12; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions button { min-height: 32px; padding: 0 10px; }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 70px; gap: 10px; align-items: center; }
.bar { height: 12px; background: #e8eeee; border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--green); }
.line-chart { display: grid; gap: 10px; }
.line-chart svg {
  width: 100%;
  height: 240px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}
.chart-note {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  flex-wrap: wrap;
}
.timeline { display: grid; gap: 10px; }
.timeline .item { border-left: 3px solid var(--green); padding-left: 10px; }
.history-card { margin-top: 16px; display: grid; gap: 12px; }
.history-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
}
.history-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbfc;
}
.history-chip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}
.history-chip strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
  color: var(--ink);
}
.history-chip.wide { grid-column: 1 / -1; }
.sync-status {
  display: grid;
  gap: 6px;
  margin: 10px 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}
.sync-status p {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
}
.sync-status small {
  color: var(--muted);
}
.import-box {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  align-items: end;
}
.import-box + small,
.card > small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.35;
}
.import-box label { margin-bottom: 0; }
.import-box .wide { grid-column: span 2; }
dialog {
  width: min(920px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
}
dialog::backdrop { background: rgba(15,31,42,.38); }
.modal-head {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; }
#modalBody { padding: 16px; overflow: auto; max-height: calc(100vh - 100px); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.message-box { display: grid; gap: 10px; }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--ink);
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  max-width: 360px;
  box-shadow: 0 12px 34px rgba(0,0,0,.2);
}
.print-header { display: none; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  nav { grid-template-columns: repeat(4, 1fr); }
  .topbar { height: auto; padding: 14px; align-items: stretch; flex-direction: column; }
  .search { width: 100%; }
  .kpis, .split, .detail-grid, .import-box, .report-kpis, .report-grid { grid-template-columns: 1fr; }
  .history-summary { grid-template-columns: 1fr 1fr; }
  .report-hero { align-items: flex-start; flex-direction: column; }
  .report-stamp { text-align: left; }
  .import-box .wide { grid-column: auto; }
}

@media print {
  .sidebar, .topbar, .toolbar, button { display: none !important; }
  .app { display: block; }
  .view { padding: 0; }
  .view.hidden { display: none !important; }
  body { background: white; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .card, table, .report-panel, .report-metric { break-inside: avoid; }
  .report-shell { gap: 12px; }
  .report-hero {
    box-shadow: none;
    padding: 20px;
  }
  .report-hero h1 { font-size: 25px; }
  .report-kpis { grid-template-columns: repeat(4, 1fr); }
  .report-grid { grid-template-columns: 1fr; }
  .report-panel.wide { grid-row: auto; }
  .report-grid > .report-panel:nth-child(3) { break-before: page; page-break-before: always; }
  .line-chart svg { height: 210px; }
  .credit {
    border-top: 1px solid #d9e1e5;
    margin-top: 16px;
    padding-top: 10px;
  }
}
