/* =============================================================
   ChiaoOrder 設計系統 (theme.css)
   適用：台灣餐飲小店自助點餐系統模板（繁體中文優先）
   風格：Warm Retro / 暖色咖啡館（來自 ui-ux-pro-max 引擎推導）
   字型：繁體中文 → Noto Sans TC / Noto Serif TC；拉丁 → Inter / Fraunces
   規範：移動優先、對比度 >=4.5:1、可見焦點、tap target >=44px
   ============================================================= */

/* ---- 字型（繁體中文專用，Google Fonts CDN） ---- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Noto+Sans+TC:wght@400;500;700&family=Noto+Serif+TC:wght@400;600;700&display=swap');

/* ============================================================
   1. 設計 Token（CSS 變數）
   ============================================================ */
:root {
  /* 色彩系統（Warm Analogous 056，對比度已驗證） */
  --c-primary:      #C43831;  /* 陶紅，主行動 / 品牌 */
  --c-primary-600:  #A82E28;  /* hover / active */
  --c-primary-50:   #FBEDEB;  /* 主色極淡底 */
  --c-secondary:    #D2954B;  /* 琥珀，次行動 / 裝飾 */
  --c-secondary-600:#B87B33;
  --c-accent:       #E3261C;  /* 強調 / 警示紅 */
  --c-bg:           #F9F6F6;  /* 頁面底 */
  --c-surface:      #FFFFFF;  /* 卡片 / 面板 */
  --c-surface-2:    #FBF3EE;  /* 次表面（分隔區） */
  --c-border:       #EAD8D7;  /* 邊框 / 分隔線 */
  --c-text:         #16181D;  /* 正文（對 bg 16.5:1） */
  --c-text-soft:    #5B5550;  /* 次要文字 */
  --c-text-faint:   #8C847E;  /* 提示 / placeholder */
  --c-success:      #2E7D5B;
  --c-success-bg:   #E6F2EC;
  --c-warn:         #B8791B;
  --c-warn-bg:      #FBF0DC;
  --c-danger:       #C43831;
  --c-danger-bg:    #FBEDEB;

  /* 字型堆疊（拉丁在前，CJK 靠 fallback 自動接 Noto） */
  --font-sans:  'Inter', 'Noto Sans TC', system-ui, -apple-system, 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  --font-serif: 'Fraunces', 'Noto Serif TC', Georgia, 'Songti TC', serif;
  --font-mono:  'SFMono-Regular', Menlo, Consolas, monospace;

  /* 字級（移動優先，body >= 16px） */
  --fs-xs:   0.75rem;   /* 12 */
  --fs-sm:   0.875rem;  /* 14 */
  --fs-base: 1rem;      /* 16 */
  --fs-md:   1.125rem;  /* 18 */
  --fs-lg:   1.375rem;  /* 22 */
  --fs-xl:   1.75rem;   /* 28 */
  --fs-2xl:  2.25rem;   /* 36 */
  --fs-3xl:  3rem;      /* 48 */

  /* 間距（4px 基準） */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

  /* 圓角 / 陰影 / 過場 */
  --r-sm: 8px;  --r-md: 12px; --r-lg: 20px; --r-pill: 999px;
  --sh-1: 0 1px 2px rgba(22,24,29,.06), 0 1px 3px rgba(22,24,29,.08);
  --sh-2: 0 4px 12px rgba(22,24,29,.08), 0 2px 4px rgba(22,24,29,.06);
  --sh-3: 0 12px 32px rgba(22,24,29,.12);
  --t-fast: 120ms ease;  --t-base: 200ms ease;

  /* 版面 */
  --maxw: 1080px;
  --header-h: 60px;
  --focus: 3px solid #2C6FB5;  /* 可見焦點環 */
}

/* ============================================================
   2. 基礎 / Reset
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.6;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
a { color: var(--c-primary-600); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { font-family: var(--font-serif); font-weight: 700; line-height: 1.2; margin: 0 0 var(--sp-3); color: var(--c-text); }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p  { margin: 0 0 var(--sp-3); }
small, .text-faint { color: var(--c-text-faint); }
.text-soft { color: var(--c-text-soft); }

/* 可見焦點環（a11y UX-005） */
:focus-visible { outline: var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }

/* ============================================================
   3. 排版工具
   ============================================================ */
.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 var(--sp-4); }
.stack > * + * { margin-top: var(--sp-4); }
.row { display: flex; gap: var(--sp-3); align-items: center; }
.row-wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.center { justify-content: center; }
.muted { color: var(--c-text-soft); }
.serif { font-family: var(--font-serif); }
.mono { font-family: var(--font-mono); }
.text-center { text-align: center; }
.mt-0{margin-top:0}.mt-2{margin-top:var(--sp-2)}.mt-4{margin-top:var(--sp-4)}.mt-6{margin-top:var(--sp-6)}
.mb-0{margin-bottom:0}.mb-2{margin-bottom:var(--sp-2)}.mb-4{margin-bottom:var(--sp-4)}
.hidden { display: none !important; }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }

/* ============================================================
   4. 元件：按鈕（tap target >= 44px，UX-013/024）
   ============================================================ */
.btn {
  --btn-bg: var(--c-primary); --btn-fg: #fff;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px; padding: 0 var(--sp-5);
  font-family: var(--font-sans); font-size: var(--fs-base); font-weight: 600;
  color: var(--btn-fg); background: var(--btn-bg);
  border: 1px solid transparent; border-radius: var(--r-pill);
  cursor: pointer; transition: background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  text-decoration: none; user-select: none; white-space: nowrap;
}
.btn:hover { background: var(--c-primary-600); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { --btn-bg: var(--c-primary); }
.btn-secondary { --btn-bg: var(--c-secondary); }
.btn-secondary:hover { background: var(--c-secondary-600); }
.btn-ghost { --btn-bg: transparent; --btn-fg: var(--c-text); border-color: var(--c-border); }
.btn-ghost:hover { background: var(--c-surface-2); }
.btn-outline { --btn-bg: #fff; --btn-fg: var(--c-primary); border-color: var(--c-primary); }
.btn-outline:hover { background: var(--c-primary-50); }
.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 36px; padding: 0 var(--sp-4); font-size: var(--fs-sm); }
.btn-lg { min-height: 52px; font-size: var(--fs-md); padding: 0 var(--sp-6); }

/* 連結型按鈕 */
.link-btn { background: none; border: none; color: var(--c-primary-600); font-size: var(--fs-sm); cursor: pointer; padding: var(--sp-2); font-weight: 600; }
.link-btn:hover { text-decoration: underline; }

/* ============================================================
   5. 元件：卡片 / 面板 / 徽章
   ============================================================ */
.card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-lg); box-shadow: var(--sh-1); padding: var(--sp-5);
}
.card-2 { box-shadow: var(--sh-2); }
.panel { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md); }
.section { padding: var(--sp-10) 0; }
.section-tight { padding: var(--sp-6) 0; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-xs); font-weight: 600; line-height: 1;
  padding: 4px 10px; border-radius: var(--r-pill);
  background: var(--c-surface-2); color: var(--c-text-soft); border: 1px solid var(--c-border);
}
.badge-primary { background: var(--c-primary-50); color: var(--c-primary-600); border-color: #F0C9C5; }
.badge-success { background: var(--c-success-bg); color: var(--c-success); border-color: #C9E5D6; }
.badge-warn    { background: var(--c-warn-bg);    color: var(--c-warn);    border-color: #F0DDB5; }
.badge-danger  { background: var(--c-danger-bg);  color: var(--c-danger);  border-color: #F0C9C5; }

/* ============================================================
   6. 元件：表單（label + 輸入，移動優先）
   ============================================================ */
.field { margin-bottom: var(--sp-4); }
.field > label { display: block; font-weight: 600; font-size: var(--fs-sm); margin-bottom: var(--sp-2); }
.field .hint { font-size: var(--fs-xs); color: var(--c-text-faint); margin-top: 4px; }
input, select, textarea {
  width: 100%; font-family: var(--font-sans); font-size: var(--fs-base); color: var(--c-text);
  background: #fff; border: 1px solid var(--c-border); border-radius: var(--r-sm);
  padding: 11px var(--sp-3); min-height: 44px; transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-50); }
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.field-error { color: var(--c-danger); font-size: var(--fs-xs); margin-top: 4px; }

/* ============================================================
   7. 元件：頂部導覽 / 提示條 / 分頁
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 50; height: var(--header-h);
  background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--sp-4);
}
.brand { display: flex; align-items: center; gap: var(--sp-2); font-family: var(--font-serif); font-weight: 700; font-size: var(--fs-md); color: var(--c-text); }
.brand:hover { text-decoration: none; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; background: var(--c-primary); color: #fff; display: grid; place-items: center; font-weight: 700; }
.nav-links { display: flex; gap: var(--sp-2); align-items: center; }
.nav-links a { color: var(--c-text-soft); font-weight: 500; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); }
.nav-links a:hover { background: var(--c-surface-2); text-decoration: none; color: var(--c-text); }

/* 服務提示條（故障優雅降級，沿用吾喵 renderSvcBanner 思路：只提示不擋單） */
.svc-banner {
  background: var(--c-warn-bg); color: var(--c-warn);
  border-bottom: 1px solid #F0DDB5; padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm); display: flex; gap: var(--sp-3); align-items: center; justify-content: center;
}
.svc-banner button { margin-left: var(--sp-2); }

/* toast */
.toast-wrap { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--c-text); color: #fff; padding: 10px 16px; border-radius: var(--r-pill); font-size: var(--fs-sm); box-shadow: var(--sh-2); opacity: 0; transform: translateY(8px); transition: all var(--t-base); pointer-events: auto; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--c-success); }
.toast.error { background: var(--c-danger); }

/* 分頁（後台） */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--c-border); overflow-x: auto; }
.tabs button { background: none; border: none; padding: var(--sp-3) var(--sp-4); font-size: var(--fs-sm); font-weight: 600; color: var(--c-text-soft); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }
.tabs button:disabled { opacity: .4; cursor: not-allowed; }

/* ============================================================
   8. 元件：菜單 / 購物車（點餐頁）
   ============================================================ */
.cat-bar { position: sticky; top: var(--header-h); z-index: 40; background: rgba(249,246,246,.95); backdrop-filter: blur(6px); border-bottom: 1px solid var(--c-border); display: flex; gap: var(--sp-2); overflow-x: auto; padding: var(--sp-2) var(--sp-4); }
.cat-bar button { background: #fff; border: 1px solid var(--c-border); border-radius: var(--r-pill); padding: 8px 14px; font-size: var(--fs-sm); font-weight: 600; color: var(--c-text-soft); white-space: nowrap; cursor: pointer; }
.cat-bar button.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }

.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-3); }
.menu-item { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md); overflow: hidden; display: flex; flex-direction: column; }
.menu-item .thumb { aspect-ratio: 1/1; background: var(--c-surface-2); object-fit: cover; }
.menu-item .body { padding: var(--sp-3); flex: 1; display: flex; flex-direction: column; gap: 4px; }
.menu-item .name { font-weight: 700; font-size: var(--fs-sm); }
.menu-item .price { color: var(--c-primary); font-weight: 700; }
.menu-item .desc { font-size: var(--fs-xs); color: var(--c-text-faint); line-height: 1.4; }
.menu-item .add { margin-top: auto; }
.menu-item.soldout { opacity: .55; }
.menu-item.soldout .add { pointer-events: none; }

/* 購物車抽屜 */
.cart-fab { position: fixed; right: 16px; bottom: 16px; z-index: 60; }
.drawer { position: fixed; inset: 0; z-index: 70; display: none; }
.drawer.open { display: block; }
.drawer .scrim { position: absolute; inset: 0; background: rgba(22,24,29,.45); }
.drawer .sheet { position: absolute; right: 0; top: 0; bottom: 0; width: min(420px, 92vw); background: var(--c-bg); box-shadow: var(--sh-3); display: flex; flex-direction: column; }
.drawer .sheet header { padding: var(--sp-4); border-bottom: 1px solid var(--c-border); display: flex; justify-content: space-between; align-items: center; }
.drawer .sheet .body { flex: 1; overflow-y: auto; padding: var(--sp-4); }
.drawer .sheet footer { padding: var(--sp-4); border-top: 1px solid var(--c-border); }

.cart-line { display: flex; gap: var(--sp-3); align-items: center; padding: var(--sp-3) 0; border-bottom: 1px solid var(--c-border); }
.cart-line .info { flex: 1; }
.cart-line .qty { display: flex; align-items: center; gap: var(--sp-2); }
.cart-line .qty button { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--c-border); background: #fff; font-size: 18px; cursor: pointer; }

/* ============================================================
   9. 表格 / 訂單看板（後台）
   ============================================================ */
.table-wrap { overflow-x: auto; border: 1px solid var(--c-border); border-radius: var(--r-md); background: #fff; }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.data th, table.data td { padding: 10px var(--sp-3); text-align: left; border-bottom: 1px solid var(--c-border); white-space: nowrap; }
table.data th { background: var(--c-surface-2); font-weight: 700; position: sticky; top: 0; }
table.data tr:last-child td { border-bottom: none; }
.order-card { border: 1px solid var(--c-border); border-radius: var(--r-md); padding: var(--sp-4); margin-bottom: var(--sp-3); background: #fff; }
.order-card .head { display: flex; justify-content: space-between; align-items: baseline; }

/* ============================================================
   10. 動效 / 響應式
   ============================================================ */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.fade-up { animation: fadeUp var(--t-base) both; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* 桌面斷點 */
@media (min-width: 768px) {
  .menu-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--sp-4); }
  h1 { font-size: var(--fs-3xl); }
  .section { padding: var(--sp-12) 0; }
}
/* ≤400px：按鈕 icon-only 友好（aria-label 必備） */
@media (max-width: 400px) {
  .nav-links a span.lbl { display: none; }
}

/* ============================================================
   9. 品牌外觀設定（後台「外觀」頁）與加購模組卡
   ============================================================ */
.mt { margin-top: var(--sp-6); }
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-4);
}
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: var(--sp-3);
}
.grid-cards .card { margin: 0; text-align: left; width: 100%; }
.preset { cursor: pointer; transition: transform var(--t-fast), box-shadow var(--t-fast); }
.preset:hover { transform: translateY(-2px); box-shadow: var(--sh-2); }
.preset.active { outline: 2px solid var(--c-primary); outline-offset: 1px; }
.preset .dot { width: 18px; height: 18px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0, 0, 0, .08); }
.module-card { display: block; }
.module-card.on { border-color: var(--c-primary); }
.hint { font-size: var(--fs-xs); color: var(--c-text-faint); margin-top: 4px; }

/* 上傳 LOGO 後移除預設色塊 */
.brand .logo[data-logo-applied="1"] { background: transparent; }

/* 表單控制項（取色器 / 滑桿 / 下拉） */
input[type="color"] {
  width: 100%; height: 44px; padding: 3px;
  border: 1px solid var(--c-border); border-radius: var(--r-sm);
  background: var(--c-surface); cursor: pointer;
}
input[type="range"] { width: 100%; height: 44px; accent-color: var(--c-primary); }
select {
  width: 100%; min-height: 44px; padding: 0 var(--sp-3);
  border: 1px solid var(--c-border); border-radius: var(--r-sm);
  background: var(--c-surface); color: var(--c-text); font-size: var(--fs-base);
}
