/* ═══════════════════════════════════════════════
   MEAL SYSTEM — общие стили и CSS переменные
   ═══════════════════════════════════════════════ */

:root {
  --bg:         #f0f2f5;
  --surface:    #ffffff;
  --surface2:   #f8f9fb;
  --border:     #e4e7ec;
  --primary:    #2563eb;
  --primary-h:  #1d4ed8;
  --primary-a:  #1e40af;
  --danger:     #dc2626;
  --danger-h:   #b91c1c;
  --danger-a:   #991b1b;
  --success:    #16a34a;
  --success-h:  #15803d;
  --success-a:  #166534;
  --warning:    #d97706;
  --text:       #111827;
  --text2:      #6b7280;
  --text3:      #9ca3af;
  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,.10);
  --font:       system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --sidebar-w:  220px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);

  min-height: 100vh;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Кнопки ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s, opacity .15s, transform .08s, filter .12s;
  white-space: nowrap;
  user-select: none;
  min-height: 34px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .08), inset 0 1px 0 rgba(255, 255, 255, .18);
}
.btn:not(:disabled):not(.is-loading):active {
  transform: translateY(1px) scale(.98);
  filter: brightness(.94);
  box-shadow: inset 0 1px 3px rgba(15, 23, 42, .18);
}
.btn:focus-visible,
.btn-icon:focus-visible,
.page-btn:focus-visible,
.btn-login:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37,99,235,.18);
}
.btn:disabled,
.btn.is-loading,
.btn[aria-busy="true"] {
  opacity: .56;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(.08);
  box-shadow: none;
}
.btn.is-loading,
.btn[aria-busy="true"] {
  cursor: progress;
}

.btn-primary   { background: var(--primary); color: #fff; box-shadow: 0 2px 5px rgba(37, 99, 235, .22), inset 0 1px 0 rgba(255, 255, 255, .16); }
.btn-primary:hover:not(:disabled):not(.is-loading)  { background: var(--primary-h); }
.btn-primary:not(:disabled):not(.is-loading):active { background: var(--primary-a); }
.btn-danger    { background: var(--danger); color: #fff; box-shadow: 0 2px 5px rgba(220, 38, 38, .22), inset 0 1px 0 rgba(255, 255, 255, .16); }
.btn-danger:hover:not(:disabled):not(.is-loading)   { background: var(--danger-h); }
.btn-danger:not(:disabled):not(.is-loading):active  { background: var(--danger-a); }
.btn-ghost {
  background: linear-gradient(#fff, #f8fafc);
  color: var(--text);
  border: 1px solid #cbd5e1;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .11), inset 0 1px 0 rgba(255, 255, 255, .82);
}
.btn-ghost:hover:not(:disabled):not(.is-loading) {
  background: linear-gradient(#fff, #eef2f7);
  border-color: #94a3b8;
  color: var(--text);
  box-shadow: 0 2px 6px rgba(15, 23, 42, .14), inset 0 1px 0 rgba(255, 255, 255, .85);
}
.btn-ghost:not(:disabled):not(.is-loading):active {
  background: #e2e8f0;
  border-color: #94a3b8;
  box-shadow: inset 0 1px 3px rgba(15, 23, 42, .14);
}
.btn-success   { background: var(--success); color: #fff; box-shadow: 0 2px 5px rgba(22, 163, 74, .22), inset 0 1px 0 rgba(255, 255, 255, .16); }
.btn-success:hover:not(:disabled):not(.is-loading)  { background: var(--success-h); }
.btn-success:not(:disabled):not(.is-loading):active { background: var(--success-a); }
.btn-sm  { padding: 5px 10px; font-size: 13px; }
.btn-icon {
  padding: 7px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, opacity .15s, transform .08s, filter .12s;
  user-select: none;
}
.btn-icon:hover:not(:disabled):not(.is-loading) { background: var(--surface2); color: var(--text); }
.btn-icon:not(:disabled):not(.is-loading):active { transform: translateY(1px) scale(.96); filter: brightness(.95); }
.btn-icon:disabled,
.btn-icon.is-loading,
.btn-icon[aria-busy="true"] {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

/* ── Поля ввода ── */
.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
  outline: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.textarea { resize: vertical; min-height: 80px; }

/* ── Карточки ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ── Таблицы ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text2);
  border-bottom: 2px solid var(--border);
  background: var(--surface2);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 11px 14px; }

/* ── Бейджи ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-gray   { background: #f3f4f6; color: #374151; }

/* ── Модальные окна ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn .15s ease;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .2s ease;
}
.modal-box.wide { max-width: 640px; }
.modal-body { min-height: 0; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text2);
  line-height: 1;
  border-radius: 50%;
  transition: background-color .15s, color .15s, opacity .15s, transform .08s;
}
.modal-close:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.modal-close:not(:disabled):active { transform: scale(.92); }
.modal-close:disabled { opacity: .45; cursor: not-allowed; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Формы ── */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 5px;
}
.form-error { color: var(--danger); font-size: 12px; margin-top: 4px; }

/* ── Уведомления ── */
.toast-container {
  position: fixed;
  top: 16px; right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideInRight .2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 260px;
  max-width: 400px;
}
.toast-success  { background: #f0fdf4; color: #166534; border-left: 4px solid var(--success); }
.toast-error    { background: #fef2f2; color: #991b1b; border-left: 4px solid var(--danger); }
.toast-info     { background: #eff6ff; color: #1e40af; border-left: 4px solid var(--primary); }
.toast-warning  { background: #fffbeb; color: #92400e; border-left: 4px solid var(--warning); }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Лоадер ── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.button-progress-label {
  display: inline-block;
}

:where(.btn, .btn-login, .btn-logout, .btn-icon, .page-btn)[aria-busy="true"],
:where(.btn, .btn-login, .btn-logout, .btn-icon, .page-btn).is-loading {
  pointer-events: none;
}

/* ── Пагинация ── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
  justify-content: center;
}
.page-btn {
  min-width: 32px; height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  transition: background-color .15s, border-color .15s, color .15s, opacity .15s, transform .08s, filter .12s;
  user-select: none;
}
.page-btn:hover:not(:disabled):not(.active):not(.is-loading) { background: var(--surface2); }
.page-btn:not(:disabled):not(.active):not(.is-loading):active { transform: translateY(1px) scale(.96); filter: brightness(.96); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled,
.page-btn.is-loading,
.page-btn[aria-busy="true"] { opacity: .45; cursor: not-allowed; transform: none; }

/* ── Поиск с крестиком ── */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;           /* растягивается на всю ширину родителя */
  flex: 1;               /* для использования в flex-контейнерах */
}

/* Для страниц сотрудников и карт: родитель .toolbar уже flex, поиск растянется */
.search-box .input {
  flex: 1;
  padding-left: 34px;
  padding-right: 32px;
  width: 100%;
}

.search-box .input[type="search"]::-webkit-search-cancel-button,
.search-box .input[type="search"]::-webkit-search-decoration,
.search-box .input[type="search"]::-webkit-search-results-button,
.search-box .input[type="search"]::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.search-box::before {
  content: '🔍';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  pointer-events: none;
  z-index: 1;
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text3);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.15s;
  z-index: 2;
  width: 24px;
  height: 24px;
}

.search-clear:hover:not(:disabled) {
  color: var(--text);
  background: rgba(0, 0, 0, 0.05);
}

.search-clear:not(:disabled):active {
  transform: translateY(-50%) scale(0.96);
}
.search-clear:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* Специально для ручной фиксации: растягиваем поле поиска внутри .filter-group */
.filter-group .search-box {
  width: auto;
  min-width: 200px;
  flex: 1;
}

/* ── Чекбокс ── */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
}
.checkbox-label input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }

/* ── Разделитель ── */
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Пустое состояние ── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text3);
}
.empty-state-icon { font-size: 36px; margin-bottom: 12px; }
.empty-state-text { font-size: 15px; }

/* ── Утилиты ── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--text2); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Утилиты для отступов и цветов (CSP-safe) ── */
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.p-12 { padding: 12px; }
.p-16 { padding: 16px; }
.text-md { font-size: 15px; }
.hidden { display: none; }
.modal-sm { max-width: 380px; }

.text-center { text-align: center; }
.p-32 { padding: 32px; }
.w-full { width: 100%; }

/* дополнительные утилиты */
.w-160 { width: 160px; }
.max-w-260 { max-width: 260px; }
.max-w-200 { max-width: 200px; }
.max-w-300 { max-width: 300px; }
.min-w-200 { min-width: 200px; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.p-20 { padding: 20px; }
.mb-14 { margin-bottom: 14px; }
.text-xs { font-size: 12px; }
.text-right {
  text-align: right;
}

body:has(#loginBtn) {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Кнопка очистки поиска */
.search-box {
  position: relative;
}

.filter-group:has(.search-box) {
  flex: 1;
}
