/* Phyto-Expert Mini App — дизайн-система по разделу 40 ТЗ.
   Токены строятся поверх переменных темы Telegram (--tg-theme-*),
   с запасными значениями на случай запуска вне Telegram (для разработки). */

:root {
  --bg:            var(--tg-theme-bg-color, #F4F5F6);
  --bg-secondary:  var(--tg-theme-secondary-bg-color, #FFFFFF);
  --text:          var(--tg-theme-text-color, #17241F);
  --hint:          var(--tg-theme-hint-color, #7C8B94);
  --link:          var(--tg-theme-link-color, #2F9E6E);
  --button:        var(--tg-theme-button-color, #2F9E6E);
  --button-text:   var(--tg-theme-button-text-color, #FFFFFF);
  --separator:     rgba(23, 36, 31, 0.07);

  /* Акцент — приглушённый "фито"-зелёный: домен ТЗ буквально про деревья
     и растения, а не декоративный выбор. */
  --accent: #2F9E6E;
  --accent-soft: #E4F3EC;
  --danger: #D64545;
  --danger-soft: #FBE7E7;
  --warning: #C98A1E;
  --warning-soft: #FAEFDA;

  --radius-lg: 16px;
  --radius-md: 13px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgba(15,23,20,0.03), 0 6px 16px rgba(15,23,20,0.045);
}

* { box-sizing: border-box; }

.icon {
  flex-shrink: 0;
  display: inline-block;
  vertical-align: -3px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100vh;
  padding-bottom: 78px; /* место под нижнюю навигацию */
}

/* ---------- Верхняя панель ---------- */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding: 12px 16px 8px;
}
.top-bar h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 4px 0 12px;
  letter-spacing: -0.01em;
}
.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.search-input-wrap {
  flex: 1;
  position: relative;
}
.search-input {
  width: 100%;
  padding: 10px 14px 10px 34px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.search-input::placeholder { color: var(--hint); }
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--hint);
  display: flex;
  align-items: center;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hint);
  flex-shrink: 0;
}
.icon-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Горизонтальная лента активных фильтров-чипов */
.chip-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 16px 2px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  border: none;
  white-space: nowrap;
}
.chip.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- Карточки списка (раздел 6.1) ---------- */
.list {
  padding: 4px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 14px 14px 12px;
  box-shadow: var(--shadow-card);
}
.order-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.order-card-id { color: var(--hint); font-size: 13px; font-weight: 600; }
.order-card-name { font-size: 16px; font-weight: 700; margin-top: 1px; }
.order-card-meta {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: var(--text);
}
.order-card-meta .row { display: flex; align-items: center; gap: 6px; }
.order-card-meta .muted { color: var(--hint); }
.order-card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}
.order-price { font-weight: 700; font-size: 15px; }
.order-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--separator);
}
.order-actions button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: none;
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 0;
  font-size: 13px;
  font-weight: 600;
}
.order-actions button.primary { background: var(--accent-soft); color: var(--accent); }

/* ---------- Статус-бейджи (10 статусов из раздела 7) ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-new_lead   { background: #EEF0EE; color: #5B6B62; }
.badge-in_progress{ background: #E4EDFB; color: #3567B8; }
.badge-assigned   { background: #EAE6FB; color: #6A4FC2; }
.badge-scheduled  { background: #F1E6FB; color: #8B4FC2; }
.badge-executing  { background: var(--warning-soft); color: var(--warning); }
.badge-done       { background: #DFF3EE; color: #23917A; }
.badge-paid       { background: var(--accent-soft); color: var(--accent); }
.badge-debt       { background: var(--danger-soft); color: var(--danger); }
.badge-cancelled  { background: #ECECEC; color: #7A7A7A; }
.badge-archive    { background: #E7E9EC; color: #62707D; }

/* ---------- Bottom sheet (фильтры, действия, формы) ---------- */
.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 20, 18, 0.4);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
.sheet-overlay.open { opacity: 1; pointer-events: auto; }
.sheet {
  background: var(--bg);
  width: 100%;
  max-height: 86vh;
  border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform .22s cubic-bezier(.22,.9,.35,1);
  overflow-y: auto;
}
.sheet-overlay.open .sheet { transform: translateY(0); }
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--separator);
  border-radius: 999px;
  margin: 4px auto 12px;
}
.sheet h2 { font-size: 17px; margin: 0 0 12px; }
.sheet-section { margin-bottom: 16px; }
.sheet-section-title { font-size: 12px; color: var(--hint); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 8px; font-weight: 700; }
.chip-grid { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Формы ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
.field textarea { resize: vertical; min-height: 70px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--button);
  color: var(--button-text);
  font-size: 15.5px;
  font-weight: 700;
  text-align: center;
}
.btn.secondary { background: var(--bg-secondary); color: var(--text); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 16px;
  bottom: 86px;
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(47,158,110,0.35);
  z-index: 30;
}

/* ---------- Нижняя навигация ---------- */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--separator);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 40;
}
.bottom-nav button {
  flex: 1;
  border: none;
  background: none;
  padding: 9px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--hint);
  font-size: 11px;
  font-weight: 600;
}
.bottom-nav button.active { color: var(--accent); }
.bottom-nav .nav-icon-wrap {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  transition: background .15s ease;
}
.bottom-nav button.active .nav-icon-wrap {
  background: var(--accent-soft);
}

/* ---------- Детальная карточка заявки ---------- */
.detail-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
}
.detail-header .back {
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: none;
  border: none;
  color: var(--text);
  flex-shrink: 0;
}
.detail-header .back:active { background: var(--separator); }
.detail-header .title { font-weight: 700; font-size: 17px; flex: 1; }
.section {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  margin: 8px 16px;
  padding: 14px;
  box-shadow: var(--shadow-card);
}
.section-title {
  font-size: 12px; color: var(--hint); text-transform: uppercase;
  letter-spacing: .03em; font-weight: 700; margin-bottom: 10px;
}
.kv-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14.5px; }
.kv-row .k { color: var(--hint); }
.kv-row .v { font-weight: 600; text-align: right; }
.quick-actions { display: flex; gap: 8px; margin-top: 10px; }
.quick-actions a, .quick-actions button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center; text-decoration: none;
  background: var(--bg); color: var(--text);
  border: none; border-radius: var(--radius-sm);
  padding: 10px 0; font-size: 13px; font-weight: 600;
}

/* ---------- Таймлайн (раздел 9) ---------- */
.timeline { position: relative; padding-left: 18px; }
.timeline::before {
  content: ""; position: absolute; left: 4px; top: 4px; bottom: 4px;
  width: 2px; background: var(--separator);
}
.timeline-item { position: relative; padding-bottom: 16px; }
.timeline-item::before {
  content: ""; position: absolute; left: -18px; top: 3px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
}
.timeline-time { font-size: 12px; color: var(--hint); font-weight: 600; }
.timeline-text { font-size: 14px; margin-top: 2px; }

/* ---------- Skeleton ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--separator) 37%, var(--bg-secondary) 63%);
  background-size: 400% 100%;
  animation: skeleton-shine 1.4s ease infinite;
  border-radius: var(--radius-md);
}
@keyframes skeleton-shine { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed; left: 0; right: 0; bottom: 96px;
  display: flex; justify-content: center; z-index: 60;
  pointer-events: none;
}
.toast {
  background: #1B2420; color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
  opacity: 0; transform: translateY(8px);
  transition: all .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 60px 24px; color: var(--hint); }
.empty-state .state-icon {
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
  color: var(--hint);
}

/* ---------- Календарь ---------- */
.calendar-date-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px 10px;
}
.calendar-day-cols { display: flex; overflow-x: auto; gap: 10px; padding: 0 16px 16px; }
.calendar-col { flex: 0 0 240px; background: var(--bg-secondary); border-radius: var(--radius-lg); padding: 10px; box-shadow: var(--shadow-card); }
.calendar-col-header { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--separator); }
.avatar-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.calendar-slot { padding: 8px; border-radius: var(--radius-sm); background: var(--bg); margin-bottom: 6px; font-size: 12.5px; }
.calendar-slot .time { font-weight: 700; color: var(--accent); }

/* ---------- Segmented control (переключение видов из раздела 6) ---------- */
.segmented { display: flex; background: var(--bg-secondary); border-radius: var(--radius-sm); padding: 3px; }
.segmented button { flex: 1; border: none; background: none; padding: 7px 0; font-size: 13px; font-weight: 600; color: var(--hint); border-radius: 8px; }
.segmented button.active { background: var(--bg); color: var(--text); }

/* ---------- Kanban (раздел 7) ---------- */
.kanban-scroller {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 16px 16px;
  scroll-snap-type: x proximity;
}
.kanban-col {
  flex: 0 0 82vw;
  max-width: 320px;
  scroll-snap-align: start;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 10px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 210px);
}
.kanban-col.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.kanban-col-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--separator);
}
.kanban-col-title { font-weight: 700; font-size: 14px; }
.kanban-col-count {
  font-size: 12px; font-weight: 700; color: var(--hint);
  background: var(--bg); border-radius: 999px; padding: 2px 8px;
}
.kanban-cards { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.kanban-card {
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 10px;
  font-size: 13px;
  cursor: grab;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.4; }
.kanban-card .kc-id { font-weight: 700; color: var(--hint); font-size: 11.5px; }
.kanban-card .kc-name { font-weight: 700; margin: 2px 0 4px; }
.kanban-card .kc-meta { display: flex; align-items: center; gap: 5px; color: var(--hint); font-size: 12px; margin-top: 2px; }
.kanban-card .kc-price { margin-top: 6px; font-weight: 700; }
.kanban-empty-col { color: var(--hint); font-size: 12.5px; text-align: center; padding: 16px 4px; }

/* ---------- Экран «Ещё»: грид карточек-иконок ---------- */
.more-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 4px 16px 20px;
}
.more-tile {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px 6px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  text-align: center;
  cursor: pointer;
}
.more-tile.disabled { opacity: .42; cursor: default; }
.more-tile-icon {
  position: relative;
  width: 46px; height: 46px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.more-tile-label { font-size: 12.5px; font-weight: 600; line-height: 1.25; }
.more-tile-lock {
  position: absolute; right: -3px; bottom: -3px;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--hint);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 2px var(--bg-secondary);
}
