:root {
  --blue: #2563eb;
  --navy: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f8fafc;
  --danger: #dc2626;
  --green: #16a34a;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--navy);
  font:
    15px/1.45 system-ui,
    -apple-system,
    Segoe UI,
    sans-serif;
}
.topbar {
  height: 68px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 4%;
  gap: 32px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand {
  font-size: 22px;
  font-weight: 800;
  color: var(--blue);
  text-decoration: none;
}
.topbar nav {
  display: flex;
  gap: 20px;
  flex: 1;
}
.topbar nav a,
.account a {
  color: #334155;
  text-decoration: none;
  font-weight: 600;
}
.topbar nav a:hover {
  color: var(--blue);
}
.account {
  display: flex;
  align-items: center;
  gap: 18px;
  text-align: right;
}
.account small {
  display: block;
  color: var(--muted);
  font-weight: 400;
}
.container {
  max-width: 1200px;
  margin: 32px auto;
  padding: 0 20px;
}
.page-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
h1 {
  font-size: 26px;
  margin: 0;
}
h2 {
  font-size: 19px;
  margin: 0 0 16px;
}
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px #0f172a0a;
  margin-bottom: 20px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.plan-summary {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.plan-summary .stat small {
  display: block;
  margin-top: 4px;
}
.stat strong {
  display: block;
  font-size: 28px;
}
.stat span,
.muted {
  color: var(--muted);
}
table {
  width: 100%;
  border-collapse: collapse;
}
#admin-layer-table {
  font-size: 13px;
  min-width: 850px;
  table-layout: fixed;
}
#admin-layer-table th,
#admin-layer-table td {
  padding: 10px 9px;
  vertical-align: middle;
  border-right: 1px solid var(--line);
  overflow-wrap: anywhere;
}
#admin-layer-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  white-space: nowrap;
}
#admin-layer-table tbody tr:nth-child(even) {
  background: #f8fafc80;
}
#admin-layer-table tbody tr:hover {
  background: #eff6ff;
}
#admin-layer-table th:nth-child(1),
#admin-layer-table td:nth-child(1) {
  width: 42px;
  text-align: center;
}
#admin-layer-table th:nth-child(2),
#admin-layer-table td:nth-child(2) {
  width: 78px;
}
#admin-layer-table th:nth-child(3),
#admin-layer-table td:nth-child(3) {
  width: 180px;
}
#admin-layer-table th:nth-child(4),
#admin-layer-table td:nth-child(4) {
  width: 265px;
}
#admin-layer-table th:nth-child(5),
#admin-layer-table td:nth-child(5) {
  width: 145px;
}
#admin-layer-table th:nth-child(6),
#admin-layer-table td:nth-child(6) {
  width: 78px;
  text-align: center;
}
#admin-layer-table th:nth-child(7),
#admin-layer-table td:nth-child(7) {
  width: 145px;
}
#admin-layer-table th:last-child,
#admin-layer-table td:last-child {
  border-right: 0;
}
#admin-layer-table .btn.small {
  padding: 4px 7px;
  font-size: 12px;
}
#admin-layer-table td.actions {
  display: table-cell;
  white-space: nowrap;
}
#admin-layer-table td.actions form {
  display: inline-block;
  margin-right: 4px;
}
#admin-layer-table td.actions form:last-child {
  margin-right: 0;
}
.compact-table-card {
  padding: 0;
  overflow-x: auto;
  border-radius: 12px;
}
th,
td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
}
.btn {
  display: inline-block;
  border: 0;
  border-radius: 7px;
  padding: 9px 13px;
  background: var(--blue);
  color: #fff;
  text-decoration: none;
  font-weight: 650;
  cursor: pointer;
}
.btn.secondary {
  background: #e2e8f0;
  color: #1e293b;
}
.btn.danger {
  background: var(--danger);
}
.btn.small {
  padding: 6px 9px;
  font-size: 13px;
}
.actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.field label {
  display: block;
  font-weight: 650;
  margin-bottom: 5px;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  font: inherit;
}
.field input[aria-invalid="true"] {
  border-color: #dc2626;
  box-shadow: 0 0 0 1px #dc2626;
}
.field-error {
  display: block;
  margin-top: 5px;
  color: #b91c1c;
  font-size: 0.875rem;
  font-weight: 600;
}
.field.full {
  grid-column: 1/-1;
}
.alert {
  padding: 12px 15px;
  border-radius: 8px;
  margin-bottom: 16px;
}
.alert.success {
  background: #dcfce7;
  color: #166534;
}
.alert.error {
  background: #fee2e2;
  color: #991b1b;
}
.badge {
  display: inline-block;
  border-radius: 99px;
  padding: 3px 8px;
  background: #e2e8f0;
  font-size: 12px;
  font-weight: 700;
}
.badge.PAGO,
.badge.ATIVO {
  background: #dcfce7;
  color: #166534;
}
.badge.ATRASADO {
  background: #fee2e2;
  color: #991b1b;
}
.badge.PENDENTE {
  background: #fef3c7;
  color: #92400e;
}
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: #0f172aa8;
  z-index: 20;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.open {
  display: flex;
}
.modal-box {
  background: #fff;
  border-radius: 13px;
  padding: 22px;
  width: min(620px, 100%);
  max-height: 90vh;
  overflow: auto;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-head button {
  border: 0;
  background: none;
  font-size: 25px;
  cursor: pointer;
}
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #172554, #2563eb);
}
.login-card {
  background: #fff;
  width: min(420px, 92%);
  padding: 34px;
  border-radius: 16px;
  box-shadow: 0 20px 50px #0004;
}
.login-card h1 {
  font-size: 30px;
  margin-bottom: 6px;
}
.login-card .field {
  margin: 16px 0;
}
.login-card .btn {
  width: 100%;
}
.login-link {
  margin: -2px 0 16px;
  text-align: right;
}
.login-link a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
}
.login-link a:hover {
  text-decoration: underline;
}
.data-table-controls,
.data-table-footer,
.data-table-pages {
  display: flex;
  align-items: center;
  gap: 12px;
}
.data-table-controls,
.data-table-footer {
  justify-content: space-between;
  margin: 16px 0;
}
.data-table-controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.data-table-controls select,
.data-table-controls input {
  width: auto;
  min-width: 80px;
}
.data-table-search input {
  min-width: 260px;
}
.data-table-pages button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
.usage-matrix th:not(:first-child),
.usage-matrix td:not(:first-child) {
  text-align: center;
}
.usage-matrix .usage-count {
  font-weight: 700;
  min-width: 72px;
}
@media (max-width: 800px) {
  .topbar {
    height: auto;
    padding: 15px 20px;
    flex-wrap: wrap;
  }
  .topbar nav {
    order: 3;
    width: 100%;
    overflow: auto;
  }
  .account span {
    display: none;
  }
  .grid,
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
  .card {
    overflow: auto;
  }
  .data-table-controls,
  .data-table-footer {
    align-items: stretch;
    flex-direction: column;
  }
  .data-table-search input {
    min-width: 0;
    width: 100%;
  }
}
@media (max-width: 520px) {
  .grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
  .field.full {
    grid-column: auto;
  }
}

/* Campos curtos do IPTU permanecem juntos, inclusive no celular. */
.iptu-fields {
  display: grid;
  grid-template-columns: 6ch 6ch 7ch 5ch max-content;
  gap: 12px;
  align-items: end;
}
.iptu-fields input {
  width: 100%;
  min-width: 0;
  padding: 10px 6px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.iptu-search-card { min-width: 0; }
@media (min-width: 521px) and (max-width: 1100px) {
  .iptu-fields { grid-template-columns: 6ch 6ch 7ch 5ch; }
  .iptu-submit { grid-column: 1 / -1; justify-self: start; }
}
@media (max-width: 800px) {
  .account span { display: block; }
}
@media (max-width: 520px) {
  .iptu-fields { grid-template-columns: 1fr 1fr 1.2fr .8fr; gap: 8px; }
  .iptu-submit { grid-column: 1 / -1; }
}

@media (max-width: 1100px) {
  .consultation-search-forms { grid-template-columns: 1fr; }
}

/* Navegação recolhida em telas pequenas. */
.topbar { z-index: 100; }
.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--navy);
  background: #fff;
  cursor: pointer;
}
.menu-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
@media (max-width: 1050px) {
  .topbar { height: 68px; padding: 8px 16px; gap: 12px; flex-wrap: nowrap; }
  .topbar .brand { flex-shrink: 0; }
  .topbar .account { order: 2; margin-left: auto; min-width: 0; gap: 8px; }
  .topbar .account > span { display: block; min-width: 0; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
  .topbar .account small { font-size: 11px; }
  .menu-toggle { display: inline-flex; order: 3; flex-shrink: 0; }
  .topbar nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    width: 100%;
    max-height: calc(100dvh - 68px);
    overflow-y: auto;
    flex-direction: column;
    gap: 0;
    padding: 8px 16px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 8px 16px #0f172a14;
  }
  .topbar.menu-open nav { display: flex; }
  .topbar nav a { display: block; padding: 12px; border-radius: 6px; }
  .topbar nav a:hover { background: var(--bg); }
}
@media (max-width: 380px) {
  .topbar { gap: 8px; padding-inline: 10px; }
  .topbar .account { gap: 5px; }
  .topbar .account > span { max-width: 32vw; }
}
