:root {
  --primary: #6200ea;
  --bg: #f0f2f5;
  --text: #2d3436;
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, system-ui, sans-serif;
  background: var(--bg);
  margin: 0;
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;

  /* ИСПРАВЛЕНИЕ: Добавляем отступ сверху */
  padding-top: var(--tg-safe-area-inset-top, 20px);
  /* Если открыто в Телеграм - возьмет его отступ, если нет - 20px */
}

.hidden {
  display: none !important;
}

/* === BUTTONS === */
.btn {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  padding: 8px 16px;
  transition: 0.2s;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-def {
  background: #fff;
  border: 1px solid #ccc;
}

.btn-text {
  background: transparent;
  color: #666;
}

.btn-p {
  background: #7b1fa2;
  color: white;
}

.btn-s {
  background: #2e7d32;
  color: white;
}

.btn-w {
  background: #ff9800;
  color: white;
}

.btn-d {
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ffcdd2;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  padding: 8px;
  border-radius: 6px;
  font-size: 14px;
}

/* === LOADER === */
#loader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.8);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #ddd;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* === SCREENS === */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.dash-header {
  /* Увеличенный отступ сверху (40px) чтобы не наезжать на кнопки телефона/телеграма */
  padding: 40px 20px 15px 20px;

  background: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);

  /* Фиксация, чтобы шапка не уезжала при скролле (опционально, но удобно) */
  position: sticky;
  top: 0;
  z-index: 100;
}

/* === KANBAN BOARD === */
.kanban-board {
  flex: 1;
  overflow-x: auto;
  padding: 20px;
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.k-col {
  flex: 1;
  min-width: 300px;
  background: #eef0f3;
  border-radius: 12px;
  padding: 10px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
}

.k-head {
  font-weight: bold;
  padding: 10px;
  color: #555;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 1px;
  border-bottom: 2px solid rgba(0, 0, 0, 0.05);
  margin-bottom: 10px;
}

.h-new {
  border-color: #ff9800;
  color: #f57c00;
}

.h-active {
  border-color: #2196f3;
  color: #1976d2;
}

.h-done {
  border-color: #4caf50;
  color: #2e7d32;
}

.k-list {
  flex: 1;
  overflow-y: auto;
  padding-right: 5px;
  min-height: 50px;
}

/* === PROJECT CARD === */
.p-card {
  background: white;
  padding: 15px;
  border-radius: 10px;
  margin-bottom: 10px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  cursor: grab;
  position: relative;
  border-left: 4px solid transparent;
}

.p-card:active {
  cursor: grabbing;
  transform: scale(0.98);
}

.p-card:hover {
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.pc-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.pc-name {
  font-weight: bold;
  font-size: 16px;
  line-height: 1.3;
}

.pc-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
}

/* INDICATORS */
.pc-ind {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: bold;
}

.ind-bad {
  color: #c62828;
  background: #ffebee;
  padding: 2px 8px;
  border-radius: 12px;
}

.ind-good {
  color: #2e7d32;
  background: #e8f5e9;
  padding: 2px 8px;
  border-radius: 12px;
}

/* MOBILE BUTTONS */
.mob-status-btn {
  display: none;
  margin-top: 10px;
  width: 100%;
  padding: 8px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 6px;
  font-size: 12px;
}

@media (max-width: 768px) {
  .kanban-board {
    flex-direction: column;
    overflow-y: auto;
  }

  .k-col {
    width: 100%;
    min-height: auto;
    margin-bottom: 20px;
  }

  .mob-status-btn {
    display: block;
  }
}

/* === MANAGER === */
.mgr-toolbar {
  background: white;
  padding: 10px;
  border-bottom: 1px solid #eee;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.mgr-grid {
  flex: 1;
  overflow: auto;
  background: white;
}

.header-input {
  font-size: 16px;
  border: none;
  border-bottom: 2px solid #ddd;
  padding: 5px;
  width: 200px;
  outline: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

th {
  position: sticky;
  top: 0;
  background: #f8f9fa;
  padding: 10px;
  text-align: left;
  z-index: 10;
  font-size: 12px;
}

td {
  padding: 5px;
  border-bottom: 1px solid #eee;
}

td input,
td select {
  width: 100%;
  border: none;
  padding: 6px;
  background: transparent;
}

tr.has-supplier {
  background: #f9f9f9;
}

/* === BUYER === */
/* === BUYER (СНАБЖЕНЕЦ - НОВЫЙ ДИЗАЙН) === */
.buy-header {
  background: var(--primary);
  color: white;
  padding: 25px 20px 5px 20px;
  /* Меньше паддинг снизу */
  border-radius: 0 0 20px 20px;
  /* Закругление как на макете */
  box-shadow: 0 4px 15px rgba(98, 0, 234, 0.2);
  z-index: 100;
  position: relative;
}

/* Фильтры - Горизонтальный скролл */
.filter-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 15px 0;
  scrollbar-width: none;
  /* Скрыть скроллбар */
  -ms-overflow-style: none;
}

.filter-scroll::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
  cursor: pointer;
  transition: 0.2s;
}

.filter-chip.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.buy-progress-wrap {
  margin-top: 5px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  opacity: 0.9;
}

/* Список карточек */
.buy-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: 100px;
  /* Место под кнопку сохранения */
}

/* Карточка товара (как на макете) */
.b-card {
  background: white;
  padding: 16px;
  border-radius: 16px;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.02);
  transition: 0.2s;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.b-card.done {
  background: #f8fff9;
  border: 1px solid #c8e6c9;
  opacity: 0.8;
}

/* Верхняя часть карточки */
.b-row-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.b-name {
  font-size: 16px;
  font-weight: 700;
  color: #333;
  line-height: 1.3;
  margin-right: 10px;
}

/* Средняя часть (инфо) */
.b-row-mid {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.b-badge {
  background: #f3e5f5;
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
}

.b-supplier {
  font-size: 12px;
  color: #666;
  background: #f5f5f5;
  padding: 4px 8px;
  border-radius: 6px;
}

/* Нижняя часть (действия) */
.b-row-bot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 5px;
}

.b-price-inp {
  flex: 1;
  background: #fafafa;
  border: 1px solid #eee;
  padding: 10px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  color: #333;
  outline: none;
}

.b-price-inp:focus {
  background: #fff;
  border-color: var(--primary);
}

/* Чекбокс-кнопка */
.b-check-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 2px solid #eee;
  background: white;
  color: #ddd;
  font-size: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: 0.2s;
}

.b-card.done .b-check-btn {
  background: #00c853;
  border-color: #00c853;
  color: white;
  box-shadow: 0 4px 10px rgba(0, 200, 83, 0.3);
}

/* ПАНЕЛЬ СОХРАНЕНИЯ (Всплывающая снизу) */
#unsavedBar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(150%);
  /* Скрыта внизу */
  background: #2d3436;
  color: white;
  padding: 12px 20px;
  border-radius: 30px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  z-index: 2000;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  width: 90%;
  max-width: 400px;
}

#unsavedBar.visible {
  transform: translateX(-50%) translateY(0);
  /* Показать */
}

.save-btn {
  margin-left: auto;
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

/* === MODALS === */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 3000;
  justify-content: center;
  align-items: center;
  display: flex;
}

.modal-box {
  background: white;
  padding: 20px;
  border-radius: 10px;
  width: 90%;
  max-width: 400px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

/* Окно импорта */
#modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: white;
  z-index: 5000;
  display: flex;
  /* Исправлено */
  flex-direction: column;
}