/* ========================================================
   熊吨吨 くまとんとん - 手作工坊管理后台样式 (移动端深度适配版)
   温暖、干净、好用的工坊管理控制台
   适配 iPhone / 微信浏览器 / iPad / 桌面端
   ======================================================== */

:root {
  --admin-bg: #F5EFE6;
  --admin-sidebar-bg: #EAE2D5;
  --admin-card-bg: #FFFDF9;
  
  --primary: #77866B;
  --primary-hover: #66755A;
  --primary-light: #EEF2EB;
  
  --linen: #C8B89D;
  --terracotta: #C9927E;
  --wood: #9A765E;
  
  --text-main: #3F3731;
  --text-sub: #786E66;
  --text-muted: #A3988F;
  
  --border: #E2D8CC;
  --border-light: #ECE5DC;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow: 0 4px 16px rgba(63, 55, 49, 0.05);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body.admin-body {
  background-color: var(--admin-bg);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* 移动端顶部标题栏 (桌面端默认隐藏) */
.mobile-admin-header {
  display: none;
  position: sticky;
  top: 0;
  z-index: 90;
  background: rgba(245, 239, 230, 0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  align-items: center;
  justify-content: space-between;
  height: 52px;
}

.mobile-admin-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-admin-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--linen);
}

.mobile-admin-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
}

.mobile-admin-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 侧边栏导航 (桌面固定) */
.admin-sidebar {
  width: 250px;
  background-color: var(--admin-sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  padding: 24px 16px;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-main);
  padding: 8px 0;
}

.sidebar-logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--linen);
  background: #fff;
}

.sidebar-brand-name {
  font-size: 1.15rem;
  font-weight: 600;
}

.sidebar-brand-tag {
  font-size: 0.72rem;
  color: var(--wood);
  font-weight: 400;
}

.btn-sidebar-close {
  display: none;
  background: transparent;
  border: none;
  font-size: 1.8rem;
  color: var(--text-sub);
  cursor: pointer;
  padding: 4px;
}

.sidebar-menu {
  list-style: none;
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.sidebar-item a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: var(--text-sub);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: all 0.2s ease;
  cursor: pointer;
  min-height: 44px;
}

.sidebar-item a:hover {
  background: rgba(255, 253, 249, 0.6);
  color: var(--text-main);
}

.sidebar-item.active a {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(119, 134, 107, 0.25);
}

.sidebar-footer {
  border-top: 1px dashed var(--linen);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-sub);
}

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
}

.btn-sidebar-action {
  font-size: 0.85rem;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--admin-card-bg);
  color: var(--text-sub);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: all 0.2s;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-sidebar-action:hover {
  background: #fff;
  color: var(--text-main);
}

/* 侧边栏遮罩 */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(63, 55, 49, 0.4);
  backdrop-filter: blur(4px);
  z-index: 95;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

/* 移动端底部导航栏 (桌面端隐藏) */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 80;
  background: rgba(245, 239, 230, 0.98);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 10px max(8px, env(safe-area-inset-bottom, 8px)) 10px;
  justify-content: space-around;
  align-items: center;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  min-width: 54px;
  padding: 4px;
  transition: color 0.2s;
}

.mobile-nav-item .nav-icon {
  font-size: 1.15rem;
}

.mobile-nav-item.active {
  color: var(--primary);
  font-weight: 600;
}

/* 主内容工作区 */
.admin-main {
  margin-left: 250px;
  flex-grow: 1;
  padding: 28px 36px 60px 36px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-main);
}

.page-actions {
  display: flex;
  gap: 10px;
}

/* 按钮通用 */
.btn-craft {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  text-decoration: none;
  min-height: 40px;
}

.btn-craft:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--admin-card-bg);
  border-color: var(--border);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: #fff;
  border-color: var(--linen);
}

.btn-danger {
  background: #FAF0EE;
  border-color: #F1D4CD;
  color: var(--terracotta);
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
  min-height: 34px;
  border-radius: 6px;
}

/* 概览统计卡片 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--admin-card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.stat-val {
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--text-main);
}

.stat-icon {
  font-size: 2rem;
  opacity: 0.8;
}

/* 数据表格与面板 */
.panel-card {
  background: var(--admin-card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
}

/* 响应式表格外框 (确保移动端横向丝滑滑动而不挤压) */
.table-responsive-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  display: block;
}

.craft-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
  min-width: 680px !important;
}

.craft-table th, .craft-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-main);
  vertical-align: middle;
  white-space: nowrap;
}

.craft-table th {
  background: #F7F2E8;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}

/* 标题列允许自然适度换行 */
.craft-table td:nth-child(3) {
  white-space: normal;
  min-width: 180px;
  max-width: 260px;
}

.craft-table tr:hover td {
  background-color: #FAF6EF;
}

.table-thumb {
  width: 48px;
  height: 60px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
  display: block;
}

.status-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.status-badge.published {
  background: var(--primary-light);
  color: var(--primary);
}

.status-badge.draft {
  background: #EFEAE2;
  color: var(--text-muted);
}

/* 弹窗表单 Modal */
.admin-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(63, 55, 49, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

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

.admin-modal-dialog {
  background: var(--admin-card-bg);
  border-radius: var(--radius-lg);
  max-width: 760px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  box-shadow: 0 16px 40px rgba(63, 55, 49, 0.15);
  display: flex;
  flex-direction: column;
}

.admin-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--admin-card-bg);
  z-index: 10;
}

.admin-modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.admin-modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: #FAF6EF;
  position: sticky;
  bottom: 0;
  z-index: 10;
}

/* 表单控件 */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-sub);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #FFFDF9;
  color: var(--text-main);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  min-height: 42px;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
}

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

/* 图片上传预览区 */
.upload-preview-box {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
}

.preview-img {
  width: 72px;
  height: 90px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
  background: #EAE2D5;
  flex-shrink: 0;
}

.upload-btn-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.upload-file-input {
  display: none;
}

/* 登录页独立样式 */
.login-container {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background-color: var(--admin-bg);
}

.login-card {
  max-width: 400px;
  width: 100%;
  background: var(--admin-card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px 24px;
  box-shadow: 0 12px 36px rgba(63, 55, 49, 0.08);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-brand {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid var(--linen);
}

.login-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-main);
}

.login-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ========================================================
   管理端移动端深度响应式适配 (iPhone / 微信浏览器)
   ======================================================== */
@media (max-width: 768px) {
  /* 开启移动端顶栏 */
  .mobile-admin-header {
    display: flex;
  }

  /* 开启移动端底栏 */
  .mobile-bottom-nav {
    display: flex;
  }

  /* 侧边栏转为抽屉式弹层 */
  .admin-sidebar {
    transform: translateX(-100%);
    box-shadow: none;
    width: 270px;
  }

  .admin-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(63, 55, 49, 0.25);
  }

  .btn-sidebar-close {
    display: block;
  }

  /* 主工作区铺满屏幕 */
  .admin-main {
    margin-left: 0;
    padding: 16px 14px max(76px, calc(56px + env(safe-area-inset-bottom, 20px))) 14px;
    width: 100vw;
  }

  /* 概览卡片转为 2x2 网格 */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-val {
    font-size: 1.45rem;
  }
  .stat-icon {
    font-size: 1.6rem;
  }

  .page-header {
    margin-bottom: 16px;
  }
  .page-title {
    font-size: 1.25rem;
  }

  .hide-mobile {
    display: none;
  }

  /* 表单行在手机端单列铺满 */
  .form-row-2 {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* 弹窗在手机端转为 Bottom Sheet 抽屉体验 */
  .admin-modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .admin-modal-dialog {
    max-height: 94vh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    animation: modalDrawerUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes modalDrawerUp {
    from { transform: translateY(100%); opacity: 0.5; }
    to { transform: translateY(0); opacity: 1; }
  }

  .admin-modal-header {
    padding: 14px 18px;
  }

  .admin-modal-body {
    padding: 18px 16px;
  }

  .admin-modal-footer {
    padding: 12px 16px max(14px, env(safe-area-inset-bottom, 14px)) 16px;
  }
}
