:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --panel: #ffffff;
  --panel-soft: #eef3f1;
  --text: #1c2422;
  --muted: #66736f;
  --line: #dce3e0;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #b42318;
  --warning: #b7791f;
  --ok: #227950;
  --shadow: 0 12px 36px rgba(25, 35, 32, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  transition: grid-template-columns 160ms ease;
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: 76px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #17211e;
  color: #f7faf8;
  padding: 22px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.brand-text {
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f5c542;
  color: #17211e;
  font-weight: 800;
}

.sidebar-toggle {
  margin-left: auto;
  width: 32px;
  height: 32px;
  border: 1px solid #40524d;
  border-radius: 8px;
  background: #24332f;
  color: #ffffff;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

body.sidebar-collapsed .sidebar {
  padding: 18px 12px;
}

body.sidebar-collapsed .brand {
  display: grid;
  justify-items: center;
  gap: 10px;
}

body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .nav button span {
  display: none;
}

body.sidebar-collapsed .sidebar-toggle {
  margin-left: 0;
}

.brand small,
.kicker,
.workshop-picker span,
.mode-picker span,
.muted {
  color: var(--muted);
}

.sidebar .brand small {
  color: #b7c7c2;
  display: block;
  margin-top: 2px;
}

.nav {
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  display: grid;
  align-content: start;
  gap: 6px;
}

.nav::-webkit-scrollbar {
  width: 8px;
}

.nav::-webkit-scrollbar-thumb {
  background: #40524d;
  border-radius: 999px;
}

.nav button {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #dce8e5;
  cursor: pointer;
  text-align: left;
  padding: 10px 12px;
}

body.sidebar-collapsed .nav button {
  text-align: center;
  padding: 10px;
}

body.sidebar-collapsed .nav button::before {
  content: attr(data-short);
  font-weight: 800;
}

.nav button:hover,
.nav button.active {
  background: #24332f;
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 24px;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 28px;
  letter-spacing: 0;
}

.topbar-controls {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 12px;
}

.kicker {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  font-weight: 700;
}

.workshop-picker,
.mode-picker {
  min-width: 260px;
  display: grid;
  gap: 6px;
}

.workshop-picker select,
.mode-picker select,
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.content {
  display: grid;
  gap: 18px;
}

.plate-intake {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(260px, 1fr);
  align-items: end;
  gap: 14px;
}

.plate-search {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto;
  gap: 10px;
}

.plate-search input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0;
}

.plate-result {
  grid-column: 1 / -1;
}

.search-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-soft);
}

.search-result p {
  margin: 4px 0 0;
}

.search-result.found {
  background: #ecfdf5;
  border-color: #bbf7d0;
}

.search-result.missing {
  background: #fffbeb;
  border-color: #fde68a;
}

.result-actions {
  display: flex;
  gap: 8px;
}

.workbench-panel {
  display: grid;
  gap: 16px;
}

.client-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.client-summary-grid div,
.work-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8faf9;
}

.client-summary-grid span,
.client-summary-grid strong {
  display: block;
}

.client-summary-grid strong {
  margin-top: 4px;
}

.work-note p {
  margin: 6px 0 0;
}

.compact-list {
  margin: 6px 0 0;
  padding-left: 18px;
}

.compact-list li {
  margin: 3px 0;
}

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

.action-button {
  min-height: 56px;
  font-weight: 800;
}

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

.modal-client-head {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8faf9;
  margin-bottom: 12px;
}

.search-picker {
  position: relative;
}

.search-picker input[type="text"] {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

.search-picker-list {
  display: none;
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.search-picker.open .search-picker-list {
  display: block;
}

.search-picker-option {
  width: 100%;
  display: grid;
  gap: 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 9px 10px;
  text-align: left;
}

.search-picker-option:last-child {
  border-bottom: 0;
}

.search-picker-option small {
  color: var(--muted);
}

.search-picker-option:hover,
.search-picker-option.active {
  background: #eef3f1;
}

.search-picker-empty {
  padding: 10px;
  color: var(--muted);
}

.quick-history {
  display: grid;
  gap: 10px;
}

.workbench-panel .panel-head p {
  margin: 4px 0 0;
}

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

.history-form > .button.full {
  width: 100%;
}

.desktop-entry-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) minmax(150px, 1fr) minmax(110px, 0.5fr) auto;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8faf9;
}

.desktop-entry-row + .desktop-entry-row {
  margin-top: -4px;
}

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

.dense-table table {
  font-size: 14px;
}

.dense-table th,
.dense-table td {
  padding: 8px 10px;
}

.dense-table tfoot th {
  border-top: 1px solid var(--line);
  background: #f8faf9;
}

.table-button {
  min-height: 32px;
  min-width: 62px;
  padding: 5px 9px;
  white-space: nowrap;
}

.table-actions,
.inline-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.item-stack {
  display: grid;
  gap: 4px;
}

.item-stack span {
  display: block;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}

.item-stack span:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.estimate-preview {
  display: grid;
  gap: 14px;
}

.estimate-header,
.remito-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.estimate-header strong,
.estimate-header span,
.remito-brand strong,
.remito-brand span,
.remito-box strong,
.remito-box span {
  display: block;
}

.remito-brand strong {
  font-size: 20px;
}

.remito-brand span,
.remito-box span,
.remito-data span {
  color: var(--muted);
}

.remito-box {
  min-width: 190px;
  border: 2px solid var(--text);
  border-radius: 4px;
  padding: 10px;
  text-align: center;
}

.remito-box strong {
  font-size: 18px;
}

.remito-data {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 4px;
}

.remito-data div {
  padding: 10px;
  border-right: 1px solid var(--line);
}

.remito-data div:last-child {
  border-right: 0;
}

.remito-data strong {
  display: block;
  margin-top: 3px;
}

.remito-notes {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px;
}

.remito-notes p {
  margin: 6px 0 0;
}

.remito-footer {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  margin-top: 24px;
}

.remito-footer div {
  border-top: 1px solid var(--text);
  padding-top: 8px;
  text-align: center;
}

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

@media print {
  body * {
    visibility: hidden;
  }

  .modal,
  .modal * {
    visibility: visible;
  }

  .modal {
    position: absolute;
    inset: 0;
    width: 100%;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }

  .modal-head,
  .inline-actions,
  .icon-button {
    display: none;
  }

  .modal-body {
    padding: 0;
  }

  .remito-print {
    width: 190mm;
    min-height: 270mm;
    margin: 0 auto;
    padding: 12mm;
    color: #000;
    background: #fff;
    font-family: Arial, sans-serif;
  }

  .remito-print .muted,
  .remito-brand span,
  .remito-box span,
  .remito-data span {
    color: #333;
  }

  .remito-header {
    border-bottom: 2px solid #000;
  }

  .remito-data,
  .remito-notes,
  .remito-table {
    border-color: #000;
    border-radius: 0;
  }

  .remito-table table {
    font-size: 12px;
  }

  .remito-table th,
  .remito-table td {
    border-color: #000;
    padding: 7px;
  }

  .remito-table tfoot th {
    background: #fff;
    border-top: 2px solid #000;
  }
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.check-item input {
  margin-top: 3px;
}

.form-actions,
.history-area,
.estimate-area {
  display: grid;
  gap: 12px;
}

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

.history-entry {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.history-entry strong,
.history-entry span {
  display: block;
}

.history-entry p {
  margin: 6px 0 0;
}

.compact-head {
  margin-bottom: 0;
}

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

.stat,
.panel,
.table-wrap,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stat {
  padding: 16px;
}

.stat strong {
  display: block;
  font-size: 28px;
  margin-top: 6px;
}

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

.panel {
  padding: 16px;
}

.panel h2,
.modal h2 {
  margin: 0;
  font-size: 18px;
}

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

.button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  padding: 8px 12px;
  background: #fff;
  color: var(--text);
}

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

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

.button.ghost {
  background: transparent;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.table-wrap {
  overflow: auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  background: var(--panel-soft);
}

.badge.ok {
  background: #dcfce7;
  color: var(--ok);
}

.badge.warn {
  background: #fef3c7;
  color: var(--warning);
}

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

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

.field {
  display: grid;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

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

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 33, 30, 0.55);
}

.modal {
  width: min(760px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.modal-body {
  padding: 16px;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
}

.empty-state.compact {
  padding: 12px;
}

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

  body.sidebar-collapsed .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    max-height: 48vh;
    overflow: auto;
    z-index: 5;
    padding: 12px;
  }

  body.sidebar-collapsed .sidebar {
    max-height: 74px;
    padding: 12px;
  }

  body.sidebar-collapsed .nav {
    display: none;
  }

  .brand {
    margin-bottom: 12px;
  }

  body.sidebar-collapsed .brand {
    margin-bottom: 0;
    display: flex;
    justify-content: space-between;
  }

  .nav {
    overflow: visible;
    padding-right: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar,
  .topbar-controls,
  .grid-2 {
    grid-template-columns: 1fr;
    display: grid;
  }

  .plate-intake,
  .plate-search,
  .search-result,
  .workbench-form,
  .history-form,
  .stock-history-form,
  .desktop-entry-row,
  .client-summary-grid,
  .action-grid,
  .check-grid,
  .stats,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .row-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .search-result {
    align-items: stretch;
  }

  .result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .workshop-picker,
  .mode-picker {
    min-width: 0;
  }
}
