:root {
  --red: #ed1c24;
  --red-dark: #9d1117;
  --ink: #171719;
  --text: #2b2b2f;
  --muted: #6f737b;
  --line: #dde1e7;
  --paper: #ffffff;
  --soft: #f4f5f7;
  --ok: #147a3f;
  --warn: #9a6500;
  --bad: #b42318;
  --blue: #245f99;
  --sidebar-w: 240px;
}

/* Elemento-assinatura: glifo de "sinal" (arcos do logo CONTECX) usado só como
   indicador de estado ativo/conectado — não decoração solta. */
.signal {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 11px;
}

.signal span {
  width: 3px;
  background: currentColor;
  border-radius: 1px;
  opacity: 0.45;
}

.signal span:nth-child(1) { height: 40%; }
.signal span:nth-child(2) { height: 65%; }
.signal span:nth-child(3) { height: 100%; }

.signal.is-live span {
  opacity: 1;
}

@media (prefers-reduced-motion: no-preference) {
  .signal.is-live span {
    animation: signal-pulse 1.8s ease-in-out infinite;
  }
  .signal.is-live span:nth-child(2) { animation-delay: 0.15s; }
  .signal.is-live span:nth-child(3) { animation-delay: 0.3s; }
}

@keyframes signal-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background: var(--soft);
  font-family: -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, transform 140ms ease;
}

button:active {
  transform: translateY(1px);
}

a {
  color: inherit;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
  margin: 0;
  font-weight: 900;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.subtitle {
  font-size: 13px;
  font-weight: 700;
  margin: 4px 0 0;
  color: var(--muted);
}

/* ---------- Estrutura: rail lateral fixo + conteúdo ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--ink) 0%, #05070a 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  padding: 20px 16px 16px;
}

.sidebar-logo-badge {
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.sidebar-logo {
  width: 100%;
  max-width: 190px;
  height: auto;
  display: block;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  transition: background-color 140ms ease, color 140ms ease;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.sidebar-link.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar-link.active .signal {
  color: var(--red);
}

.sidebar-link.active .signal span {
  opacity: 1;
}

.sidebar-footer {
  padding: 14px 18px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.page-topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 18px 28px;
}

.page {
  padding: 22px 28px 48px;
  max-width: 1400px;
  width: 100%;
}

/* ---------- KPIs ---------- */

.kpis {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(240px, 1.1fr) 2fr;
  margin-bottom: 16px;
  align-items: stretch;
}

.kpis-secondary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.card-result {
  justify-content: center;
}

.card-result .label {
  color: inherit;
  opacity: 0.72;
}

.card-result .value {
  font-size: clamp(28px, 3.4vw, 42px);
}

.card-result.is-positive {
  background: linear-gradient(155deg, #eafcf2 0%, #fff 62%);
  border-color: rgba(20, 122, 63, 0.22);
}

.card-result.is-positive .value {
  color: var(--ok);
}

.card-result.is-negative {
  background: linear-gradient(155deg, #fff0ef 0%, #fff 62%);
  border-color: rgba(180, 35, 24, 0.22);
}

.card-result.is-negative .value {
  color: var(--bad);
}

.panel-count {
  color: var(--muted);
  font-weight: 700;
  text-transform: none;
  margin-left: 4px;
}

.card,
.panel {
  background: var(--paper);
  border: 1px solid rgba(17, 18, 20, 0.06);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(17, 18, 20, 0.06);
}

.card {
  border-top: 2px solid transparent;
  transition: border-color 160ms ease, box-shadow 160ms ease;
  min-height: 116px;
  padding: 17px;
  display: grid;
  gap: 9px;
  align-content: start;
}

.card:hover {
  border-top-color: var(--red);
  box-shadow: 0 14px 32px rgba(17, 18, 20, 0.1);
}

.card .label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.card .value {
  color: var(--ink);
  font-size: clamp(20px, 2.4vw, 30px);
  line-height: 1.05;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.card .hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

/* ---------- Painéis, formulários ---------- */

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(320px, 420px) 1fr;
  align-items: start;
}

/* Itens de grid têm min-width:auto por padrão, o que deixa o conteúdo (ex.: a
   tabela larga dentro de .table-wrap) forçar a página inteira a ficar mais
   larga que a tela no mobile, mesmo com overflow-x:auto no wrapper. */
.grid > * {
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  padding: 16px 20px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.form-panel-solo {
  max-width: 960px;
}

.panel-title {
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
  text-transform: uppercase;
}

.panel-body {
  padding: 20px;
}

.form-section + .form-section {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.form-section-title {
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 16px;
  align-items: start;
}

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

label {
  display: grid;
  gap: 6px;
  color: #4f535b;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfd4dc;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  height: 42px;
  padding: 0 11px;
  outline: none;
  line-height: normal;
  box-sizing: border-box;
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23626872'%3E%3Cpath d='M5.5 7.5l4.5 5 4.5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
  padding-right: 32px;
}

input[type="number"] {
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

textarea {
  height: auto;
  min-height: 90px;
  padding: 10px 11px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(237, 28, 36, 0.12);
}

input[readonly] {
  background: var(--soft);
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--red);
  color: white;
  box-shadow: 0 8px 18px rgba(237, 28, 36, 0.24);
}

.btn-primary:hover {
  background: #c9161d;
}

.btn-ghost {
  background: #f8f9fb;
  border-color: #d7dce3;
  color: #363a41;
}

.btn-ghost:hover {
  background: #eef0f3;
  border-color: #c3c9d2;
}

.btn-icon {
  width: 36px;
  min-height: 36px;
  padding: 0;
}

.filters {
  display: grid;
  grid-template-columns: 1.2fr repeat(2, minmax(130px, 0.7fr)) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.filter-actions {
  display: flex;
  gap: 10px;
}

.filter-actions .btn {
  flex: 1;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
  font-size: 13px;
}

table.table-wide {
  min-width: 1540px;
}

th,
td {
  border-bottom: 1px solid #e6e9ee;
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #fafafa;
  color: #626872;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

td strong {
  color: var(--ink);
}

.money {
  text-align: right;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.tag {
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.tag-in {
  background: #e8f7ee;
  color: var(--ok);
}

.tag-out {
  background: #fff0ef;
  color: var(--bad);
}

.tag-paid {
  background: #e8f7ee;
  color: var(--ok);
}

.tag-note {
  background: #eaf2fb;
  color: var(--blue);
}

.tag-open {
  background: #fff7df;
  color: var(--warn);
}

.tag-late {
  background: #fff0ef;
  color: var(--bad);
}

.tag-muted {
  background: #f1f2f4;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chart-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chart-box {
  background: #fff;
  border: 1px solid rgba(17, 18, 20, 0.06);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(17, 18, 20, 0.08);
  padding: 17px;
}

.chart-box h3 {
  color: var(--ink);
  font-size: 14px;
  margin: 0 0 14px;
  text-transform: uppercase;
}

.bar-row {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.bar-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #4f535b;
  font-size: 12px;
  font-weight: 900;
}

.bar-track {
  background: #edf0f4;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.bar-fill {
  background: linear-gradient(90deg, var(--red), #171719);
  border-radius: 999px;
  height: 100%;
  min-width: 3px;
}

.dre {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.dre-box {
  border: 1px solid #e2e6ec;
  border-radius: 8px;
  background: #fbfcfd;
  padding: 14px;
}

.dre-box h3 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 13px;
  text-transform: uppercase;
}

.line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid #e8ebef;
  padding: 10px 0;
  color: #4f535b;
  font-size: 13px;
  font-weight: 700;
}

.line:first-of-type {
  border-top: 0;
}

.empty {
  color: var(--muted);
  font-weight: 700;
  padding: 18px;
  text-align: center;
}

.right-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.hidden {
  display: none;
}

/* ---------- Login ---------- */

.login-screen {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(237, 28, 36, 0.1), transparent 26rem),
    linear-gradient(135deg, #ffffff 0%, #f4f5f7 46%, #e7eaef 100%);
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(430px, 100%);
  background: #fff;
  border: 1px solid rgba(17, 18, 20, 0.08);
  border-radius: 10px;
  box-shadow: 0 22px 52px rgba(17, 18, 20, 0.16);
  overflow: hidden;
}

.login-head {
  position: relative;
  background: linear-gradient(150deg, var(--ink) 0%, #05070a 100%);
  color: #fff;
  padding: 26px 24px;
}

.login-logo-badge {
  background: #fff;
  border-radius: 8px;
  padding: 14px 18px;
  display: inline-flex;
  margin-bottom: 18px;
}

.login-logo {
  height: 46px;
  width: auto;
  display: block;
}

.login-tagline {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.75);
}

.login-tagline span {
  color: rgba(255, 255, 255, 0.4);
}

.login-head h2 {
  font-size: 24px;
  line-height: 1;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: -0.01em;
}

.login-head p {
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-weight: 700;
}

.login-form {
  display: grid;
  gap: 13px;
  padding: 22px;
}

.login-error {
  border-radius: 8px;
  background: #fff0ef;
  color: var(--bad);
  font-size: 13px;
  font-weight: 900;
  padding: 11px 12px;
}

.remember-row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #4f535b;
  font-size: 13px;
  font-weight: 800;
  text-transform: none;
}

.remember-row input {
  width: 17px;
  height: 17px;
  padding: 0;
  accent-color: var(--red);
}

.user-chip {
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.68);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.5);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-btn:hover {
  color: #fff;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  border-radius: 8px;
  background: #171719;
  color: #fff;
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.24);
  font-size: 14px;
  font-weight: 900;
  min-width: 210px;
  padding: 14px 16px;
}

@media (max-width: 1180px) {
  .kpis {
    grid-template-columns: 1fr;
  }

  .kpis-secondary {
    grid-template-columns: repeat(3, 1fr);
  }

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

  .filters,
  .dre {
    grid-template-columns: 1fr 1fr;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
  }

  .sidebar-brand {
    padding: 0;
  }

  .sidebar-nav {
    flex-direction: row;
    padding: 0;
    overflow-x: auto;
  }

  .sidebar-link span.link-text {
    display: none;
  }

  .sidebar-footer {
    padding: 0;
    border-top: 0;
    margin-left: auto;
  }

  .user-chip {
    max-width: 90px;
  }

  .page-topbar {
    padding: 14px 18px;
  }

  .page {
    padding: 18px 18px 40px;
  }
}

@media (max-width: 760px) {
  .kpis,
  .kpis-secondary,
  .filters,
  .dre,
  .two {
    grid-template-columns: 1fr;
  }

  .toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }
}

:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
