/* ===== CSS Variables & Design System ===== */
:root {
  /* Color Palette - Warm & Appetizing */
  --primary: #E8652B;
  --primary-light: #FF8A50;
  --primary-dark: #C44D1A;
  --primary-bg: rgba(232, 101, 43, 0.08);
  --primary-bg-hover: rgba(232, 101, 43, 0.14);

  --accent: #F5A623;
  --accent-light: #FFD180;

  --bg-body: #F5F0EB;
  --bg-sidebar: #1E1E2A;
  --bg-card: #FFFFFF;
  --bg-card-hover: #FFFBF7;
  --bg-input: #F7F3EF;
  --bg-table-header: #FAF6F2;
  --bg-modal-overlay: rgba(30, 30, 42, 0.55);

  --text-primary: #2D2A26;
  --text-secondary: #7A746C;
  --text-muted: #B0A99F;
  --text-inverse: #FFFFFF;
  --text-sidebar: #A8A4B8;
  --text-sidebar-active: #FFFFFF;

  --border: #E8E2DA;
  --border-light: #F0EBE4;

  --danger: #E53935;
  --danger-light: rgba(229, 57, 53, 0.08);
  --success: #43A047;
  --success-light: rgba(67, 160, 71, 0.1);

  /* Dimensions */
  --sidebar-width: 250px;
  --topbar-height: 68px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(45, 42, 38, 0.06);
  --shadow-md: 0 4px 16px rgba(45, 42, 38, 0.08);
  --shadow-lg: 0 8px 32px rgba(45, 42, 38, 0.12);
  --shadow-card: 0 2px 8px rgba(45, 42, 38, 0.06), 0 0 1px rgba(45, 42, 38, 0.08);
  --shadow-card-hover: 0 8px 28px rgba(232, 101, 43, 0.12), 0 0 1px rgba(45, 42, 38, 0.1);

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: 0.15s var(--ease-out);
  --transition-normal: 0.25s var(--ease-out);
  --transition-slow: 0.4s var(--ease-out);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition-normal);
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
  color: var(--primary);
  background: var(--primary-bg);
  padding: 8px;
  border-radius: var(--radius-sm);
}

.logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-inverse);
  letter-spacing: -0.02em;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-sidebar);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-sidebar-active);
}

.nav-item.active {
  background: var(--primary);
  color: var(--text-inverse);
  box-shadow: 0 4px 12px rgba(232, 101, 43, 0.35);
}

.nav-item .material-icons-round {
  font-size: 20px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-footer-text {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-sidebar);
  font-size: 0.8rem;
  opacity: 0.5;
}

.sidebar-footer-text .material-icons-round {
  font-size: 16px;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Topbar ===== */
.topbar {
  height: var(--topbar-height);
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 0 32px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.menu-toggle:hover {
  background: var(--primary-bg);
}

.topbar-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.topbar-actions {
  margin-left: auto;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn .material-icons-round {
  font-size: 18px;
}

.btn-primary {
  background: var(--primary);
  color: var(--text-inverse);
  box-shadow: 0 2px 8px rgba(232, 101, 43, 0.3);
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 16px rgba(232, 101, 43, 0.4);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 16px;
}

.btn-ghost:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px dashed var(--border);
  padding: 8px 16px;
}

.btn-outline:hover {
  border-color: var(--primary);
  background: var(--primary-bg);
}

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

.btn-danger:hover {
  background: #C62828;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--primary-bg);
  color: var(--primary);
}

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

/* ===== Pages ===== */
.page {
  display: none;
  padding: 28px 32px;
  flex: 1;
  animation: fadeIn 0.3s var(--ease-out);
}

.page.active {
  display: block;
}

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

/* ===== Filter Bar ===== */
.filter-bar {
  margin-bottom: 24px;
}

.filter-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 8px 18px;
  border: 1.5px solid var(--border);
  border-radius: 50px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.filter-tab:hover {
  border-color: var(--primary-light);
  color: var(--primary);
  background: var(--primary-bg);
}

.filter-tab.active {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(232, 101, 43, 0.25);
}

/* ===== Card Grid ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

/* ===== Dish Card ===== */
.dish-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: all var(--transition-normal);
  cursor: default;
  display: flex;
  flex-direction: column;
}

.dish-card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-4px);
}

.dish-card-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: linear-gradient(135deg, #F5E6D3, #FAD0B5);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.dish-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-slow);
}

.dish-card:hover .dish-card-image img {
  transform: scale(1.05);
}

.dish-card-image .no-image {
  color: var(--text-muted);
  font-size: 48px;
  opacity: 0.4;
}

.dish-card-category-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(30, 30, 42, 0.7);
  backdrop-filter: blur(8px);
  color: var(--text-inverse);
  padding: 4px 12px;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 600;
}

.dish-card-body {
  padding: 18px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.dish-card-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}

.dish-card-tips {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.dish-card-ingredients {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.ingredient-tag {
  background: var(--bg-input);
  color: var(--text-secondary);
  padding: 3px 10px;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 500;
}

.dish-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border-light);
}

.dish-card-date {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.dish-card-actions {
  display: flex;
  gap: 4px;
}

/* ===== Table ===== */
.table-container {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  background: var(--bg-table-header);
}

.data-table th {
  padding: 14px 20px;
  text-align: left;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 16px 20px;
  font-size: 0.92rem;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition-fast);
}

.data-table tbody tr:hover td {
  background: var(--bg-card-hover);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.table-actions {
  display: flex;
  gap: 4px;
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-state .material-icons-round {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 1rem;
  font-weight: 500;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-modal-overlay);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  animation: fadeOverlay 0.2s ease;
}

.modal-overlay.show {
  display: flex;
}

@keyframes fadeOverlay {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideModal 0.3s var(--ease-out);
}

.modal-lg {
  max-width: 640px;
}

.modal-sm {
  max-width: 400px;
}

@keyframes slideModal {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 28px 0;
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.modal-body {
  padding: 24px 28px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 0 28px 22px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===== Form ===== */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--bg-input);
  color: var(--text-primary);
  transition: all var(--transition-fast);
  outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237A746C' d='M6 8.825L1.175 4l.825-.825L6 7.175 9.975 3.2l.85.825z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.form-row {
  display: flex;
  gap: 16px;
}

.flex-1 {
  flex: 1;
}

/* ===== Image Upload ===== */
.image-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  transition: all var(--transition-fast);
  cursor: pointer;
  overflow: hidden;
}

.image-upload-area:hover,
.image-upload-area.dragover {
  border-color: var(--primary);
  background: var(--primary-bg);
}

.upload-placeholder {
  padding: 36px 20px;
  text-align: center;
  color: var(--text-muted);
}

.upload-placeholder .material-icons-round {
  font-size: 40px;
  margin-bottom: 8px;
  color: var(--primary-light);
}

.upload-placeholder p {
  font-size: 0.9rem;
  font-weight: 500;
}

.upload-hint {
  font-size: 0.78rem !important;
  margin-top: 4px;
  opacity: 0.7;
}

.upload-preview {
  position: relative;
  height: 200px;
}

.upload-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.btn-remove-img {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(229, 57, 53, 0.85);
  color: white;
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  backdrop-filter: blur(4px);
}

.btn-remove-img:hover {
  background: var(--danger);
  transform: scale(1.1);
}

.btn-remove-img .material-icons-round {
  font-size: 18px;
}

/* ===== Ingredients List ===== */
.ingredients-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.ingredient-row {
  display: flex;
  align-items: center;
  gap: 10px;
  animation: fadeIn 0.2s var(--ease-out);
}

.ingredient-row input {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.88rem;
  background: var(--bg-input);
  color: var(--text-primary);
  transition: all var(--transition-fast);
  outline: none;
}

.ingredient-row input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.ingredient-row .ing-name {
  flex: 2;
}

.ingredient-row .ing-amount {
  flex: 1;
}

.ingredient-row .btn-icon {
  flex-shrink: 0;
}

/* ===== Suggestions ===== */
.unread-row td {
  background: rgba(232, 101, 43, 0.05);
  font-weight: 500;
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  min-width: 280px;
  animation: toastIn 0.35s var(--ease-out);
  border-left: 4px solid var(--success);
}

.toast.error {
  border-left-color: var(--danger);
}

.toast .material-icons-round {
  font-size: 20px;
}

.toast.success .material-icons-round {
  color: var(--success);
}

.toast.error .material-icons-round {
  color: var(--danger);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(245, 240, 235, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main-content {
    margin-left: 0;
  }

  .menu-toggle {
    display: flex;
  }

  .topbar {
    padding: 0 16px;
  }

  .page {
    padding: 20px 16px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .modal {
    margin: 10px;
  }

  .btn-add-text-hide {
    display: none;
  }
}

@media (max-width: 480px) {
  .filter-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
  }

  .filter-tab {
    flex-shrink: 0;
  }
}
