/* MZM Lots — страница портфеля. Адаптивна для desktop и mobile. */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #1f2328;
  background: #f6f8fa;
  min-height: 100vh;
}

.topbar {
  background: #ffffff;
  border-bottom: 1px solid #d0d7de;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.count {
  color: #6e7681;
  font-size: 13px;
}

select, button {
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #d0d7de;
  background: #ffffff;
  cursor: pointer;
}

button.btn-secondary:hover {
  background: #f3f4f6;
}

main {
  padding: 16px 20px 80px;
  margin: 0 auto;
}

.status-bar {
  font-size: 13px;
  color: #6e7681;
  margin-bottom: 12px;
  min-height: 18px;
}

.region-tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 12px 0;
  border-bottom: 1px solid #d0d7de;
}
.region-tab {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: #6e7681;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.region-tab:hover { color: #1f2328; }
.region-tab.active {
  color: #1f2328;
  border-bottom-color: #0969da;
}
.region-tab-count {
  font-size: 12px;
  color: #8b949e;
  margin-left: 4px;
}
.region-tab.active .region-tab-count { color: #0969da; }

.empty {
  background: #ffffff;
  border: 1px dashed #d0d7de;
  border-radius: 8px;
  padding: 40px;
  text-align: center;
  color: #6e7681;
}

.empty p { margin: 6px 0; }
.empty .hint { font-size: 13px; }

.lots-table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.lots-table thead {
  background: #f6f8fa;
  border-bottom: 1px solid #d0d7de;
}

.lots-table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 12px;
  color: #6e7681;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.lots-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #eaeef2;
  vertical-align: top;
}

.lots-table tbody tr:hover { background: #f6f8fa; }
.lots-table tbody tr:last-child td { border-bottom: none; }

.car-info { min-width: 180px; }
.car-info .make-model { font-weight: 600; }
.car-info .vin { font-size: 11px; color: #6e7681; font-family: SFMono-Regular, Menlo, monospace; }
.car-info .drom-line {
  font-size: 12px;
  color: #1f6e30;
  margin-top: 2px;
  font-weight: 500;
}
.car-info .drom-count { color: #6e7681; font-weight: 400; font-size: 11px; }

.price { white-space: nowrap; font-variant-numeric: tabular-nums; }

.delta { font-weight: 600; white-space: nowrap; }
.delta.good { color: #155724; }
.delta.warn { color: #856404; }
.delta.bad  { color: #721c24; }

.reduction-date {
  white-space: normal;
  font-size: 13px;
  min-width: 80px;
  max-width: 110px;
  line-height: 1.3;
}
.reduction-date .redu-date { font-weight: 500; }
.reduction-date .redu-sub { font-size: 11px; color: #6e7681; }
.reduction-date.reduction-soon .redu-sub { color: #c84a31; font-weight: 600; }
.reduction-soon { color: #c84a31; font-weight: 600; }
.reduction-today { background: #fff3cd; padding: 2px 6px; border-radius: 4px; }

.editable {
  padding: 4px 6px;
  border-radius: 4px;
  cursor: text;
  min-height: 22px;
  min-width: 100px;
  word-break: break-word;
}
.editable:hover { background: #eaeef2; }
.editable:focus { background: #fffbea; outline: 2px solid #ffe28a; }
.editable.empty::before { content: "—"; color: #c0c4ca; }

.mileage-cell {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 90px;
}

.target-cell {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 100px;
  color: #0c5460;
  font-weight: 500;
}

/* Заметки — пошире */
.lots-table td.editable[data-field="notes"] {
  min-width: 260px;
  max-width: 340px;
  white-space: pre-wrap;
}

.editable-multiline {
  white-space: pre-wrap;
  min-width: 200px;
  max-width: 280px;
  font-size: 13px;
  line-height: 1.4;
}

.status-cell { min-width: 160px; max-width: 220px; }
.status-cell .editable { white-space: pre-wrap; font-size: 13px; }

.status-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 10px;
  background: #eaeef2;
  color: #6e7681;
}
.status-active     { background: #d4edda; color: #155724; }
.status-bid_placed { background: #cce5ff; color: #003d80; }
.status-won        { background: #d1ecf1; color: #0c5460; }
.status-lost       { background: #f8d7da; color: #721c24; }
.status-archived   { background: #e9ecef; color: #495057; }

button.status-badge {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
}
button.status-badge:hover { filter: brightness(0.95); }

.status-menu {
  position: absolute;
  background: #ffffff;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
  z-index: 100;
}
.status-menu button {
  text-align: left;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.status-menu button:hover { background: #f6f8fa; }
.status-menu .status-menu-delete {
  border-top: 1px solid #eaeef2;
  margin-top: 4px;
  padding-top: 8px;
  color: #c84a31;
}

.delete-cell { width: 100px; text-align: center; display: flex; gap: 4px; justify-content: flex-end; }
.recheck-btn, .delete-btn, .move-btn {
  background: transparent;
  border: 1px solid #d0d7de;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.recheck-btn:hover, .move-btn:hover { background: #eaeef2; }
.delete-btn {
  border-color: #f1c0c0;
  color: #c84a31;
  font-size: 18px;
}
.delete-btn:hover { background: #fbeaea; }

.car-info .source-link {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  color: #6e7681;
  text-decoration: none;
}
.car-info .source-link:hover { color: #0969da; text-decoration: underline; }

.source-link {
  font-size: 12px;
  color: #0969da;
  text-decoration: none;
  white-space: nowrap;
}
.source-link:hover { text-decoration: underline; }

.attach-cell {
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.attach-link {
  font-size: 13px;
  color: #0969da;
  text-decoration: none;
}
.attach-link:hover { text-decoration: underline; }
.attach-empty { color: #c0c4ca; }
.attach-edit {
  padding: 2px 6px;
  font-size: 12px;
  background: transparent;
  border: 1px solid #d0d7de;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}
.attach-edit:hover { background: #eaeef2; }
.attach-cell-v2 {
  min-width: 110px;
  max-width: 140px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border-radius: 6px;
  transition: background 0.15s;
}
.attach-cell-v2.attach-dragover {
  background: #fff8e0;
  outline: 2px dashed #ffd966;
}
.attach-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 140px;
  overflow-y: auto;
}
.attach-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 3px;
}
.attach-item:hover { background: #eaeef2; }
.attach-file-link {
  flex: 1;
  color: #0969da;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-file-link:hover { text-decoration: underline; }
.attach-file-del {
  background: transparent;
  border: none;
  color: #c84a31;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  line-height: 1;
}
.attach-file-del:hover { color: #a01;
}
.attach-uploading { color: #6e7681; font-style: italic; }
.attach-error { color: #c84a31; }
.attach-empty-hint { color: #c0c4ca; font-size: 12px; font-style: italic; }
.attach-add {
  font-size: 12px;
  padding: 4px 8px;
  background: #f6f8fa;
  border: 1px dashed #d0d7de;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  color: #6e7681;
}
.attach-add:hover { background: #eaeef2; color: #1f2328; }

.row-actions {
  display: flex;
  gap: 4px;
  flex-direction: column;
}

.row-actions button {
  padding: 3px 8px;
  font-size: 12px;
  background: transparent;
  border: 1px solid #d0d7de;
  border-radius: 4px;
}
.row-actions button:hover { background: #eaeef2; }
.row-actions .btn-danger { color: #c84a31; border-color: #f1c0c0; }
.row-actions .btn-danger:hover { background: #fbeaea; }

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1f2328;
  color: #9ca3af;
  font-size: 11px;
  padding: 6px 20px;
  text-align: center;
}
footer span { font-family: SFMono-Regular, Menlo, monospace; }

/* Mobile: превращаем таблицу в вертикальный список карточек. */
@media (max-width: 768px) {
  .topbar h1 { font-size: 16px; }
  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  main { padding: 8px 8px 80px; }

  /* Таблица → блок. Строки → карточки. Ячейки → строки с лейблами. */
  .lots-table, .lots-table thead, .lots-table tbody, .lots-table tr, .lots-table td {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }
  .lots-table thead { display: none; }
  .lots-table tr {
    background: #ffffff;
    border-radius: 8px;
    margin-bottom: 10px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #eaeef2;
  }
  .lots-table tbody tr:hover { background: #ffffff; }
  .lots-table td {
    padding: 6px 0;
    border-bottom: 1px solid #eaeef2;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
  }
  .lots-table tr td:last-child { border-bottom: none; }
  .lots-table tr td:first-child { border-bottom: 1px solid #d0d7de; padding-bottom: 10px; margin-bottom: 4px; }

  /* Псевдо-лейбл слева через data-атрибут. */
  .lots-table td[data-mobile-label]::before {
    content: attr(data-mobile-label);
    flex: 0 0 110px;
    font-size: 11px;
    color: #6e7681;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 600;
    padding-top: 4px;
  }

  /* Первую ячейку (Авто) показываем без лейбла — она и так выделена. */
  .lots-table td.car-info { flex-direction: column; align-items: stretch; }
  .lots-table td.car-info::before { display: none; }
  .car-info .make-model { font-size: 16px; }

  /* Редактируемые ячейки на мобильном — фон и padding для удобства тыка. */
  .editable {
    flex: 1;
    background: #f6f8fa;
    min-height: 32px;
    min-width: 0;
  }

  /* Статус-ячейка — текст и бейдж стопкой справа. */
  .status-cell {
    flex-direction: row;
    align-items: flex-start;
  }
  .status-cell::before {
    content: "Статус";
    flex: 0 0 110px;
    font-size: 11px;
    color: #6e7681;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 600;
    padding-top: 4px;
  }
  .status-cell > div, .status-cell > button {
    display: block;
    margin-bottom: 4px;
  }
  .status-cell-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  /* Кнопки материалов — крупнее на мобильном. */
  .attach-create, .attach-edit, .attach-link {
    font-size: 14px;
    padding: 6px 10px;
  }
  /* На мобильном drag-drop не работает — убираем подсказку. */
  .attach-empty-hint { display: none; }
  .attach-cell-v2 { padding: 4px 0; max-width: 100%; }

  /* Скрываем пустые поля чтобы карточки не растягивались. */
  .lots-table td.editable.empty,
  .lots-table td.reduction-date.empty,
  .lots-table td.delta.empty,
  .lots-table td.price.empty {
    display: none;
  }

  /* Меню смены статуса — занимает ширину экрана. */
  .status-menu {
    left: 8px !important;
    right: 8px;
    width: auto !important;
  }

  /* Удаление на мобильном — кнопка во всю ширину */
  .delete-cell { display: flex; justify-content: flex-end; }
  .delete-cell::before { display: none; }
  .delete-btn { width: auto; padding: 6px 14px; font-size: 14px; }
  .delete-btn::after { content: " Удалить лот"; font-size: 13px; }
}

/* Навигация между Портфелем и Календарём */
.nav-tabs {
  display: flex;
  gap: 4px;
  margin: 0 20px 12px;
  border-bottom: 1px solid #d0d7de;
}
.nav-tab {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  color: #6e7681;
  text-decoration: none;
  margin-bottom: -1px;
}
.nav-tab:hover { color: #1f2328; }
.nav-tab.active {
  color: #1f2328;
  border-bottom-color: #0969da;
}
