:root {
  /* Colors - Light Theme */
  --bg-gradient: linear-gradient(135deg, #e6f7eb 0%, #fefce8 100%);
  --surface-color: #ffffff;
  --text-main: #273e3a;
  --text-muted: #6b847f;
  --primary: #10b981; /* Emerald green */
  --primary-hover: #059669;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --warning: #f59e0b;
  --border-color: #e5ebe9;
  
  /* Radii & Shadows */
  --radius-md: 16px;
  --radius-lg: 24px;
  --shadow-sm: 0 2px 8px rgba(16, 185, 129, 0.05);
  --shadow-md: 0 8px 16px -4px rgba(16, 185, 129, 0.1), 0 4px 8px -4px rgba(16, 185, 129, 0.06);
  --shadow-lg: 0 20px 25px -5px rgba(16, 185, 129, 0.1), 0 8px 10px -6px rgba(16, 185, 129, 0.05);
  
  /* Typography */
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  /* Colors - Dark Theme (Gray-Green) */
  --bg-gradient: linear-gradient(135deg, #162420 0%, #1c2d28 100%);
  --surface-color: #233530;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #10b981;
  --primary-hover: #34d399;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --border-color: #2f453f;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 25px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  padding-left: 260px;
  width: 100%;
  overflow-x: hidden;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s, padding-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-collapsed {
  padding-left: 0;
}

.fixed-brand {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  height: 80px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 50;
  pointer-events: none;
}

#sidebar-toggle {
  pointer-events: auto;
  padding: 8px;
  margin-right: 8px;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
#sidebar-toggle:hover {
  background: rgba(16, 185, 129, 0.1);
}

.fixed-brand .logo {
  pointer-events: auto;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Sidebar Navigation */
.sidebar {
  width: 260px;
  background-color: var(--surface-color);
  border-right: 1px solid var(--border-color);
  padding: 24px;
  padding-top: 80px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  z-index: 40;
}

.sidebar.collapsed {
  transform: translateX(-100%);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.nav-item {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.2s ease-in-out;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-item:hover {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--primary-hover);
}

.nav-item.active {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--primary-hover);
  font-weight: 600;
}

.settings-group {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
}

/* Main Content */
.main-content {
  flex-grow: 1;
  padding: 40px;
  padding-top: 80px; /* Safe space from fixed brand */
  max-width: 1200px;
  margin: 0 auto; /* Centers perfectly within available space */
}

.view {
  display: none;
  animation: fadeIn 0.4s ease-out;
}

.view.active {
  display: block;
}

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

/* Header */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

h1 {
  font-size: 2.25rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Buttons */
.btn {
  padding: 12px 24px;
  border-radius: var(--radius-md);
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.btn-danger {
  background-color: var(--danger);
  color: white;
}

.btn-danger:hover {
  background-color: var(--danger-hover);
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background-color: rgba(16, 185, 129, 0.1);
  border-color: var(--primary);
  color: var(--primary-hover);
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--primary-hover);
}

/* Grid & Cards */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

.card {
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  display: flex;
  flex-direction: column;
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px);
  border-color: var(--primary);
}

.dish-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 8px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  line-height: 1.3;
}

.dish-meta {
  color: var(--text-muted);
  font-size: 0.875rem;
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  font-weight: 500;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: auto;
}

.tag {
  background: rgba(16, 185, 129, 0.1);
  color: var(--primary);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.card-actions {
  margin-top: 24px;
  display: flex;
  flex-wrap: wrap; /* Fix button overflow by wrapping if necessary */
  gap: 8px;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
}
.card-actions .btn {
  flex: 1 1 calc(33% - 8px); /* Grow to fill evenly, prevent hard overflow */
  padding: 10px;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* Weekly Plan Table */
.plan-container {
  overflow-x: auto;
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.plan-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.plan-table th, .plan-table td {
  padding: 12px;
  border: 1px solid var(--border-color);
  vertical-align: middle;
  position: relative;
}

.warning-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
  margin-left: 8px;
  cursor: help;
  position: relative;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
  animation: pulse-ring-red 2s infinite;
  border: 1px solid white;
}

@keyframes pulse-ring-red {
  0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
  100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.custom-tooltip {
  position: fixed;
  background: #000000;
  color: white;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  width: 220px;
  text-align: left;
  z-index: 10000;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s;
  transform: translateY(-50%);
}

.custom-tooltip.active {
  opacity: 1;
  visibility: visible;
}

.day-has-warning {
  background: rgba(239, 68, 68, 0.08) !important;
}

.plan-table th {
  background: transparent;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-align: center;
  height: 50px;
}

.plan-table th:first-child, .plan-table td:first-child {
  width: 150px;
  background: rgba(16, 185, 129, 0.05);
  color: var(--primary);
  text-align: center;
}

.plan-table tr:last-child td {
  border-bottom: none;
}
.plan-table td:last-child, .plan-table th:last-child {
  border-right: none;
}

.meal-slot {
  min-height: 80px;
  background: transparent;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  padding: 12px;
  position: relative;
}

.meal-slot:hover {
  background: rgba(16, 185, 129, 0.05);
  border-color: var(--primary);
  color: var(--primary-hover);
}

.meal-slot.filled {
  background: var(--surface-color);
  border: 1px solid var(--border-color); 
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.meal-dish-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
}
.meal-slot-actions {
  display: flex;
  gap: 4px;
}
.meal-slot-actions button {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 8px;
  transition: all 0.2s;
}
.meal-slot-actions button:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}
.meal-slot-actions button[title="Замінити"]:hover {
  background: rgba(16, 185, 129, 0.1);
  color: var(--primary);
}

/* Forms */
.form-group {
  margin-bottom: 24px;
}

.form-label {
  display: block;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-main);
  font-size: 0.9rem;
}

.form-control {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-family: var(--font-family);
  transition: all 0.2s;
  background-color: var(--surface-color);
  color: var(--text-main);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
}

/* Shopping List */
.shopping-list {
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}
.shopping-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: transform 0.2s ease;
}

.shopping-item-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.shopping-item-category {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-color);
  padding: 2px 8px;
  border-radius: 12px;
  width: fit-content;
}

.shopping-item:hover {
  transform: translateX(4px);
  border-color: var(--primary);
}

.shopping-item-name {
  font-weight: 500;
}
.shopping-item-amount {
  color: var(--primary);
  font-weight: 600;
}

/* Toasts / Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 1000;
}
.toast {
  background: var(--surface-color);
  color: var(--text-main);
  padding: 16px 24px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--warning);
  border-top: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  animation: slideIn 0.3s ease-out forwards;
  max-width: 350px;
  font-weight: 500;
}
.toast.toast-error { border-left-color: var(--danger); }
.toast.toast-success { border-left-color: var(--success); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Ingredient Rows */
.ingredient-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  align-items: center;
}
.ingredient-row input, .ingredient-row select {
  flex: 1;
}
.ingredient-row input.amount {
  flex: 0 0 100px;
}
.ingredient-row select.unit {
  flex: 0 0 120px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.modal {
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 32px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(0.98);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid var(--border-color);
}
.modal-overlay.active .modal {
  transform: translateY(0) scale(1);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.modal-header h2 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em;}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  color: var(--border-color);
}

/* Responsive */
@media (max-width: 768px) {
  body { padding-left: 0 !important; }
  .fixed-brand { width: 100%; }
  .sidebar {
    width: 100%;
    transform: translateX(-100%);
  }
  .sidebar.collapsed {
    transform: translateX(0); /* On mobile, toggle brings it in */
  }
  .main-content {
    padding: 20px;
    padding-top: 80px;
  }
  .nav-menu { flex-direction: column; overflow-x: visible; padding-bottom: 8px;}
  .settings-group { flex-direction: column; justify-content: flex-start;}
}

.hidden { display: none !important; }
.text-warning { color: var(--warning); }
.fav-icon { cursor: pointer; color: #cbd5e1; font-size: 1.5rem; transition: color 0.2s;}
.fav-icon:hover { color: #fcd34d; }
.fav-icon.active { color: #f59e0b; }

.filters-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 32px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--surface-color);
  padding: 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}
.filters-bar input, .filters-bar select {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  font-family: var(--font-family);
  transition: all 0.2s;
  background-color: var(--surface-color);
  color: var(--text-main);
}
.filters-bar input:focus, .filters-bar select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--surface-color);
  padding: 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.stat-card.warning {
  border-left: 4px solid var(--warning);
}

.stat-card.warning .stat-value {
  color: var(--warning);
}

.stat-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
  line-height: 1;
}
.stat-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.day-select-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--surface-color);
  color: var(--text-main);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}
.day-select-btn:hover {
  background: rgba(16, 185, 129, 0.05);
  border-color: var(--primary);
  color: var(--primary-hover);
}
