:root {
  --sidebar-w: 148px;
  --bg: #0f1419;
  --sidebar: #1a2332;
  --sidebar-hover: #243044;
  --sidebar-active: #2d5a87;
  --panel: #f4f6f9;
  --card: #ffffff;
  --text: #1a2332;
  --text-muted: #5c6b7a;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #059669;
  --error: #dc2626;
  --border: #dde3ea;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(15, 20, 25, 0.08);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--panel);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* App shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar) 0%, #121a26 100%);
  color: #e8edf3;
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  text-align: center;
  padding: 8px 4px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 12px;
}

.brand-mark {
  display: block;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: 0.06em;
  color: #60a5fa;
}

.brand-text {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.7;
}

.sidebar-brand .brand-mark,
.sidebar-brand .brand-text {
  color: #d4af37;
  opacity: 1;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 72px;
  padding: 10px 6px;
  border-radius: var(--radius);
  color: #c5d0dc;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  border: 1px solid transparent;
}

.nav-btn:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
  transform: translateY(-1px);
}

.nav-btn.is-active {
  background: var(--sidebar-active);
  color: #fff;
  border-color: rgba(96, 165, 250, 0.4);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.nav-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
  letter-spacing: 0.02em;
}

.sidebar-user {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.7rem;
  text-align: center;
}

.user-name {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
}

.user-logout {
  color: #93c5fd;
  font-size: 0.65rem;
}

.main-panel {
  flex: 1;
  padding: 24px 32px 48px;
  overflow-x: auto;
}

/* Inventory: make/model filter bar beside main menu */
.page-inventory-list .main-panel,
.page-inventory-vehicle .main-panel,
.page-inventory-new .main-panel,
.page-accounts .main-panel {
  padding: 0;
  display: flex;
  flex-direction: column;
}

.inventory-page {
  display: flex;
  flex: 1;
  align-items: stretch;
  min-height: 100vh;
}

.inventory-filter {
  width: 200px;
  flex-shrink: 0;
  background: #e8edf3;
  border-right: 1px solid var(--border);
  padding: 16px 12px 24px;
  overflow-y: auto;
  position: sticky;
  top: 0;
  align-self: flex-start;
  max-height: 100vh;
}

.stock-view-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.stock-view-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.stock-view-btn:hover {
  background: #fff;
  text-decoration: none;
  border-color: var(--accent);
}

.stock-view-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.stock-view-btn.is-active .stock-view-count {
  color: rgba(255, 255, 255, 0.9);
}

.stock-view-count {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.inventory-filter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.inventory-filter-header h2 {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.filter-clear {
  font-size: 0.75rem;
  font-weight: 600;
}

.filter-tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.filter-make {
  margin-bottom: 2px;
}

.filter-make-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.filter-expand {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}

.filter-expand:hover {
  background: #dbeafe;
  border-color: var(--accent);
}

.filter-make-link,
.filter-model-link {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.filter-make-link:hover,
.filter-model-link:hover {
  background: rgba(255, 255, 255, 0.7);
  text-decoration: none;
}

.filter-make-link.is-active,
.filter-model-link.is-active {
  background: var(--accent);
  color: #fff;
}

.filter-make-link.is-active .filter-count,
.filter-model-link.is-active .filter-count {
  color: rgba(255, 255, 255, 0.85);
}

.filter-count {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
}

.filter-models {
  list-style: none;
  margin: 0 0 6px 26px;
  padding: 0;
}

.filter-models.is-collapsed {
  display: none;
}

.filter-model-link {
  font-weight: 500;
  font-size: 0.8rem;
  padding-left: 12px;
}

.filter-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

/* Accounts sidebar — section nav with optional filter panel below */
.accounts-sidebar {
  display: flex;
  flex-direction: column;
  width: 220px;
}

.accounts-sidebar-rule {
  border-top: 1px solid var(--border);
  margin: 14px 0 12px;
}

.purchases-status-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.purchases-status-panel .inventory-filter-header {
  margin-bottom: 10px;
  padding-bottom: 8px;
}

.purchases-period-tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 1.25rem;
  margin: 0 0 1rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.purchases-period-tab {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.15rem 0;
  border-bottom: 2px solid transparent;
}

.purchases-period-tab:hover {
  color: var(--accent);
  text-decoration: none;
}

.purchases-period-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.purchases-table .purchases-col-money {
  text-align: right;
  white-space: nowrap;
  width: 8.5rem;
}

.purchases-col-actions {
  width: 5.5rem;
  white-space: nowrap;
  text-align: right;
  vertical-align: middle;
}

.purchases-col-actions .costing-icon-btn + .costing-icon-btn {
  margin-left: 0.35rem;
}

.purchases-table th.purchases-col-actions,
.purchases-table td.purchases-col-actions {
  padding-right: 0.65rem;
}

.purchases-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 1.5rem !important;
}

.badge-po {
  text-transform: none;
  letter-spacing: 0;
}

.badge-po-draft { background: #f3f4f6; color: #4b5563; }
.badge-po-approved { background: #dbeafe; color: #1d4ed8; }
.badge-po-processing { background: #fef3c7; color: #b45309; }
.badge-po-cancelled { background: #fee2e2; color: #b91c1c; }
.badge-po-paid { background: #dcfce7; color: #15803d; }

/* Vehicle record sub-menu (replaces filter bar on vehicle pages) */
.vehicle-nav-back {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
}

.vehicle-nav-back:hover {
  background: #fff;
  border-color: var(--accent);
  text-decoration: none;
}

.vehicle-nav-gap {
  height: 16px;
}

.vehicle-nav-menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.vehicle-nav-btn {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  line-height: 1.3;
}

.vehicle-nav-btn:hover {
  background: #fff;
  border-color: var(--accent);
  text-decoration: none;
}

.vehicle-nav-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.vehicle-nav-doc-btn {
  font-size: 0.78rem;
}

.inventory-main {
  flex: 1;
  padding: 24px 32px 48px;
  overflow-x: auto;
  min-width: 0;
}

/* New vehicle wizard */
.new-vehicle-page {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.new-vehicle-progress {
  background: #e8eaed;
  border-bottom: 1px solid var(--border);
  padding: 1.35rem 32px 1.5rem;
}

.new-vehicle-progress-steps {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 0;
  margin: 0 auto;
  padding: 0;
  list-style: none;
  max-width: 980px;
}

.new-vehicle-progress-step {
  position: relative;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  text-align: center;
}

.new-vehicle-progress-step:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 1.35rem;
  left: calc(50% + 1.45rem);
  right: calc(-50% + 1.45rem);
  height: 2px;
  background: #c5cad3;
  z-index: 0;
}

.new-vehicle-progress-icon {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.7rem;
  height: 2.7rem;
  border: 2px solid #c5cad3;
  border-radius: 999px;
  background: #f1f3f5;
  color: #9aa3b2;
}

.new-vehicle-progress-icon svg {
  width: 1.35rem;
  height: 1.35rem;
}

.new-vehicle-progress-label {
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  color: #9aa3b2;
}

.new-vehicle-progress-step.is-active .new-vehicle-progress-icon {
  border-color: var(--accent);
  background: #fff;
  color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.new-vehicle-progress-step.is-active .new-vehicle-progress-label {
  color: var(--accent);
}

.new-vehicle-header {
  padding: 1.5rem 32px 0;
}

.new-vehicle-form {
  padding: 0 32px 48px;
  max-width: 1100px;
}

.new-vehicle-step-panel .form-section:first-child {
  margin-top: 1rem;
}

.vehicle-vrm-search-row {
  margin-bottom: 1.15rem;
}

.vfield-vrm-search {
  max-width: 28rem;
}

.vehicle-vrm-search-controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.vehicle-vrm-search-controls .vfield-vrm-input {
  flex: 1 1 9.5rem;
  min-width: 9.5rem;
}

.vehicle-vrm-search-status {
  margin: 0.45rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.vehicle-vrm-search-status.is-error {
  color: var(--error);
}

.vehicle-vrm-search-status.is-success {
  color: #15803d;
}

@media (max-width: 760px) {
  .new-vehicle-progress {
    padding: 1rem 16px 1.15rem;
  }

  .new-vehicle-progress-label {
    font-size: 0.68rem;
  }

  .new-vehicle-progress-icon {
    width: 2.35rem;
    height: 2.35rem;
  }

  .new-vehicle-progress-icon svg {
    width: 1.15rem;
    height: 1.15rem;
  }

  .new-vehicle-header,
  .new-vehicle-form {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* Vehicle record */
.vehicle-record {
  max-width: 1100px;
}

.vehicle-record-header {
  align-items: center;
}

.vehicle-record-actions {
  flex-shrink: 0;
}

/* Vehicle advertising */
.ad-photos-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 10rem;
  margin-bottom: 1.25rem;
  padding: 2rem 1.5rem;
  background: #e8eaed;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ad-photos-title {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.ad-photos-btn {
  min-width: 10rem;
}

.ad-details-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem 1.35rem;
}

.ad-details-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

.ad-details-fields .vfield {
  margin: 0;
}

.ad-text-block {
  white-space: pre-wrap;
}

/* Vehicle photos manager */
.vehicle-photos-workspace {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem 1.25rem;
  align-items: start;
  margin-bottom: 1.25rem;
}

.photo-dropzone {
  min-height: 9.5rem;
  padding: 1.5rem 1.25rem;
  border: 2px dashed #b8c0cc;
  border-radius: var(--radius);
  background: #f8fafc;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.photo-dropzone:hover,
.photo-dropzone.is-dragover {
  border-color: var(--accent);
  background: #eef4ff;
}

.photo-dropzone.is-uploading {
  opacity: 0.65;
  pointer-events: none;
}

.photo-dropzone-title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.photo-dropzone-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.vehicle-photos-grid-controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  padding: 0.65rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.photo-grid-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-align: center;
}

.photo-grid-btn {
  min-width: 2.75rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}

.photo-grid-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.photo-grid-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.photo-gallery {
  display: grid;
  gap: 0.75rem;
}

.photo-gallery-cols-2 { grid-template-columns: repeat(2, 1fr); }
.photo-gallery-cols-3 { grid-template-columns: repeat(3, 1fr); }
.photo-gallery-cols-4 { grid-template-columns: repeat(4, 1fr); }
.photo-gallery-cols-6 { grid-template-columns: repeat(6, 1fr); }

.photo-gallery-item {
  position: relative;
  margin: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f3f4f6;
}

.photo-gallery-item img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.photo-delete-btn {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 1.6rem;
  height: 1.6rem;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.photo-delete-btn:hover {
  background: #b91c1c;
}

.photo-gallery-empty {
  margin-top: 0.5rem;
}

.vehicle-section legend {
  font-size: 1rem;
}

.vehicle-field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem 1.25rem;
}

.seller-field-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.vfield-span-2 {
  grid-column: span 2;
}

.vfield-span-4 {
  grid-column: span 4;
}

.purchase-field-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.purchase-from-field,
.purchase-contact-name-field,
.purchase-vehicle-field,
.sale-to-field,
.sale-contact-name-field,
.sale-vehicle-field {
  position: relative;
}

.sale-field-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 900px) {
  .sale-field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sale-field-grid .vfield-span-2,
  .sale-field-grid .vfield-span-4 {
    grid-column: span 2;
  }
}

.purchase-invoice-items {
  margin-top: 2rem;
}

.purchase-invoice-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 700;
}

.purchase-invoice-rule {
  border-top: 1px solid var(--border);
  margin-bottom: 1rem;
}

.purchase-lines-table input,
.purchase-lines-table select {
  width: 100%;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.purchase-lines-table input[readonly] {
  background: var(--surface-muted, #f4f4f5);
}

@media (max-width: 900px) {
  .purchase-field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .purchase-field-grid .vfield-span-2,
  .purchase-field-grid .vfield-span-4 {
    grid-column: span 2;
  }
}

.seller-name-field {
  position: relative;
}

.seller-autocomplete-menu {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 30;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  max-height: 14rem;
  overflow-y: auto;
}

.seller-autocomplete-item {
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  font-size: 0.9rem;
  background: var(--card);
}

.seller-autocomplete-item:hover,
.seller-autocomplete-item.is-active {
  background: #eef2f7;
}

.seller-autocomplete-item strong {
  display: block;
  font-weight: 600;
}

.seller-autocomplete-item span {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.seller-autocomplete-empty {
  padding: 0.5rem 0.65rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--card);
}

.seller-autocomplete-create {
  font-weight: 600;
  color: var(--accent, #1a56db);
  border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
  .seller-field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .seller-field-grid .vfield-span-2 {
    grid-column: span 2;
  }
}

.vehicle-field-full {
  margin-top: 1rem;
}

.vfield {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.vfield label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.vfield-required label::after {
  content: " *";
  color: var(--error);
}

.vfield input,
.vfield select,
.vfield textarea {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

.vfield-value {
  font-size: 0.95rem;
  padding: 0.35rem 0;
  min-height: 1.5rem;
}

.vehicle-section-muted {
  opacity: 0.95;
  border-style: dashed;
}

.vfield-money-vat-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.vfield-money-vat-row input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

.vfield-vat-select {
  flex-shrink: 0;
  min-width: 8.5rem;
  padding: 0.5rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--card);
}

.vfield-vat-tag {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: #eef4ff;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
}

/* Vehicle costing table */
.vehicle-costing {
  max-width: 1100px;
}

.costing-advertised {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  margin-bottom: 0.65rem;
}

.costing-advertised-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem;
  width: min(100%, 320px);
  padding-right: 0.65rem;
}

.costing-table-wrap {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.costing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.costing-table th,
.costing-table td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.costing-table th {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: #f8fafc;
}

.costing-table tbody tr:last-child td {
  border-bottom: none;
}

.costing-col-action {
  width: 2.25rem;
  text-align: center;
  padding-left: 0.35rem;
  padding-right: 0.35rem;
}

.costing-col-num {
  text-align: right;
  white-space: nowrap;
}

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

.costing-col-total {
  font-weight: 600;
}

.costing-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 1.5rem !important;
}

.costing-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  padding: 0;
}

.costing-icon-btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}

.costing-icon-btn-danger:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.costing-delete-form {
  margin: 0;
}

.costing-row-form {
  display: contents;
}

.costing-row-edit input,
.costing-row-edit select {
  width: 100%;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.costing-add-row {
  display: flex;
  justify-content: flex-end;
  margin: 0.85rem 0 1.25rem;
}

.costing-add-row .btn,
.account-codes-header .btn {
  background: var(--accent);
  border: none;
  color: #fff;
}

.costing-add-row .btn:hover,
.account-codes-header .btn:hover {
  background: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}

.costing-totals {
  margin-left: auto;
  width: min(100%, 320px);
  margin-top: 0.5rem;
}

.costing-totals-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem;
  padding: 0.2rem 0;
  font-size: 0.92rem;
}

.costing-totals-label {
  font-weight: 600;
  color: var(--text);
}

.costing-totals-value {
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.costing-totals-grand {
  font-size: 1.15rem;
  font-weight: 800;
  padding-top: 0.15rem;
}

.costing-totals-grand .costing-totals-value {
  font-weight: 800;
}

.costing-totals-rule {
  border-top: 1px solid var(--text);
  margin: 0.35rem 0;
}

.costing-totals-rule-double {
  border-top: 3px double var(--text);
}

.costing-profit-negative {
  color: var(--error);
}

.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;
}

/* Account codes */
.account-codes-page {
  max-width: 1100px;
}

.account-codes-header {
  align-items: flex-start;
}

.account-codes-header .btn {
  flex-shrink: 0;
  margin-top: 0.15rem;
}

.vehicle-history {
  margin-top: 1.5rem;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg) 0%, #1e3a5f 100%);
}

.login-card {
  background: var(--card);
  padding: 0;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.login-brand-panel {
  background: linear-gradient(180deg, var(--sidebar) 0%, #121a26 100%);
  padding: 1.25rem 1.5rem 1.35rem;
  text-align: center;
}

.login-brand-panel .login-brand {
  padding: 0;
  margin: 0;
  border: none;
}

.login-brand-panel .brand-mark,
.login-brand-panel .brand-text {
  color: #d4af37;
  opacity: 1;
}

.login-card-body {
  padding: 2rem 2.5rem 2.5rem;
}

.login-tagline {
  color: var(--text-muted);
  margin: 0 0 1.5rem;
  text-align: center;
  font-size: 0.92rem;
}

.login-form label {
  display: block;
  margin-bottom: 1rem;
}

.login-form span {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.login-form input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.login-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1.25rem;
}

/* Page */
.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
}

.page-subtitle {
  color: var(--text-muted);
  margin: 0;
}

.page-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text);
}

.btn-block {
  width: 100%;
}

/* Forms */
.toolbar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.input-search,
.input-select,
.form-grid input,
.form-grid select,
.form-grid textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

.input-search {
  min-width: 220px;
  flex: 1;
}

.form-grid {
  max-width: 960px;
}

.form-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.form-section legend {
  font-weight: 700;
  padding: 0 0.25rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.form-row label,
.form-section > label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.required span::after {
  content: " *";
  color: var(--error);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.form-actions-end {
  justify-content: flex-end;
}

.vfield input.is-invalid,
.vfield select.is-invalid,
.vfield textarea.is-invalid {
  border-color: var(--error);
}

/* Sortable table headers (Purchases, Sales, Inventory) */
.th-sortable {
  white-space: nowrap;
  vertical-align: middle;
}

.th-sort-inner {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.th-sort-label {
  line-height: 1.2;
}

.th-sort-arrows {
  display: inline-flex;
  flex-direction: column;
  gap: 0.05rem;
}

.th-sort-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 0.72rem;
  font-size: 0.58rem;
  line-height: 1;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 3px;
}

.th-sort-arrow:hover {
  color: var(--accent);
  background: #eef4ff;
  text-decoration: none;
}

.th-sort-arrow.is-active {
  color: #fff;
  background: var(--accent);
}

.inventory-list-sort-wrap {
  margin-bottom: 0;
}

.inventory-list-sort-wrap .table-wrap,
.inventory-list-sort-wrap.table-wrap {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: none;
}

.inventory-sort-table {
  margin-bottom: 0;
}

.inventory-sort-table th.inventory-col-actions {
  width: 8rem;
}

.inventory-col-actions {
  width: 8rem;
}

/* Inventory stock list */
.inventory-stock-list {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.inventory-vehicle-item {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

.inventory-vehicle-stock {
  flex-shrink: 0;
  align-self: flex-start;
  width: 2.75rem;
  margin-right: 0.75rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1.35;
  padding-top: 0.1rem;
}

.inventory-vehicle-thumb {
  flex-shrink: 0;
  align-self: stretch;
  position: relative;
  width: 7rem;
  margin-right: 0.85rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #eef0f3;
}

.inventory-vehicle-thumb img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.inventory-vehicle-thumb-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  color: var(--text-muted);
}

.inventory-vehicle-thumb--preview {
  cursor: zoom-in;
}

.inventory-thumb-preview {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  background: #fff;
}

.inventory-thumb-preview[hidden] {
  display: none !important;
}

.inventory-thumb-preview img {
  display: block;
  width: 320px;
  max-width: min(320px, calc(100vw - 2rem));
  max-height: min(240px, calc(100vh - 2rem));
  height: auto;
  object-fit: contain;
}

.inventory-vehicle-content {
  flex: 1;
  min-width: 0;
}

.inventory-vehicle-item:last-child {
  border-bottom: none;
}

.inventory-vehicle-header {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 0.5rem;
}

.inventory-vehicle-header-end {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  flex-shrink: 0;
  margin-left: auto;
}

.inventory-vehicle-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.inventory-vehicle-title {
  flex: 0 1 auto;
  min-width: 0;
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  line-height: 1.35;
}

.inventory-vehicle-title:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.inventory-vehicle-price {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.inventory-vrm-plate {
  flex-shrink: 0;
  margin-left: 100px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.1rem 0.3rem;
  border: 2px solid #1a1a1a;
  border-radius: 4px;
  background: #f9d71c;
  color: #1a1a1a;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.btn-compact {
  padding: 0.32rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  text-align: center;
  min-width: 5.5rem;
}

.vfield-uppercase {
  text-transform: uppercase;
}

.vfield-value-uppercase {
  text-transform: uppercase;
}

.vfield-vrm-input,
.vfield-vrm-plate {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.75rem;
  border: 2px solid #1a1a1a;
  border-radius: 4px;
  background: #f9d71c;
  color: #1a1a1a;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.vfield-vrm-input {
  min-width: 9.5rem;
  max-width: 100%;
  text-align: center;
}

.vfield-vrm-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.inventory-vehicle-details {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.75rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.inventory-detail-field {
  display: inline-flex;
  gap: 0.35rem;
  align-items: baseline;
}

.inventory-detail-label {
  font-weight: 600;
  color: var(--text);
}

.mot-days-expired {
  color: var(--error);
  font-weight: 600;
}

/* Table */
.table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: auto;
}

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

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

.data-table th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.data-table th.th-sortable {
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
}

.data-table-compact th,
.data-table-compact td {
  padding: 0.5rem 0.75rem;
}

.cell-actions {
  white-space: nowrap;
}

.cell-actions a {
  margin-right: 0.75rem;
}

.cell-actions-icons {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.cell-actions-icons a {
  margin-right: 0;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-purchased { background: #dbeafe; color: #1e40af; }
.badge-in_prep { background: #fef3c7; color: #92400e; }
.badge-for_sale { background: #d1fae5; color: #065f46; }
.badge-reserved { background: #ede9fe; color: #5b21b6; }
.badge-sold { background: #e2e8f0; color: #334155; }
.badge-withdrawn { background: #fee2e2; color: #991b1b; }

.badge-type {
  margin-right: 0.25rem;
  text-transform: none;
}
.badge-type-prospect { background: #e0e7ff; color: #3730a3; }
.badge-type-customer { background: #d1fae5; color: #065f46; }
.badge-type-supplier { background: #ffedd5; color: #9a3412; }
.badge-type-staff { background: #fce7f3; color: #9d174d; }
.badge-type-other { background: #f1f5f9; color: #475569; }

.row-inactive { opacity: 0.55; }

.type-picker { margin-top: 1rem; }
.type-picker-label { font-weight: 600; font-size: 0.85rem; display: block; margin-bottom: 0.35rem; }
.required-mark { color: var(--error); }
.type-picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.type-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  background: #f8fafc;
}
.type-chip:has(input:checked) {
  background: #dbeafe;
  border-color: var(--accent);
  color: #1e40af;
}
.type-chip input { accent-color: var(--accent); }

.settings-page {
  max-width: 960px;
}

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

.settings-section-hint,
.settings-fy-hint {
  margin: 0 0 1rem;
}

.settings-mot-status {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
}

.settings-mot-status--ready {
  color: #15803d;
}

@media (max-width: 900px) {
  .settings-field-grid {
    grid-template-columns: 1fr;
  }

  .settings-field-grid .vfield-span-2 {
    grid-column: span 1;
  }
}

.contact-type-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 1rem;
}

.contact-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  background: #f8fafc;
  user-select: none;
}

.contact-filter-chip input {
  accent-color: currentColor;
}

.contact-filter-all:has(input:checked) {
  background: #e2e8f0;
  border-color: #94a3b8;
  color: #334155;
}

.contact-filter-prospect:has(input:checked) {
  background: #e0e7ff;
  border-color: #818cf8;
  color: #3730a3;
}

.contact-filter-customer:has(input:checked) {
  background: #d1fae5;
  border-color: #34d399;
  color: #065f46;
}

.contact-filter-supplier:has(input:checked) {
  background: #ffedd5;
  border-color: #fb923c;
  color: #9a3412;
}

.contact-filter-staff:has(input:checked) {
  background: #fce7f3;
  border-color: #f472b6;
  color: #9d174d;
}

.contact-filter-other:has(input:checked) {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #475569;
}

.contacts-filter-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 1.5rem 1rem;
  margin: 0;
}

.checkbox-block {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
  font-size: 0.9rem;
}
.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  white-space: nowrap;
}
.field-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
  display: block;
  margin-top: 0.25rem;
}
label .field-hint a { font-weight: 600; }

/* Detail */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.detail-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.detail-card h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  margin: 0;
  font-size: 0.9rem;
}

.detail-list dt {
  color: var(--text-muted);
  font-weight: 600;
}

.detail-list dd {
  margin: 0;
}

.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
}

.timeline li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.timeline time {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.muted {
  color: var(--text-muted);
}

/* Cards dashboard */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
}

.stat-card:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.stat-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.stat-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.stat-card-muted {
  opacity: 0.65;
  pointer-events: none;
}

.empty-state {
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem;
  text-align: center;
}

/* Flash */
.flash-stack {
  margin-bottom: 1rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.flash-success { background: #d1fae5; color: #065f46; }
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-info { background: #dbeafe; color: #1e40af; }

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 8px;
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1;
    justify-content: center;
  }
  .nav-btn {
    min-height: 64px;
    min-width: 72px;
    flex: 0 1 auto;
  }
  .sidebar-user {
    width: 100%;
    margin-top: 8px;
  }
  .inventory-page {
    flex-direction: column;
  }
  .inventory-filter,
  .vehicle-nav,
  .accounts-sidebar {
    width: 100%;
    max-height: none;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .vehicle-nav-menu {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .vehicle-nav-btn {
    flex: 1 1 auto;
    min-width: 140px;
  }
}