:root {
  --primary: #185FA5;
  --primary-dark: #0C447C;
  --primary-soft: #E6F1FB;
  --accent: #EF9F27;
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --border: #E3E8EF;
  --text: #1B2430;
  --muted: #6B7785;
  --danger: #E24B4A;
  --success: #1D9E75;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.view { display: none; min-height: 100vh; }
.view.active { display: flex; flex-direction: column; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 13px; margin: 10px 0 0; }
.hint { color: var(--muted); font-size: 12px; margin: 14px 0 0; line-height: 1.6; }
code {
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .92em;
}

/* ---------- 登入 ---------- */
#view-login { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 34px 28px 26px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-card .logo { width: 68px; height: 68px; border-radius: 20px; display: block; margin: 0 auto; }
.login-card h1 { font-size: 19px; font-weight: 600; margin: 16px 0 4px; }
.login-card p { margin: 0 0 20px; font-size: 13.5px; }
#login-form { display: flex; flex-direction: column; gap: 10px; }

/* ---------- 主框架 ---------- */
#view-app { height: 100vh; height: 100dvh; overflow: hidden; }
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; }
.brand img { width: 26px; height: 26px; border-radius: 8px; }
.content { flex: 1 1 auto; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.tabbar {
  flex: 0 0 auto;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  background: none; border: none; cursor: pointer;
  padding: 9px 0 11px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 11.5px;
  transition: color .15s;
}
.tab svg { width: 21px; height: 21px; }
.tab.active { color: var(--primary); }

/* ---------- 麥克風 ---------- */
.mic-stage { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 30px 0 6px; }
.mic {
  width: 142px; height: 142px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 10px 30px rgba(24, 95, 165, .28);
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease;
}
.mic svg { width: 58px; height: 58px; }
.mic:active { transform: scale(.96); }
.mic.listening { background: var(--accent); animation: pulse 1.6s infinite; }
.mic.thinking { background: var(--muted); }
.mic:disabled { cursor: default; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 159, 39, .45); }
  70% { box-shadow: 0 0 0 26px rgba(239, 159, 39, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 159, 39, 0); }
}
.mic-hint { margin: 0; font-size: 13.5px; color: var(--muted); }

/* ---------- 對話 ---------- */
.dialog { display: flex; flex-direction: column; gap: 9px; margin: 14px 0 16px; }
.bubble {
  max-width: 86%; padding: 10px 14px; border-radius: 16px;
  font-size: 14px; line-height: 1.6; word-break: break-word;
  animation: fadeUp .22s ease both;
}
.bubble.ai { background: var(--primary-soft); color: var(--primary-dark); align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble.me { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 5px; }
.bubble.sys { background: transparent; color: var(--muted); font-size: 12.5px; align-self: center; text-align: center; max-width: 96%; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.confirm-bar { display: flex; gap: 10px; justify-content: center; margin: 4px 0 12px; }

/* ---------- 表單元件 ---------- */
input[type=text], input[type=password] {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 14px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type=text]:focus, input[type=password]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24, 95, 165, .12);
}
button { font-family: inherit; font-size: 14px; cursor: pointer; }
.btn-primary {
  background: var(--primary); color: #fff; border: none;
  padding: 11px 18px; border-radius: 10px; font-weight: 500; white-space: nowrap;
  transition: background .15s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 8px 14px; border-radius: 9px; transition: border-color .15s, color .15s;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-icon {
  background: none; border: none; color: var(--muted);
  font-size: 15px; line-height: 1; padding: 4px 6px; border-radius: 6px;
}
.btn-icon:hover { color: var(--danger); background: #FCEBEB; }

.text-form { display: flex; gap: 8px; }
.text-form input { flex: 1 1 auto; }
.inline-form { display: flex; gap: 8px; margin: 12px 0 4px; }
.inline-form input { flex: 1 1 auto; }

.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

/* ---------- 清單 / 卡片 ---------- */
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.panel-head h2 { font-size: 17px; font-weight: 600; margin: 0; }
.pill {
  font-size: 12px; background: var(--primary-soft); color: var(--primary-dark);
  padding: 3px 10px; border-radius: 999px;
}
.list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.card { display: flex; gap: 12px; align-items: flex-start; }
.card.block { display: block; margin-bottom: 14px; }
.card.block h3 { font-size: 14.5px; font-weight: 600; margin: 0 0 8px; }
.card-main { flex: 1 1 auto; min-width: 0; }
.card-title { font-size: 14.5px; font-weight: 500; line-height: 1.5; word-break: break-word; }
.card-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.card-side { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }

.badge { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge.pending { background: #FAEEDA; color: #854F0B; }
.badge.sent { background: #E1F5EE; color: #0F6E56; }
.badge.failed { background: #FCEBEB; color: #A32D2D; }
.badge.self { background: var(--primary-soft); color: var(--primary-dark); }
.badge.unlinked { background: #F1EFE8; color: #5F5E5A; }

.empty { color: var(--muted); font-size: 13.5px; line-height: 1.7; padding: 22px 4px; text-align: center; }

.notice { border-radius: 12px; padding: 12px 15px; font-size: 13px; line-height: 1.6; margin-bottom: 14px; }
.notice-warn { background: #FAEEDA; color: #633806; }

.kv { font-size: 13px; line-height: 2; color: var(--muted); }
.kv b { color: var(--text); font-weight: 500; }

/* ---------- Toast ---------- */
#toast-wrap {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 84px; z-index: 50;
  display: flex; flex-direction: column; gap: 8px;
  width: min(92vw, 420px); pointer-events: none;
}
.toast {
  background: #1B2430; color: #fff;
  padding: 11px 15px; border-radius: 12px;
  font-size: 13.5px; line-height: 1.5;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .18);
  animation: fadeUp .22s ease both;
}

@media (min-width: 720px) {
  .content { max-width: 680px; margin: 0 auto; width: 100%; }
}
