:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --panel: #ffffff;
  --ink: #1d252c;
  --muted: #69727c;
  --line: #d9dedf;
  --green: #24745b;
  --teal: #0f6b78;
  --gold: #a66f16;
  --red: #b84732;
  --blue: #315f9e;
  --shadow: 0 18px 45px rgba(31, 42, 48, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  background: #142326;
  color: #f7faf8;
  padding: 24px 18px;
  min-height: 100vh;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: #d99b3d;
  color: #142326;
  font-weight: 800;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p {
  color: #b8c7c5;
  margin-top: 3px;
}

.user-switcher {
  display: grid;
  gap: 12px;
}

.user-switcher label {
  display: grid;
  gap: 6px;
  color: #b8c7c5;
  font-weight: 700;
}

.user-switcher select {
  background: #203438;
  border-color: rgba(255, 255, 255, 0.16);
  color: #f7faf8;
}

.user-card {
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #f7faf8;
  padding: 12px;
}

.user-card span,
.user-card small {
  color: #b8c7c5;
}

.readonly-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 28px;
  border: 1px solid rgba(217, 155, 61, 0.45);
  border-radius: 999px;
  padding: 4px 9px;
  background: rgba(217, 155, 61, 0.14);
  color: #ffd18b;
  font-size: 12px;
  font-weight: 800;
}

.auth-form {
  display: grid;
  gap: 8px;
}

.auth-form input {
  width: 100%;
  background: #203438;
  border-color: rgba(255, 255, 255, 0.16);
  color: #f7faf8;
}

.auth-message {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: #b8c7c5;
  line-height: 1.35;
  font-size: 13px;
}

.auth-message.error {
  border-color: rgba(255, 145, 122, 0.42);
  background: rgba(184, 71, 50, 0.16);
  color: #ffd3ca;
}

.workspace {
  padding: 28px;
  min-width: 0;
}

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

.eyebrow {
  color: var(--teal);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
}

.topbar h2 {
  margin-top: 4px;
  font-size: 30px;
}

.page-message {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcfc;
  color: var(--ink);
  font-weight: 700;
}

.page-message.success {
  border-color: rgba(36, 116, 91, 0.28);
  background: #edf7f3;
  color: var(--green);
}

.page-message.error {
  border-color: rgba(184, 71, 50, 0.32);
  background: #fff8f6;
  color: var(--red);
}

.topbar-actions,
.dialog-actions,
.action-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.action-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 14px;
  font-weight: 700;
}

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

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

a.ghost-button {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.action-button.approve {
  background: var(--teal);
  color: #fff;
}

.action-button.reject {
  color: var(--red);
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 24px;
  background: #fff;
  border-color: var(--line);
}

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

.metrics article,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 18px;
}

.metrics span {
  font-size: 28px;
  font-weight: 800;
}

.metrics p {
  color: var(--muted);
  margin-top: 3px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.78fr) minmax(520px, 1.22fr);
  gap: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

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

.panel-heading h3 {
  font-size: 18px;
}

.list-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #edf4ff;
  color: var(--blue);
  font-weight: 800;
}

.queue-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 12px 12px 0;
}

.queue-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  min-height: 34px;
  padding: 0 11px;
  font-weight: 800;
  white-space: nowrap;
}

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

.list-filters {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}

.filter-row.filter-row-sort {
  grid-template-columns: 1fr;
  margin-top: 6px;
}

.quick-toggle {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  min-height: 42px;
  padding: 0 12px;
  font-weight: 850;
  white-space: nowrap;
}

.quick-toggle.active {
  background: #fff3dc;
  border-color: rgba(165, 103, 15, 0.35);
  color: var(--gold);
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px;
  min-width: 0;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.request-list {
  display: grid;
  gap: 8px;
  padding: 12px;
  max-height: calc(100vh - 265px);
  overflow: auto;
}

.request-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 13px;
  text-align: left;
}

.request-card.active {
  border-color: var(--teal);
  outline: 2px solid rgba(15, 107, 120, 0.18);
}

.request-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.request-card h4 {
  font-size: 16px;
  margin-top: 2px;
}

.request-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.35;
  font-size: 13px;
}

.request-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: #eef2f1;
  color: var(--muted);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.tag.warning {
  background: #fff3dc;
  color: var(--gold);
}

.tag.danger {
  background: #ffe8e2;
  color: var(--red);
}

.tag.blue {
  background: #edf4ff;
  color: var(--blue);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #e9f2ef;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.warning {
  background: #fff3dc;
  color: var(--gold);
}

.status-pill.danger {
  background: #ffe8e2;
  color: var(--red);
}

.status-pill.info {
  background: #e1ecff;
  color: #1f4ea8;
}

.status-pill.done {
  background: #eef0f3;
  color: #5a6573;
}

.status-pill.draft {
  background: #f3f0e8;
  color: #6b6358;
}

.status-pill.approval {
  background: #ecf0f8;
  color: #3a4f7a;
}

.status-pill.purchase {
  background: #e6f0eb;
  color: #2a6b50;
}

.status-pill.review {
  background: #efe7f7;
  color: #5d3a8a;
}

.inline-hint {
  margin: 8px 0 4px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff7e0;
  color: #6b531c;
  font-size: 12px;
  line-height: 1.4;
}

@media (max-width: 1100px) {
  .mobile-detail-bar:not(.hidden) {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 12px 12px 0;
  }
}

.details-panel {
  position: sticky;
  top: 28px;
  max-height: calc(100vh - 56px);
  overflow: auto;
  min-height: 560px;
}

.mobile-detail-bar {
  display: none;
}

.mobile-detail-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.mobile-detail-meta strong,
.mobile-detail-meta span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.mobile-back-button {
  min-height: 36px;
  padding: 0 10px;
}

.hidden-mobile-panel {
  display: none !important;
}

.empty-state {
  display: grid;
  place-content: center;
  min-height: 560px;
  padding: 24px;
  text-align: center;
}

.empty-state p {
  color: var(--muted);
  margin-top: 8px;
}

.request-list .empty-state {
  min-height: 180px;
}

.details {
  padding: 16px;
}

.hidden {
  display: none;
}

/* === Auth lock: closed system before signedIn ===
   While body.is-locked is set (authState !== 'signedIn'), all data
   containers are hidden — only the sidebar with the login form and
   the topbar title remain visible. */
body.is-locked .metrics,
body.is-locked .content-grid,
body.is-locked .topbar-actions,
body.is-locked .mobile-detail-bar {
  display: none !important;
}

.details-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 14px;
}

.details-header h3 {
  margin-top: 4px;
  font-size: 22px;
  line-height: 1.15;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.info-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfc;
}

.info-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
  line-height: 1.2;
}

.info-grid strong {
  overflow-wrap: anywhere;
  font-size: 17px;
  line-height: 1.2;
}

.route-wrap,
.items-wrap,
.deliveries-wrap,
.comments-wrap,
.history-wrap {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.route-wrap h4,
.items-wrap h4,
.deliveries-wrap h4,
.comments-wrap h4,
.history-wrap h4 {
  margin-bottom: 8px;
  font-size: 18px;
  line-height: 1.2;
}

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

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

.route-step {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
}

.route-step.done {
  border-color: rgba(36, 116, 91, 0.4);
  background: #edf7f3;
  color: var(--green);
}

.route-step.current {
  border-color: rgba(49, 95, 158, 0.45);
  background: #edf4ff;
  color: var(--blue);
  font-weight: 800;
}

.route-step.parallel-active {
  border-style: dashed;
  background: #f4ebff;
  color: #5d3a8a;
  border-color: rgba(93, 58, 138, 0.45);
}

.items-table {
  display: grid;
  gap: 10px;
}

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

.item-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.item-card-title strong {
  font-size: 18px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.item-card-unit {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  background: #f7faf8;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.item-card-grid {
  display: grid;
  gap: 8px;
}

.item-card-grid.commercial-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.item-card-grid.basic-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.item-row input,
.item-row select {
  width: 100%;
  padding: 8px;
}

.item-stat {
  display: grid;
  gap: 5px;
  align-items: start;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fcfdfd;
}

.item-cell span {
  color: var(--muted);
  font-size: 11px;
  display: block;
  line-height: 1.2;
}

.item-cell strong,
.item-cell input,
.item-cell select {
  min-width: 0;
  overflow-wrap: anywhere;
}

.item-stat strong {
  font-size: 16px;
  line-height: 1.2;
}

.item-stat-price {
  gap: 8px;
}

.item-stat-supplier strong {
  font-size: 15px;
  line-height: 1.2;
}

.price-editor {
  display: grid;
  gap: 8px;
}

.mini-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mini-checkbox input {
  width: auto;
  margin: 0;
}

.receive-cell {
  display: grid;
  gap: 6px;
}

.receive-cell small {
  display: block;
  color: var(--muted);
  margin-top: 0;
}

.price-error {
  border-color: var(--red) !important;
  background: #fff8f6;
}

.items-total {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.items-total span {
  color: var(--muted);
}

.items-total strong {
  font-size: 18px;
}

.inline-error {
  margin-top: 10px;
  border: 1px solid rgba(184, 71, 50, 0.35);
  border-radius: 8px;
  padding: 10px;
  background: #fff8f6;
  color: var(--red);
  font-weight: 700;
}

.buyer-dialog-card {
  width: 100%;
  max-height: calc(100dvh - 48px);
  overflow: auto;
}

#buyerDialog {
  width: min(1040px, calc(100vw - 48px));
  max-height: calc(100dvh - 48px);
}

.buyer-lines {
  display: grid;
  gap: 12px;
}

.buyer-line {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfc;
}

.buyer-line-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.buyer-line-head strong {
  font-size: 16px;
}

.buyer-line-head span {
  color: var(--muted);
  font-size: 13px;
}

.buyer-dialog-card .dialog-heading h3 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.buyer-line-fields {
  display: grid;
  grid-template-columns: minmax(170px, 0.7fr) minmax(320px, 1fr) minmax(120px, 0.35fr);
  gap: 12px;
  align-items: end;
}

.buyer-field {
  display: grid;
  gap: 6px;
  font-weight: 700;
  color: var(--ink);
}

.buyer-field > label,
.buyer-vat-row > span {
  color: var(--ink);
  font-weight: 800;
}

.buyer-vat-row {
  display: grid;
  gap: 6px;
  align-content: end;
}

.buyer-vat-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.buyer-vat-toggle input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
}

.contractor-search {
  position: relative;
}

.contractor-search input[type="text"] {
  width: 100%;
}

.contractor-suggestions {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  display: grid;
  gap: 2px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: #fff;
  box-shadow: 0 14px 30px rgba(31, 42, 48, 0.16);
}

.contractor-suggestions.hidden {
  display: none;
}

.contractor-suggestions button {
  border: 0;
  border-radius: 6px;
  background: #fff;
  padding: 10px 12px;
  color: var(--ink);
  text-align: left;
  font-weight: 750;
}

.contractor-suggestions button:hover,
.contractor-suggestions button:focus-visible {
  background: #eef5f2;
}

.contractor-empty {
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 700;
}

.delivery-dialog-card {
  width: 100%;
  max-height: calc(100dvh - 48px);
  overflow: auto;
}

#deliveryDialog {
  width: min(920px, calc(100vw - 48px));
  max-height: calc(100dvh - 48px);
}

.delivery-form-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 0.8fr) minmax(150px, 0.7fr);
  gap: 12px;
  margin-bottom: 12px;
}

.camera-capture-block {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.camera-button {
  min-height: 44px;
}

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

.delivery-photo-card {
  margin-bottom: 10px;
}

.delivery-photo-card.compact {
  align-items: start;
}

.delivery-photo-card.compact img {
  width: 60px;
  height: 60px;
}

.delivery-photo-info {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.delivery-photo-preview img,
.delivery-photo-card img {
  width: 74px;
  height: 74px;
  object-fit: cover;
  border-radius: 7px;
  background: #eef2f1;
}

.delivery-photo-preview strong,
.delivery-photo-card strong {
  display: block;
  line-height: 1.2;
}

.delivery-photo-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.delivery-photo-filename {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.delivery-photo-preview span,
.delivery-photo-card a,
.delivery-photo-empty {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.delivery-photo-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: #fff;
}

.delivery-form-grid label,
.delivery-form-line label {
  display: grid;
  gap: 6px;
  color: var(--ink);
  font-weight: 800;
}

.delivery-form-lines {
  display: grid;
  gap: 12px;
}

.delivery-form-line {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfc;
}

.delivery-form-line-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.delivery-form-line-head strong {
  font-size: 18px;
  line-height: 1.2;
}

.delivery-form-line-head span {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

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

/* Read-only summary, не похоже на input — без рамки и без белого фона. */
.delivery-form-stats div {
  padding: 0;
  background: transparent;
  border: none;
}

.delivery-form-stats span {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.delivery-form-stats strong {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.delivery-receive-field {
  max-width: 320px;
}

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

.delivery-list.inner {
  margin-top: 10px;
}

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

.delivery-work-block + .delivery-work-block {
  margin-top: 10px;
}

.delivery-work-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.delivery-work-head h5 {
  margin: 0 0 4px;
  font-size: 16px;
}

.delivery-work-head p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.delivery-work-status {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
  font-size: 14px;
}

.delivery-work-status.success {
  border-color: rgba(36, 116, 91, 0.28);
  background: #edf7f3;
  color: var(--green);
}

.delivery-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfc;
}

.delivery-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.delivery-title {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.delivery-title strong {
  font-size: 16px;
  line-height: 1.2;
}

.delivery-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.accounting-delivery-card .delivery-meta {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.delivery-meta.readonly div {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.delivery-meta.readonly span,
.accounting-status-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.delivery-meta.readonly strong,
.accounting-status-grid strong {
  font-size: 13px;
  line-height: 1.2;
}

.accounting-status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.accounting-status-grid div {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.delivery-meta label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.delivery-items {
  display: grid;
  gap: 6px;
}

.delivery-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.delivery-item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px minmax(150px, 0.8fr) 190px;
  gap: 8px;
  align-items: center;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.delivery-item-row.supplier-hidden {
  grid-template-columns: minmax(0, 1fr) 150px 190px;
}

.delivery-item-row label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.delivery-item-row em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.quantity-control {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.quantity-control strong {
  color: var(--muted);
  font-size: 12px;
}

.delivery-row-over {
  background: #fff0ec;
  border: 1px solid rgba(184, 71, 50, 0.35);
}

.delivery-over {
  border-color: var(--red) !important;
  background: #fff8f6;
  color: var(--red);
  font-weight: 800;
}

.compact-button {
  min-height: 32px;
}

.empty-note {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--muted);
  background: #fbfcfc;
  font-size: 14px;
  line-height: 1.35;
}

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

.timeline-entry,
.comment-entry {
  border: 0;
  border-bottom: 1px solid rgba(205, 214, 218, 0.65);
  border-radius: 0;
  padding: 8px 0;
  background: transparent;
}

.timeline-entry.comment {
  border-left: 0;
}

.timeline-entry.event {
  border-left: 0;
}

.timeline-entry.important {
  background: transparent;
}

.timeline-entry.muted {
  opacity: 0.68;
}

.timeline-entry.empty {
  border-bottom: 0;
  color: var(--muted);
}

.timeline-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.timeline-head strong {
  font-size: 14px;
  line-height: 1.25;
}

.timeline-head span,
.timeline-meta,
.comment-entry span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.timeline-meta {
  margin-top: 4px;
}

.timeline-entry p,
.comment-entry p {
  margin-top: 5px;
  font-size: 14px;
  line-height: 1.35;
}

.timeline-note {
  border-left: 2px solid var(--line);
  padding-left: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.timeline-note span {
  color: var(--ink);
  font-weight: 800;
}

.comment-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}

.delivery-card-overage {
  border-color: rgba(184, 71, 50, 0.42);
  background: #fff8f6;
}

.delivery-volume-list {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.delivery-volume-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: #fff;
}

.delivery-volume-row span {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.delivery-volume-row strong {
  flex: 0 0 auto;
  font-size: 14px;
  line-height: 1.2;
}

.delivery-volume-row.danger {
  border-color: rgba(184, 71, 50, 0.35);
  background: #fff2ee;
}

.delivery-status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.mini-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 3px 8px;
  font-size: 12px;
  line-height: 1.2;
}

.mini-status b {
  color: var(--ink);
  margin-right: 4px;
}

.comment-form textarea {
  min-height: 54px;
  padding: 10px 12px;
  font-size: 15px;
  line-height: 1.35;
}

.action-bar {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 0 0 16px;
  padding: 14px 0;
  align-items: end;
}

.action-field {
  display: grid;
  gap: 6px;
  min-width: min(260px, 100%);
  color: var(--muted);
  font-weight: 700;
}

.action-error {
  flex-basis: 100%;
}

.view-status {
  display: grid;
  gap: 8px;
}

.view-status p {
  color: var(--muted);
  margin: 0;
}

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

.history-entry {
  border-left: 3px solid var(--teal);
  padding-left: 10px;
  color: var(--muted);
}

dialog {
  border: none;
  border-radius: 8px;
  padding: 0;
  width: min(720px, calc(100vw - 28px));
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(20, 35, 38, 0.45);
}

.dialog-card {
  padding: 18px;
}

.confirm-card {
  display: grid;
  gap: 0;
  overflow: hidden;
  background: #fff;
}

.confirm-accent {
  min-height: 12px;
  background: var(--teal);
}

.confirm-body {
  display: grid;
  gap: 12px;
  padding: 20px 18px 14px;
}

.confirm-text {
  color: var(--ink);
  line-height: 1.45;
  font-size: 18px;
  font-weight: 700;
}

.confirm-meta {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  background: #fbfcfc;
}

.confirm-actions {
  padding: 0 18px 18px;
}

#draftConfirmDialog[data-variant="teal"] .confirm-accent {
  background: linear-gradient(90deg, #0f6b78, #2e8f84);
}

#draftConfirmDialog[data-variant="amber"] .confirm-accent {
  background: linear-gradient(90deg, #a66f16, #d99b3d);
}

#draftConfirmDialog[data-variant="blue"] .confirm-accent {
  background: linear-gradient(90deg, #315f9e, #5a84c0);
}

#draftConfirmDialog[data-variant="clay"] .confirm-accent {
  background: linear-gradient(90deg, #9d4f34, #c97855);
}

#draftConfirmDialog[data-variant="teal"] .primary-button {
  background: #0f6b78;
}

#draftConfirmDialog[data-variant="amber"] .primary-button {
  background: #b47a1c;
}

#draftConfirmDialog[data-variant="blue"] .primary-button {
  background: #315f9e;
}

#draftConfirmDialog[data-variant="clay"] .primary-button {
  background: #9d4f34;
}

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

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

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

.form-grid .checkbox-label {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--ink);
  padding-top: 24px;
}

.checkbox-label input {
  width: auto;
}

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

.materials-editor {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 16px;
}

.materials-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.add-material {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-size: 26px;
  line-height: 1;
}

.material-lines {
  display: grid;
  gap: 10px;
}

.material-line {
  display: grid;
  grid-template-columns: minmax(160px, 1.5fr) minmax(90px, 0.7fr) minmax(100px, 0.8fr) 40px;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.material-line label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.remove-material {
  color: var(--red);
}

.dialog-actions {
  justify-content: end;
  margin-top: 16px;
}

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

  .sidebar {
    position: static;
    min-height: auto;
  }

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

  .details-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 760px) {
  body {
    background: #f6f4ef;
  }

  .app-shell {
    display: block;
  }

  .workspace,
  .sidebar {
    padding: 12px;
  }

  .sidebar {
    position: static;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .brand {
    margin-bottom: 10px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .brand h1 {
    font-size: 18px;
  }

  .brand p {
    display: none;
  }

  .user-switcher {
    gap: 8px;
  }

  .user-switcher label {
    font-size: 12px;
    gap: 4px;
  }

  .user-switcher select {
    min-height: 42px;
  }

  .user-card {
    display: block;
    padding: 8px 10px;
    line-height: 1.3;
  }

  .user-card strong,
  .user-card span {
    display: inline;
  }

  .user-card span::before {
    content: " · ";
    color: #b8c7c5;
  }

  .user-card small {
    display: block;
    margin-top: 2px;
  }

  .workspace {
    display: grid;
    gap: 12px;
  }

  .topbar,
  .details-header {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 0;
  }

  .topbar h2 {
    font-size: 22px;
    line-height: 1.15;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .topbar-actions button,
  .dialog-actions button,
  .action-bar button {
    width: 100%;
  }

  .primary-button,
  .ghost-button,
  .action-button,
  .icon-button {
    min-height: 44px;
  }

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

  .metrics article {
    padding: 12px;
    box-shadow: none;
  }

  .metrics span {
    font-size: 22px;
  }

  .metrics p {
    font-size: 12px;
  }

  .content-grid {
    display: grid;
    gap: 12px;
  }

  .content-grid.layout--mobile-list {
    grid-template-columns: 1fr;
  }

  .content-grid.layout--mobile-detail {
    grid-template-columns: 1fr;
  }

  .panel {
    box-shadow: none;
  }

  .panel-heading {
    padding: 12px;
  }

  .queue-tabs {
    padding: 10px 10px 8px;
    background: #fff;
    border-bottom: 1px solid var(--line);
  }

  .queue-tab {
    min-height: 38px;
    padding: 0 12px;
  }

  .list-filters {
    padding: 10px;
  }

  .filter-row,
  .comment-form,
  .delivery-meta,
  .form-grid,
  .buyer-line-fields {
    grid-template-columns: 1fr;
  }

  .request-list {
    max-height: none;
    padding: 10px;
  }

  .request-card {
    padding: 12px;
  }

  .request-card-top {
    gap: 8px;
  }

  .request-card-top .status-pill {
    max-width: 42%;
    white-space: normal;
    justify-content: center;
    text-align: center;
  }

  .request-card h4 {
    font-size: 15px;
    line-height: 1.25;
  }

  .request-meta {
    font-size: 12px;
  }

  .details-panel {
    min-height: auto;
  }

  .content-grid.layout--mobile-detail .details-panel {
    display: block;
  }

  .mobile-detail-bar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 12px 12px 0;
  }

  .mobile-detail-meta strong {
    font-size: 13px;
    line-height: 1.2;
  }

  .mobile-detail-meta span {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.2;
  }

  .details {
    padding: 10px;
  }

  .details-header h3 {
    font-size: 20px;
    line-height: 1.16;
  }

  .details-header .status-pill {
    justify-content: center;
    white-space: normal;
    text-align: center;
  }

  .info-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 10px;
  }

  .info-grid div {
    padding: 9px;
  }

  .info-grid strong {
    font-size: 15px;
  }

  .action-bar {
    position: sticky;
    bottom: 0;
    z-index: 12;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 0 -12px 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 -10px 24px rgba(31, 42, 48, 0.12);
  }

  .action-bar .status-pill {
    justify-content: center;
    white-space: normal;
    text-align: center;
  }

  .route-wrap,
  .items-wrap,
  .deliveries-wrap,
  .comments-wrap,
  .history-wrap {
    padding-top: 12px;
    margin-top: 12px;
  }

  .route {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
  }

  .route-step {
    flex: 0 0 auto;
    white-space: nowrap;
    scroll-snap-align: start;
  }

  .item-row {
    padding: 10px;
    gap: 8px;
  }

  .item-card-head {
    align-items: center;
  }

  .item-card-title strong {
    font-size: 17px;
    line-height: 1.18;
  }

  .item-card-grid.commercial-grid,
  .item-card-grid.basic-grid {
    grid-template-columns: 1fr;
  }

  .item-stat {
    padding: 9px;
  }

  .item-cell span {
    font-size: 11px;
    line-height: 1.2;
    text-transform: uppercase;
  }

  .item-stat strong,
  .item-stat-supplier strong,
  .item-cell input,
  .item-cell select {
    font-size: 15px;
    line-height: 1.22;
  }

  .price-editor {
    gap: 6px;
  }

  .items-total {
    align-items: stretch;
    flex-direction: column;
    gap: 4px;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .camera-capture-block,
  .delivery-work-head,
  .delivery-meta,
  .accounting-status-grid {
    grid-template-columns: 1fr;
  }

  .delivery-work-head {
    display: grid;
  }

  .delivery-photo-preview,
  .delivery-photo-card {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .delivery-photo-preview img,
  .delivery-photo-card img {
    width: 64px;
    height: 64px;
  }

  .delivery-card {
    padding: 9px;
  }

  .delivery-card-head {
    align-items: stretch;
    flex-direction: column;
  }

  .delivery-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .delivery-item-row {
    grid-template-columns: 1fr;
    gap: 6px;
    border: 1px solid var(--line);
    background: #fff;
    padding: 8px;
  }

  .delivery-volume-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .delivery-item-row em {
    font-size: 12px;
  }

  .quantity-control {
    grid-template-columns: minmax(0, 1fr) 48px;
  }

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

  .comment-form {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .comment-form textarea {
    min-height: 52px;
    font-size: 14px;
  }

  .comment-form button {
    width: 100%;
    min-height: 42px;
  }

  .timeline-entry,
  .comment-entry {
    padding: 8px 0;
  }

  .timeline-head strong {
    font-size: 14px;
  }

  .timeline-entry p,
  .comment-entry p {
    font-size: 14px;
  }

  .material-line {
    grid-template-columns: 1fr;
  }

  dialog {
    width: 100vw;
    max-width: none;
    max-height: 100dvh;
    border-radius: 0;
  }

  #buyerDialog {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: 8px;
  }

  #deliveryDialog {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: 8px;
  }

  .dialog-card {
    max-height: 100dvh;
    overflow: auto;
    padding: 14px;
  }

  #buyerDialog .dialog-card {
    max-height: calc(100dvh - 16px);
    padding: 12px;
  }

  #deliveryDialog .dialog-card {
    max-height: calc(100dvh - 16px);
    padding: 12px;
  }

  .buyer-dialog-card .dialog-heading {
    align-items: flex-start;
    gap: 10px;
  }

  .delivery-dialog-card .dialog-heading {
    align-items: flex-start;
    gap: 10px;
  }

  .buyer-dialog-card .dialog-heading h3 {
    font-size: 22px;
    line-height: 1.15;
  }

  .delivery-dialog-card .dialog-heading h3 {
    font-size: 22px;
    line-height: 1.15;
  }

  .buyer-line {
    padding: 12px;
  }

  .buyer-line-fields {
    gap: 10px;
  }

  .buyer-vat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .buyer-vat-toggle {
    min-width: 132px;
    justify-content: center;
  }

  .contractor-suggestions {
    position: static;
    margin-top: 6px;
    max-height: 180px;
  }

  .delivery-form-grid,
  .delivery-form-stats {
    grid-template-columns: 1fr;
  }

  .delivery-form-line {
    gap: 10px;
  }

  .delivery-receive-field {
    max-width: none;
  }

  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

@media (max-width: 360px) {
  .topbar-actions,
  .metrics,
  .info-grid,
  .compact-values {
    grid-template-columns: 1fr;
  }

  .request-card-top {
    align-items: stretch;
    flex-direction: column;
  }

  .request-card-top .status-pill {
    max-width: none;
  }
}
