/* =========================================================
   ORDERS.CSS — вкладка "Заказы": список заказов, покупатели, товары, позиции.
   ========================================================= */

/* =========================================================
   ЗАКАЗЫ
   ========================================================= */
.orders-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.orders-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.orders-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.orders-list { max-height: 480px; overflow-y: auto; }

.order-item, .customer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--bg);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.12s ease;
}
.order-item:hover, .customer-item:hover { background: var(--surface-hover); }
.order-item.active, .customer-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.order-item span:first-child, .customer-item span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.orders-main { flex: 1; min-width: 0; }

.order-header { margin-bottom: 16px; }
.order-name-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  outline: none;
}
.order-name-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.order-meta-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.order-meta-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12.5px;
}
.order-meta-field input[type="text"] {
  width: 76px;
  min-width: 0;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}
.order-meta-field.checkbox-field {
  padding-right: 12px;
}
.order-meta-field.checkbox-field span {
  color: var(--text);
  font-weight: 500;
}

.order-dates-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin: 2px 0 12px;
  padding: 10px 12px;
  background: rgba(37, 99, 235, 0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.order-dates-row label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.order-dates-row input[type="date"] {
  font-size: 13px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 32px;
  background: var(--surface);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
}

.customers-section, .items-section { margin-bottom: 20px; }

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

.customers-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.customers-list .customer-item {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  padding: 6px 6px 6px 14px;
  flex-wrap: wrap;
  row-gap: 4px;
  max-width: 100%;
}
.customers-list .customer-item.active { border-color: var(--accent); }

.customer-add-btn,
.btn-add-centered {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #fff;
  border: 1px solid rgba(37, 99, 235, 0.5);
  border-radius: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 9px 16px;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.16);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.customer-add-btn:hover,
.customer-add-btn:focus-visible,
.btn-add-centered:hover,
.btn-add-centered:focus-visible {
  background: rgba(79, 70, 229, 0.08);
  border-color: rgba(79, 70, 229, 0.45);
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.12);
  color: var(--accent);
  transform: translateY(-1px);
}
.customer-add-btn:active,
.btn-add-centered:active {
  transform: translateY(0);
  box-shadow: 0 6px 14px rgba(79, 70, 229, 0.1);
  color: var(--accent);
}

.editable-name { cursor: pointer; }

.all-customers-product-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}
.all-customers-product-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
}
.all-customers-product-detail {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.all-customers-product-meta {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}
.customer-badge-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  width: 100%;
}
.customer-badge {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  max-width: 100%;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.06);
  color: var(--accent);
  font-size: 11px;
  border: 1px solid rgba(37, 99, 235, 0.12);
  line-height: 1.3;
  min-height: 32px;
}
.customer-badge > span {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.customer-badge.muted {
  color: var(--text-muted);
  background: rgba(148, 163, 184, 0.08);
}

.receiving-breakdown-cell {
  background: var(--bg);
  padding: 8px 10px;
  width: 100%;
  max-width: 100%;
  overflow: visible;
  box-sizing: border-box;
}
.receiving-breakdown-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px 72px minmax(120px, 180px);
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
  box-sizing: border-box;
}
.receiving-breakdown-name,
.receiving-breakdown-sum,
.receiving-breakdown-weight,
.receiving-breakdown-status {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.receiving-breakdown-name {
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.receiving-breakdown-weight {
  width: 78px;
  max-width: 100%;
  font-size: 12px;
  justify-self: center;
}
.receiving-breakdown-sum {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  text-align: right;
}
.receiving-breakdown-status {
  width: 100%;
  min-width: 120px;
  max-width: 100%;
  font-size: 12px;
}

.add-item-bar { padding: 10px; }

.add-item-picker {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 10px;
}
.add-item-picker-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.add-item-picker-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.add-item-picker-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.add-item-options {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.add-item-option {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}
.add-item-option:hover { background: var(--accent-soft); }
.add-item-option-new { color: var(--accent); font-weight: 500; }
.add-item-empty { padding: 10px; color: var(--text-muted); font-size: 12.5px; text-align: center; }

.order-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  /* Минимальная ширина гарантирует, что название товара никогда не
     сжимается до нечитаемого размера — ни на мобильных, ни в модалках.
     Для колонки товара (первый <td> строки) устанавливается напрямую в
     заголовке таблицы (min-width: 180px на <th>). */
  min-width: 120px;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
}
.order-select:focus { border-color: var(--accent); }

/* Первая колонка таблицы заказа (товар) — всегда не уже 180px,
   чтобы название не сворачивалось ни при каком экране. */
.items-section .order-table td:first-child,
.items-section .order-table th:first-child {
  min-width: 180px;
}

.order-input, .weight-input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.order-input:focus, .weight-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.order-total { font-weight: 600; white-space: nowrap; }

.delivery-status-summary {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
}
.delivery-status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid rgba(37, 99, 235, 0.12);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.03);
}
.delivery-status-button {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.delivery-status-panel {
  display: block;
  width: 100%;
  margin-top: 6px;
}
.delivery-status-panel .order-select {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  font-size: 12px;
}

/* Роль user не должна видеть суммы/выручку — колонка скрывается целиком */
.role-restricted .order-total-col,
.role-restricted .order-total { display: none; }

.total-box {
  display: flex;
  justify-content: flex-end;
  padding: 10px 14px;
  font-size: 14px;
}

@media (max-width: 900px) {
  .orders-layout {
    flex-direction: column;
  }

  .orders-sidebar {
    width: 100%;
  }

  .order-dates-row {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .delivery-status-summary {
    justify-content: flex-start;
  }

  .delivery-status-pill {
    min-height: 32px;
    padding: 7px 10px;
    font-size: 11.5px;
    width: 100%;
    justify-content: center;
  }

  .delivery-status-panel {
    display: none;
    margin-top: 6px;
    width: 100%;
  }
  .delivery-status-cell.open .delivery-status-panel {
    display: block;
  }

  .receiving-breakdown-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(64px, 88px);
    align-items: center;
    gap: 4px 6px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 28px;
    padding: 5px 0;
  }
  .receiving-breakdown-name,
  .receiving-breakdown-weight,
  .receiving-breakdown-sum,
  .receiving-breakdown-status {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  .receiving-breakdown-name {
    grid-column: 1;
    font-size: 12px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .receiving-breakdown-weight {
    grid-column: 2;
    width: 100%;
    min-height: 28px;
    height: 28px;
    padding: 4px 6px;
    font-size: 11px;
    justify-self: end;
  }
  .receiving-breakdown-sum,
  .receiving-breakdown-status {
    grid-column: 1 / -1;
    width: 100%;
    font-size: 11px;
    line-height: 1.3;
  }
  .receiving-breakdown-sum {
    text-align: left;
  }
}

