:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --ink: #172126;
  --muted: #62717a;
  --line: #d8e0e4;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-dark: #0b554f;
  --accent-soft: #dff2ef;
  --warn: #a15c07;
  --blue: #285d91;
  --danger: #a1362f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background: linear-gradient(135deg, #142126 0%, #17363a 58%, #0f766e 100%);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 26px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 24px 80px rgba(11, 24, 29, .28);
}

.login-card h1 {
  color: var(--ink);
}

.login-card p {
  color: var(--muted);
  margin-top: 4px;
}

.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.login-error {
  min-height: 20px;
  color: var(--danger) !important;
  font-weight: 650;
}

.unauthenticated .app-shell {
  display: none !important;
}

.authenticated .login-screen {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 28px;
  background: #142126;
  color: #fff;
  border-bottom: 4px solid var(--accent);
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 28px;
  font-weight: 750;
}

h2 {
  font-size: 16px;
}

.topbar p {
  color: #b9c7cc;
  margin-top: 4px;
}

.header-tools {
  display: flex;
  align-items: end;
  gap: 20px;
}

.header-tools label {
  display: grid;
  gap: 4px;
  color: #b9c7cc;
  font-size: 13px;
}

.header-tools select {
  min-width: 145px;
}

.user-box {
  display: grid;
  gap: 2px;
  min-width: 150px;
}

.user-box span {
  color: #fff;
  font-weight: 700;
}

.user-box strong {
  color: #b9c7cc;
  font-size: 13px;
}

.totals {
  display: grid;
  justify-items: end;
  gap: 2px;
  white-space: nowrap;
}

.totals span {
  color: #b9c7cc;
}

.totals strong {
  font-size: 22px;
}

main {
  width: min(1500px, calc(100vw - 32px));
  margin: 18px auto 40px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tab, .ghost {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.filters {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) repeat(4, minmax(140px, 180px)) 150px 150px auto auto;
  gap: 10px;
  margin-bottom: 16px;
}

.filter-badge {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #9fd0ca;
  border-radius: 8px;
  background: var(--accent-soft);
  color: #0d4d48;
}

.filter-badge button {
  height: 32px;
}

.quick-filters,
.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.quick-filters {
  margin: -4px 0 14px;
}

.quick-filters button,
.bulk-bar button {
  height: 34px;
  padding: 0 10px;
}

.saved-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.saved-filter {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button {
  width: 34px;
  padding: 0;
}

.bulk-bar {
  padding: 10px;
  margin: -4px 0 18px;
  border: 1px solid #9fd0ca;
  border-radius: 8px;
  background: var(--accent-soft);
}

.bulk-bar select,
.bulk-bar input {
  height: 34px;
  min-width: 150px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.toolbar-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  width: min(680px, 100%);
}

.toolbar input {
  width: 100%;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 42px;
  white-space: nowrap;
  color: var(--muted);
  font-weight: 650;
}

.inline-check input {
  width: 16px;
  height: 16px;
}

input, select, button, textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font: inherit;
}

input, select, button {
  height: 42px;
}

textarea {
  min-height: 74px;
  padding-top: 9px;
  resize: vertical;
}

button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.danger {
  background: #fff;
  color: var(--danger);
  border-color: #e0b6b2;
}

.dashboard {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.panel h2 {
  margin-bottom: 14px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.settings-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
}

.settings-panel.wide {
  grid-column: 1 / -1;
}

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

.settings-panel h3 {
  margin: 0;
}

.compact-settings-table table {
  min-width: 0;
}

.compact-settings-table th:last-child,
.compact-settings-table td:last-child {
  width: 140px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #0d4d48;
  border-color: #63aaa3;
  font-weight: 650;
  height: auto;
}

.bars {
  display: grid;
  gap: 9px;
}

.bar {
  display: grid;
  grid-template-columns: 150px 1fr 42px;
  align-items: center;
  gap: 10px;
}

.bar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 9px;
  border-radius: 99px;
  background: #e8edf0;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--blue);
}

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

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

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

th {
  position: sticky;
  top: 0;
  background: #eef3f5;
  color: #40505a;
  font-size: 13px;
  text-transform: uppercase;
  z-index: 1;
}

td.part {
  min-width: 280px;
  max-width: 460px;
  white-space: normal;
  padding-top: 7px;
}

.part-title {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  margin: 0;
  line-height: 1.2;
}

.part-title strong,
.part-title .code {
  display: block;
  margin: 0;
  padding: 0;
  line-height: 1.2;
}

.date-cell {
  min-width: 86px;
  white-space: nowrap;
}

td.comment {
  min-width: 150px;
  max-width: 260px;
  white-space: pre-wrap;
  color: var(--muted);
}

.vehicle-cell {
  min-width: 130px;
  line-height: 1.28;
}

.vehicle-cell strong {
  display: block;
}

.meta-line {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 6px;
  margin-top: 2px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.2;
}

.meta-line span {
  color: var(--muted);
  font-family: inherit;
}

.price-stack {
  min-width: 120px;
}

.price-stack .meta-line {
  grid-template-columns: 42px minmax(0, 1fr);
  justify-items: end;
}

tr.own-request td {
  background: #eaf7f5;
}

tr.request-row {
  cursor: pointer;
}

tr.request-row:hover td {
  background: #f7fbfc;
}

tr.request-row.own-request:hover td {
  background: #e1f2ef;
}

tr.own-request td:first-child {
  border-left: 4px solid var(--accent);
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 8px;
  background: #edf1f3;
  color: #34444d;
  white-space: nowrap;
}

.badge.order {
  background: #fff2d9;
  color: var(--warn);
}

.danger-badge {
  background: #fde8e6;
  color: var(--danger);
}

.urgent-badge {
  margin-top: 4px;
  background: #e8f0ff;
  color: var(--blue);
}

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

.row-actions {
  display: grid;
  gap: 6px;
  padding-top: 8px;
}

.row-actions button {
  height: 32px;
  padding: 0 9px;
  font-size: 13px;
}

.actions-menu {
  position: relative;
  width: 96px;
}

.actions-menu summary {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  cursor: pointer;
  list-style: none;
}

.actions-menu summary::-webkit-details-marker {
  display: none;
}

.actions-menu[open] .row-actions {
  position: absolute;
  right: 0;
  top: 38px;
  z-index: 3;
  min-width: 120px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(17, 31, 37, .16);
}

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

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

dialog {
  width: min(980px, calc(100vw - 28px));
  max-width: calc(100vw - 28px);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(17, 31, 37, .25);
}

#analogDialog {
  width: min(1120px, calc(100vw - 28px));
}

#requestCardDialog {
  width: min(1120px, calc(100vw - 28px));
}

#vehicleCardDialog {
  width: min(1180px, calc(100vw - 28px));
}

dialog::backdrop {
  background: rgba(20, 33, 38, .45);
}

.dialog-form {
  padding: 18px;
}

.dialog-form.small {
  width: min(560px, calc(100vw - 28px));
}

.dialog-form.analog-form {
  width: auto;
  max-width: 100%;
  overflow-x: hidden;
}

.dialog-form.card-dialog {
  width: auto;
  max-width: 100%;
  overflow-x: hidden;
}

.dialog-form.vehicle-card-dialog {
  width: auto;
  max-width: 100%;
  overflow-x: hidden;
}

.dialog-form header,
.dialog-form footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-form header {
  margin-bottom: 16px;
}

.dialog-form footer {
  margin-top: 16px;
}

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

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

.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.form-grid label input,
.form-grid label select,
.form-grid label textarea {
  color: var(--ink);
  font-weight: 400;
}

.analog-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-width: 0;
}

.analog-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbfc;
  min-width: 0;
}

.analog-card h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.analog-card dl {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 8px 10px;
  margin: 0;
}

.analog-card dt {
  color: var(--muted);
  font-weight: 650;
}

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

.analog-card.wide {
  grid-column: 1 / -1;
}

.analog-list {
  display: grid;
  gap: 8px;
}

.analog-item {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 4px 10px;
  align-items: start;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.analog-item small {
  grid-column: 2;
  color: var(--muted);
}

.analog-picker {
  margin-top: 12px;
}

.analog-picker select {
  height: 190px;
  padding: 8px;
}

.mini-table-wrap {
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.mini-table {
  min-width: 0;
  width: 100%;
  table-layout: fixed;
  font-size: 14px;
}

.mini-table th,
.mini-table td {
  padding: 7px 8px;
  overflow-wrap: anywhere;
}

.vehicle-card-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-bottom: 12px;
}

.vehicle-card-filters label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.vehicle-card-filters input {
  width: 150px;
}

.vehicle-history-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #9fd0ca;
  border-radius: 8px;
  background: var(--accent-soft);
  color: #0d4d48;
}

.vehicle-history-table,
.vehicle-history-table thead,
.vehicle-history-table tbody {
  display: block;
}

.vehicle-history-table thead {
  display: none;
}

.vehicle-history-table tbody {
  width: 100%;
}

.vehicle-history-table tr {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) minmax(92px, 128px);
  gap: 4px 12px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.vehicle-history-table td {
  border-bottom: 0;
  min-width: 0;
  padding: 0;
  vertical-align: top;
}

.vehicle-history-request {
  grid-column: 1;
  grid-row: 1 / span 3;
}

.vehicle-history-product {
  grid-column: 2;
  grid-row: 1;
}

.vehicle-history-qty {
  grid-column: 3;
  grid-row: 1;
  text-align: right;
}

.vehicle-history-status {
  grid-column: 2;
  grid-row: 2;
}

.vehicle-history-supply {
  grid-column: 2;
  grid-row: 3;
  color: var(--muted);
}

.vehicle-history-money {
  grid-column: 3;
  grid-row: 2 / span 2;
  align-self: start;
}

.vehicle-history-comment {
  grid-column: 1 / -1;
  grid-row: 4;
  color: var(--muted);
  white-space: pre-wrap;
}

.vehicle-history-comment:empty {
  display: none;
}

.vehicle-history-empty {
  display: block !important;
}

.vehicle-history-table .price-stack {
  min-width: 0;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: #f4faf9;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -6px 0 14px;
}

.card-actions button {
  height: 34px;
}

.card-grid {
  display: grid;
  grid-template-columns: 120px 1fr 120px 1fr;
  gap: 8px 12px;
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfc;
}

.card-grid dt {
  color: var(--muted);
  font-weight: 650;
}

.card-grid dd {
  margin: 0;
}

.history-panel {
  margin-top: 14px;
}

.history-panel h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.event-list,
.notification-list,
.price-history {
  display: grid;
  gap: 8px;
}

.attachment-panel {
  margin-top: 14px;
}

.attachment-panel h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.attachment-grid a {
  display: grid;
  gap: 6px;
  color: var(--ink);
  text-decoration: none;
}

.attachment-grid img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f5;
}

.attachment-grid span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.event-item,
.notification-item,
.price-history-row {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.event-item small,
.notification-item small,
.price-history-row small {
  color: var(--muted);
}

.notification-button {
  position: relative;
}

.notification-count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  margin-left: 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
}

.notification-item.unread {
  border-color: #9fd0ca;
  background: var(--accent-soft);
}

button.notification-item {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

button.notification-item:hover {
  border-color: #7eb8b0;
}

.audit-filters {
  align-items: end;
}

.audit-summary {
  margin-top: 10px;
}

.audit-table td,
.audit-table th {
  vertical-align: top;
}

.mechanic .audit-tab {
  display: none;
}

.price-history-row {
  grid-template-columns: 88px 1fr;
}

.price-history-row small {
  grid-column: 1 / -1;
}

.wide {
  grid-column: 1 / -1;
}

.hidden {
  display: none !important;
}

.batch-items {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbfc;
}

.batch-head,
.batch-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.batch-head h3 {
  margin: 0;
  font-size: 15px;
}

.batch-row {
  grid-template-columns: minmax(220px, 1.4fr) 110px 150px 100px 100px auto;
}

.batch-row.edit-position {
  grid-template-columns: minmax(220px, 1.4fr) 110px 140px 110px 80px 140px 95px 95px 125px;
}

.batch-row input {
  width: 100%;
}

.photo-field {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfc;
}

.vehicle-hint,
.part-insight {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid #9fd0ca;
  border-radius: 8px;
  background: var(--accent-soft);
}

.vehicle-hint {
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.vehicle-hint span,
.part-insight span {
  color: var(--muted);
}

.part-insight {
  grid-column: 1 / -1;
}

.part-insight > div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
}

.part-insight-actions {
  padding-top: 2px;
}

.part-insight-actions button {
  height: 34px;
}

.photo-field label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.photo-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.photo-chip {
  display: grid;
  gap: 2px;
  max-width: 220px;
  padding: 8px 10px;
  border: 1px solid #9fd0ca;
  border-radius: 8px;
  background: var(--accent-soft);
}

.photo-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.duplicate-warning {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #e1ba72;
  border-radius: 8px;
  background: #fff8e8;
  color: #5f3a06;
}

.duplicate-list {
  display: grid;
  gap: 6px;
}

.duplicate-list button {
  display: grid;
  grid-template-columns: 82px 92px minmax(0, 1fr) 110px;
  gap: 8px;
  align-items: center;
  height: auto;
  padding: 8px;
  border-color: #e1ba72;
  background: #fff;
  color: var(--ink);
  text-align: left;
  white-space: normal;
}

.part-search-field {
  position: relative;
  min-width: 0;
}

.part-search-field input {
  width: 100%;
}

.part-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 10;
  display: grid;
  gap: 4px;
  max-height: 270px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(17, 31, 37, .18);
}

.part-suggestions button {
  display: grid;
  gap: 2px;
  height: auto;
  padding: 8px;
  border-color: transparent;
  background: #fff;
  color: var(--ink);
  text-align: left;
  white-space: normal;
}

.part-suggestions button:hover {
  background: #f4faf9;
  border-color: #9fd0ca;
}

.part-suggestions span,
.part-suggestion-empty {
  color: var(--muted);
  font-size: 13px;
}

.part-suggestion-empty {
  padding: 8px;
}

.mechanic .staff-only,
.mechanic .managed-col,
.viewer .staff-only,
body:not(.admin) .admin-only {
  display: none !important;
}

.mechanic .dashboard {
  display: none;
}

@media (max-width: 1120px) {
  .filters {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .topbar,
  .header-tools,
  .toolbar,
  .toolbar-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .totals {
    justify-items: start;
  }

  .tabs {
    overflow-x: auto;
  }

  .filters,
  .dashboard,
  .settings-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}
