:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d232b;
  --muted: #677282;
  --line: #d9dee7;
  --primary: #155eef;
  --primary-dark: #0f47b8;
  --ok: #087f5b;
  --danger: #c92a2a;
  --soft: #eef4ff;
  --focus: 0 0 0 3px rgba(21, 94, 239, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 7px 12px;
  cursor: pointer;
}

button:hover {
  border-color: #a9b4c4;
}

button:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  box-shadow: var(--focus);
  border-color: var(--primary);
}

button.primary,
.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

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

button.secondary,
.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

button.secondary:hover,
.secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

button[disabled] {
  cursor: wait;
  opacity: 0.65;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  background: #18202b;
  color: #f8fafc;
  padding: 18px 14px;
}

.brand {
  display: grid;
  gap: 2px;
  padding: 8px 8px 20px;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  color: #b9c3d2;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  width: 100%;
  border-color: transparent;
  background: transparent;
  color: #d8deea;
  text-align: left;
}

.nav button:hover,
.nav button.active {
  background: #273447;
  color: #fff;
}

.content {
  min-width: 0;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.topbar > div:first-child {
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.panel h2 {
  grid-column: 1 / -1;
  margin: 0 0 8px;
  font-size: 17px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 8px 9px;
  min-height: 36px;
  text-transform: none;
  font-weight: 400;
}

textarea {
  resize: vertical;
}

.wide {
  grid-column: 1 / -1;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  padding-top: 18px;
  color: var(--text);
  text-transform: none;
  font-size: 13px;
}

.checkline input {
  width: auto;
  min-height: auto;
}

.field-with-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.vin-field {
  max-width: 620px;
}

.section-label {
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.hint {
  margin: -3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 6px;
}

.message {
  color: var(--muted);
}

.message.ok {
  color: var(--ok);
}

.message.error {
  color: var(--danger);
}

.conflict-panel {
  display: grid;
  gap: 8px;
  border: 1px solid #f2c94c;
  border-radius: 8px;
  background: #fff8db;
  color: #3f3420;
  padding: 12px;
}

.conflict-panel span {
  color: #665530;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mini-table {
  min-width: 520px;
  margin-top: 8px;
  background: #fffdf2;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.stat span {
  display: block;
  color: var(--muted);
}

.stat strong {
  display: block;
  font-size: 28px;
  margin-top: 4px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1100px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: #fbfcfe;
}

tbody tr:hover {
  background: #f9fbff;
}

.row-actions {
  text-align: right;
  white-space: nowrap;
}

.row-actions button {
  margin-left: 5px;
}

.row-actions button.danger {
  border-color: #f3b4b4;
  color: var(--danger);
}

td small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: #174ea6;
  font-size: 12px;
  font-weight: 700;
  text-transform: capitalize;
}

.deal-preview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.deal-preview div {
  display: grid;
  gap: 3px;
}

.deal-preview span {
  color: var(--muted);
  font-size: 12px;
}

.deal-preview strong {
  font-size: 18px;
}

.print-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.print-links a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 11px;
  color: var(--text);
  text-decoration: none;
  background: #fff;
}

.print-links a:hover {
  border-color: var(--primary);
  color: var(--primary);
}

footer {
  color: var(--muted);
  padding: 20px 4px 4px;
  font-size: 12px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav button {
    text-align: center;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .deal-preview,
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .content {
    padding: 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .nav {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid,
  .deal-preview,
  .stats {
    grid-template-columns: 1fr;
  }
}
