/* ============================================================
   AI Love Home Kit v1 — 全域基礎樣式
   Reset、版面、底部 Tab、安全區、按鈕、卡片、聊天泡泡、輸入列
   規格 §2 Task 2 / §3 底部 Tab / §6 視覺
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--on-background);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* 手機置中容器（規格：手機友好，390px 基準）*/
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  background: var(--background);
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
img { max-width: 100%; display: block; }

:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---- 可捲動主內容：預留底部 Tab + 安全區空間 ---- */
.page-main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
}
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* ============================================================
   頂部欄
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 16px var(--margin-page);
  padding-top: calc(16px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface-low) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid color-mix(in srgb, var(--outline-variant) 30%, transparent);
}
.topbar__title {
  font-size: var(--fs-headline-m);
  line-height: var(--lh-headline-m);
  font-weight: 700;
  color: var(--on-surface);
  margin: 0;
}
.topbar__back {
  width: var(--tap-min); height: var(--tap-min);
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--on-surface);
  border-radius: var(--radius-full);
  margin-left: -8px;
}

/* ============================================================
   底部 Tab（規格 §3：Chat / Call / Memory / Settings）
   ============================================================ */
.tabbar {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 100%; max-width: 480px; z-index: 50;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid color-mix(in srgb, var(--outline-variant) 30%, transparent);
}
.tabbar__item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  border: none; background: transparent;
  color: var(--on-surface-variant);
  text-decoration: none;
  transition: color var(--dur) var(--ease);
}
.tabbar__item .material-symbols-outlined { font-size: 22px; }
.tabbar__item svg { width: 22px; height: 22px; }
.tabbar__label { font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 500; }
.tabbar__item[aria-current="page"] { color: var(--primary); }
.tabbar__item[aria-current="page"] .material-symbols-outlined {
  font-variation-settings: 'FILL' 1;
}
.tabbar__item:active { transform: scale(0.94); }

/* ============================================================
   按鈕
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--btn-lg); padding: 0 20px;
  border: none; border-radius: var(--radius-full);
  font-size: var(--fs-body); font-weight: 600;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.btn:active { transform: scale(0.96); }
.btn--primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-card); }
.btn--ghost {
  background: var(--surface); color: var(--primary);
  border: 1px solid color-mix(in srgb, var(--outline-variant) 40%, transparent);
  box-shadow: var(--etch);
}
.btn--danger { background: var(--danger); color: #fff; }
.btn--sm { height: var(--btn-sm); padding: 0 14px; font-size: var(--fs-label); }

.icon-btn {
  width: var(--tap-min); height: var(--tap-min);
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--on-surface-variant);
  border-radius: var(--radius-full);
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn--filled { background: var(--primary); color: var(--on-primary); }

/* ============================================================
   卡片 / 區塊
   ============================================================ */
.card {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
}
.section { padding: 0 var(--margin-page); }
.section__label {
  font-size: var(--fs-label); font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--on-surface-variant); opacity: 0.7;
  padding: 0 4px 8px;
}

/* ============================================================
   聊天泡泡（規格 §6 / DESIGN.md：三角無尾、對側 78%）
   ============================================================ */
.bubble-row { display: flex; flex-direction: column; min-width: 0; }
.bubble-row--user { align-items: flex-end; padding-left: 48px; }
.bubble-row--ai { align-items: flex-start; padding-right: 48px; }
.bubble {
  max-width: 78%;
  min-width: 0;
  overflow-wrap: anywhere;
  padding: var(--pad-bubble-y) var(--pad-bubble-x);
  border-radius: var(--radius-xl);
  font-family: var(--font-serif);
  font-size: var(--fs-body-lg); line-height: var(--lh-body-lg);
}
.bubble--user {
  background: var(--primary-container); color: var(--on-primary-container);
  border-top-right-radius: 4px; box-shadow: var(--shadow-soft);
}
.bubble--ai {
  background: var(--surface-low); color: var(--on-surface);
  border: 1px solid color-mix(in srgb, var(--outline-variant) 30%, transparent);
  border-top-left-radius: 4px; box-shadow: var(--shadow-soft);
}
.bubble__time { font-size: var(--fs-label); color: var(--outline); }
.bubble__actions {
  display: flex; align-items: center; gap: 4px;
  margin-top: 4px; padding: 0 2px;
}
.bubble__actions .bubble__time { margin-left: auto; margin-top: 0; }
.act-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap-min); height: var(--tap-min); padding: 0; border: none;
  flex: 0 0 var(--tap-min);
  background: transparent; color: var(--outline);
  cursor: pointer; border-radius: var(--radius-sm, 6px);
  transition: color .15s ease, background .15s ease;
}
.act-btn:hover, .act-btn:active { color: var(--on-surface); background: color-mix(in srgb, var(--outline) 12%, transparent); }
.act-btn svg { width: 20px; height: 20px; }
.act-btn--active { color: var(--primary); }
.act-btn--playing { animation: act-pulse 1s ease-in-out infinite; }
@keyframes act-pulse { 0%,100%{ opacity:1; } 50%{ opacity:.4; } }
.bubble-row--loading .bubble__actions { display: none; }

/* ============================================================
   底部輸入列（Chat）
   ============================================================ */
.composer {
  position: sticky; bottom: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 12px var(--margin-page);
  padding-bottom: calc(12px + var(--tabbar-h) + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid color-mix(in srgb, var(--outline-variant) 12%, transparent);
}
.composer > .icon-btn,
.composer > .btn { flex-shrink: 0; }
.composer > .btn--sm { height: 40px; }
.composer__input {
  flex: 1 1 auto; min-width: 0; height: 40px;
  padding: 0 16px;
  background: var(--surface-lowest);
  border: 1px solid color-mix(in srgb, var(--outline-variant) 30%, transparent);
  border-radius: var(--radius-full);
  color: var(--on-surface); font-size: var(--fs-body);
  box-shadow: var(--shadow-card);
}
.composer__input::placeholder { color: color-mix(in srgb, var(--outline) 60%, transparent); }
.composer__input:focus { outline: none; border-color: color-mix(in srgb, var(--primary) 50%, transparent); }

/* ============================================================
   工具
   ============================================================ */
.empty-state {
  text-align: center; color: var(--on-surface-variant);
  padding: 48px var(--margin-page); line-height: 1.6;
}
.hidden { display: none !important; }
