:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #1d2630;
  --muted: #687386;
  --line: #d9e1ec;
  --blue: #246bfe;
  --blue-dark: #1857d8;
  --yellow: #ffe066;
  --sidebar: #ffffff;
  --green: #157f4f;
  --red: #b42318;
  --amber: #9a6700;
  --shadow: 0 8px 24px rgba(29, 38, 48, .07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.hosted-hidden {
  display: none !important;
}

.environment-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 190px;
  padding: 8px 12px;
  border: 1px solid rgba(29, 38, 48, .16);
  border-radius: 6px;
  background: rgba(255, 255, 255, .68);
}

.environment-status div {
  display: grid;
  gap: 2px;
}

.environment-status small {
  color: #5d6878;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(21, 127, 79, .14);
}

.pending-tab::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-left: auto;
  border-radius: 50%;
  background: #b6bfcc;
}

.development-state {
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.development-state h2,
.development-state p {
  margin: 0;
}

.development-label {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  color: #5b6472;
  background: #edf1f6;
  font-size: 12px;
  font-weight: 700;
}

.error-state {
  min-height: 150px;
  border-color: #efc7c3;
}

.table-note {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.hosted td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.op-alert {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin: 2px 4px 2px 0;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.op-alert.red { color: #8a1c15; background: #fde7e4; border: 1px solid #f5b8b1; }
.op-alert.yellow { color: #755200; background: #fff3bf; border: 1px solid #e5c94b; }
.op-alert.orange { color: #8a4a00; background: #ffe5c2; border: 1px solid #f0b15f; }
.op-alert.blue { color: #174ea6; background: #dbeafe; border: 1px solid #9dc0ff; }
.op-alert.purple { color: #5b2aa0; background: #eee4ff; border: 1px solid #c8b5f2; }
.op-alert.gray { color: #4b5563; background: #eef2f7; border: 1px solid #cbd5e1; }

.operational-alerts-detail {
  display: grid;
  gap: 10px;
  width: 100%;
}

.operational-alerts-detail h3 {
  margin: 0;
  font-size: 14px;
}

.operational-alert-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.operational-alert-card dl {
  display: grid;
  grid-template-columns: minmax(90px, 140px) minmax(0, 1fr);
  gap: 6px 10px;
  margin: 8px 0 0;
}

.operational-alert-card dt {
  color: var(--muted);
  font-size: 12px;
}

.operational-alert-card dd {
  margin: 0;
  font-weight: 700;
}

.hosted .metric small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

@media (max-width: 760px) {
  .environment-status {
    width: 100%;
  }

  .development-state {
    min-height: 190px;
    padding: 22px;
  }
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  min-height: 70px;
  padding: 10px 24px 10px 260px;
  background: var(--yellow);
  color: var(--ink);
  border-bottom: 1px solid rgba(29, 38, 48, .12);
  box-shadow: 0 2px 12px rgba(29, 38, 48, .08);
}

h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.1;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

main {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  gap: 18px;
  padding: 18px 24px 36px;
}

main > :not(.tabs) {
  grid-column: 2;
}

.tax-control,
.upload-grid,
.filters,
.metrics {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}

.tax-control label,
.filters label {
  display: grid;
  gap: 5px;
  font-size: 12px;
  color: #3d4654;
}

.tax-control input,
.tax-control select,
.filters input,
.filters select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}

button {
  height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  color: white;
  background: var(--blue);
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, transform .08s ease, box-shadow .15s ease;
  box-shadow: 0 3px 10px rgba(36, 107, 254, .18);
}

button:hover,
.download-button:hover {
  background: var(--blue-dark);
}

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

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(36, 107, 254, .16);
}

button:disabled {
  opacity: .55;
  cursor: wait;
}

.upload-grid {
  align-items: stretch;
  margin-bottom: 4px;
}

.upload-box {
  flex: 1 1 210px;
  display: grid;
  gap: 7px;
  min-width: 200px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.upload-box span {
  color: var(--muted);
  font-size: 12px;
}

.upload-box input {
  min-width: 0;
}

.hosted-import-card {
  position: relative;
}

.hosted-import-card .import-status {
  justify-self: start;
  margin: 0;
}

.hosted-import-card button {
  width: 100%;
}

.metrics {
  margin-bottom: 6px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.import-history {
  margin-bottom: 0;
}

.import-history h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.section-head h2 {
  margin: 0;
}

.download-button.compact {
  padding: 8px 10px;
  font-size: 12px;
}

#importHistory {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

#integrityPanel,
#diagnosticsPanel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.maintenance-panel {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 10px rgba(29, 38, 48, .05);
}

.maintenance-panel summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 700;
  color: #3b4654;
}

.maintenance-panel[open] summary {
  border-bottom: 1px solid var(--line);
}

.maintenance-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 12px;
}

.roadmap-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 10px rgba(29, 38, 48, .05);
}

.roadmap-panel summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 700;
  color: #3b4654;
}

.roadmap-panel[open] {
  padding-bottom: 12px;
}

.roadmap-panel[open] summary {
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.roadmap-panel > .metrics,
.roadmap-panel > .report-grid {
  padding: 0 12px;
}

.maintenance-grid .import-history {
  min-width: 0;
}

.integrity-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.integrity-item span {
  color: var(--muted);
  font-size: 12px;
}

.integrity-item strong {
  font-size: 18px;
}

.integrity-item.ok strong {
  color: var(--green);
}

.integrity-item.warn strong {
  color: var(--amber);
}

.import-card {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.import-card span,
.import-card small,
.muted {
  color: var(--muted);
}

.import-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.import-stats span {
  padding: 2px 6px;
  border-radius: 5px;
  background: #eef2f7;
  color: #3b4654;
  font-size: 12px;
}

.import-warnings {
  color: var(--amber);
}

.metric {
  min-width: 150px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 3px;
  font-size: 22px;
}

.filters {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.filters label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  height: 36px;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  grid-column: 1;
  grid-row: 1 / span 80;
  position: sticky;
  top: 18px;
  align-self: start;
  max-height: calc(100vh - 36px);
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar);
  box-shadow: var(--shadow);
}

.tab {
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  justify-content: flex-start;
  text-align: left;
  box-shadow: none;
  width: 100%;
}

.tab-group-label {
  display: block;
  margin: 8px 4px 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tab.active {
  background: #f1f6ff;
  border-color: #c7d7ff;
  color: var(--blue-dark);
  box-shadow: none;
}

.tab:hover {
  background: #f6f8fb;
  color: var(--blue-dark);
}

.view-hidden {
  display: none;
}

.locked-hidden {
  display: none !important;
}

body.auth-locked main {
  display: block;
  max-width: 760px;
}

#search {
  flex: 1 1 320px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 10px rgba(29, 38, 48, .05);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1260px;
}

th, td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf3f9;
  color: #3b4654;
  font-size: 12px;
}

tbody tr:nth-child(even) {
  background: #fafbfd;
}

tbody tr:hover {
  background: #f1f6ff;
}

.money {
  text-align: right;
  white-space: nowrap;
}

.positive { color: var(--green); font-weight: 700; }
.negative { color: var(--red); font-weight: 700; }

.pill {
  display: inline-block;
  margin: 0 4px 4px 0;
  padding: 3px 7px;
  border-radius: 999px;
  background: #e7edf6;
  color: #354256;
  font-size: 12px;
  white-space: nowrap;
}

.pill.ok { background: #ddf4e8; color: var(--green); }
.pill.warn { background: #fff0c2; color: var(--amber); }
.pill.bad { background: #ffe1de; color: var(--red); }
.pill.low { background: #e7edf6; color: #354256; }

.ghost {
  color: var(--ink);
  background: #e7edf6;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.row-actions button {
  height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.report-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.download-button {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  background: var(--blue);
  color: white;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 3px 10px rgba(36, 107, 254, .18);
  transition: background .15s ease, box-shadow .15s ease;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.report-grid article,
.report-single {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .72);
}

.report-grid h2,
.report-single h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.report-single {
  margin-top: 12px;
}

.compact-table table {
  min-width: 760px;
}

dialog {
  width: min(620px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(23, 33, 47, .28);
}

.wide-dialog {
  width: min(860px, calc(100vw - 28px));
}

dialog::backdrop {
  background: rgba(23, 33, 47, .42);
}

#reviewForm,
#saleDetailForm,
#importPreviewForm,
#importDetailForm {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 20px;
}

.dialog-head p {
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.detail-grid article {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.detail-grid span {
  color: var(--muted);
  font-size: 12px;
}

.detail-grid strong {
  overflow-wrap: anywhere;
}

.compact-filters {
  margin-bottom: 0;
}

.module-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.module-heading h2,
.module-heading p {
  margin: 0;
}

.module-heading p {
  margin-top: 4px;
  color: var(--muted);
}

.reconciliation-metrics {
  margin-bottom: 14px;
}

#reconciliationView table {
  min-width: 1440px;
}

.reconciliation-alert-cell {
  min-width: 220px;
  max-width: 300px;
  white-space: normal;
}

#reconciliationView code {
  overflow-wrap: anywhere;
}

.reconciliation-alert {
  padding: 10px;
  border-left: 3px solid var(--amber);
  background: #fff8e5;
  color: var(--ink);
}

.form-grid label,
.wide-label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.form-grid input,
.wide-label textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
  color: var(--ink);
}

.wide-label textarea {
  resize: vertical;
}

.sale-history {
  margin-top: 2px;
}

.sale-history h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

#reviewHistory,
#saleDetailHistory {
  display: grid;
  gap: 6px;
  max-height: 170px;
  overflow: auto;
}

#reviewHistory article,
#saleDetailHistory article,
#importPreviewWarnings article,
#importDetailAudit article {
  display: grid;
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.list-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.list-pagination label,
.pagination-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.list-pagination select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  background: #fff;
}

.pagination-actions span {
  min-width: 110px;
  text-align: center;
}

.sale-detail-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

@media (max-width: 620px) {
  .list-pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination-actions {
    justify-content: space-between;
  }
}

#reviewHistory span,
#reviewHistory small,
#saleDetailHistory span,
#saleDetailHistory small,
#importPreviewWarnings span,
#importDetailAudit span {
  color: var(--muted);
}

#importDetailAudit {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
}

.import-audit {
  margin-top: 8px;
}

.import-audit summary {
  cursor: pointer;
  font-weight: 700;
}

.import-audit div {
  display: grid;
  gap: 3px;
  margin-top: 6px;
}

.import-audit small {
  color: var(--muted);
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #17212f;
  color: white;
  opacity: 0;
  transform: translateY(10px);
  transition: .18s ease;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

.financial-foundation {
  border-top: 1px solid #d9e0e8;
  border-bottom: 1px solid #d9e0e8;
  margin: 8px 0 18px;
  padding: 18px 0;
}

.financial-foundation h2,
.financial-foundation h3 {
  margin: 4px 0 12px;
}

.foundation-metrics {
  margin: 14px 0;
}

.foundation-grid {
  display: grid;
  grid-template-columns: minmax(300px, .9fr) minmax(420px, 1.4fr);
  gap: 20px;
  align-items: start;
}

.foundation-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.foundation-form label {
  display: grid;
  gap: 5px;
  font-size: 13px;
}

.foundation-form button {
  align-self: end;
  min-height: 40px;
}

.foundation-history {
  margin-top: 16px;
}

.foundation-history > summary {
  cursor: pointer;
  font-weight: 700;
  padding: 10px 0;
}

.pendency-metrics {
  margin-bottom: 14px;
}

#pendenciesView .filters {
  align-items: end;
}

#pendenciesView .filters label {
  min-width: 135px;
}

#pendenciesView .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 180px;
}

#pendenciesView td small {
  display: block;
  margin-top: 4px;
}

.closure-metrics {
  margin-bottom: 14px;
}

.closing-checklist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
}

.closing-checklist-head div {
  display: grid;
  gap: 4px;
}

.closing-checklist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.closing-check-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-left-width: 4px;
  border-radius: 8px;
  background: white;
}

.closing-check-item.blocked {
  border-left-color: #dc2626;
}

.closing-check-item.released {
  border-left-color: #15803d;
}

.closing-check-item > div {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.closing-check-item small {
  grid-column: 1 / -1;
}

.expense-metrics {
  margin-bottom: 14px;
}

.module-notice {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid #f59e0b;
  border-left-width: 4px;
  border-radius: 8px;
  background: #fffbeb;
  color: #78350f;
}

#expensesView .filters {
  align-items: end;
}

#expensesView .row-actions {
  display: flex;
  gap: 6px;
  min-width: 130px;
}

#expensesView td small {
  display: block;
  margin-top: 4px;
}

.sanitation-metrics {
  margin-bottom: 14px;
}

#sanitationView .filters {
  align-items: end;
}

#sanitationView td small {
  display: block;
  margin-top: 4px;
}

.sanitation-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(82px, 1fr));
  gap: 6px;
  min-width: 190px;
}

@media (max-width: 820px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 14px 16px;
  }

  main {
    display: block;
    padding: 16px;
  }

  main > :not(.tabs) {
    grid-column: auto;
  }

  .tabs {
    position: static;
    flex-direction: row;
    overflow: auto;
    margin-bottom: 12px;
    padding: 8px;
  }

  .tab {
    width: auto;
    white-space: nowrap;
  }

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

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

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

  .foundation-grid,
  .foundation-form {
    grid-template-columns: 1fr;
  }
}
