/**
 * ============================================
 * 家庭点餐系统 - 样式表
 * Family Meal Ordering System - Styles
 * ============================================
 */

/* ============================================
   CSS 变量 - 设计令牌
   ============================================ */
:root {
  /* 主色调 - 温暖的橙色系 */
  --primary-50: #fff7ed;
  --primary-100: #ffedd5;
  --primary-200: #fed7aa;
  --primary-300: #fdba74;
  --primary-400: #fb923c;
  --primary-500: #f97316;
  --primary-600: #ea580c;
  --primary-700: #c2410c;

  /* 成功色 - 绿色 */
  --success-500: #22c55e;
  --success-600: #16a34a;

  /* 危险色 - 红色 */
  --danger-500: #ef4444;
  --danger-600: #dc2626;

  /* 中性色 */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* 布局 */
  --max-width: 1200px;
  --header-height: 64px;
  --border-radius: 12px;
  --border-radius-sm: 8px;

  /* 阴影 */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  /* 过渡 */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

/* ============================================
   重置与基础样式
   ============================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: linear-gradient(135deg, var(--primary-50) 0%, var(--gray-100) 100%);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

/* ============================================
   布局容器
   ============================================ */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1rem;
}

/* ============================================
   顶部导航
   ============================================ */
.header {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
}

.header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-600);
  text-decoration: none;
}

.logo-icon {
  font-size: 2rem;
}

/* 导航标签页 */
.nav-tabs {
  display: flex;
  gap: 0.5rem;
}

.nav-tab {
  padding: 0.75rem 1.25rem;
  border: none;
  background: transparent;
  color: var(--gray-600);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--border-radius-sm);
  transition: all var(--transition-fast);
  text-decoration: none;
}

.nav-tab:hover {
  background: var(--gray-100);
  color: var(--gray-800);
}

.nav-tab.active {
  background: var(--primary-500);
  color: white;
}

/* ============================================
   主内容区
   ============================================ */
main {
  padding: 2rem 0;
  min-height: calc(100vh - var(--header-height));
}

.view {
  display: none;
  animation: fadeIn 0.3s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 视图标题 */
.view-header {
  margin-bottom: 2rem;
  text-align: center;
}

.view-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 0.5rem;
}

.view-subtitle {
  color: var(--gray-500);
  font-size: 1.1rem;
}

/* ============================================
   菜品网格 (儿子视图)
   ============================================ */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.5rem;
}

.menu-card {
  background: white;
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: all var(--transition-normal);
  position: relative;
}

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

.menu-card:active {
  transform: scale(0.98);
}

.menu-card-image {
  width: 100%;
  height: 150px;
  object-fit: cover;
  background: var(--gray-200);
}

.menu-card-image.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  color: var(--gray-300);
}

.menu-card-content {
  padding: 1rem;
}

.menu-card-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 0.25rem;
}

.menu-card-category {
  font-size: 0.875rem;
  color: var(--gray-500);
}

/* 分类标题 */
.category-section {
  margin-bottom: 2rem;
}

.category-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--primary-200);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ============================================
   管理表格 (妈妈视图)
   ============================================ */
.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.admin-table-wrapper {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

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

.admin-table th,
.admin-table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

.admin-table th {
  background: var(--gray-50);
  font-weight: 600;
  color: var(--gray-700);
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.admin-table tr:hover {
  background: var(--gray-50);
}

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

/* 菜品图片缩略图 */
.table-image {
  width: 60px;
  height: 60px;
  border-radius: var(--border-radius-sm);
  object-fit: cover;
}

.table-image.placeholder {
  background: var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

/* 可用状态切换 */
.toggle-switch {
  position: relative;
  width: 50px;
  height: 28px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--gray-300);
  border-radius: 28px;
  transition: var(--transition-fast);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked+.toggle-slider {
  background: var(--success-500);
}

.toggle-switch input:checked+.toggle-slider::before {
  transform: translateX(22px);
}

/* 操作按钮组 */
.action-buttons {
  display: flex;
  gap: 0.5rem;
}

/* ============================================
   厨房视图 (阿姨视图)
   ============================================ */
.kitchen-orders {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.kitchen-card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.kitchen-card-info {
  flex: 1;
}

.kitchen-card-name {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 0.25rem;
}

.kitchen-card-meta {
  font-size: 1rem;
  color: var(--gray-500);
}

.kitchen-card-time {
  font-size: 0.875rem;
  color: var(--gray-400);
}

/* 大按钮 - 厨房完成按钮 */
.btn-kitchen-done {
  padding: 1rem 2rem;
  font-size: 1.25rem;
  font-weight: 600;
  background: var(--success-500);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-width: 120px;
}

.btn-kitchen-done:hover {
  background: var(--success-600);
  transform: scale(1.05);
}

.btn-kitchen-done:active {
  transform: scale(0.98);
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--gray-400);
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.empty-state-text {
  font-size: 1.25rem;
  color: var(--gray-500);
}

/* ============================================
   统计卡片 (妈妈视图)
   ============================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
}

.stat-card-title {
  font-size: 0.875rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.stat-card-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary-600);
}

.stat-card-subtitle {
  font-size: 0.875rem;
  color: var(--gray-400);
}

/* 热门菜品列表 */
.top-items-list {
  list-style: none;
}

.top-items-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--gray-100);
}

.top-items-list li:last-child {
  border-bottom: none;
}

.top-item-name {
  font-weight: 500;
  color: var(--gray-700);
}

.top-item-count {
  background: var(--primary-100);
  color: var(--primary-700);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 600;
}

/* ============================================
   按钮样式
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

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

.btn-primary:hover {
  background: var(--primary-600);
}

.btn-secondary {
  background: var(--gray-200);
  color: var(--gray-700);
}

.btn-secondary:hover {
  background: var(--gray-300);
}

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

.btn-success:hover {
  background: var(--success-600);
}

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

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

.btn-sm {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
}

/* ============================================
   模态框
   ============================================ */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-xl);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9) translateY(20px);
  transition: all var(--transition-normal);
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-900);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--gray-400);
  cursor: pointer;
  padding: 0.5rem;
  line-height: 1;
}

.modal-close:hover {
  color: var(--gray-600);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1.5rem;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ============================================
   表单样式
   ============================================ */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 0.5rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--border-radius-sm);
  background: white;
  color: var(--gray-800);
  transition: all var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary-400);
  box-shadow: 0 0 0 3px var(--primary-100);
}

.form-input::placeholder {
  color: var(--gray-400);
}

/* ============================================
   确认弹窗 (点餐确认)
   ============================================ */
.confirm-modal .modal-body {
  text-align: center;
  padding: 2rem;
}

.confirm-item-image {
  width: 150px;
  height: 150px;
  border-radius: var(--border-radius);
  object-fit: cover;
  margin-bottom: 1rem;
}

.confirm-item-name {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 0.5rem;
}

.confirm-message {
  color: var(--gray-500);
  margin-bottom: 1.5rem;
}

/* ============================================
   Toast 通知
   ============================================ */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.toast {
  background: var(--gray-800);
  color: white;
  padding: 1rem 1.5rem;
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideIn 0.3s ease;
}

.toast.success {
  background: var(--success-500);
}

.toast.error {
  background: var(--danger-500);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ============================================
   加载状态
   ============================================ */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  color: var(--gray-400);
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-text {
  margin-top: 1rem;
  font-size: 1rem;
}

/* ============================================
   响应式设计
   ============================================ */
@media (max-width: 768px) {
  .header {
    height: auto;
    position: static;
    /* 移动端取消吸顶，避免占据过多屏幕空间，或者保留 sticky 但修复高度 */
  }

  .header .container {
    flex-direction: column;
    gap: 0.5rem;
    height: auto;
    padding: 1rem;
  }

  .nav-tabs {
    width: 100%;
    overflow-x: auto;
    justify-content: center;
    padding-bottom: 0.5rem;
    /* 增加一点底部呼吸空间 */
  }

  .nav-tab {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    white-space: nowrap;
    /* 防止换行 */
  }

  main {
    padding: 1rem 0;
  }

  /* 移动端隐藏儿子视图的大标题，因为 Header 已经有了 */
  #son-view .view-title {
    display: none;
  }

  /* 调整 Tab 容器的上边距 */
  .tabs-container {
    margin-top: 0;
  }

  .menu-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
  }

  .menu-card-image {
    height: 120px;
  }

  /* 移动端表格转卡片视图 */
  .admin-table,
  .admin-table tbody,
  .admin-table tr,
  .admin-table td {
    display: block;
    width: 100%;
  }

  .admin-table thead {
    display: none;
  }

  .admin-table tr {
    background: white;
    margin-bottom: 1rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    position: relative;
    border: 1px solid var(--gray-200);
  }

  .admin-table td {
    padding: 0.5rem 0;
    text-align: right;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .admin-table td:last-child {
    border-bottom: none;
    justify-content: flex-end;
    padding-top: 1rem;
  }

  /* 添加标签 */
  .admin-table td::before {
    content: attr(data-label);
    float: left;
    font-weight: 600;
    color: var(--gray-500);
    font-size: 0.875rem;
  }

  /* 特定列样式调整 */
  /* 图片列 */
  .admin-table td:nth-of-type(1) {
    justify-content: center;
    border-bottom: none;
    padding-bottom: 0;
  }

  .table-image {
    width: 80px;
    height: 80px;
    border-radius: var(--border-radius);
  }

  /* 名称列 */
  .admin-table td:nth-of-type(2) {
    text-align: center;
    justify-content: center;
    font-size: 1.1rem;
    padding-top: 0;
    border-bottom: 1px solid var(--gray-100);
  }

  /* 为每一列添加伪元素标签 (如果不能修改 HTML 添加 data-label，只能用 nth-of-type hack) */
  /* 由于没有 data-label，这里手动添加 */
  .admin-table td:nth-of-type(3)::before {
    content: "分类";
  }

  .admin-table td:nth-of-type(4)::before {
    content: "今日可点";
  }

  /* 操作列不需要标签 */


  .admin-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .kitchen-card {
    flex-direction: column;
    text-align: center;
  }

  .kitchen-card-name {
    font-size: 1.5rem;
  }

  .view-title {
    font-size: 1.5rem;
  }

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

/* 大屏幕厨房模式 */
@media (min-width: 1024px) {
  .kitchen-card-name {
    font-size: 2rem;
  }

  .btn-kitchen-done {
    padding: 1.25rem 2.5rem;
    font-size: 1.5rem;
  }
}

/* ============================================
   餐段切换 Tab (儿子视图)
   ============================================ */
.tabs-container {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

.tab-btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  border: 2px solid var(--primary-300);
  background: white;
  color: var(--primary-600);
  border-radius: 30px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab-btn:hover {
  background: var(--primary-100);
  border-color: var(--primary-400);
}

.tab-btn.active {
  background: var(--primary-500);
  border-color: var(--primary-500);
  color: white;
  box-shadow: var(--shadow-md);
}

@media (max-width: 768px) {
  .tabs-container {
    gap: 0.25rem;
  }

  .tab-btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
  }
}

/* ============================================
   图片搜索结果
   ============================================ */
.image-search-results {
  margin-top: 1rem;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--border-radius-sm);
  padding: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
}

.search-results-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.search-image-item {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition-fast);
}

.search-image-item:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-sm);
}

.search-image-item.selected {
  border-color: var(--primary-500);
  opacity: 0.8;
}

.search-loading,
.search-empty {
  text-align: center;
  padding: 1rem;
  color: var(--gray-500);
  font-size: 0.875rem;
}