:root {
  color-scheme: light;
  --bg: #f7f3ed;
  --panel: #fffaf2;
  --ink: #222733;
  --muted: #667085;
  --line: #ded6ca;
  --accent: #2f6f73;
  --accent-strong: #22575b;
  --assistant: #ffffff;
  --user: #d9ece8;
  --shadow: 0 18px 60px rgba(41, 34, 26, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  background:
    linear-gradient(135deg, rgba(47, 111, 115, 0.14), transparent 36%),
    linear-gradient(315deg, rgba(156, 74, 64, 0.12), transparent 32%),
    var(--bg);
  color: var(--ink);
}

body.modal-open {
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 26px;
  background: rgba(255, 250, 242, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card h1,
.login-card p {
  margin: 0;
}

.login-copy {
  color: var(--muted);
}

.login-card label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.login-card input,
.billing-form input,
.billing-form select,
.invoice-form input,
.invoice-form textarea,
.user-form input,
.user-form select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.login-card input:focus,
.billing-form input:focus,
.billing-form select:focus,
.invoice-form input:focus,
.invoice-form textarea:focus,
.user-form input:focus,
.user-form select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 115, 0.16);
}

.login-card button,
.billing-form button,
.invoice-form button,
.user-form button,
.topbar-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  padding: 10px 14px;
}

.topbar-button.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent-strong);
}

.login-error {
  color: #8d3024;
  font-weight: 700;
}

.chat-panel {
  width: min(920px, 100%);
  height: min(820px, calc(100vh - 48px));
  min-height: 560px;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  background: rgba(255, 250, 242, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.billing-panel {
  width: min(1500px, calc(100vw - 32px));
  height: calc(100vh - 32px);
  min-height: 720px;
  grid-template-rows: auto 1fr;
}

.billing-shell {
  place-items: stretch;
  align-items: start;
  justify-items: center;
  padding: 16px;
}

.users-panel {
  grid-template-rows: auto 1fr;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 1.8rem;
  line-height: 1.1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar form {
  margin: 0;
}

.api-link,
.topbar-actions button,
.memory-panel-header button {
  color: var(--accent-strong);
  text-decoration: none;
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 12px;
  background: #fff;
}

.memory-panel {
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
  padding: 16px 22px;
}

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

.memory-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.memory-panel h2 {
  margin: 0;
  font-size: 1.05rem;
}

.memory-list {
  display: grid;
  gap: 10px;
  max-height: 230px;
  overflow-y: auto;
}

.memory-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.memory-item p {
  margin: 0;
  line-height: 1.35;
}

.memory-item span {
  color: var(--muted);
  font-size: 0.88rem;
}

.memory-item button {
  min-height: 34px;
  border: 1px solid #d9b7b0;
  border-radius: 6px;
  background: #fff4f1;
  color: #8d3024;
  font-weight: 700;
  padding: 6px 10px;
}

.memory-empty {
  margin: 0;
  color: var(--muted);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px 22px;
  overflow-y: auto;
}

.billing-panel .topbar {
  padding-top: 14px;
  padding-bottom: 14px;
}

.billing-panel .topbar-button {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 0.9rem;
}

.billing-workspace {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: #fffdf8;
}

.billing-workspace.upload-mode {
  overflow-y: auto;
}

.billing-workspace.upload-mode .billing-controls-column {
  overflow: visible;
  max-height: none;
}

.billing-workspace.upload-mode .billing-results-area {
  display: none;
}

.billing-workspace.upload-mode #search-panel,
.billing-workspace.upload-mode #invoice-panel {
  display: none;
}

.billing-workspace.upload-mode #upload-panel {
  display: block;
}

.billing-controls-column {
  min-height: 0;
  overflow: visible;
  background: #fffdf8;
}

.billing-search {
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
}

.billing-panel .topbar,
.billing-panel .messages {
  padding-left: 28px;
  padding-right: 28px;
}

.billing-panel .billing-search {
  padding: 14px 24px;
}

.billing-workspace.search-mode #search-panel,
.billing-workspace:not(.upload-mode):not(.invoice-mode):not(.dictionary-mode) #search-panel {
  display: block;
}

.billing-workspace.search-mode #upload-panel,
.billing-workspace.search-mode #invoice-panel,
.billing-workspace:not(.upload-mode):not(.invoice-mode):not(.dictionary-mode) #upload-panel,
.billing-workspace:not(.upload-mode):not(.invoice-mode):not(.dictionary-mode) #invoice-panel {
  display: none;
}

.billing-workspace.search-mode .billing-controls-column,
.billing-workspace:not(.upload-mode):not(.invoice-mode):not(.dictionary-mode) .billing-controls-column {
  border-bottom: 1px solid var(--line);
}

.billing-form {
  display: grid;
  grid-template-columns: minmax(320px, 1.4fr) minmax(440px, 1.6fr) auto;
  align-items: end;
  gap: 10px 14px;
}

.billing-form label,
.invoice-form label {
  font-weight: 800;
}

.billing-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.billing-form > label[for="billing-query"] {
  grid-column: 1;
  font-size: 0.92rem;
}

.billing-input-row {
  grid-column: 1;
}

.billing-form input,
.billing-form select {
  min-height: 34px;
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 0.9rem;
}

.billing-input-row button {
  min-height: 34px;
  padding: 6px 16px;
}

.primary-filter-row {
  display: grid;
  grid-column: 2;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 8px;
}

.primary-filter-row label {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}

.search-mode-row {
  grid-column: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: flex-end;
}

.search-mode-row button {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-strong);
  background: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 2px 8px;
}

.search-mode-row button.active,
.search-mode-row button:hover {
  border-color: var(--accent);
  background: var(--user);
}

.search-filters {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf8;
  padding: 6px 8px;
}

.search-filters summary {
  color: var(--accent-strong);
  cursor: pointer;
  font-weight: 800;
}

.search-filter-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 6px;
  margin-top: 6px;
}

.search-filter-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.search-filter-grid input,
.search-filter-grid select {
  min-height: 28px;
  font-size: 0.9rem;
  padding: 4px 7px;
}

.billing-panel .billing-results-area {
  min-height: 0;
  align-content: start;
  padding: 14px 24px 18px;
  overflow: hidden;
}

.billing-workspace.search-mode .billing-results-area,
.billing-workspace:not(.upload-mode):not(.invoice-mode):not(.dictionary-mode) .billing-results-area {
  display: flex;
}

.billing-workspace.invoice-mode {
  overflow-y: auto;
}

.billing-workspace.invoice-mode .billing-controls-column {
  display: block;
}

.billing-workspace.invoice-mode #invoice-panel {
  display: block;
  width: min(70vw, 1120px);
  margin: 0 auto;
  border-bottom: 0;
}

.billing-workspace.invoice-mode .billing-results-area {
  width: min(70vw, 1120px);
  min-height: 280px;
  margin: 0 auto;
  padding: 0 0 22px;
  overflow: visible;
}

.billing-workspace.dictionary-mode {
  grid-template-columns: minmax(0, 1fr);
}

.billing-workspace.dictionary-mode .billing-controls-column {
  display: block;
  width: 100%;
  max-width: none;
}

.dictionary-panel {
  width: 100%;
}

.dictionary-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.dictionary-heading h2,
.dictionary-review-section h3 {
  margin: 0;
}

.dictionary-review-content {
  display: grid;
  gap: 14px;
}

.dictionary-action-status {
  min-height: 20px;
  color: #5f6a80;
  font-weight: 700;
}

.dictionary-action-status.success {
  color: #165b60;
}

.dictionary-action-status.error {
  color: #9f2c21;
}

.dictionary-editor-panel {
  border: 1px solid #d9ccbc;
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  box-shadow: 0 10px 24px rgba(50, 42, 33, 0.08);
  position: sticky;
  top: 10px;
  z-index: 3;
}

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

.dictionary-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.dictionary-editor-header h3 {
  margin: 0;
}

.dictionary-review-section {
  border: 1px solid #e0d6c8;
  border-radius: 6px;
  background: #fffdfa;
  padding: 12px;
}

.dictionary-review-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.dictionary-review-item {
  border: 1px solid #e7ded2;
  border-radius: 6px;
  background: #fff;
  padding: 10px;
  display: grid;
  gap: 6px;
  font-size: 14px;
  align-content: start;
  word-break: break-word;
}

.dictionary-action {
  margin-top: 6px;
  margin-right: 6px;
}

.dictionary-inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.dictionary-inline-form label {
  display: grid;
  gap: 3px;
  color: #5f6a80;
  font-size: 12px;
  font-weight: 700;
}

.dictionary-inline-form .dictionary-wide-field {
  grid-column: 1 / -1;
}

.dictionary-inline-form input,
.dictionary-inline-form select,
.dictionary-inline-form textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid #d9ccbc;
  border-radius: 6px;
  padding: 6px 8px;
  color: #202532;
  font: inherit;
  background: #fff;
}

.dictionary-inline-form textarea {
  min-height: 82px;
  resize: vertical;
}

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

.dictionary-form-hint {
  margin: 0;
  color: #5f6a80;
  font-size: 12px;
  grid-column: 1 / -1;
}

.compact-repair-results {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.compact-repair-results h2 {
  margin: 0;
  font-size: 1rem;
}

.search-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.search-results-title {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.search-results-title span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.search-summary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.search-summary-bar span {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  font-size: 0.78rem;
  font-weight: 800;
}

.search-summary-bar strong {
  color: var(--accent-strong);
}

.invoice-grid-frame {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.invoice-grid-main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
}

.invoice-detail-modal[hidden] {
  display: none;
}

.invoice-detail-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(34, 39, 51, 0.38);
}

.invoice-detail-dialog {
  width: min(1500px, calc(100vw - 44px));
  height: calc(100vh - 44px);
  max-height: 900px;
  min-height: 620px;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.invoice-detail-heading {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #eef6f3;
}

.invoice-detail-heading h3 {
  margin: 0;
  font-size: 1rem;
}

.invoice-detail-heading span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.invoice-detail-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(190px, 1fr));
  gap: 6px 14px;
  margin: 0;
  padding: 8px 12px;
  border-bottom: 1px solid #eee5d9;
}

.invoice-detail-list div {
  display: flex;
  min-width: 0;
  gap: 5px;
  align-items: baseline;
}

.invoice-detail-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.invoice-detail-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid #eee5d9;
}

.invoice-detail-lines {
  display: grid;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  padding: 8px 12px 12px;
}

.invoice-detail-lines h4 {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.86rem;
  text-transform: uppercase;
}

.invoice-detail-lines-wrap {
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.invoice-detail-lines-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  table-layout: fixed;
}

.invoice-detail-lines-table th,
.invoice-detail-lines-table td {
  padding: 7px 8px;
  border-bottom: 1px solid #eee5d9;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.invoice-detail-lines-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f3eee6;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.invoice-detail-lines-table th:nth-child(1),
.invoice-detail-lines-table td:nth-child(1) {
  width: 24%;
}

.invoice-detail-lines-table th:nth-child(7),
.invoice-detail-lines-table td:nth-child(7) {
  width: 24%;
}

.search-results-table-wrap {
  height: 100%;
  max-height: none;
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.billing-results-grid .search-results-table-wrap {
  min-height: min(70vh, 680px);
}

.search-results-table {
  width: 100%;
  min-width: 1755px;
  border-collapse: collapse;
  table-layout: fixed;
}

.search-results-table th,
.search-results-table td {
  border-bottom: 1px solid var(--line);
  height: 42px;
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-results-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f3eee6;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.grid-sort-button {
  width: 100%;
  min-height: 24px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  padding: 0 12px 0 0;
  text-align: left;
  text-transform: inherit;
}

.grid-sort-button[data-direction="asc"]::after {
  content: " ^";
}

.grid-sort-button[data-direction="desc"]::after {
  content: " v";
}

.column-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
}

.column-resize-handle::after {
  content: "";
  position: absolute;
  top: 9px;
  right: 3px;
  bottom: 9px;
  border-right: 1px solid #c7bdb0;
}

body.column-resizing {
  cursor: col-resize;
  user-select: none;
}

.invoice-result-row {
  cursor: pointer;
}

.invoice-result-row:hover,
.invoice-result-row.selected {
  background: #f3fbf9;
}

.invoice-result-row:focus {
  outline: 2px solid rgba(47, 111, 115, 0.38);
  outline-offset: -2px;
}

.search-results-table th:nth-child(1),
.search-results-table td:nth-child(1) {
  width: 8%;
}

.search-results-table th:nth-child(2),
.search-results-table td:nth-child(2) {
  width: 13%;
}

.search-results-table th:nth-child(3),
.search-results-table td:nth-child(3) {
  width: 5%;
}

.search-results-table th:nth-child(4),
.search-results-table td:nth-child(4) {
  width: 8%;
}

.search-results-table th:nth-child(5),
.search-results-table td:nth-child(5) {
  width: 18%;
}

.search-results-table th:nth-child(6),
.search-results-table td:nth-child(6) {
  width: 7%;
}

.search-results-table th:nth-child(7),
.search-results-table td:nth-child(7) {
  width: 15%;
}

.search-results-table th:nth-child(8),
.search-results-table td:nth-child(8) {
  width: 8%;
}

.search-results-table th:nth-child(9),
.search-results-table td:nth-child(9),
.search-results-table th:nth-child(10),
.search-results-table td:nth-child(10),
.search-results-table th:nth-child(11),
.search-results-table td:nth-child(11) {
  width: 7%;
}

.search-results-table th:nth-child(12),
.search-results-table td:nth-child(12) {
  width: 11%;
}

.search-results-table th:nth-child(13),
.search-results-table td:nth-child(13) {
  width: 14%;
}

.search-results-table th,
.search-results-table td {
  width: auto;
}

.search-detail-row td {
  white-space: normal;
  overflow: visible;
  text-overflow: initial;
  padding: 0;
  background: #fffdf8;
}

.search-detail-panel {
  padding: 10px 12px;
  border-top: 1px solid #eee5d9;
}

.search-detail-panel dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 8px 12px;
  margin: 0;
}

.search-detail-panel div {
  min-width: 0;
}

.search-detail-panel dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.search-detail-panel dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

.search-result-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  min-width: 0;
}

.mini-action {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 6px;
  text-decoration: none;
  white-space: nowrap;
}

.invoice-grid-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-height: 32px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.invoice-grid-pager button,
.invoice-grid-pager select {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--accent-strong);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 4px 8px;
}

.invoice-grid-pager button:disabled {
  cursor: default;
  opacity: 0.45;
}

.empty-result-note {
  margin: 0;
  color: var(--muted);
}

.upload-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.upload-form label {
  display: flex;
  gap: 7px;
  align-items: center;
  font-weight: 800;
}

.upload-form input {
  min-height: 26px;
}

.upload-panel .topbar-button,
.billing-panel .topbar-button,
.upload-form button,
.upload-review-heading button {
  min-height: 32px;
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 0.88rem;
}

.billing-workspace.upload-mode .upload-panel {
  padding: 14px 24px 0;
  border-bottom: 0;
}

.billing-workspace.upload-mode .upload-form {
  grid-template-columns: minmax(420px, 1fr) auto;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.billing-workspace.upload-mode .upload-form label {
  display: grid;
  gap: 6px;
}

.billing-workspace.upload-mode .upload-form input {
  width: 100%;
}

.upload-status-message {
  margin: 8px 0 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  line-height: 1.35;
}

.upload-status-message.error {
  border-color: #d69f2a;
  background: #fff8e6;
  color: #653c00;
}

.upload-status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 5px;
  margin-top: 6px;
}

.upload-status-grid span {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 7px;
  color: var(--muted);
  background: #fff;
  font-weight: 800;
  font-size: 0.82rem;
  text-align: center;
}

.upload-status-grid span.active {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--user);
}

.upload-review {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.upload-review-panels {
  height: max(560px, calc(100vh - 276px));
  min-height: 560px;
  display: grid;
  grid-template-columns: minmax(420px, 62%) minmax(460px, 1fr);
  gap: 12px;
}

.upload-preview-panel,
.upload-review-content {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.upload-review-content {
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.upload-preview-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #eef6f3;
}

.upload-preview-heading h2 {
  margin: 0;
  font-size: 0.98rem;
}

.upload-preview-heading span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: right;
}

.upload-preview-frame {
  min-height: 0;
  display: grid;
  place-items: stretch;
  background: #f7f3ed;
  overflow: auto;
}

.upload-preview-frame iframe,
.upload-preview-frame img {
  width: 100%;
  height: 100%;
  min-height: 560px;
  border: 0;
  object-fit: contain;
  background: #fff;
}

.upload-preview-empty {
  display: grid;
  place-items: center;
  min-height: 520px;
  padding: 24px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.upload-review-heading {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
}

.upload-review-heading h2 {
  margin: 0;
  font-size: 0.98rem;
}

.upload-review-heading .eyebrow {
  margin-bottom: 2px;
  font-size: 0.74rem;
}

.upload-review-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 4px 8px;
  padding: 8px 12px;
}

.upload-review-grid label {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 5px;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 800;
  min-width: 0;
}

.upload-review-grid label.meta {
  grid-template-columns: auto minmax(0, 1fr);
}

.upload-review-grid label.model {
  grid-column: span 2;
  min-width: 0;
}

.upload-review-grid input,
.upload-review-table input,
.upload-review-table select {
  width: 100%;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
  font: inherit;
  min-width: 0;
}

.duplicate-warning {
  display: grid;
  gap: 7px;
  border: 1px solid #d69f2a;
  border-radius: 8px;
  background: #fff5db;
  color: #653c00;
  padding: 9px 11px;
  font-size: 0.9rem;
  margin: 10px 12px 0;
  max-height: 132px;
  overflow: auto;
}

.upload-validation-issues {
  display: grid;
  gap: 6px;
  margin: 10px 12px 0;
  padding: 9px 11px;
  border: 1px solid #d69f2a;
  border-radius: 8px;
  background: #fff8e6;
  color: #653c00;
  font-size: 0.88rem;
}

.upload-validation-issues[hidden] {
  display: none;
}

.upload-validation-issues ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
}

.duplicate-warning.blocked {
  border-color: #a3261d;
  background: #fff1ed;
  color: #8f261d;
}

.duplicate-warning-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 4px 10px;
  color: #4b3b1f;
}

.duplicate-warning-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.duplicate-warning-actions button,
.duplicate-warning-actions a {
  min-height: 30px;
  border: 1px solid #d2bd92;
  border-radius: 7px;
  background: #fff;
  color: var(--accent-strong);
  font-weight: 800;
  padding: 5px 9px;
  text-decoration: none;
}

.upload-review-table-wrap {
  max-height: none;
  min-height: 0;
  height: 100%;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  padding-bottom: 8px;
}

.upload-review-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  background: #fff;
}

.upload-review-table th,
.upload-review-table td {
  border-bottom: 1px solid var(--line);
  padding: 5px 6px;
  text-align: left;
}

.upload-review-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f3eee6;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.upload-panel + .messages,
.upload-panel ~ .messages {
  max-height: 145px;
}

.billing-controls-column .invoice-grid {
  grid-template-columns: 1fr;
}

.billing-workspace.invoice-mode .invoice-form {
  gap: 14px;
}

.billing-workspace.invoice-mode .invoice-grid {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}

.billing-workspace.invoice-mode .invoice-form textarea {
  min-height: 260px;
  max-height: none;
}

.billing-workspace.invoice-mode .invoice-form > button[type="submit"] {
  justify-self: end;
  min-width: 220px;
}

.inline-secondary {
  justify-self: start;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  background: #fff;
  font-weight: 800;
  padding: 8px 10px;
}

.vin-history-panel {
  width: min(100%, 1180px);
  display: grid;
  gap: 14px;
}

.vin-history-panel h2,
.vin-history-panel h3 {
  margin: 0;
}

.vin-history-facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.vin-history-facts dt,
.vin-history-facts dd {
  margin: 0;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.vin-history-facts dt {
  color: var(--muted);
  font-weight: 800;
  background: #f3eee6;
}

.history-mini-section,
.history-timeline {
  display: grid;
  gap: 8px;
}

.history-mini-section ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-mini-section li {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 9px;
  background: #fff;
}

.repeat-notices li {
  border-color: #d8a39b;
  border-radius: 8px;
  color: #8d3024;
}

.history-timeline-card {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.history-timeline-card span {
  color: var(--muted);
  font-weight: 700;
}

.billing-results-area {
  padding-bottom: 22px;
}

.billing-panel .billing-results-area {
  min-height: 0;
}

.invoice-form {
  display: grid;
  gap: 14px;
}

.invoice-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1.2fr) minmax(190px, 0.8fr) minmax(260px, 1fr);
  align-items: start;
  gap: 12px;
}

.invoice-form label {
  display: grid;
  gap: 7px;
}

.invoice-request-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 14px;
}

.field-hint {
  min-height: 16px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.invoice-form textarea {
  min-height: 150px;
  resize: vertical;
  font-size: 1.05rem;
  line-height: 1.5;
}

.invoice-request-grid textarea {
  min-height: 220px;
}

.user-admin {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 22px;
  padding: 22px;
  overflow-y: auto;
}

.user-form,
.user-list-section {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.user-form h2,
.user-list-section h2 {
  margin: 0;
  font-size: 1.08rem;
}

.user-form label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

.form-status {
  min-height: 20px;
  margin: 0;
  color: var(--accent-strong);
  font-weight: 700;
}

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

.user-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.user-item span {
  color: var(--accent-strong);
  font-weight: 800;
  text-transform: capitalize;
}

.user-item small {
  grid-column: 1 / -1;
  color: var(--muted);
}

.message {
  display: flex;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(680px, 88%);
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.assistant .bubble {
  background: var(--assistant);
}

.user .bubble {
  background: var(--user);
  border-color: #bad8d2;
}

.repair-message {
  display: block;
}

.billing-results-area .repair-message {
  flex: 1 1 auto;
  min-height: 0;
}

.repair-results {
  display: grid;
  gap: 16px;
  width: 100%;
  font-size: 0.94rem;
}

.repair-results h2 {
  margin: 0;
  font-size: 1.05rem;
}

.repair-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.repair-card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #eef6f3;
  border-bottom: 1px solid #d5e6e1;
  cursor: pointer;
  list-style: none;
}

.repair-card-heading::-webkit-details-marker {
  display: none;
}

.repair-card-heading::before {
  content: "+";
  flex: 0 0 auto;
  color: var(--accent-strong);
  font-weight: 900;
}

.repair-card[open] .repair-card-heading::before {
  content: "-";
}

.repair-card-title {
  flex: 1 1 auto;
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.3;
}

.repair-score {
  flex: 0 0 auto;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 800;
}

.repair-summary {
  display: grid;
  grid-template-columns: 92px 1fr;
  margin: 0;
  border-bottom: 1px solid #eee5d9;
}

.repair-summary dt,
.repair-summary dd {
  margin: 0;
  padding: 8px 10px;
  line-height: 1.35;
  border-bottom: 1px solid #f1e8dc;
}

.repair-summary dt {
  color: var(--muted);
  font-weight: 800;
  background: #fffaf2;
}

.repair-summary dd {
  overflow-wrap: anywhere;
}

.repair-summary dt:last-of-type,
.repair-summary dd:last-of-type {
  border-bottom: 0;
}

.line-items-wrap {
  overflow-x: auto;
}

.line-items-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  table-layout: fixed;
}

.line-items-table th,
.line-items-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #eee5d9;
  text-align: left;
  vertical-align: top;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.line-items-table th {
  background: #f6f1e9;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.line-items-table th:nth-child(1),
.line-items-table td:nth-child(1) {
  width: 24%;
}

.line-items-table th:nth-child(2),
.line-items-table td:nth-child(2) {
  width: 15%;
}

.line-items-table th:nth-child(3),
.line-items-table td:nth-child(3),
.line-items-table th:nth-child(4),
.line-items-table td:nth-child(4),
.line-items-table th:nth-child(5),
.line-items-table td:nth-child(5),
.line-items-table th:nth-child(6),
.line-items-table td:nth-child(6),
.line-items-table th:nth-child(7),
.line-items-table td:nth-child(7) {
  width: 12.2%;
}

.invoice-draft {
  display: grid;
  gap: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.invoice-draft-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(34, 39, 51, 0.34);
}

.invoice-draft-overlay[hidden] {
  display: none;
}

.invoice-draft-modal {
  width: min(1720px, calc(100vw - 48px));
  height: min(900px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.invoice-draft-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
}

.invoice-draft-modal-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.invoice-draft-modal-body {
  min-height: 0;
  padding: 18px;
  overflow: auto;
}

.invoice-draft-modal-body .message {
  display: block;
}

.invoice-draft-modal-body .invoice-draft {
  min-width: 1180px;
}

.billing-panel .invoice-draft {
  min-width: 0;
}

.invoice-draft-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: #eef6f3;
  border-bottom: 1px solid #d5e6e1;
}

.invoice-draft-heading h2 {
  margin: 0;
  font-size: 1.05rem;
}

.invoice-draft-heading button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--accent-strong);
  font-weight: 800;
  padding: 6px 12px;
}

.invoice-summary {
  border-bottom: 1px solid #eee5d9;
}

.invoice-summary-strip {
  display: grid;
  grid-template-columns: minmax(190px, 0.8fr) minmax(140px, 0.55fr) minmax(320px, 1.5fr);
  gap: 0;
  border-bottom: 1px solid #eee5d9;
  background: #fff;
}

.invoice-summary-item {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 9px 12px;
  border-right: 1px solid #eee5d9;
}

.invoice-summary-item:last-child {
  border-right: 0;
}

.invoice-summary-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.invoice-summary-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.invoice-table th:nth-child(1),
.invoice-table td:nth-child(1) {
  width: 15%;
}

.invoice-table th:nth-child(2),
.invoice-table td:nth-child(2) {
  width: 5%;
}

.invoice-table th:nth-child(3),
.invoice-table td:nth-child(3) {
  width: 13%;
}

.invoice-table th:nth-child(4),
.invoice-table td:nth-child(4),
.invoice-table th:nth-child(8),
.invoice-table td:nth-child(8) {
  width: 9%;
}

.invoice-table th:nth-child(5),
.invoice-table td:nth-child(5) {
  width: 8%;
}

.invoice-table th:nth-child(6),
.invoice-table td:nth-child(6),
.invoice-table th:nth-child(7),
.invoice-table td:nth-child(7) {
  width: 10%;
}

.invoice-table th:nth-child(9),
.invoice-table td:nth-child(9) {
  width: 21%;
}

.invoice-table td:nth-child(9) {
  font-size: 0.88rem;
  line-height: 1.25;
}

.invoice-table th {
  white-space: nowrap;
}

.invoice-totals {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0;
  width: min(360px, 100%);
  justify-self: end;
  margin: 0;
  padding: 12px;
}

.invoice-totals dt,
.invoice-totals dd {
  margin: 0;
  padding: 7px 0;
  border-bottom: 1px solid #eee5d9;
}

.invoice-totals dt {
  color: var(--muted);
  font-weight: 800;
}

.invoice-totals dd {
  text-align: right;
  font-weight: 800;
}

.invoice-totals dt:last-of-type,
.invoice-totals dd:last-of-type {
  color: var(--ink);
  font-size: 1.05rem;
  border-bottom: 0;
}

.invoice-notes {
  padding: 11px 12px;
  border-top: 1px solid #eee5d9;
  color: #8d3024;
  font-weight: 700;
  line-height: 1.4;
}

.invoice-notes li {
  white-space: pre-wrap;
}

.invoice-narrative {
  display: grid;
  gap: 9px;
  padding: 12px;
  border-top: 1px solid #eee5d9;
  background: #fffdf8;
}

.invoice-narrative h3,
.invoice-narrative h4,
.invoice-narrative p,
.invoice-narrative ul,
.invoice-narrative ol {
  margin: 0;
}

.invoice-narrative h3 {
  font-size: 1rem;
}

.invoice-narrative h4 {
  color: var(--accent-strong);
  font-size: 0.86rem;
  text-transform: uppercase;
}

.invoice-narrative ul,
.invoice-narrative ol {
  display: grid;
  gap: 8px;
  padding-left: 20px;
  line-height: 1.42;
}

.invoice-narrative li p {
  margin-top: 4px;
}

.invoice-narrative-status {
  color: var(--muted);
}

.invoice-correction-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid #cfe1df;
  background: #f3fbf9;
}

.invoice-correction-panel label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.invoice-correction-panel small {
  color: var(--muted);
  font-weight: 400;
  line-height: 1.35;
}

.invoice-correction-panel textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  font: inherit;
}

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

.invoice-correction-modal {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(35, 31, 27, 0.48);
}

.invoice-correction-dialog {
  width: min(1120px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
}

.invoice-correction-modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
}

.invoice-correction-modal-header span {
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
}

.invoice-correction-modal-header h2 {
  margin: 2px 0 0;
}

.invoice-correction-body {
  display: grid;
  gap: 14px;
  padding: 16px 18px;
}

.invoice-correction-section {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f5ee;
}

.invoice-correction-section h3,
.invoice-correction-section p {
  margin: 0;
}

.invoice-correction-section p {
  color: var(--muted);
  line-height: 1.35;
}

.invoice-correction-request-list {
  display: grid;
  gap: 10px;
}

.invoice-correction-request-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.invoice-correction-request-card strong {
  display: block;
}

.invoice-correction-request-card small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.3;
}

.invoice-correction-status-pill {
  justify-self: start;
  padding: 5px 8px;
  border-radius: 999px;
  background: #efe8dd;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.invoice-correction-status-pill--matched {
  background: #e4f3ec;
  color: #236746;
}

.invoice-correction-status-pill--missing,
.invoice-correction-status-pill--review-required {
  background: #fff0ce;
  color: #8b4f00;
}

.invoice-correction-table-wrap {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.invoice-correction-table {
  width: 100%;
  min-width: 1240px;
  border-collapse: collapse;
}

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

.invoice-correction-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f1eadf;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.invoice-correction-table input,
.invoice-correction-table select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.invoice-correction-row-removed {
  opacity: 0.45;
}

.invoice-correction-row-removed input,
.invoice-correction-row-removed select {
  text-decoration: line-through;
}

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

.invoice-correction-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.invoice-correction-field--wide {
  grid-column: 1 / -1;
}

.invoice-correction-field input,
.invoice-correction-field select,
.invoice-correction-field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

.invoice-correction-field textarea {
  min-height: 92px;
  resize: vertical;
}

.invoice-correction-dialog .invoice-correction-actions {
  padding: 0 18px 16px;
}

@media (max-width: 860px) {
  .invoice-correction-modal {
    align-items: stretch;
    padding: 12px;
  }

  .invoice-correction-dialog {
    width: 100%;
    max-height: calc(100vh - 24px);
  }

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

  .invoice-correction-request-card {
    grid-template-columns: 1fr;
  }
}

.invoice-draft-modal .line-items-wrap {
  max-height: none;
  overflow-x: auto;
  overflow-y: visible;
}

.invoice-draft-modal .line-items-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.missing-value {
  color: var(--muted);
}

.repair-clue,
.repair-clues {
  padding: 9px 12px 11px;
  border-top: 1px solid #eee5d9;
}

.repair-clue summary,
.repair-clues summary {
  color: var(--accent-strong);
  font-weight: 800;
}

.repair-clue p,
.repair-clues p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.repair-clues dl {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 7px 10px;
  margin: 10px 0 0;
}

.repair-clues dt {
  color: var(--muted);
  font-weight: 800;
}

.repair-clues dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.training-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-top: 1px solid #eee5d9;
  background: #fffdf8;
}

.training-actions span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.training-actions button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--accent-strong);
  font-size: 0.86rem;
  font-weight: 800;
  padding: 5px 9px;
}

.training-actions button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.training-status {
  color: var(--accent-strong);
  font-weight: 700;
}

.quick-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 0 22px 14px;
}

.quick-actions button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--accent-strong);
  font-weight: 700;
  padding: 8px 12px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px 22px 20px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.46);
}

textarea {
  width: 100%;
  min-height: 48px;
  max-height: 150px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 115, 0.16);
}

.composer button {
  min-width: 88px;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.composer button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 0;
  }

  .chat-panel {
    min-height: 100vh;
    height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .topbar,
  .memory-panel,
  .messages,
  .quick-actions,
  .composer {
    padding-left: 14px;
    padding-right: 14px;
  }

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

  .billing-input-row {
    grid-template-columns: 1fr;
  }

  .primary-filter-row,
  .upload-form {
    grid-template-columns: 1fr;
  }

  .search-filter-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .vin-history-facts {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .billing-shell {
    padding: 0;
  }

  .billing-panel {
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
  }

  .invoice-draft-overlay {
    padding: 0;
  }

  .invoice-draft-modal {
    width: 100vw;
    height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .invoice-draft-modal-header {
    align-items: flex-start;
  }

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

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

  .upload-status-grid,
  .vin-history-facts {
    grid-template-columns: 1fr;
  }

  .invoice-summary-strip {
    grid-template-columns: 1fr;
  }

  .invoice-summary-item {
    border-right: 0;
    border-bottom: 1px solid #eee5d9;
  }

  .invoice-summary-item:last-child {
    border-bottom: 0;
  }

  .user-admin {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .composer button {
    width: 100%;
  }

  .memory-item {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .repair-card-heading {
    display: grid;
  }

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

  .repair-summary dt {
    padding-bottom: 3px;
  }

  .repair-summary dd {
    padding-top: 3px;
  }

  .bubble {
    max-width: 94%;
  }

  .invoice-detail-modal {
    padding: 0;
  }

  .invoice-detail-dialog {
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .invoice-detail-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1120px) {
  .billing-workspace {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .billing-controls-column {
    max-height: none;
    border-bottom: 1px solid var(--line);
  }

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

  .billing-form > label[for="billing-query"],
  .billing-input-row,
  .primary-filter-row,
  .search-mode-row,
  .search-filters {
    grid-column: 1;
  }

  .search-mode-row {
    justify-content: flex-start;
  }

  .primary-filter-row {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .search-filter-grid {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .billing-results-grid .search-results-table-wrap {
    min-height: min(58vh, 620px);
  }

  .billing-workspace.upload-mode {
    overflow-y: auto;
  }

  .billing-workspace.upload-mode .billing-controls-column {
    max-height: none;
  }

  .billing-workspace.upload-mode .upload-form,
  .upload-review-panels {
    grid-template-columns: 1fr;
  }

  .upload-preview-frame iframe,
  .upload-preview-frame img,
  .upload-preview-empty {
    min-height: 460px;
  }

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

@media (max-width: 640px) {
  .primary-filter-row,
  .search-filter-grid {
    grid-template-columns: 1fr;
  }

  .billing-controls-column {
    max-height: none;
  }

  .billing-workspace.upload-mode .billing-controls-column {
    max-height: none;
  }

  .billing-workspace.upload-mode .upload-panel {
    padding: 12px 12px 0;
  }

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