:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --panel: #ffffff;
  --text: #1f2a24;
  --muted: #6b766f;
  --line: #dce3dc;
  --accent: #1f7a5a;
  --accent-dark: #155d44;
  --danger: #b42318;
  --warn: #a15c00;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
h1, h2, p { margin-top: 0; }
.strong-link {
  display: block;
  font-weight: 800;
}
button, .button {
  border: 0;
  background: var(--accent);
  color: #fff;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:hover, .button:hover { background: var(--accent-dark); }
.secondary, .ghost { background: #e5ece7; color: var(--text); }
.secondary:hover, .ghost:hover { background: #d6e1d9; }
.danger-button { background: var(--danger); }
.danger-button:hover { background: #8f1c14; }
.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}
.full { width: 100%; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 40px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
}
textarea { resize: vertical; }
.preserve-lines { white-space: pre-wrap; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

.shell { min-height: 100vh; display: grid; grid-template-columns: 220px 1fr; }
.sidebar {
  background: #24352b;
  color: #fff;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.brand { color: #fff; font-size: 22px; font-weight: 800; }
.sidebar nav { display: grid; gap: 8px; }
.sidebar nav a {
  color: #d9e5dd;
  padding: 10px 12px;
  border-radius: 6px;
}
.sidebar nav a.active, .sidebar nav a:hover { background: rgba(255,255,255,0.12); color: #fff; }
.user-role {
  color: #c8d8cf;
  display: block;
}
.content { padding: 28px; overflow: auto; }
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-header p { color: var(--muted); margin-bottom: 0; }
.alert {
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.alert.success { border-color: #a8d5bd; color: var(--accent-dark); }
.alert.error { border-color: #f2b8b5; color: var(--danger); }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.metrics.compact { margin-bottom: 14px; }
.metrics.compact div { padding: 12px 14px; }
.metrics.compact strong { font-size: 22px; }
.metrics div, .panel, .login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}
.metrics span { color: var(--muted); display: block; margin-bottom: 8px; }
.metrics strong { font-size: 28px; }
.metrics small {
  display: block;
  margin-top: 6px;
}
.section-grid, .detail-grid, .actions-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.7fr);
  gap: 18px;
}
.crm-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.crm-form .wide { grid-column: 1 / -1; }
.danger-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
  border-color: #f2b8b5;
}
.danger-zone h2 { color: var(--danger); }
.danger-zone p { margin-bottom: 0; color: var(--muted); }
.crm-workspace { margin-top: 18px; margin-bottom: 18px; }
.inline-crm-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.inline-crm-form .wide { grid-column: 1 / -1; }
.timeline, .task-list { display: grid; gap: 10px; }
.funnel-steps { display: grid; gap: 8px; }
.funnel-step {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fbf9;
}
.funnel-step small { display: block; color: var(--muted); margin-top: 4px; }
.funnel-message-form { display: flex; gap: 6px; min-width: 260px; }
.funnel-message-form input { min-width: 0; }
.timeline-item, .task-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #f9fbf9;
}
.timeline-meta, .task-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.timeline-meta span { color: var(--muted); font-size: 12px; }
.timeline-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
.inline-delete-form { display: inline; margin-left: 6px; }
.link-button {
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-dark);
  font: inherit;
  text-decoration: underline;
}
.link-button:hover { background: none; }
.danger-link { color: #b42318; }
.timeline-item p { margin: 8px 0 0; }
.task-item small { display: block; margin-top: 5px; }
.task-done { opacity: .65; }
.task-done strong { text-decoration: line-through; }
.empty-state { color: var(--muted); margin: 6px 0; }
.customers-map {
  width: 100%;
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #eef2ef;
}

.map-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 12px;
  align-items: end;
}
.map-legend,
.map-layer-controls,
.map-statuses {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
}
.map-layer-controls {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbf9;
}
.map-layer-controls label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}
.map-layer-controls input {
  width: 17px;
  min-height: 17px;
  margin: 0;
}
.map-legend {
  margin: 2px 0;
  font-size: 13px;
}
.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.map-legend i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, .2);
}
.map-legend-exact {
  background: #2563eb;
}
.map-legend-locality {
  background: #eab308;
}
.map-legend-market {
  background: #dc2626;
}
.map-statuses {
  justify-content: space-between;
}
.map-toolbar label {
  margin: 0;
}
.map-toolbar span {
  color: var(--muted);
  font-size: 13px;
  padding-bottom: 10px;
  white-space: nowrap;
}
.map-route-status {
  max-width: 380px;
  padding: 8px 10px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: rgba(239, 246, 255, .96);
  color: #1e3a8a;
  font-size: 13px;
  box-shadow: 0 6px 18px rgba(16, 24, 40, .12);
}
.map-route-button {
  margin-top: 8px;
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}
.map-list,
.delivery-location-list {
  display: grid;
  gap: 10px;
}
.map-list {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.map-list-item,
.delivery-location-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f9fbf9;
}
.map-list-item {
  color: inherit;
  text-decoration: none;
  display: grid;
  gap: 4px;
}
.map-list-item:hover {
  border-color: var(--accent);
}
.map-list-item[hidden] {
  display: none;
}
.map-list-item span,
.map-list-item small,
.delivery-location-item small {
  color: var(--muted);
}
.leaflet-control-layers {
  border: 1px solid var(--line) !important;
  border-radius: 10px !important;
  box-shadow: 0 8px 22px rgba(16, 24, 40, .14) !important;
  font: 13px Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.leaflet-control-layers-expanded {
  padding: 8px 10px !important;
  background: rgba(255, 255, 255, .96) !important;
}
.leaflet-control-layers-overlays {
  display: grid;
  gap: 4px;
}
.leaflet-control-layers label {
  display: block;
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
}
.leaflet-control-layers label span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.leaflet-control-layers input {
  width: auto;
  min-height: 0;
  margin: 0;
}
.delivery-location-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.delivery-location-item p {
  margin: 4px 0;
}
.merge-panel {
  display: grid;
  grid-template-columns: minmax(260px, .7fr) minmax(320px, 1.3fr);
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
  border-color: #f2b8b5;
}
.merge-panel p { margin-bottom: 0; color: var(--muted); }
.merge-form { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.attention-grid {
  display: grid;
  gap: 18px;
  margin-bottom: 24px;
}
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.section-links {
  display: flex;
  gap: 12px;
}
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); background: #f9fbf9; }
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover { color: var(--accent-dark); text-decoration: underline; }
.column-total {
  display: block;
  margin-top: 5px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: none;
  white-space: nowrap;
}
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}
.select-column { width: 54px; text-align: center; }
.select-column input { width: 18px; height: 18px; }
tr:last-child td { border-bottom: 0; }
small { color: var(--muted); }
.status {
  display: inline-block;
  background: #ecf6f0;
  color: var(--accent-dark);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.status-new { background: #fff7e6; color: #8a4b00; border-color: #f1d49d; }
.status-confirmed { background: #eaf7ef; color: #176344; border-color: #a8d8bc; }
.status-processing { background: #eaf2ff; color: #2457a6; border-color: #b7cdf5; }
.status-done { background: #eef8ee; color: #2e6f32; border-color: #b9ddb9; }
.status-cancelled { background: #fdeceb; color: #a12018; border-color: #efb9b4; }
.order-number {
  display: inline-block;
  font-weight: 800;
  margin-bottom: 5px;
}
.order-detail-link,
.muted-value {
  display: block;
  margin-top: 5px;
  font-size: 13px;
}
.muted-value { color: var(--muted); }
.orders-table td {
  vertical-align: middle;
}
.orders-table td > small,
.orders-table td strong + small,
.orders-table td a + small {
  display: block;
}
.item-lines {
  display: grid;
  gap: 5px;
  min-width: 180px;
}
.item-lines span {
  line-height: 1.3;
}
.row-actions {
  display: grid;
  gap: 8px;
  min-width: 240px;
}
.quick-status {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.quick-status form {
  margin: 0;
}
.status-button {
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid currentColor;
  font-size: 12px;
}
.admin-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) minmax(160px, 1fr) auto;
  gap: 12px;
  align-items: end;
}
.inline-form {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.audit-panel {
  margin-top: 18px;
}
.nested-table {
  border: 0;
}
.list { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.list-row { display: flex; justify-content: space-between; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.dashboard-product {
  align-items: center;
}
.dashboard-product span:first-child {
  display: block;
  font-weight: 700;
}
.dashboard-product.warn {
  background: #fffaf0;
}
.dashboard-product.danger {
  background: #fff7f6;
}
.attention-panel {
  border-left: 6px solid var(--warn);
}
.attention-list {
  display: grid;
  gap: 8px;
}
.attention-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}
.attention-row strong,
.attention-row small {
  display: block;
}
.attention-row.warn {
  border-color: #f1d49d;
  background: #fffaf0;
}
.attention-row.danger {
  border-color: #efb9b4;
  background: #fff7f6;
}
.compact-empty {
  padding: 16px;
}
.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px 160px 160px 160px auto auto;
  gap: 10px;
  margin-bottom: 16px;
  align-items: end;
}
.filter-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.shipments-filter {
  grid-template-columns: 220px auto auto auto;
  justify-content: start;
}
.customers-filter {
  grid-template-columns: minmax(240px, 1fr) 180px auto auto;
  justify-content: start;
}
.stack { display: grid; gap: 12px; }
.login-panel { max-width: 420px; margin: 12vh auto; }
dl { display: grid; grid-template-columns: 130px 1fr; gap: 10px 14px; }
dt { color: var(--muted); }
dd { margin: 0; }
.total { text-align: right; margin: 16px 0 0; }
.inline-status {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto;
  gap: 6px;
  min-width: 190px;
}
.inline-status select,
.inline-status button {
  min-height: 34px;
}
.inline-status button {
  padding: 0 10px;
}
.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px;
}
.embedded {
  border: 0;
  border-radius: 0;
}
.crm-panel {
  background: #f7fcf9;
  border-color: #b9ddb9;
}
.crm-notes {
  display: grid;
  gap: 10px;
}
.crm-notes p {
  margin: 0;
  line-height: 1.45;
}
.status-actions,
.message-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.order-edit-panel {
  margin: 18px 0;
}
.order-edit-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
  align-items: end;
}
.edit-items {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.edit-items h3 {
  grid-column: 1 / -1;
  margin: 0;
}
.header-actions,
.shipment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}
.shipment-groups {
  display: grid;
  gap: 12px;
}
.shipment-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.shipment-group h2 {
  margin-bottom: 4px;
}
.shipment-group p {
  margin: 0;
  color: var(--muted);
}
.add-product { margin-bottom: 18px; }
.product-list { display: grid; gap: 12px; }
.product-row {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.4fr) auto;
  gap: 14px;
  align-items: end;
  background: #f7fcf9;
  border: 1px solid #b9ddb9;
  border-left: 6px solid #1f7a5a;
  border-radius: 8px;
  padding: 16px;
}
.product-row.is-disabled {
  background: #fff7f6;
  border-color: #efb9b4;
  border-left-color: #b42318;
}
.product-row.is-empty {
  border-color: #efb9b4;
  border-left-color: #b42318;
}
.product-row.is-low {
  border-color: #f1d49d;
  border-left-color: #a15c00;
}
.product-row h2 { font-size: 18px; margin-bottom: 4px; }
.product-row p { color: var(--muted); margin: 0; }
.product-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.product-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
}
.product-facts div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #f9fbf9;
}
.product-facts span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}
.product-facts strong {
  font-size: 14px;
}
.product-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.product-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 10px;
  align-items: end;
}
.product-form.create {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
}
.product-form button { align-self: end; }
.product-summary { display: grid; gap: 10px; align-self: start; }
.media-preview {
  display: grid;
  gap: 6px;
  max-width: 320px;
}
.media-preview img,
.media-preview video {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 180px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef2ef;
}
.media-preview small {
  overflow-wrap: anywhere;
}
.empty-media {
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 12px;
  color: var(--muted);
  background: #f9fbf9;
}
.checkbox {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--text);
}
.checkbox input {
  width: 18px;
  min-height: 18px;
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .metrics, .section-grid, .detail-grid, .actions-grid, .filters, .shipments-filter, .customers-filter, .product-row, .product-form, .product-form.create, .admin-form, .inline-form, .order-edit-form, .crm-form {
    grid-template-columns: 1fr;
  }
  .map-toolbar {
    grid-template-columns: 1fr;
  }
  .map-toolbar span {
    padding-bottom: 0;
    white-space: normal;
  }
  .shipment-group,
  .attention-row,
  .danger-zone,
  .delivery-location-item,
  .timeline-meta,
  .task-item,
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }
  .inline-crm-form, .merge-panel, .merge-form { grid-template-columns: 1fr; }
  .header-actions,
  .shipment-actions {
    justify-content: stretch;
  }
  .content { padding: 18px; }
  .orders-table,
  .orders-table thead,
  .orders-table tbody,
  .orders-table tr,
  .orders-table th,
  .orders-table td {
    display: block;
  }
  .orders-table thead {
    display: none;
  }
  .orders-table tr {
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }
  .orders-table td {
    border-bottom: 0;
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 10px;
    padding: 8px 0;
  }
  .orders-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
  }
  .row-actions,
  .inline-status {
    min-width: 0;
  }
  .product-heading {
    align-items: stretch;
  }
  .product-facts {
    grid-template-columns: 1fr;
  }
  .media-preview {
    max-width: none;
  }
}

.print-page {
  background: #fff;
  color: #111;
  padding: 18px;
}
.print-header {
  margin-bottom: 16px;
}
.print-header h1 {
  margin-bottom: 4px;
}
.print-table {
  font-size: 12px;
}
.print-table th,
.print-table td {
  padding: 7px;
  border: 1px solid #999;
}

@media print {
  body { background: #fff; }
  .print-page { padding: 0; }
  .print-table th,
  .print-table td {
    border-color: #666;
  }
}
