:root {
  color-scheme: light;
  --ink: #000000;
  --muted: #3f444b;
  --surface: #ffffff;
  --line: #e6e6e6;
  --accent: #1d1d1b;
  --accent-soft: #000000b3;
  --accent-ink: #ffffff;
  --page: #f7f7f5;
  --quiet: #fdfdfd;
  --warning: #d9534f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  font: inherit;
  padding: 0.6rem 0.9rem;
}

button:hover,
.button-link:hover {
  background: var(--accent-soft);
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2rem);
}

.site-header__row {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}

.site-nav {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}

.site-nav-primary,
.site-nav-utility {
  align-items: center;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-nav-primary {
  min-width: 0;
}

.site-nav-link {
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.site-nav-link:hover {
  color: var(--accent-soft);
}

.site-nav-toggle {
  display: none;
}

.brand {
  align-items: center;
  display: inline-flex;
  gap: 0.7rem;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: var(--ink);
  border-radius: 2px;
  color: var(--surface);
  display: inline-flex;
  font-size: 0.85rem;
  height: 2rem;
  justify-content: center;
  width: 2.6rem;
}

.site-header form {
  margin: 0;
}

.language-form {
  align-items: center;
  display: flex;
  gap: 0.45rem;
}

.language-form label {
  color: var(--muted);
  font-size: 0.9rem;
}

.language-form select {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  padding: 0.45rem 0.6rem;
}

.page-shell {
  margin: 0 auto;
  max-width: 1600px;
  padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 4vw, 2rem);
}

.page-intro,
.auth-panel,
.content-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 1.25rem;
  padding: clamp(1.25rem, 4vw, 2rem);
}

.page-heading {
  align-items: start;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.page-heading > :first-child {
  flex: 1 1 24rem;
  min-width: 0;
}

.page-heading p {
  margin-top: 0.35rem;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 0.5rem;
  text-transform: uppercase;
}

h1 {
  font-size: 2rem;
  line-height: 1.2;
  margin: 0 0 1rem;
}

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

h2 {
  font-size: 1.15rem;
  margin: 0 0 1rem;
}

.button-link {
  background: var(--accent);
  border-radius: 6px;
  color: var(--accent-ink);
  display: inline-flex;
  font-weight: 700;
  padding: 0.6rem 0.9rem;
  text-decoration: none;
}

.button-link.secondary {
  background: var(--quiet);
  border: 1px solid var(--line);
  color: var(--ink);
}

.button-link.secondary:hover {
  background: var(--line);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.summary-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: start;
  margin-bottom: 1.5rem;
}

.summary-grid article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
}

.summary-grid span,
.plain-list span {
  color: var(--muted);
  display: block;
  font-size: 0.9rem;
}

.summary-grid strong {
  display: block;
  font-size: 1.45rem;
  margin-top: 0.25rem;
  overflow-wrap: anywhere;
}

.detail-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  align-items: start;
}

.data-table {
  border-collapse: collapse;
  font-size: 0.95rem;
  table-layout: auto;
  width: 100%;
}

.table-scroll {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  width: 100%;
}

.table-scroll .data-table {
  min-width: 980px;
}

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

.table-scroll--wide .data-table {
  min-width: 1260px;
}

.table-scroll--xwide .data-table {
  min-width: 1560px;
}

.table-scroll--auto .data-table {
  min-width: max(100%, 720px);
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 0.75rem;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.data-table td {
  overflow-wrap: break-word;
  word-break: normal;
}

.data-table td a,
.generated-content {
  overflow-wrap: anywhere;
}

.table-scroll .data-table tr:last-child td,
.data-table tr:last-child td {
  border-bottom: 0;
}

.status-pill {
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  padding: 0.25rem 0.55rem;
}

.plain-list {
  display: grid;
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.stacked-form {
  display: grid;
  gap: 1rem;
}

.form-row {
  display: grid;
  gap: 0.35rem;
}

.form-row input,
.form-row select,
.form-row textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  padding: 0.6rem 0.75rem;
  width: 100%;
}

.form-row small {
  color: var(--muted);
}

.blueprint-callout {
  background: var(--quiet);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.errorlist {
  color: #9f1239;
  margin: 0;
  padding-left: 1rem;
}

.message-stack {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.message {
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 0.75rem 1rem;
}

.message.error {
  background: #fff1f2;
  border-color: #fecdd3;
  color: var(--warning);
}

.workspace {
  display: grid;
  gap: 1rem;
}

.tab-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  padding: 0.5rem;
}

.tab-list button {
  background: transparent;
  color: var(--ink);
  min-height: 2.75rem;
  white-space: nowrap;
}

.tab-list button.is-active {
  background: var(--accent);
  color: var(--accent-ink);
}

.workspace-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 1.25rem;
  padding: clamp(1rem, 3vw, 2rem);
}

.workspace-panel[hidden] {
  display: none;
}

.panel-heading {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
}

.panel-heading input,
.filter-bar input,
.filter-bar select {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  padding: 0.55rem 0.7rem;
  width: 100%;
}

.inline-form {
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
}

.inline-form p {
  display: grid;
  gap: 0.3rem;
  margin: 0;
}

.inline-form input,
.inline-form select,
.inline-form textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  padding: 0.55rem 0.7rem;
  width: 100%;
}

.inline-form ul,
.stacked-form ul {
  display: grid;
  gap: 0.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.inline-form li label,
.stacked-form li label {
  align-items: start;
  display: flex;
  gap: 0.5rem;
  font-weight: 400;
}

.inline-form input[type="checkbox"],
.stacked-form input[type="checkbox"] {
  width: auto;
}

.inline-form label,
.filter-bar label {
  color: var(--ink);
  font-weight: 700;
}

.inline-form .helptext {
  color: var(--muted);
  font-size: 0.85rem;
}

.compact-form {
  margin: 0;
}

.compact-form button {
  padding: 0.35rem 0.55rem;
}

.form-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
  align-items: start;
}

h3 {
  font-size: 1rem;
  margin: 0;
}

.area-grid,
.split-grid,
.fact-grid {
  display: grid;
  gap: 1rem;
  align-items: start;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.area-card,
.area-band,
.split-grid article,
.fact-card {
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
}

.fact-card {
  color: inherit;
  display: grid;
  gap: 0.75rem;
  text-decoration: none;
}

.fact-card:hover {
  background: var(--surface);
  border-color: var(--accent);
}

.fact-card dl {
  display: grid;
  gap: 0.5rem;
  margin: 0;
}

.fact-card div {
  display: grid;
  gap: 0.1rem;
}

.fact-card dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.fact-card dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.area-card > span,
.area-heading span,
.data-table td span {
  color: var(--muted);
  font-size: 0.9rem;
}

.area-card strong {
  display: block;
  font-size: 1.2rem;
  margin: 0.35rem 0 0.8rem;
}

.metric-row,
.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.metric-row span {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.2rem 0.55rem;
}

.area-stack {
  display: grid;
  gap: 1rem;
}

.area-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.area-band .data-table {
  background: var(--surface);
}

.detail-grid > .content-section,
.summary-grid > .content-section {
  margin-bottom: 0;
}

.auth-panel {
  max-width: 440px;
  margin: min(10vh, 5rem) auto 0;
}

.auth-panel form {
  display: grid;
  gap: 1rem;
}

.login-divider {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 0.9rem;
  gap: 0.75rem;
  margin: 1rem 0;
}

.login-divider::before,
.login-divider::after {
  background: var(--line);
  content: "";
  flex: 1;
  height: 1px;
}

.auth-panel p {
  display: grid;
  gap: 0.35rem;
}

.auth-panel input {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  padding: 0.6rem 0.75rem;
  width: 100%;
}

.generated-content {
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 6px;
  margin: 0;
  overflow: auto;
  padding: 0.75rem;
  white-space: pre-wrap;
}

.manual-body {
  display: grid;
  gap: 1rem;
}

.manual-body h2,
.manual-body h3,
.manual-body h4 {
  margin: 0;
}

.manual-body p,
.manual-body ul,
.manual-body ol,
.manual-body pre {
  margin: 0;
}

.manual-body ul,
.manual-body ol {
  padding-left: 1.25rem;
}

.manual-body li + li {
  margin-top: 0.35rem;
}

.manual-body pre {
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
  padding: 0.85rem 1rem;
}

.manual-body code {
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
  padding: 0.1rem 0.3rem;
}

.manual-body pre code {
  background: transparent;
  border: 0;
  padding: 0;
}

.subsection-heading {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  padding-top: 1rem;
}

.subsection-heading a {
  color: var(--accent);
  font-weight: 700;
}

.filter-bar {
  align-items: end;
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  padding: 1rem;
}

.filter-bar button {
  justify-self: start;
  min-width: 9rem;
  width: auto;
}

.filter-bar--crm {
  grid-template-columns: minmax(320px, 1.8fr) repeat(4, minmax(180px, 1fr));
}

.filter-bar--crm label:first-of-type {
  grid-column: span 2;
}

.filter-bar label {
  display: grid;
  gap: 0.35rem;
}

.filter-bar .checkbox-label {
  align-items: center;
  display: flex;
  gap: 0.5rem;
  min-height: 2.75rem;
}

.filter-bar .checkbox-label input {
  width: auto;
}

.badge {
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 0.85rem;
  font-weight: 700;
  margin: 0 0.25rem 0.25rem 0;
  padding: 0.25rem 0.55rem;
  white-space: nowrap;
}

.badge.danger {
  background: #fff1f2;
  border-color: #fecdd3;
  color: var(--warning);
}

.pagination {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: flex-end;
}

.pagination a {
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-weight: 700;
  padding: 0.45rem 0.7rem;
  text-decoration: none;
}

.audit-table {
  min-width: 1080px;
}

.diff-table {
  background: var(--surface);
  margin-top: 0.75rem;
}

.cell-value,
.formula-text {
  max-width: 32rem;
  white-space: pre-wrap;
}

.formula-text {
  color: var(--muted);
  font-family: Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
}

.fact-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.summary-grid--crm strong {
  font-size: clamp(1.05rem, 1.8vw, 1.35rem);
}

.crm-list-table th:nth-child(1),
.crm-list-table td:nth-child(1),
.participants-table th:nth-child(2),
.participants-table td:nth-child(2) {
  min-width: 15rem;
}

.crm-list-table th:nth-child(4),
.crm-list-table td:nth-child(4),
.crm-list-table th:nth-child(5),
.crm-list-table td:nth-child(5),
.crm-list-table th:nth-child(8),
.crm-list-table td:nth-child(8),
.crm-list-table th:nth-child(9),
.crm-list-table td:nth-child(9),
.project-info-table th:nth-child(2),
.project-info-table td:nth-child(2),
.project-info-table th:nth-child(5),
.project-info-table td:nth-child(5),
.task-table th:nth-child(2),
.task-table td:nth-child(2),
.crm-audit-table th:nth-child(5),
.crm-audit-table td:nth-child(5) {
  min-width: 14rem;
}

.project-info-table th:nth-child(4),
.project-info-table td:nth-child(4),
.task-table th:nth-child(4),
.task-table td:nth-child(4),
.task-table th:nth-child(5),
.task-table td:nth-child(5),
.documents-table th:nth-child(1),
.documents-table td:nth-child(1),
.communication-table th:nth-child(1),
.communication-table td:nth-child(1) {
  min-width: 11rem;
}

.crm-contact-table th:nth-child(1),
.crm-contact-table td:nth-child(1),
.crm-contact-table th:nth-child(3),
.crm-contact-table td:nth-child(3),
.audit-table td:last-child,
.crm-audit-table td:last-child {
  min-width: 12rem;
}

.commercial-table th:nth-child(2),
.commercial-table td:nth-child(2),
.sales-object-table th:nth-child(2),
.sales-object-table td:nth-child(2),
.installments-table th:nth-child(2),
.installments-table td:nth-child(2) {
  min-width: 12rem;
}

.sales-units-table th:nth-child(5),
.sales-units-table td:nth-child(5),
.sales-units-table th:nth-child(8),
.sales-units-table td:nth-child(8),
.sales-units-table th:nth-child(9),
.sales-units-table td:nth-child(9),
.buyer-todo-table th:nth-child(20),
.buyer-todo-table td:nth-child(20) {
  min-width: 14rem;
}

@media (min-width: 1080px) {
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1180px) {
  .filter-bar--crm {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  .filter-bar--crm label:first-of-type {
    grid-column: auto;
  }
}

@media (max-width: 760px) {
  .page-heading,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .site-nav,
  .site-nav-primary,
  .site-nav-utility,
  .action-row {
    align-items: stretch;
  }

  .site-header {
    gap: 0.75rem;
    padding: 0.85rem 1rem;
  }

  .site-nav {
    align-items: stretch;
    display: none;
    flex-direction: column;
    gap: 0.85rem;
  }

  .site-header[data-authenticated="false"] .site-nav {
    display: flex;
  }

  .site-nav.is-open {
    display: flex;
  }

  .site-nav-primary,
  .site-nav-utility {
    align-items: stretch;
    flex-direction: column;
    gap: 0.75rem;
  }

  .site-nav-toggle {
    display: inline-flex;
    justify-content: center;
    min-width: 5.5rem;
  }

  .site-nav-link,
  .site-nav form button,
  .language-form select {
    min-height: 2.75rem;
  }

  .site-nav-link {
    align-items: center;
    background: var(--quiet);
    border: 1px solid var(--line);
    border-radius: 6px;
    display: flex;
    padding: 0.7rem 0.85rem;
  }

  .language-form {
    align-items: stretch;
    flex-direction: column;
  }

  .page-shell {
    padding: 1rem;
  }

  .content-section,
  .auth-panel,
  .workspace-panel {
    padding: 1rem;
  }

  .button-link,
  button {
    justify-content: center;
  }

  .summary-grid,
  .detail-grid,
  .area-grid,
  .split-grid,
  .fact-grid,
  .filter-bar {
    grid-template-columns: 1fr;
  }

  .filter-bar button {
    width: 100%;
  }

  .table-scroll {
    margin-inline: -0.25rem;
    width: calc(100% + 0.5rem);
  }

  .subsection-heading,
  .area-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination {
    justify-content: center;
  }
}
