/* --- SILICON VALLEY SAAS AESTHETIC --- */

:root {
  /* Кольорова палітра */
  --bg-main: #F3F4F6; /* Світло-сірий фон додатку */
  --panel-bg: #FFFFFF; /* Білі панелі */
  --border-color: #E5E7EB; /* М'які бордери */
  --text-main: #111827; /* Майже чорний для заголовків */
  --text-muted: #6B7280; /* Сірий для другорядного тексту */
  --accent: #2563EB; /* Глибокий синій (SaaS класика) */
  --accent-hover: #1D4ED8;
  --danger: #EF4444;
  --success: #10B981;

  /* Тіні та радіуси */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --border-radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.app-container {
  width: 95vw;
  height: 95vh;
  max-width: 1400px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* --- SPA ЕКРАНИ --- */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
  animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- ГОЛОВНЕ МЕНЮ --- */
#screen-main-menu {
  justify-content: center;
  align-items: center;
}

.menu-header {
  text-align: center;
  margin-bottom: 48px;
}

.menu-header h1 {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}

.menu-header p {
  color: var(--text-muted);
  font-size: 18px;
}

.app-modules-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* Рівно 2 колонки */
  gap: 24px;
  width: 100%;
  max-width: 700px; /* Зменшили ширину, щоб картки не були занадто розтягнутими */
  margin: 0 auto; /* Центруємо сітку */
}

/* Робимо адаптивність: на телефонах буде 1 колонка */
@media (max-width: 768px) {
  .app-modules-grid {
    grid-template-columns: 1fr;
  }
}

.module-card {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.module-card:hover:not(.disabled) {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px);
}

.module-card.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #F9FAFB;
  box-shadow: none;
}

.module-icon {
  font-size: 40px;
  margin-bottom: 20px;
  background: var(--bg-main);
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.module-card h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.module-card p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* --- ШАПКА РОБОЧОГО ЕКРАНУ --- */
.screen-header {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 24px;
}

.screen-header h2 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.btn-back {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.btn-back:hover {
  color: var(--text-main);
  border-color: #D1D5DB;
  background: #F9FAFB;
}

/* --- РОБОЧА ЗОНА (ДАШБОРД) --- */
.workspace {
  display: flex;
  gap: 24px;
  flex: 1;
  overflow: hidden;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}

.input-panel {
  flex: 1;
  min-width: 350px;
}

.output-panel {
  flex: 1.5;
  background: #FAFAFA;
}

.panel h2 {
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 12px;
}

/* --- КНОПКИ ТА ІНПУТИ --- */
.btn-primary {
  background: var(--accent);
  color: #FFFFFF;
  border: none;
  padding: 14px 24px;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s ease;
  width: 100%;
  margin-top: auto;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  background: #9CA3AF;
  cursor: not-allowed;
  opacity: 0.7;
}

/* Другорядна кнопка (для очищення) */
.btn-secondary {
  background-color: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  padding: 16px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
}

.btn-secondary:hover {
  background-color: #F3F4F6;
  color: var(--text-main);
  border-color: var(--text-muted);
}

/* --- РУЛЕТКА ХОЛОДИЛЬНИКА --- */
.fridge-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  margin-bottom: 24px;
  padding: 4px 8px 8px 4px;
  flex: 1;           /* <--- ДОДАТИ */
  min-height: 0;     /* <--- ДОДАТИ */
}

.fridge-grid::-webkit-scrollbar { width: 6px; }
.fridge-grid::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }

.fridge-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #FFFFFF;
  transition: border-color 0.2s ease;
}

.fridge-item:hover {
  border-color: #D1D5DB;
}

.fridge-item-name {
  font-weight: 500;
  font-size: 15px;
}

.fridge-input-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.fridge-item input {
  width: 90px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  text-align: right;
  font-family: inherit;
  font-size: 14px;
  transition: all 0.2s ease;
}

.fridge-item input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.fridge-unit {
  color: var(--text-muted);
  font-size: 14px;
  width: 30px;
  font-weight: 500;
}

/* Порожній стан (Empty state) */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* --- ФІКС СТРЬОМНИХ СТРІЛОЧОК В ІНПУТАХ --- */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield; /* Для Firefox */
}

/* --- СТИЛІ ДЛЯ КАРТОК МЕНЮ (Калькулятор) --- */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
  /* max-height: 400px; <--- ЦЕ ВИДАЛИТИ */
  flex: 1;              /* <--- ЦЕ ДОДАТИ */
  min-height: 0;        /* <--- ЦЕ ДОДАТИ */
  align-content: start; /* <--- ЦЕ ДОДАТИ */
  overflow-y: auto;
  /* Трохи збільшуємо нижній відступ, щоб тінь останньої картки при наведенні не обрізалася */
  padding: 4px 8px 12px 4px; 
}

.menu-grid::-webkit-scrollbar { width: 6px; }
.menu-grid::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }

.menu-item {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.menu-item:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.menu-item-title {
  font-weight: 500;
  font-size: 15px;
  margin-bottom: 16px;
  color: var(--text-main);
  line-height: 1.4;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #F3F4F6;
  border-radius: 8px;
  padding: 4px;
}

.btn-ctrl {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.btn-ctrl:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.qty-display {
  font-weight: 600;
  font-size: 15px;
  width: 30px;
  text-align: center;
  color: var(--text-main);
}

/* --- ПОТОЧНИЙ СТЕК (Список до розрахунку) --- */
.current-order h3 {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#order-list {
  list-style: none;
  margin-bottom: 24px;
  background: #F9FAFB;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0 16px;
}

.order-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
}

.order-row:last-child {
  border-bottom: none;
}

.order-row span:last-child {
  font-weight: 600;
  color: var(--accent);
}

/* --- АНАЛІТИКА (КБЖУ та Час) --- */
.analytics-grid {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.stat-box {
  flex: 1;
  padding: 16px;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  background: #FFFFFF;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.stat-icon {
  font-size: 28px;
  background: var(--bg-main);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  font-weight: 600;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
}

/* Додаємо стилі для батьківського контейнера */
.receipt-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Оновлюємо стилі самого дерева */
.tree-container {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  /* max-height: 500px;  <--- ЦЕ ВИДАЛИТИ */
  flex: 1;               /* <--- ЦЕ ДОДАТИ */
  min-height: 0;         /* <--- ЦЕ ДОДАТИ */
  overflow-y: auto;
}

.tree-container::-webkit-scrollbar { width: 6px; }
.tree-container::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }

details { margin-bottom: 8px; }

summary {
  cursor: pointer;
  padding: 12px 16px;
  background: #F9FAFB;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s ease;
}

summary::-webkit-details-marker { display: none; }
summary:hover {
  border-color: #D1D5DB;
  background: #F3F4F6;
}

.node-raw {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px 10px 40px;
  font-size: 14px;
  border-bottom: 1px dashed var(--border-color);
  position: relative;
}

.node-raw:last-child { border-bottom: none; }

/* Лінії-зв'язки для дочірніх елементів дерева */
.node-raw::before {
  content: '';
  position: absolute;
  left: 24px; top: 0; bottom: 0;
  width: 2px;
  background: #E5E7EB;
}

.node-raw::after {
  content: '';
  position: absolute;
  left: 24px; top: 20px;
  width: 10px; height: 2px;
  background: #E5E7EB;
}

/* --- КАТАЛОГ РЕЦЕПТІВ --- */
.recipe-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 8px;
  /* max-height: 500px; <--- ВИДАЛИТИ */
  flex: 1;           /* <--- ДОДАТИ */
  min-height: 0;
}

.recipe-list::-webkit-scrollbar { width: 6px; }
.recipe-list::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }

.recipe-list-item {
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #FFFFFF;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
}

.recipe-list-item:hover {
  border-color: #9CA3AF;
}

.recipe-list-item.active {
  border-color: var(--accent);
  background: #EFF6FF; /* Світло-синій бекграунд */
  color: var(--accent);
}

#preview-steps li {
  margin-bottom: 16px;
  padding-left: 8px;
}

/* --- Скрол для результатів Рулетки холодильника --- */
#recipes-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 8px; /* Відступ, щоб скролбар не налізав на текст/бордери карток */
}

/* Стилізуємо скролбар, щоб він був в одному стилі з іншими */
#recipes-list::-webkit-scrollbar { 
  width: 6px; 
}
#recipes-list::-webkit-scrollbar-thumb { 
  background: #D1D5DB; 
  border-radius: 3px; 
}

/* --- Красиві інпути для Книги рецептів --- */
.pretty-input {
  transition: all 0.2s ease;
}

.pretty-input:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}