/*
 * 績效考核系統共用樣式（前台與後台）。
 * 視覺：沿用「產品處績效考核表」artifact 的深青色系。
 * 間距級距：4 / 8 / 12 / 16 / 24 / 32 / 48（--s1 ~ --s7），版面一律取用這組變數。
 * 規範：所有文字 font-size 不小於 14px。
 */
:root {
  /* 色彩 */
  --bg: #0f1a1d;
  --panel: #142326;
  --panel-2: #192c30;
  --field: #0d1719;
  --line: #24393d;
  --line-strong: #31494e;
  --text: #e6efef;
  --muted: #8fa5a8;
  --accent: #5fd3c2;
  --accent-ink: #062521;
  --accent-soft: #1d4744;
  --gold: #f0b45a;
  --gold-soft: #3a2c17;
  --danger: #ff8a80;
  --ok: #7ee0a3;

  /* 間距 */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --radius: 12px;
  --radius-sm: 8px;

  /* 字型 */
  --sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --num: "JetBrains Mono", ui-monospace, Menlo, monospace;

  font-family: var(--sans);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; }
a { color: var(--accent); }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { line-height: 1.3; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 頂部列 ─────────────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 30; background: rgba(15, 26, 29, .94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar .inner { max-width: 1080px; margin: 0 auto; padding: var(--s3) var(--s5); display: flex; align-items: center; gap: var(--s5); }
.topbar .brand { font-weight: 700; font-size: 16px; line-height: 1.35; white-space: nowrap; }
.topbar .brand small { display: block; font-weight: 400; color: var(--muted); font-size: 14px; }
.topbar nav { display: flex; gap: var(--s1); flex-wrap: wrap; }
.topbar nav a { padding: 6px var(--s3); border-radius: var(--radius-sm); color: var(--muted); text-decoration: none; font-size: 15px; }
.topbar nav a:hover { color: var(--text); }
.topbar nav a.on { background: var(--panel-2); color: var(--text); }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 14px; color: var(--muted); white-space: nowrap; }
.app-admin .topbar { border-bottom-color: #4a3a1f; }
.app-admin .topbar .brand::before { content: "後台"; font-size: 14px; font-weight: 500; color: var(--gold); border: 1px solid var(--gold); border-radius: 6px; padding: 0 6px; margin-right: var(--s2); }
body:has(main.narrow) .topbar .inner { max-width: 800px; }
@media (max-width: 760px) {
  .topbar .inner { flex-wrap: wrap; gap: var(--s2) var(--s4); padding: var(--s3) var(--s4); }
  .topbar .who { display: none; }
}

/* ── 版面與區塊節奏 ─────────────────────────────── */
main { max-width: 1080px; margin: 0 auto; padding: var(--s6) var(--s5) 0; }
main.narrow { max-width: 800px; }
@media (max-width: 760px) { main { padding: var(--s5) var(--s4) 0; } }

/* 區塊標題：區塊之間 48、標題到內容 16 */
.section-title { display: flex; align-items: center; gap: var(--s2); margin: var(--s7) 0 var(--s4); padding-bottom: var(--s3); border-bottom: 1px solid var(--line); }
.section-title:first-child { margin-top: 0; }
.section-title h2 { font-family: var(--serif); font-size: 24px; font-weight: 700; }
.section-title .grow { flex: 1; }
.subhead { font-size: 15px; font-weight: 500; color: var(--muted); margin: var(--s5) 0 var(--s3); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s5); }
.card + .card { margin-top: var(--s3); }
.card.bonus { border-color: #4a3a1f; background: linear-gradient(180deg, #221d14, var(--panel) 60%); }
.card-head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s4); }
.card-head h3 { font-size: 17px; font-weight: 700; }
.card-head .grow { flex: 1; }
.card-head .index { font-size: 14px; color: var(--muted); }

.stack > * + * { margin-top: var(--s4); }
.grid { display: grid; gap: var(--s4); }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.proj-head { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1.2fr) 120px; }
@media (max-width: 760px) { .grid.c2, .grid.c3, .grid.c4, .proj-head { grid-template-columns: minmax(0, 1fr); } }

.pill { display: inline-flex; align-items: center; font-size: 14px; line-height: 1.5; padding: 1px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.pill.gold { background: var(--gold-soft); color: var(--gold); }
.pill.gray { background: var(--panel-2); color: var(--muted); }
.pill.ok { background: #183a28; color: var(--ok); }
.pill:empty { display: none; }

/* ── Tooltip：ⓘ 按鈕，滑鼠移上、鍵盤 focus、手機點擊都會顯示 ── */
.tip { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; flex: none; border-radius: 50%; border: 1px solid var(--line-strong); background: transparent; color: var(--muted); font: 600 14px/1 var(--sans); cursor: help; padding: 0; vertical-align: middle; }
.tip:hover, .tip:focus-visible { color: var(--text); border-color: var(--accent); }
.tip::after {
  content: attr(data-tip);
  position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%);
  width: max-content; max-width: min(320px, 80vw);
  background: #223a3e; color: var(--text); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: var(--s2) var(--s3); font: 400 14px/1.6 var(--sans); text-align: left; white-space: pre-line;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  opacity: 0; visibility: hidden; transition: opacity .12s; z-index: 40; pointer-events: none;
}
.tip:hover::after, .tip:focus::after { opacity: 1; visibility: visible; }
.tip.left::after { left: auto; right: -8px; transform: none; }

/* ── 表單 ─────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > .label { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
input, select, textarea { font: inherit; font-size: 15px; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px var(--s3); width: 100%; min-height: 42px; }
textarea { min-height: 88px; resize: vertical; line-height: 1.6; }
textarea.short { min-height: 64px; }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(95, 211, 194, .15); }
::placeholder { color: #5f7579; }
.suffix { position: relative; }
.suffix input { padding-right: 32px; text-align: right; font-variant-numeric: tabular-nums; }
.suffix span { position: absolute; right: var(--s3); top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.suffix.warn input { border-color: var(--gold); }

/* 唯讀：純文字，不畫輸入框，避免讓人以為可以編輯 */
.ro { font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.ro.empty { color: #5f7579; }

/* ── 按鈕 ─────────────────────────────────────── */
.btn { font: inherit; font-size: 15px; font-weight: 500; border: 1px solid var(--line-strong); background: var(--panel-2); color: var(--text); padding: 8px var(--s4); min-height: 40px; border-radius: var(--radius-sm); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); border-color: var(--line-strong); }
.btn.danger { color: var(--danger); border-color: #5a2f2c; background: transparent; }
.btn.small { padding: 4px var(--s3); min-height: 32px; font-size: 14px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.armed { background: var(--danger); color: #2a0c0a; border-color: var(--danger); }
.actions { display: flex; gap: var(--s3); flex-wrap: wrap; align-items: center; }
.actions .spacer { flex: 1; }

/* ── 評分列：自評、主管評各一列，標籤對齊 ─────────── */
.rates { margin-top: var(--s5); padding-top: var(--s4); border-top: 1px solid var(--line); display: grid; gap: var(--s3); }
.rate { display: grid; grid-template-columns: 56px auto 1fr; align-items: center; gap: var(--s3); }
.rate .who { font-size: 14px; color: var(--muted); }
.rate .dots { display: flex; gap: 6px; }
.rate .dots button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line-strong); background: transparent; color: var(--text); font: 500 15px/1 var(--sans); cursor: pointer; }
.rate .dots button:hover:not([disabled]) { border-color: var(--accent); }
.rate .dots button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.rate.mgr .dots button.on { border-color: var(--gold); background: var(--gold-soft); color: var(--gold); }
.rate .dots button[disabled] { cursor: default; }
.rate .dots button[disabled]:not(.on) { opacity: .5; }
.rate .result { font-size: 14px; color: var(--muted); }
.rate .result.set { color: var(--text); }
@media (max-width: 480px) { .rate { grid-template-columns: 1fr; gap: var(--s2); } }

/* 能力的 3 分／5 分描述 */
.anchors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); margin-bottom: var(--s4); }
.anchors div { background: var(--field); border-left: 3px solid var(--line-strong); border-radius: 0 6px 6px 0; padding: var(--s2) var(--s3); font-size: 14px; color: var(--muted); }
.anchors b { color: var(--text); margin-right: 6px; }
@media (max-width: 760px) { .anchors { grid-template-columns: minmax(0, 1fr); } }

/* ── 標題卡與分數 ─────────────────────────────── */
.hero { background: linear-gradient(135deg, #1b4a47, #12302f); border: 1px solid #2b5a56; border-radius: 16px; padding: var(--s6); }
.hero .title { display: flex; align-items: center; gap: var(--s2); }
.hero h1 { font-family: var(--serif); font-size: 30px; font-weight: 700; }
.hero .who-line { margin-top: var(--s2); color: #c9e3df; }
.score-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); margin-top: var(--s5); }
.score-card { background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .12); border-radius: var(--radius); padding: var(--s4); }
.score-card .head { display: flex; align-items: center; gap: var(--s2); font-size: 14px; color: #b9d3cf; }
.score-card .num { font-family: var(--num); font-size: 36px; font-weight: 700; line-height: 1.2; margin-top: var(--s1); font-variant-numeric: tabular-nums; }
.score-card .bar { height: 6px; background: rgba(255, 255, 255, .1); border-radius: 4px; overflow: hidden; margin-top: var(--s3); }
.score-card .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.score-card.mgr .bar i { background: var(--gold); }
.notice { margin-top: var(--s4); background: rgba(0, 0, 0, .2); border-radius: var(--radius-sm); padding: var(--s3) var(--s4); font-size: 15px; }
.notice.warn { border: 1px solid #5a4a1f; color: var(--gold); }
@media (max-width: 760px) { .hero { padding: var(--s5); } .score-cards { grid-template-columns: minmax(0, 1fr); } }

/* 捲過標題卡後才出現的分數列 */
.scorebar { position: fixed; left: 0; right: 0; top: var(--topbar-h, 65px); z-index: 25; background: rgba(15, 26, 29, .96); border-bottom: 1px solid var(--line); backdrop-filter: blur(8px); transform: translateY(-100%); opacity: 0; transition: transform .18s, opacity .18s; pointer-events: none; }
.scorebar.on { transform: none; opacity: 1; pointer-events: auto; }
.scorebar .inner { max-width: 800px; margin: 0 auto; padding: var(--s2) var(--s5); display: flex; align-items: center; gap: var(--s3); font-size: 14px; }
.scorebar .inner .grow { flex: 1; }
.scorebar .badge { color: var(--muted); }
.scorebar .badge b { font-family: var(--num); color: var(--text); font-size: 16px; margin: 0 6px; font-variant-numeric: tabular-nums; }
.scorebar .badge em { font-style: normal; color: var(--accent); }
.scorebar .badge.mgr em { color: var(--gold); }
@media (prefers-reduced-motion: reduce) { .scorebar, .score-card .bar i, .tip::after { transition: none; } }

/* ── 表格 ─────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); }
table.list th, table.list td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); text-align: left; font-size: 15px; vertical-align: middle; }
table.list th { color: var(--muted); font-weight: 500; font-size: 14px; background: var(--panel-2); white-space: nowrap; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.total td { font-weight: 700; background: #173331; }
table.list .sub { font-size: 14px; color: var(--muted); }
table.list tr.off td { color: var(--muted); }

/* ── 統計 ─────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s3); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4); }
.stat .label { font-size: 14px; color: var(--muted); }
.stat .n { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ── 登入 ─────────────────────────────────────── */
.login { max-width: 420px; margin: 12vh auto 0; }
.login h1 { font-family: var(--serif); font-size: 26px; }
.login .lead { margin-top: var(--s2); color: var(--muted); }
.login form { display: grid; gap: var(--s4); margin-top: var(--s5); }
.code-input { letter-spacing: .5em; font-size: 22px; text-align: center; font-variant-numeric: tabular-nums; }

/* ── 提示 ─────────────────────────────────────── */
.toast { position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 12px); background: var(--accent-soft); color: var(--text); padding: 10px 18px; border-radius: 10px; font-size: 15px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; max-width: 90vw; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: #5a2a2a; }

/* ── 底部固定操作列 ───────────────────────────── */
.dock { position: sticky; bottom: 0; z-index: 20; margin-top: var(--s7); padding: var(--s3) 0; background: rgba(15, 26, 29, .96); border-top: 1px solid var(--line); backdrop-filter: blur(8px); display: flex; gap: var(--s3); align-items: center; }
.dock:empty { display: none; }
.dock .spacer { flex: 1; }
.save-state { font-size: 14px; color: var(--muted); }
main > :last-child:not(.dock) { margin-bottom: var(--s7); }

/* ── 其他 ─────────────────────────────────────── */
details > summary { cursor: pointer; font-weight: 500; list-style: none; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }
details > summary:hover { color: var(--text); }
details[open] > summary { margin-bottom: var(--s4); }
.mt { margin-top: var(--s4); }
.mt-lg { margin-top: var(--s5); }
.w140 { width: 140px; }
.w-auto { width: auto; min-height: 0; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }
.axis-list { display: grid; gap: var(--s2); }
.axis-list .row { display: flex; gap: var(--s2); align-items: center; }
.axis-list .row input { flex: 1; }
.check-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s2) var(--s4); }
.check-grid label { display: flex; align-items: center; gap: var(--s2); font-size: 15px; cursor: pointer; }
@media (max-width: 760px) { .check-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.empty-state { padding: var(--s6); text-align: center; color: var(--muted); }
.mb { margin-bottom: var(--s4); }
.mb-lg { margin-bottom: var(--s5); }

/* 表格欄位不換行（單位、姓名、主管這類短欄位） */
table.list td.nowrap { white-space: nowrap; }

/* 姓名旁的角色圖示（沿用 .tip 的 tooltip，外觀改為無框圖示） */
.name-line { display: inline-flex; align-items: center; gap: 6px; }
.tip.icon { border: 0; width: 20px; height: 20px; font-size: 15px; color: var(--muted); }
.tip.icon:hover, .tip.icon:focus-visible { color: var(--text); }
.tip.icon.crown { color: var(--gold); font-size: 18px; }

/* ── 能力題目頁：分組與加分等級編輯 ───────────── */
.group + .group { margin-top: var(--s6); }
.group-head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); }
.group-head h3 { font-size: 17px; font-weight: 700; }
.group-head .grow { flex: 1; }
.levels { display: grid; gap: var(--s2); }
.level-row { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; gap: var(--s2); align-items: center; }
.prefix { position: relative; }
.prefix span { position: absolute; left: var(--s3); top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.prefix input { padding-left: 26px; text-align: right; font-variant-numeric: tabular-nums; }
