/* ============ 基礎 ============ */
:root {
  --primary: #2f6bff;
  --primary-dark: #1f54d6;
  --danger: #e5484d;
  --text: #1a1d23;
  --text-2: #5a6472;
  --text-3: #98a2b3;
  --border: #e5e9f0;
  --bg: #f4f6fa;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "PingFang SC", "Microsoft JhengHei", "Noto Sans TC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
main.container { flex: 1; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* ============ 頂部導航 ============ */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.logo-wrap { display: flex; align-items: center; gap: 10px; }
.logo-img { height: 30px; max-width: 140px; object-fit: contain; }
.logo-emoji { font-size: 24px; }
.logo-text { font-weight: 700; font-size: 16.5px; letter-spacing: .2px; }
.nav { display: flex; align-items: center; gap: 4px; height: 100%; }
.nav a {
  padding: 6px 14px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav a:hover { background: #eef2ff; color: var(--primary); }
.nav a.active { background: #eef2ff; color: var(--primary); }
.nav a.nav-logout { color: var(--text-3); }
.nav a.nav-logout:hover { background: #fef1f1; color: var(--danger); }

/* ============ 版面 ============ */
.container { max-width: 1080px; margin: 0 auto; padding: 26px 24px 40px; width: 100%; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.page-head h2 { font-size: 20px; font-weight: 700; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }

/* ============ 表格 ============ */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid #f0f2f6; font-size: 14px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfd; }
th { color: var(--text-2); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; }
.col-id { width: 44px; color: var(--text-3); }
.col-ops { width: 1%; white-space: nowrap; text-align: right; }
.col-ops form { display: inline; }
.row-link { font-weight: 600; color: var(--text); }
.row-link:hover { color: var(--primary); }

/* ============ 按鈕 ============ */
button { cursor: pointer; border: none; border-radius: 8px; padding: 9px 18px; font-size: 14px; font-weight: 500; font-family: inherit; transition: background .15s, transform .05s; }
button:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c93338; }
.btn-ghost { background: #eef1f6; color: var(--text); }
.btn-ghost:hover { background: #e2e7ef; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; }
a.btn-ghost, a.btn-danger, a.btn-primary { display: inline-block; }

/* ============ 表單 ============ */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47,107,255,.12);
}
.field textarea { resize: vertical; }
.hint { font-size: 12.5px; color: var(--text-3); line-height: 1.7; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form input { flex: 1; padding: 9px 13px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; min-width: 170px; font-family: inherit; }
.grow2 { flex: 2 !important; }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; margin-bottom: 14px; font-weight: 500; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

/* ============ 提示訊息 ============ */
.alert { border-radius: 10px; padding: 12px 16px; margin-bottom: 18px; font-size: 14px; border: 1px solid transparent; }
.alert.ok { background: #edf9f0; color: #18794e; border-color: #bfe8cd; }
.alert.err { background: #fef1f1; color: #b42318; border-color: #f5c8c6; }
.alert.warn { background: #fff7e8; color: #9a6700; border-color: #f5dfa8; }

/* ============ 徽章 / 日誌等級 ============ */
.badge { font-size: 12px; background: #e8efff; color: var(--primary); padding: 2px 9px; border-radius: 20px; font-weight: 600; }
.badge.gray { background: #eef1f6; color: var(--text-2); }
.lv { padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.lv.info { background: #edf9f0; color: #18794e; }
.lv.warn { background: #fff7e8; color: #9a6700; }
.lv.error { background: #fef1f1; color: #b42318; }
.log-content { word-break: break-all; max-width: 480px; color: var(--text-2); }
.empty { text-align: center; color: var(--text-3); padding: 40px 0; background: var(--card); border: 1px dashed var(--border); border-radius: var(--radius); margin-bottom: 18px; }

/* ============ 可視化按鈕編輯器 ============ */
.bb { margin-bottom: 14px; }
.bb-label { display: block; font-size: 13px; color: var(--text-2); font-weight: 500; margin-bottom: 8px; }
.bb-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.bb-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; align-items: center; }
.bb-row input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
}
.bb-row input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,107,255,.12); }
.bb-x { padding: 6px 11px; }
.bb-empty { padding: 10px 0; }

/* ============ 登入頁 ============ */
.auth-body { display: flex; flex-direction: column; align-items: center; justify-content: center; background: linear-gradient(160deg, #eef2ff 0%, #f4f6fa 45%, #f4f6fa 100%); }
.auth-card {
  width: 380px;
  max-width: 92vw;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px 30px;
  box-shadow: 0 8px 30px rgba(16,24,40,.08);
  margin-top: 8vh;
}
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 8px; }
.auth-logo .logo-img { height: 46px; max-width: 200px; object-fit: contain; }
.auth-logo .logo-emoji { font-size: 42px; }
.auth-title { font-size: 19px; font-weight: 700; }
.auth-card .sub { text-align: center; color: var(--text-3); font-size: 13.5px; margin-bottom: 22px; }

/* ============ Footer ============ */
.footer {
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 20px;
  border-top: 1px solid var(--border);
  background: var(--card);
}
.footer a { color: var(--text-2); }

/* ============ 品牌預覽 ============ */
.brand-preview { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.brand-preview .header { border-bottom: 1px solid var(--border); }
.brand-preview-footer { text-align: center; color: var(--text-3); font-size: 13px; padding: 14px; }

/* ============ RWD ============ */
@media (max-width: 680px) {
  .header { padding: 0 14px; height: 56px; }
  .logo-text { font-size: 15px; }
  .nav a { padding: 5px 9px; font-size: 13px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .inline-form { flex-direction: column; }
  .col-ops { white-space: normal; }
  .bb-row { grid-template-columns: 1fr; }
  .container { padding: 18px 14px 32px; }
}
