:root{ --brand-red:#B11E2D; --brand-gold:#E8B22E; --line:#ececec; --ink:#1c1c1c; --muted:#8a8a8a; }
*{ box-sizing:border-box; }
body{ margin:0; font-family:-apple-system,"Segoe UI","Microsoft JhengHei",sans-serif; color:var(--ink); background:#fafafa; }

/* 頂列 */
.topbar{ display:flex; align-items:center; justify-content:space-between; padding:12px 22px; background:#fff; border-bottom:1px solid var(--line); }
.brand{ display:flex; align-items:center; gap:10px; }
.logo{ width:30px; height:30px; border-radius:7px; background:var(--brand-red); color:#fff; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px; }
.logo.lg{ width:52px; height:52px; font-size:20px; border-radius:12px; }
.logo-img{ height:34px; max-width:200px; object-fit:contain; }
.login-logo-img{ height:54px; max-width:240px; object-fit:contain; }
.brand-name{ font-size:15px; font-weight:600; }
.topbar-right{ display:flex; align-items:center; gap:16px; font-size:13px; color:var(--muted); }
.user .dot{ display:inline-block; width:7px; height:7px; border-radius:50%; background:#3aa76d; margin-right:6px; }
.logout{ color:var(--brand-red); text-decoration:none; }

.container{ max-width:920px; margin:26px auto; padding:0 22px; }
.page-head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:16px; }
.page-head h1{ font-size:20px; font-weight:600; margin:0; }

.btn-primary{ background:var(--brand-red); color:#fff; text-decoration:none; font-size:14px; padding:8px 14px; border-radius:7px; display:inline-flex; align-items:center; gap:6px; }
.btn-primary .plus{ font-weight:700; }

/* 表格 */
table.data{ width:100%; border-collapse:collapse; background:#fff; border:1px solid var(--line); border-radius:10px; overflow:hidden; font-size:14px; }
table.data th{ text-align:left; font-weight:500; color:var(--muted); padding:11px 14px; border-bottom:1px solid var(--line); background:#fcfcfc; }
table.data td{ padding:12px 14px; border-bottom:1px solid var(--line); }
table.data tr:last-child td{ border-bottom:none; }
.r{ text-align:right; }
.mono{ font-family:ui-monospace,Consolas,monospace; font-size:12px; color:#555; }
.struck{ text-decoration:line-through; color:var(--muted); }
.muted{ color:var(--muted); }
.actions a{ margin-left:12px; text-decoration:none; color:var(--brand-red); }
.actions a.muted{ color:var(--muted); }

.badge{ font-size:12px; padding:2px 9px; border-radius:6px; }
.badge.ok{ background:#e7f6ed; color:#1f7a47; }
.badge.off{ background:#f0f0f0; color:#999; }

.icon{ border:none; background:none; cursor:pointer; color:var(--brand-red); font-size:15px; padding:0 4px; }
.empty{ background:#fff; border:1px solid var(--line); border-radius:10px; padding:28px; text-align:center; color:var(--muted); }
.hint{ color:var(--muted); font-size:12.5px; margin-top:14px; line-height:1.7; }

/* 登入 */
.login-body{ display:flex; min-height:100vh; align-items:center; justify-content:center; background:#fafafa; }
.login-card{ background:#fff; border:1px solid var(--line); border-radius:14px; padding:34px 32px; width:330px; text-align:center; }
.login-logo{ display:flex; justify-content:center; margin-bottom:14px; }
.login-title{ font-size:17px; font-weight:600; margin:0 0 20px; }
.login-form{ text-align:left; display:flex; flex-direction:column; }
.login-form label{ font-size:13px; color:var(--muted); margin:10px 0 5px; }
.login-form input{ padding:10px 12px; border:1px solid #ddd; border-radius:8px; font-size:14px; }
.login-form input:focus{ outline:none; border-color:var(--brand-red); }
.login-form button{ margin-top:20px; background:var(--brand-red); color:#fff; border:none; padding:11px; border-radius:8px; font-size:15px; cursor:pointer; }
.alert{ background:#fdecec; color:#c0303a; font-size:13px; padding:9px; border-radius:8px; margin-bottom:6px; }

/* flash 通知 */
.flash{ background:#eaf6ee; color:#1f7a47; border:1px solid #cfe9d8; font-size:13.5px; padding:10px 14px; border-radius:9px; margin-bottom:16px; }

/* 卡片 / 表單 */
.card{ background:#fff; border:1px solid var(--line); border-radius:11px; padding:18px 20px; margin-bottom:16px; }
.card-title{ font-size:14px; font-weight:600; margin-bottom:14px; }
.form label, .grid2 label{ display:block; font-size:13px; color:var(--muted); margin:10px 0 5px; }
.form input, .form select, .grid2 input, .grid2 select{ width:100%; padding:9px 11px; border:1px solid #ddd; border-radius:8px; font-size:14px; }
input:focus, select:focus{ outline:none; border-color:var(--brand-red); }
.grid2{ display:grid; grid-template-columns:1fr 1fr; gap:8px 18px; }
.grid2 > div{ min-width:0; }
.form-actions{ display:flex; justify-content:flex-end; gap:12px; align-items:center; margin:8px 0 22px; }
.btn-text{ background:none; border:none; color:var(--brand-red); cursor:pointer; font-size:14px; text-decoration:none; padding:6px 4px; }
.btn-text.danger{ color:#b02a37; }
.btn-primary.sm, .btn-primary[type=submit].sm{ padding:7px 12px; font-size:13px; }
button.btn-primary{ border:none; cursor:pointer; }
.inline{ display:inline; }

/* 連結列 */
.link-row{ display:flex; align-items:center; gap:10px; margin-bottom:8px; flex-wrap:wrap; }
.link-row .link{ background:#f6f6f6; padding:7px 10px; border-radius:7px; font-size:12.5px; word-break:break-all; }

/* 活動勾選 */
.acc-group{ margin-bottom:14px; }
.acc-name{ font-size:13px; font-weight:600; color:#444; margin-bottom:6px; }
.chk{ display:flex; align-items:center; gap:8px; padding:5px 0; font-size:14px; cursor:pointer; }
.chk input{ width:auto; }
.status-tag{ font-size:11px; color:var(--muted); background:#f2f2f2; padding:1px 7px; border-radius:5px; }

/* 指標雙欄穿梭 */
.sub{ font-size:12.5px; color:var(--muted); margin:-4px 0 12px; }
.transfer{ display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.tcol-head{ font-size:12.5px; font-weight:600; color:#555; margin-bottom:8px; }
.itemlist{ min-height:120px; background:#fafafa; border:1px dashed #d8d8d8; border-radius:9px; padding:8px; display:flex; flex-direction:column; gap:6px; }
#selected{ background:#fbf3f4; border-color:#e6c4c8; }
.xitem{ display:flex; align-items:center; gap:8px; padding:8px 10px; background:#fff; border:1px solid var(--line); border-radius:8px; font-size:13.5px; }
.xitem:hover{ border-color:#cfcfcf; }
#pool .xitem{ cursor:pointer; }
#pool .xitem:hover{ border-color:var(--brand-red); background:#fdf5f5; }
.xlabel{ flex:1; }
.xctrl{ display:flex; align-items:center; gap:4px; }
.xctrl button{ border:1px solid var(--line); background:#fff; border-radius:6px; cursor:pointer; font-size:11px; line-height:1; padding:4px 6px; color:#666; }
.xctrl button:hover{ background:#f3f3f3; }
.ctrl-add{ color:var(--brand-red)!important; border-color:#e6c4c8!important; }
.ctrl-remove{ color:#b02a37!important; }
#pool .xitem .up, #pool .xitem .down, #pool .xitem .ctrl-remove{ display:none; }
#selected .xitem .ctrl-add{ display:none; }
.kindtag{ font-size:10.5px; padding:1px 6px; border-radius:5px; }
.kindtag.manual{ background:#fff3e0; color:#b26a00; }
.kindtag.computed{ background:#eef0ff; color:#3a43b0; }
.xdetail{ font-size:11.5px; color:var(--muted); }
.grip{ cursor:grab; user-select:none; }
.drag-ghost{ opacity:.4; background:#fdeced; border-color:var(--brand-red); }

/* 計算型指標表單 */
.compute-add{ display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.compute-add input, .compute-add select{ padding:8px 10px; border:1px solid #ddd; border-radius:8px; font-size:13px; }
.compute-add input[name=label]{ flex:1; min-width:160px; }
.compute-add input[name=field]{ flex:1; min-width:200px; }

/* Meta 指標參考清單（可展開、兩欄、可捲動） */
details.ref{ margin-top:12px; }
details.ref summary{ cursor:pointer; font-size:13px; color:var(--brand-red); padding:6px 0; user-select:none; }
.ref-box{ max-height:300px; overflow:auto; border:1px solid var(--line); border-radius:8px; padding:8px; margin-top:8px; }
.ref-grid{ display:grid; grid-template-columns:1fr 1fr; gap:6px; }
.ref-item{ display:flex; align-items:center; gap:4px; min-width:0; }
.ref-fill{ flex:1; min-width:0; text-align:left; background:#fff; border:1px solid var(--line); border-radius:6px; padding:5px 8px; cursor:pointer; display:flex; flex-direction:column; line-height:1.35; }
.ref-fill:hover{ border-color:var(--brand-red); background:#fdf5f5; }
.ri-label{ font-size:12px; font-weight:500; display:flex; align-items:center; gap:6px; }
.ri-fam{ font-size:10px; color:#aaa; font-weight:400; }
.ri-key{ font-family:ui-monospace,Consolas,monospace; font-size:10px; color:#999; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ri-copy{ border:none; background:none; color:var(--brand-red); cursor:pointer; font-size:13px; padding:2px; }
.nowrap{ white-space:nowrap; }

/* 覆寫 */
table.data.sm{ margin-bottom:14px; }
table.data.sm th, table.data.sm td{ padding:8px 10px; font-size:13px; }
.override-add{ display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.override-add input{ flex:1; min-width:120px; padding:8px 10px; border:1px solid #ddd; border-radius:8px; font-size:13px; }

.danger-zone{ display:flex; gap:20px; align-items:center; }
.link-btn{ background:none; border:none; color:var(--brand-red); cursor:pointer; font-size:14px; padding:0; margin-left:12px; }
