/* ===== 後台管理系統樣式 ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --color-primary: #5c4033;
  --color-primary-light: #8b6f47;
  --color-accent: #c8a27a;
  --color-accent-light: #e8d5b7;
  --color-bg: #f5f1eb;
  --color-white: #ffffff;
  --color-text: #3a3a3a;
  --color-text-light: #6b6b6b;
  --color-dark: #2c1e14;
  --color-success: #27ae60;
  --color-danger: #c0392b;
  --color-warning: #f39c12;
  --sidebar-width: 260px;
  --font-serif: 'Noto Serif TC', serif;
  --font-sans: 'Noto Sans TC', sans-serif;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
  --radius: 10px;
  --transition: 0.3s ease;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  display: flex;
  min-height: 100vh;
}

/* ===== 側邊欄 ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-dark);
  color: var(--color-white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

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

.sidebar-header h2 {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  margin-bottom: 4px;
}

.sidebar-header span {
  font-size: 0.78rem;
  color: var(--color-accent);
  letter-spacing: 1px;
}

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

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.92rem;
  transition: var(--transition);
}

.sidebar-link:hover {
  background: rgba(255,255,255,0.08);
  color: var(--color-white);
}

.sidebar-link.active {
  background: var(--color-primary);
  color: var(--color-white);
}

.sidebar-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
}

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

.sidebar-footer a {
  color: rgba(255,255,255,0.5);
  text-decoration: none;
  font-size: 0.85rem;
  transition: var(--transition);
}

.sidebar-footer a:hover {
  color: var(--color-accent);
}

/* ===== 主內容 ===== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 32px;
  background: var(--color-white);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h1 {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--color-primary);
  flex: 1;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--color-text);
  cursor: pointer;
}

.admin-badge {
  padding: 5px 14px;
  background: var(--color-accent-light);
  color: var(--color-primary);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
}

/* ===== Panels ===== */
.panel {
  display: none;
  padding: 32px;
  animation: fadeIn 0.3s ease;
}

.panel.active {
  display: block;
}

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

/* ===== 統計卡片 ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--color-white);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.coffee-icon { background: #fef3e2; }
.dessert-icon { background: #fce4ec; }
.message-icon { background: #e8f5e9; }
.total-icon { background: #e3f2fd; }

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

.stat-number {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.2;
}

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

.dashboard-hint {
  background: var(--color-white);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-sm);
}

.dashboard-hint h3 {
  font-family: var(--font-serif);
  color: var(--color-primary);
  margin-bottom: 8px;
}

.dashboard-hint p {
  color: var(--color-text-light);
  line-height: 1.8;
}

/* ===== 工具列 ===== */
.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 200px;
}

.search-box input {
  width: 100%;
  padding: 10px 16px;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  background: var(--color-white);
  transition: var(--transition);
}

.search-box input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(200,162,122,0.15);
}

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

/* ===== 按鈕 ===== */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

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

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

.btn-outline {
  background: transparent;
  color: var(--color-text-light);
  border: 1.5px solid #ddd;
}

.btn-outline:hover,
.btn-outline.active {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: rgba(92,64,51,0.04);
}

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

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

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

.btn-icon {
  padding: 6px 10px;
  background: none;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: var(--transition);
}

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

.btn-icon.danger:hover {
  background: #fce4ec;
  border-color: var(--color-danger);
  color: var(--color-danger);
}

/* ===== 表格 ===== */
.table-wrapper {
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  text-align: left;
  padding: 14px 18px;
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-light);
  background: var(--color-bg);
  border-bottom: 1px solid #eee;
  white-space: nowrap;
}

.data-table td {
  padding: 14px 18px;
  border-bottom: 1px solid #f5f5f5;
  vertical-align: middle;
}

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

.data-table tr:hover td {
  background: rgba(200,162,122,0.04);
}

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-coffee {
  background: #fef3e2;
  color: #b8860b;
}

.badge-dessert {
  background: #fce4ec;
  color: #c0392b;
}

.badge-available {
  background: #e8f5e9;
  color: var(--color-success);
}

.badge-unavailable {
  background: #fbe9e7;
  color: var(--color-danger);
}

.badge-visible {
  background: #e8f5e9;
  color: var(--color-success);
}

.badge-hidden {
  background: #f5f5f5;
  color: #999;
}

.actions-cell {
  display: flex;
  gap: 6px;
}

.message-preview {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-light);
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

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

.modal {
  background: var(--color-white);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: modalIn 0.3s ease;
}

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

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid #f0f0f0;
}

.modal-header h3 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  color: var(--color-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #aaa;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: var(--transition);
}

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

.modal form,
.confirm-text {
  padding: 24px;
}

.confirm-text {
  color: var(--color-text-light);
  line-height: 1.7;
}

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

.form-group {
  margin-bottom: 18px;
}

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

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  transition: var(--transition);
  background: var(--color-white);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(200,162,122,0.15);
}

.form-group textarea {
  resize: vertical;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 24px 24px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  padding: 14px 24px;
  background: var(--color-primary);
  color: var(--color-white);
  border-radius: 8px;
  font-size: 0.88rem;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.4s ease;
  z-index: 9999;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

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

/* ===== 登入畫面 ===== */
.login-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #2c1e14 0%, #5c4033 50%, #8b6f47 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  background: var(--color-white);
  border-radius: var(--radius);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: modalIn 0.5s ease;
}

.login-header {
  text-align: center;
  margin-bottom: 36px;
}

.login-header h1 {
  font-family: var(--font-serif);
  font-size: 2rem;
  color: var(--color-primary);
  margin-bottom: 6px;
}

.login-header p {
  font-size: 0.88rem;
  color: var(--color-text-light);
  letter-spacing: 1px;
}

.login-error {
  color: var(--color-danger);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin-bottom: 8px;
  text-align: center;
}

.login-hint {
  margin-top: 20px;
  text-align: center;
  font-size: 0.78rem;
  color: #bbb;
}

/* 登入前隱藏後台 */
.sidebar.auth-hidden,
.main-content.auth-hidden {
  display: none;
}

.logout-link {
  display: block;
  margin-top: 10px;
  color: rgba(255,255,255,0.4) !important;
}

.logout-link:hover {
  color: #e74c3c !important;
}

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

  .sidebar.open {
    transform: translateX(0);
  }

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

  .menu-toggle {
    display: block;
  }

  .panel {
    padding: 20px;
  }

  .topbar {
    padding: 16px 20px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .filter-group {
    justify-content: flex-start;
  }
}
