/* ============================================================================
   AgroCRM — дизайн-токены (раздел 3 ТЗ)
   ============================================================================ */
:root {
  /* Цвета */
  --accent:            #059669;
  --accent-hover:      #047857;
  --bg:                #F9FAFB;
  --card:              #FFFFFF;
  --border:            #E5E7EB;
  --text:              #111827;
  --text-muted:        #6B7280;
  --success:           #10B981;
  --warning:           #F59E0B;
  --danger:            #EF4444;
  --info:              #3B82F6;

  /* Статусы */
  --stage-small-bg:     #DBEAFE;  --stage-small-fg:     #1E40AF;
  --stage-large-bg:     #D1FAE5;  --stage-large-fg:     #065F46;
  --stage-remainder-bg: #FEF3C7;  --stage-remainder-fg: #92400E;
  --stage-finished-bg:  #F3F4F6;  --stage-finished-fg:  #374151;
  --stage-overdue-bg:   #FEE2E2;  --stage-overdue-fg:   #991B1B;

  /* Радиусы и тени */
  --radius-card:  12px;
  --radius-ctrl:  8px;
  --radius-pill:  9999px;
  --shadow-card:  0 1px 3px rgba(0,0,0,0.05);
  --shadow-pop:   0 10px 25px -5px rgba(0,0,0,0.08), 0 4px 10px -3px rgba(0,0,0,0.04);
}

/* ============================================================================
   Базовая типографика (Inter через Google Fonts подключается в <head>)
   ============================================================================ */
html, body {
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
/* Всегда резервируем вертикальный скроллбар, чтобы страница не прыгала по X
   при переключении между короткими/длинными экранами. */
html { overflow-y: scroll; }
body { min-width: 1200px; margin: 0; }
*, *::before, *::after { box-sizing: border-box; }

h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 24px; font-weight: 600; letter-spacing: -0.015em; }
h3 { font-size: 18px; font-weight: 600; }
.text-small { font-size: 12px; }
.kpi-number { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }

/* ============================================================================
   Layout: sidebar + topbar
   ============================================================================ */
.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--card);
  border-right: 1px solid var(--border);
  position: sticky; top: 0;
  height: 100vh;
  padding: 24px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.sidebar .logo { display: flex; align-items: center; gap: 10px; padding: 0 8px 24px; }
.sidebar .logo-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.sidebar .logo-text { font-weight: 700; font-size: 16px; color: var(--text); }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-ctrl);
  color: var(--text-muted); font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: #F3F4F6; color: var(--text); }
.nav-item.active { background: #ECFDF5; color: var(--accent); }
.nav-item.active svg { color: var(--accent); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.topbar {
  height: 64px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .search {
  flex: 1; max-width: 560px; margin: 0 auto;
  position: relative;
}
.topbar .search input {
  width: 100%; height: 40px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctrl);
  padding: 0 14px 0 40px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.topbar .search input:focus { border-color: var(--accent); background: var(--card); }
.topbar .search svg { position: absolute; left: 12px; top: 11px; width: 18px; height: 18px; color: var(--text-muted); }
.topbar .icon-btn {
  width: 40px; height: 40px; border-radius: var(--radius-ctrl);
  display: grid; place-items: center; cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s;
  position: relative;
}
.topbar .icon-btn:hover { background: var(--bg); color: var(--text); }
.topbar .avatar {
  width: 40px; height: 40px; border-radius: 9999px;
  object-fit: cover; cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.topbar .avatar:hover { border-color: var(--accent); }
.notif-dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 9999px;
  background: var(--danger);
  border: 2px solid var(--card);
}

.page {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px;
  min-height: calc(100vh - 64px);   /* 64 = высота топбара */
  display: flex;
  flex-direction: column;
  gap: 24px;                         /* равномерные отступы между секциями */
}
/* Прямые дети .page всегда занимают всю ширину контейнера,
   чтобы сетки/карточки не коллапсировали по содержимому. */
.page > * { width: 100%; }
@media (max-width: 1200px) { .page { padding: 24px; } }

/* ============================================================================
   Карточки, кнопки, бейджи
   ============================================================================ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 24px;
}
.card-tight { padding: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border-radius: var(--radius-ctrl);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); border-color: #D1D5DB; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-icon { width: 32px; height: 32px; padding: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 500;
  white-space: nowrap;
}
.badge-small     { background: var(--stage-small-bg);     color: var(--stage-small-fg); }
.badge-large     { background: var(--stage-large-bg);     color: var(--stage-large-fg); }
.badge-remainder { background: var(--stage-remainder-bg); color: var(--stage-remainder-fg); }
.badge-finished  { background: var(--stage-finished-bg);  color: var(--stage-finished-fg); }
.badge-overdue   { background: var(--stage-overdue-bg);   color: var(--stage-overdue-fg); }
.badge-info      { background: #DBEAFE; color: #1E40AF; }
.badge-muted     { background: #F3F4F6; color: #374151; }
.badge-success   { background: #D1FAE5; color: #065F46; }
.badge-warning   { background: #FEF3C7; color: #92400E; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 500;
  background: var(--card); border: 1px solid var(--border); color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { color: var(--text); border-color: #D1D5DB; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ============================================================================
   Таблицы
   ============================================================================ */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table thead th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.04em;
  cursor: pointer; user-select: none;
  white-space: nowrap;
}
.data-table thead th:first-child { border-top-left-radius: var(--radius-card); }
.data-table thead th:last-child { border-top-right-radius: var(--radius-card); }
.data-table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background 0.12s; cursor: pointer; }
.data-table tbody tr:hover { background: #F9FAFB; }
.data-table .avatar-xs { width: 28px; height: 28px; border-radius: 9999px; object-fit: cover; }

.sort-indicator { display: inline-flex; margin-left: 4px; color: var(--text-muted); }

/* ============================================================================
   Формы
   ============================================================================ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text); }
.field .required { color: var(--danger); }
.input, .select, .textarea {
  width: 100%;
  height: 40px; padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctrl);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
}
.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Toggle switch */
.toggle {
  position: relative;
  width: 36px; height: 20px;
  background: #E5E7EB;
  border-radius: 9999px;
  cursor: pointer;
  transition: background 0.15s;
}
.toggle::after {
  content: '';
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff; border-radius: 9999px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  transition: transform 0.15s;
}
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(16px); }

/* ============================================================================
   Модалки
   ============================================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, 0.5);
  display: grid; place-items: center;
  z-index: 50;
  padding: 20px;
  animation: fadeIn 0.15s ease-out;
}
.modal-box {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  max-height: 90vh;
  overflow-y: auto;
  animation: popIn 0.18s ease-out;
}
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 12px;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.96) translateY(8px); } to { opacity: 1; transform: none; } }

/* ============================================================================
   Прочее
   ============================================================================ */
.kpi-card { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.kpi-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.kpi-delta { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }
.kpi-card.accent-danger .kpi-number { color: var(--danger); }

.pulse-dot {
  width: 8px; height: 8px; border-radius: 9999px;
  background: var(--danger);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.divider { height: 1px; background: var(--border); margin: 16px 0; }

.alert {
  border-radius: var(--radius-card);
  padding: 16px 20px;
  display: flex; align-items: center; gap: 14px;
}
.alert-danger { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-warning { background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }
.alert-info { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }

.tab-list { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 12px 16px;
  font-size: 14px; font-weight: 500; color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.progress-track {
  height: 8px; background: var(--bg); border-radius: 9999px; overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 9999px; transition: width 0.3s; }

/* Dropdown (для смены роли) */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 240px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  padding: 8px;
  z-index: 30;
}
.dropdown-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-ctrl);
  font-size: 14px; color: var(--text); cursor: pointer;
}
.dropdown-item:hover { background: var(--bg); }
.dropdown-section { padding: 8px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; }

/* Breadcrumb */
.crumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.crumb a { color: var(--text-muted); text-decoration: none; }
.crumb a:hover { color: var(--accent); }
.crumb .sep { opacity: 0.4; }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 4px; margin-top: 20px; justify-content: flex-end; }
.pagination button {
  min-width: 36px; height: 36px; padding: 0 10px;
  border-radius: var(--radius-ctrl); border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: 13px; cursor: pointer;
  transition: all 0.15s;
}
.pagination button:hover:not(:disabled) { background: var(--bg); }
.pagination button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Хлебные крошки timeline */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: ''; position: absolute; left: 7px; top: 8px; bottom: 8px;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-item::before {
  content: ''; position: absolute; left: -21px; top: 6px;
  width: 12px; height: 12px; border-radius: 9999px;
  background: var(--card); border: 2px solid var(--accent);
}

/* Копировать-подсказка */
.copy-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.copy-row:last-child { border-bottom: none; }
.copy-row .copy-btn { opacity: 0; transition: opacity 0.15s; cursor: pointer; }
.copy-row:hover .copy-btn { opacity: 1; }

/* Cloak Alpine */
[x-cloak] { display: none !important; }
