:root {
  --admin-bg: #f8fafc; /* Slate 50 */
  --admin-surface: #ffffff;
  --admin-border: #e2e8f0; /* Slate 200 */
  
  --admin-primary: #3b82f6; /* Blue 500 */
  --admin-primary-hover: #2563eb;
  --admin-success: #10b981; /* Emerald 500 */
  --admin-danger: #ef4444; /* Red 500 */
  
  --admin-text-main: #0f172a; /* Slate 900 */
  --admin-text-muted: #64748b; /* Slate 500 */
  
  --sidebar-w: 260px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background: var(--admin-bg); color: var(--admin-text-main); display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar { width: var(--sidebar-w); background: var(--admin-surface); border-right: 1px solid var(--admin-border); display: flex; flex-direction: column; }
.brand { padding: 24px; display: flex; align-items: center; border-bottom: 1px solid var(--admin-border); }
.brand-icon { width: 36px; height: 36px; background: var(--admin-primary); color: white; display: flex; align-items: center; justify-content: center; font-weight: bold; border-radius: 8px; margin-right: 12px; font-size: 18px; }
.brand-text { font-size: 1.2rem; font-weight: 700; color: var(--admin-text-main); }
.nav-menu { flex: 1; padding: 20px 12px; display: flex; flex-direction: column; gap: 8px; }
.nav-item { display: flex; align-items: center; padding: 12px 16px; color: var(--admin-text-muted); text-decoration: none; border-radius: 8px; font-weight: 500; transition: all 0.2s; }
.nav-icon { width: 20px; height: 20px; margin-right: 12px; }
.nav-item:hover { background: #f1f5f9; color: var(--admin-text-main); }
.nav-item.active { background: #eff6ff; color: var(--admin-primary); }

/* Main Content */
.main-content { flex: 1; padding: 40px; overflow-y: auto; background: var(--admin-bg); }
.panel { display: none; }
.panel.active { display: block; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }
.panel-title { font-size: 1.8rem; font-weight: 700; }
.card { background: var(--admin-surface); border-radius: 12px; border: 1px solid var(--admin-border); padding: 24px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05); }
.table-card { padding: 0; overflow: hidden; }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; text-align: left; }
.data-table th { padding: 12px 14px; background: #f8fafc; font-size: 0.78rem; text-transform: uppercase; color: var(--admin-text-muted); font-weight: 600; border-bottom: 1px solid var(--admin-border); white-space: nowrap; }
.data-table td { padding: 12px 14px; font-size: 0.88rem; border-bottom: 1px solid var(--admin-border); vertical-align: middle; }
.data-table tr:hover { background: #f8fafc; }

.status-badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.status-badge.confirmed { background: #d1fae5; color: #047857; }
.status-badge.cancelled { background: #fee2e2; color: #b91c1c; }
.status-badge.pending-payment { background: #fef3c7; color: #92400e; }
.status-badge.payment-review { background: #fed7aa; color: #9a3412; }
.status-badge.completed { background: #ede9fe; color: #5b21b6; }
.btn-confirm-payment { background: #10b981; color: white; border: none; padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; font-weight: 600; }
.btn-confirm-payment:hover { background: #059669; }
.btn-reject-payment { background: #ef4444; color: white; border: none; padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; font-weight: 600; }
.btn-reject-payment:hover { background: #dc2626; }

/* Buttons & Inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 18px; border-radius: 8px; font-size: 0.95rem; font-weight: 500; cursor: pointer; border: none; transition: 0.2s; }
.btn-icon { width: 18px; height: 18px; margin-right: 6px; }
.btn-primary { background: var(--admin-primary); color: white; }
.btn-primary:hover { background: var(--admin-primary-hover); }
.btn-success { background: var(--admin-success); color: white; }
.btn-success:hover { background: #059669; }
.btn-outline { background: transparent; border: 1px solid var(--admin-border); color: var(--admin-text-main); }
.btn-outline:hover { background: #f8fafc; }
.btn-danger-sm { background: #fee2e2; color: #b91c1c; border-radius: 6px; padding: 6px 12px; font-size: 0.8rem; cursor: pointer; border: none; font-weight: bold;}
.btn-danger-sm:hover { background: #fecaca; }
.btn-restore-sm { background: #e0e7ff; color: #4338ca; border-radius: 6px; padding: 6px 12px; font-size: 0.8rem; cursor: pointer; border: none; font-weight: bold;}
.btn-restore-sm:hover { background: #c7d2fe; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--admin-text-muted); margin-bottom: 8px; }
.form-control { width: 100%; padding: 12px; border-radius: 8px; border: 1px solid var(--admin-border); font-family: inherit; font-size: 0.95rem; outline: none; transition: 0.2s; }
.form-control:focus { border-color: var(--admin-primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.mt-4 { margin-top: 24px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.full-width { grid-column: 1 / -1; }

/* Plans Grid */
.plans-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.plan-item { background: #f8fafc; border: 1px solid var(--admin-border); border-radius: 10px; padding: 20px; position: relative;}
.plan-item .remove-plan { position: absolute; top: 10px; right: 10px; width: 24px; height: 24px; background: #fee2e2; color: #ef4444; border:none; border-radius: 4px; cursor: pointer; display: flex; align-items:center; justify-content:center; }
.plan-item .remove-plan:hover { background: #ef4444; color: white;}

.slide-fade-in { animation: slideFade 0.4s ease forwards; }
/* 營運數據儀表板樣式 */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-bottom: 30px; }
.stats-card { background: var(--admin-surface); border: 1px solid var(--admin-border); border-radius: 12px; padding: 24px; display: flex; align-items: center; gap: 20px; transition: transform 0.2s, box-shadow 0.2s; }
.stats-card:hover { transform: translateY(-3px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); }
.stats-icon { width: 56px; height: 56px; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: white; }
.stats-icon svg { width: 28px; height: 28px; }
.stats-icon.bg-primary { background: #3b82f6; }
.stats-icon.bg-success { background: #10b981; }
.stats-icon.bg-warning { background: #f59e0b; }
.stats-info { flex: 1; }
.stats-label { display: block; font-size: 0.85rem; color: var(--admin-text-muted); font-weight: 500; margin-bottom: 4px; }
.stats-value { font-size: 1.8rem; font-weight: 800; color: var(--admin-text-main); }

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

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal.hidden { display: none; }
.modal-content { background: white; border-radius: 16px; width: 100%; max-width: 600px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); overflow: hidden; animation: modalPop 0.3s ease-out; }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--admin-border); display: flex; justify-content: space-between; align-items: center; }
.close-btn { font-size: 24px; color: var(--admin-text-muted); cursor: pointer; border: none; background: transparent; }
.close-btn:hover { color: var(--admin-text-main); }

@keyframes modalPop { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* Search & Filter bar */
.search-filter-bar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search-filter-bar .form-control { flex: 1; min-width: 160px; }

/* CRM & Marketing */
.crm-records-list { max-height: 400px; overflow-y: auto; padding: 10px 5px; }
.marketing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 20px; }
.inline-form { display: flex; gap: 10px; align-items: center; margin-bottom: 15px; }

#adminCalendar { height: 700px; background: white; border-radius: 12px; }

/* iCal UI */
.ical-box { background: #f0f9ff; border: 1px solid #bae6fd; padding: 15px 20px; border-radius: 12px; display: flex; align-items: center; justify-content: space-between; margin-bottom: 25px; }
.ical-text { color: #0369a1; font-size: 0.9rem; margin-bottom: 4px; }
.ical-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 15px 20px; }
.ical-info { flex: 1; min-width: 0; }
.ical-actions { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.ical-actions .form-control { width: 260px; }


/* ── 手機版響應式 ──────────────────────────────────── */
.hamburger {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 1001;
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  align-items: center;
  justify-content: center;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 999;
}

@media (max-width: 768px) {
  .hamburger { display: flex; }

  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    height: 100vh;
    z-index: 1000;
    transition: left 0.25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay.active { display: block; }

  .main-content { padding: 68px 14px 24px; }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .panel-title { font-size: 1.4rem; }

  /* 操作按鈕列：換行顯示 */
  .header-actions {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  .header-actions .btn {
    font-size: 0.8rem;
    padding: 8px 10px;
  }

  .table-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .data-table { min-width: 980px; }

  /* ── 訂單卡片視圖（手機版）─────────────────────── */
  #panel-dashboard .table-card {
    overflow-x: unset;
    background: none;
    box-shadow: none;
    border: none;
    padding: 0;
  }
  #panel-dashboard .data-table,
  #panel-dashboard .data-table tbody { display: block; min-width: unset; }
  #panel-dashboard .data-table thead { display: none; }

  #panel-dashboard .data-table tbody tr {
    display: grid;
    grid-template-areas:
      "name    name"
      "time    status"
      "plan    phone"
      "actions actions";
    grid-template-columns: 1fr auto;
    padding: 14px 16px;
    margin-bottom: 12px;
    border-radius: 12px;
    border: 1px solid var(--admin-border);
    background: #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  }
  #panel-dashboard .data-table td {
    padding: 3px 0 !important;
    border: none !important;
    font-size: 0.9rem;
    min-width: 0;
  }

  /* 隱藏次要欄位 */
  #panel-dashboard .col-check,
  #panel-dashboard .col-created,
  #panel-dashboard .col-email,
  #panel-dashboard .col-payment,
  #panel-dashboard .col-note,
  #panel-dashboard .col-cancel,
  #panel-dashboard .col-admin-note { display: none !important; }

  #panel-dashboard .col-name {
    grid-area: name;
    padding-bottom: 10px !important;
    border-bottom: 1px solid #f1f5f9 !important;
    margin-bottom: 4px;
    font-size: 1rem !important;
  }
  #panel-dashboard .col-time {
    grid-area: time;
    color: var(--admin-text-muted);
    font-size: 0.83rem !important;
    line-height: 1.5;
  }
  #panel-dashboard .col-status {
    grid-area: status;
    display: flex !important;
    justify-content: flex-end;
    align-items: flex-start;
  }
  #panel-dashboard .col-plan {
    grid-area: plan;
    font-size: 0.85rem !important;
  }
  #panel-dashboard .col-phone {
    grid-area: phone;
    text-align: right;
    font-size: 0.85rem !important;
    display: flex !important;
    justify-content: flex-end;
    align-items: center;
  }
  #panel-dashboard .col-actions {
    grid-area: actions;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 10px !important;
    border-top: 1px solid #f1f5f9 !important;
    margin-top: 6px;
  }
  #panel-dashboard .col-actions button {
    flex: 1;
    min-width: 72px;
    padding: 8px 6px;
    font-size: 0.78rem;
    min-height: 36px;
    text-align: center;
  }
  /* ─────────────────────────────────────────────── */

  .stats-grid { grid-template-columns: 1fr; gap: 12px; margin-bottom: 20px; }
  .stats-card { padding: 16px; gap: 14px; }
  .stats-value { font-size: 1.5rem; }

  /* 圖表雙欄 → 單欄 */
  #panel-dashboard > div[style*="grid-template-columns:2fr 1fr"] { grid-template-columns: 1fr !important; }

  .plans-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .marketing-grid { grid-template-columns: 1fr; }
  .search-filter-bar { flex-direction: column; align-items: stretch; }
  .search-filter-bar select { width: 100% !important; min-width: unset; }

  /* iCal 手機版 */
  .ical-card { flex-direction: column; align-items: stretch; gap: 12px; }
  .ical-actions { flex-direction: column; }
  .ical-actions .form-control { width: 100%; }

  /* 備註欄縮小 */
  .note-input { min-height: 36px; font-size: 0.78rem; }

  #adminCalendar { height: 500px; }

  /* 黑名單表格橫向捲動 */
  #panel-blacklist .table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #panel-blacklist .data-table { min-width: 520px; }

  /* 時段鎖定表格橫向捲動 */
  #blockForm { grid-template-columns: 1fr 1fr !important; }
  #blockForm button[type="submit"] { grid-column: 1 / -1; }

  /* 黑名單新增表單：垂直堆疊 */
  #panel-blacklist .form-grid { grid-template-columns: 1fr !important; }
  #panel-blacklist .form-grid button { grid-column: 1; padding: 11px; }

  /* 行銷工具輸入列換行 */
  #panel-marketing .card > .form-group > div[style*="flex"] { flex-wrap: wrap; }

  /* Modal 手機版全屏 */
  .modal { padding: 0; align-items: flex-end; }
  .modal-content {
    max-width: 100% !important;
    width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 90vh;
    overflow-y: auto;
  }
}

/* 分頁按鈕 disabled */
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

/* 預約模式選擇卡片 */
.mode-card {
  border: 2px solid var(--admin-border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  transition: all 0.2s;
  background: #f8fafc;
  user-select: none;
}
.mode-card:hover { border-color: var(--admin-primary); background: #eff6ff; }
input[name="businessMode"]:checked + .mode-card {
  border-color: var(--admin-primary);
  background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
input[name="businessMode"][value="parttime"]:checked + .mode-card {
  border-color: #f97316;
  background: #fff7ed;
  box-shadow: 0 0 0 3px rgba(249,115,22,0.15);
}

/* 批次操作列 */
#bulkBar { animation: slideFade 0.2s ease; }

/* 操作記錄面板 */
#panel-logs .data-table td { font-size: 0.85rem; }
