:root {
  --ink: #18222f;
  --muted: #647084;
  --line: #d9e0e8;
  --surface: #ffffff;
  --wash: #f5f7fa;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --warning: #c2410c;
  --danger: #b91c1c;
  --paid: #2563eb;
  --shadow: 0 18px 45px rgba(25, 34, 47, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--wash);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: grid;
  grid-template-columns: 260px 1fr;
}

body,
main,
.section,
.panel,
.table-shell {
  min-width: 0;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 22px;
  background: #111827;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.sidebar h1,
.section h2,
.panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.sidebar h1 {
  font-size: 28px;
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 8px;
  color: #7dd3fc;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

nav {
  display: grid;
  gap: 8px;
  margin-top: 36px;
}

nav a {
  color: #dbeafe;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 6px;
}

nav a:hover {
  background: rgba(255, 255, 255, 0.08);
}

main {
  padding: 30px;
}

.section {
  max-width: 1280px;
  margin: 0 auto 28px;
}

.section-heading,
.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}

.section h2 {
  font-size: 30px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toolbar select {
  width: auto;
  max-width: 220px;
}

input,
textarea,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

#search {
  width: min(420px, 50vw);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpis article,
.panel,
.table-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpis article {
  padding: 18px;
}

.kpis span,
.panel-heading span,
label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpis strong {
  display: block;
  margin: 8px 0 2px;
  font-size: 32px;
}

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

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 18px;
}

.exposure-section {
  margin-bottom: 18px;
}

.exposure-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.exposure-card {
  min-width: 0;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.exposure-card span,
.aging-list span,
.compact-row span,
.document-row span,
.muted-text {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.exposure-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  overflow-wrap: anywhere;
}

.exposure-details,
.documents-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.documents-grid {
  grid-template-columns: minmax(260px, 0.75fr) minmax(0, 1.25fr);
}

.interventions-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.7fr) minmax(0, 1.3fr);
  gap: 18px;
  align-items: start;
}

.intervention-form,
.interventions-list {
  display: grid;
  gap: 12px;
}

.intervention-card {
  min-width: 0;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.focus-section {
  margin-bottom: 18px;
}

.receivables-list {
  display: grid;
  gap: 12px;
}

.receivable-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  background: #fff;
  border: 1px solid #fed7aa;
  border-left: 5px solid var(--warning);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.receivable-card.is-paid {
  border-color: #bbf7d0;
  border-left-color: var(--accent);
}

.receivable-card strong,
.receivable-card span {
  display: block;
  overflow-wrap: anywhere;
}

.receivable-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.receivable-card .suggestion-inline {
  color: var(--accent-strong);
}

.receivable-actions,
.intervention-actions,
.status-stack {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.intervention-card-heading,
.intervention-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.intervention-card-heading div {
  min-width: 0;
}

.intervention-card-heading strong,
.intervention-card-heading span {
  display: block;
  overflow-wrap: anywhere;
}

.intervention-card-heading span,
.intervention-footer span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.compact-status {
  max-width: 220px;
  margin-top: 12px;
}

.compact-status select {
  min-height: 36px;
}

.work-pill,
.payment-pill {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.work-pill.todo {
  color: #7c2d12;
  background: #ffedd5;
}

.work-pill.in_progress {
  color: #1e3a8a;
  background: #dbeafe;
}

.work-pill.done,
.payment-pill.paid {
  color: #064e3b;
  background: #ccfbf1;
}

.payment-pill.unpaid {
  color: #7f1d1d;
  background: #fee2e2;
}

.suggestion-panel {
  display: grid;
  gap: 3px;
  margin: 12px 0;
  padding: 10px 12px;
  color: #064e3b;
  background: #ecfdf5;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  font-size: 13px;
}

.suggestion-panel span {
  color: #047857;
  font-weight: 800;
}

.intervention-card-heading select {
  width: 160px;
  min-height: 36px;
}

.intervention-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

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

.intervention-metrics small {
  color: var(--muted);
  font-weight: 800;
}

.intervention-badge {
  display: inline-flex;
  max-width: 180px;
  min-height: 30px;
  align-items: center;
  padding: 5px 8px;
  color: #064e3b;
  background: #ccfbf1;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.aging-list,
.compact-list,
.documents-list,
.document-panel {
  display: grid;
  gap: 10px;
}

.aging-list div,
.compact-row,
.document-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.aging-list div:first-child,
.compact-row:first-child,
.document-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.document-row div {
  min-width: 0;
}

.document-row strong,
.document-row span {
  display: block;
  overflow-wrap: anywhere;
}

.ai-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
  gap: 18px;
}

.panel {
  padding: 18px;
}

.ai-panel {
  display: grid;
  gap: 12px;
}

.balance-list,
.bar-list,
.vehicle-list {
  display: grid;
  gap: 10px;
}

.balance-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(100px, auto) minmax(90px, auto);
  gap: 12px;
  align-items: center;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.balance-row:first-child {
  border-top: 0;
}

.amount-pending {
  color: var(--warning);
  font-weight: 800;
}

.amount-paid {
  color: var(--paid);
  font-weight: 700;
}

.amount-profit {
  color: var(--accent-strong);
}

.amount-loss {
  color: var(--danger);
}

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 700;
}

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

.bar-fill {
  height: 100%;
  width: var(--width);
  background: linear-gradient(90deg, var(--accent), #f59e0b);
}

.form-grid,
.vehicle-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.service-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.service-presets button {
  min-height: 38px;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: 8px 11px;
  color: #1e3a8a;
  background: #eff6ff;
  cursor: pointer;
  font-weight: 900;
}

.service-presets button:hover {
  background: #dbeafe;
}

label {
  display: grid;
  gap: 7px;
}

.wide {
  grid-column: span 2;
}

.primary-button,
.secondary-button,
.ghost-button,
.ghost-light-button,
.document-link,
.document-badge,
.status-toggle,
.suggestion-button,
.edit-button,
.delete-button {
  border: 0;
  border-radius: 6px;
  min-height: 42px;
  padding: 9px 13px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  align-self: end;
  color: white;
  background: var(--accent);
}

.primary-button:hover,
.secondary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  color: white;
  background: #334155;
}

.ghost-button {
  color: #dbeafe;
  background: rgba(255, 255, 255, 0.08);
}

.ghost-light-button {
  color: var(--ink);
  background: #e5e7eb;
}

.suggestion-button {
  min-height: 34px;
  color: #064e3b;
  background: #d1fae5;
}

.suggestion-button:hover {
  background: #a7f3d0;
}

.document-link,
.document-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 10px;
  color: #064e3b;
  background: #ccfbf1;
  text-decoration: none;
  white-space: nowrap;
}

.document-badge + .document-badge {
  margin-left: 6px;
}

.form-actions,
.row-actions {
  display: flex;
  gap: 8px;
  align-items: end;
}

.quote-preview {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px;
  color: var(--muted);
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.quote-preview strong {
  color: var(--ink);
}

#quote-advice {
  color: var(--accent-strong);
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.status-toggle {
  width: 154px;
  min-height: 34px;
  color: white;
}

.status-toggle.pending {
  background: var(--warning);
}

.status-toggle.paid {
  background: var(--paid);
}

.edit-button {
  min-height: 34px;
  color: #1f2937;
  background: #e0f2fe;
}

.delete-button {
  width: 34px;
  min-height: 34px;
  color: #991b1b;
  background: #fee2e2;
  font-size: 20px;
  line-height: 1;
}

.vehicle-form {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-bottom: 14px;
}

.vehicle-list {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

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

.vehicle-card strong {
  display: block;
  margin-bottom: 4px;
}

.vehicle-card span {
  color: var(--muted);
  font-size: 13px;
}

.helper-text {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.helper-text.ok {
  color: var(--accent-strong);
}

.helper-text.error {
  color: #b91c1c;
}

.analysis-result {
  margin-top: 22px;
}

.compact-heading {
  align-items: center;
}

.notes-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.notes-list p {
  margin: 0;
  padding: 10px 12px;
  color: #475569;
  background: #eef6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
}

.analysis-list {
  display: grid;
  gap: 10px;
}

.analysis-card {
  display: grid;
  grid-template-columns: 96px minmax(220px, 1.2fr) minmax(220px, 1fr) minmax(150px, 0.7fr) 58px;
  gap: 12px;
  align-items: center;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.analysis-card strong {
  display: block;
  margin-bottom: 4px;
}

.analysis-card span {
  color: var(--muted);
  font-size: 13px;
}

.analysis-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.analysis-check input {
  width: 18px;
  min-height: 18px;
}

.confidence {
  justify-self: end;
  padding: 5px 8px;
  background: #f1f5f9;
  border-radius: 999px;
  font-weight: 800;
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    gap: 18px;
    padding: 22px;
  }

  nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 20px;
  }

  main {
    padding: 20px;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  #search {
    width: 100%;
  }

  .toolbar select {
    width: 100%;
    max-width: none;
  }

  .dashboard-grid,
  .exposure-details,
  .interventions-layout,
  .ai-grid {
    grid-template-columns: 1fr;
  }

  .intervention-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .wide {
    grid-column: auto;
  }
}

@media (max-width: 900px) {
  main {
    padding: 16px;
  }

  .section {
    margin-bottom: 22px;
  }

  .section h2 {
    font-size: 26px;
  }

  .kpis strong {
    font-size: 30px;
  }

  .panel,
  .kpis article,
  .form-grid,
  .vehicle-form,
  .analysis-card {
    padding: 16px;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .balance-row {
    grid-template-columns: 1fr auto;
  }

  .amount-paid {
    grid-column: 2;
  }

  .table-shell {
    overflow: visible;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    overflow-wrap: anywhere;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
  }

  td:last-child {
    border-bottom: 0;
  }

  .row-actions {
    justify-content: stretch;
    align-items: center;
  }

  .row-actions::before {
    align-self: center;
  }

  .edit-button,
  .status-toggle {
    width: 100%;
  }

  .analysis-card {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .confidence {
    justify-self: start;
  }
}

@media (max-width: 520px) {
  .sidebar {
    padding: 18px 16px;
  }

  .sidebar h1 {
    font-size: 25px;
  }

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

  .toolbar,
  .form-actions,
  .service-presets {
    flex-direction: column;
    align-items: stretch;
  }

  .form-grid,
  .vehicle-form,
  .vehicle-list,
  .interventions-layout,
  .documents-grid {
    grid-template-columns: 1fr;
  }

  .intervention-card-heading,
  .intervention-footer,
  .receivable-card {
    align-items: stretch;
    display: flex;
    flex-direction: column;
  }

  .intervention-card-heading select,
  .compact-status,
  .receivable-actions,
  .intervention-actions,
  .status-stack {
    width: 100%;
    max-width: none;
    justify-content: stretch;
  }

  .receivable-actions > *,
  .intervention-actions > *,
  .status-stack > * {
    flex: 1;
  }

  .balance-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .amount-paid {
    grid-column: auto;
  }

  td {
    grid-template-columns: 82px minmax(0, 1fr);
  }
}
