:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --line: #e3e8ef;
  --line-2: #d5dce6;
  --text: #16202c;
  --text-2: #4d5a6b;
  --text-3: #7d8a9c;
  --brand: #1d4ed8;
  --brand-2: #3b82f6;
  --brand-soft: #eff4ff;
  --ok: #15803d;
  --ok-soft: #edfaf1;
  --warn: #b45309;
  --warn-soft: #fff7ed;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 12px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 佈局 ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: #101d33;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar .brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar .brand h1 { margin: 0; font-size: 16px; color: #fff; font-weight: 700; letter-spacing: .5px; }
.sidebar .brand p { margin: 6px 0 0; font-size: 11.5px; color: #94a3b8; line-height: 1.5; }
.sidebar nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin-bottom: 3px; border-radius: 8px;
  color: #cbd5e1; font-size: 13.5px; cursor: pointer;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
.sidebar nav a.active { background: var(--brand); color: #fff; font-weight: 600; }
.sidebar nav a .ico { width: 18px; text-align: center; opacity: .9; }
.sidebar .foot {
  padding: 12px 16px; font-size: 11px; color: #64748b;
  border-top: 1px solid rgba(255, 255, 255, .08); line-height: 1.6;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar h2 { margin: 0; font-size: 17px; font-weight: 700; }
.topbar .meta { font-size: 12px; color: var(--text-3); display: flex; gap: 14px; flex-wrap: wrap; }

.content { padding: 22px 24px 60px; overflow-y: auto; }

/* ---------- 元件 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 18px; overflow: hidden;
}
.card > .hd {
  padding: 13px 18px; border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 14.5px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel-2);
}
.card > .bd { padding: 18px; }
.card > .bd.tight { padding: 12px 18px; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 780px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .app { flex-direction: column; } .sidebar { width: 100%; } }

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
label .req { color: var(--danger); margin-left: 3px; }
input[type=text], input[type=number], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line-2); border-radius: 8px;
  font-size: 13.5px; font-family: inherit; background: #fff; color: var(--text);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.65; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand-2); }
.field { margin-bottom: 14px; }

button, .btn {
  padding: 8px 16px; border: 1px solid var(--brand); background: var(--brand); color: #fff;
  border-radius: 8px; font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { background: #1740b8; text-decoration: none; }
button.sec { background: #fff; color: var(--brand); }
button.sec:hover { background: var(--brand-soft); }
button.gray { background: #fff; color: var(--text-2); border-color: var(--line-2); }
button.gray:hover { background: var(--panel-2); }
button.danger { background: #fff; color: var(--danger); border-color: #f2c4c4; }
button.danger:hover { background: var(--danger-soft); }
button.ok { background: var(--ok); border-color: var(--ok); }
button.ok:hover { background: #11632f; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; line-height: 1.8;
}
.tag.high, .tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.medium, .tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.low, .tag.info { background: var(--brand-soft); color: var(--brand); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.gray { background: #f1f5f9; color: var(--text-3); }

.muted { color: var(--text-3); font-size: 12.5px; }
.small { font-size: 12.5px; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; line-height: 1.7; }
.alert.info { background: var(--brand-soft); color: #1e3a8a; border: 1px solid #c7d9fe; }
.alert.warn { background: var(--warn-soft); color: #7c2d12; border: 1px solid #fcd9a8; }
.alert.danger { background: var(--danger-soft); color: #7f1d1d; border: 1px solid #f5c2c2; }
.alert.ok { background: var(--ok-soft); color: #14532d; border: 1px solid #b6e6c8; }

.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .n { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat .l { font-size: 12px; color: var(--text-3); margin-top: 3px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--panel-2); font-weight: 700; font-size: 12.5px; color: var(--text-2); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fbfcfe; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs .tab {
  padding: 9px 16px; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--text-3);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active { color: var(--brand); border-bottom-color: var(--brand); }

pre.output {
  background: #fbfcfe; border: 1px solid var(--line); border-radius: 8px;
  padding: 16px; font-family: "Noto Sans TC", "PingFang TC", monospace;
  white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.85;
  max-height: 620px; overflow-y: auto; margin: 0;
}

.clause-item { border: 1px solid var(--line); border-radius: 8px; padding: 11px 13px; margin-bottom: 9px; background: #fff; }
.clause-item .top { display: flex; align-items: flex-start; gap: 10px; }
.clause-item .top label { margin: 0; flex: 1; font-size: 13.5px; font-weight: 600; color: var(--text); }
.clause-item textarea { margin-top: 9px; font-size: 12.5px; min-height: 70px; }

.chat { display: flex; flex-direction: column; gap: 14px; max-height: 560px; overflow-y: auto; padding: 4px; }
.msg { display: flex; gap: 10px; }
.msg .avatar {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: #fff;
}
.msg.user .avatar { background: #475569; }
.msg.ai .avatar { background: var(--brand); }
.msg .bubble {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 14px; white-space: pre-wrap; word-break: break-word; font-size: 13.5px; line-height: 1.8;
}
.msg.user .bubble { background: var(--brand-soft); border-color: #c7d9fe; }
.msg.blocked .bubble { background: var(--warn-soft); border-color: #fcd9a8; }
.msg .refs { margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--line-2); font-size: 12.5px; }

.risk-card { border: 1px solid var(--line); border-left: 4px solid var(--text-3); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; background: #fff; }
.risk-card.high { border-left-color: var(--danger); }
.risk-card.medium { border-left-color: var(--warn); }
.risk-card.low { border-left-color: var(--brand-2); }
.risk-card .t { font-weight: 700; font-size: 13.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.risk-card .d { margin: 6px 0; font-size: 13px; color: var(--text-2); }
.risk-card .s { background: var(--ok-soft); border-radius: 6px; padding: 8px 11px; font-size: 12.5px; color: #14532d; }
.risk-card .b { margin-top: 7px; font-size: 12px; color: var(--text-3); }
.risk-card .ev { font-family: monospace; background: #f1f5f9; padding: 1px 6px; border-radius: 4px; font-size: 12px; }

.score-ring { display: flex; align-items: center; gap: 16px; }
.score-ring .big { font-size: 40px; font-weight: 800; line-height: 1; }
.score-ring .big.ok { color: var(--ok); }
.score-ring .big.warn { color: var(--warn); }
.score-ring .big.danger { color: var(--danger); }

.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { border: 1px solid var(--line-2); border-radius: 20px; padding: 4px 12px; font-size: 12.5px; background: #fff; cursor: pointer; }
.pill:hover { border-color: var(--brand-2); color: var(--brand); }
.pill.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.empty { padding: 34px; text-align: center; color: var(--text-3); font-size: 13px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.nowrap { white-space: nowrap; }

/* ---------- 會員系統 ---------- */
.acct { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.08); border-bottom: 1px solid rgba(255,255,255,.08); }
.acct-title { color: #e2e8f0; font-size: 13px; font-weight: 700; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.acct .muted { color: #94a3b8; font-size: 11.5px; line-height: 1.5; }
.acct .row { gap: 6px; }
.acct button { padding: 6px 10px; font-size: 12px; }
.acct .quota { margin: 8px 0 10px; display: flex; flex-direction: column; gap: 6px; }
.acct .quota .q { font-size: 11.5px; color: #cbd5e1; }
.acct .quota .bar { height: 4px; background: rgba(255,255,255,.12); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.acct .quota .bar i { display: block; height: 100%; background: #60a5fa; }
.acct .quota .bar i.full { background: #f87171; }

/* 方案卡 */
.plan-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
.plan-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; background: var(--panel); display: flex; flex-direction: column; }
.plan-card.reco { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
.plan-card .pname { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.plan-card .pdesc { font-size: 12.5px; color: var(--text-3); line-height: 1.6; min-height: 40px; }
.plan-card ul { margin: 12px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--text-2); line-height: 1.9; }
.plan-card .pfoot { margin-top: auto; padding-top: 12px; }
.quota-table td { font-size: 12.5px; }
.quota-badge { font-variant-numeric: tabular-nums; }

/* 模態框 */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 9000; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 430px; box-shadow: 0 20px 60px rgba(2,6,23,.28); overflow: hidden; }
.modal .mhd { padding: 15px 20px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.modal .mbd { padding: 20px; }
.modal .mft { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.modal .x { cursor: pointer; color: var(--text-3); font-size: 20px; line-height: 1; background: none; border: none; padding: 0 4px; }
.auth-switch { text-align: center; font-size: 12.5px; color: var(--text-3); margin-top: 10px; }
.auth-switch a { cursor: pointer; }

/* 後台登入閘 */
#loginGate { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 9500; }
#loginGate .box { width: 100%; max-width: 380px; }

/* ================= 語音輸入 ================= */
#voiceStatus { font-size: 12px; }
#btnVoice.recording { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }

/* ================= 超出範圍 → 專人服務表單 ================= */
.oos-form { border-top: 1px dashed var(--line); padding-top: 12px; }
.oos-form .field { margin-bottom: 10px; }
.oos-form .field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.oos-form .field input, .oos-form .field textarea { width: 100%; }
.oos-form .row { margin-top: 4px; }
.msg .bubble .oos-form { max-width: 460px; }

/* ================= 交付狀態 ================= */
#genDelivery .alert, #customDelivery .alert { margin-bottom: 12px; }
#genDelivery code, #customDelivery code { font-size: 11.5px; }
#dvResult .card { margin-top: 12px; }
#deliveryList code { font-size: 11px; }

/* ================= 後台：側欄待辦數字與警示色 ================= */
#nav a .badge {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  font-size: 11px; line-height: 17px; border-radius: 9px;
  background: #ef4444; color: #fff; font-weight: 700;
  vertical-align: middle;
}
.c-warn { color: #b45309; }
.c-danger { color: #b91c1c; }
.c-ok { color: #15803d; }

/* ================= 資安與帳號自助流程 ================= */
.forgot-row { text-align: right; margin: -4px 0 10px; }
.forgot-row a { font-size: 12.5px; color: var(--accent); cursor: pointer; }

.consent {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 12.5px; line-height: 1.55; color: var(--text-2);
  margin: 4px 0 12px;
}
.consent input { width: auto; margin-top: 2px; flex: none; }
.consent a { color: var(--accent); }

.verify-note {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  font-size: 12px; line-height: 1.5;
  background: #fffbeb; border: 1px solid #fcd34d; color: #92400e;
  border-radius: 8px; padding: 7px 9px; margin: 8px 0;
}
.link-btn {
  background: none; border: none; padding: 0;
  color: #92400e; text-decoration: underline; cursor: pointer;
  font-size: 12px; font-family: inherit;
}

.foot-links { margin-top: 8px; font-size: 12px; }
.foot-links a { color: var(--text-2); }
