:root {
    --primary: #2456d6;
    --primary-soft: #edf4ff;
    --bg: #f5f7fb;
    --card: #fff;
    --text: #172033;
    --muted: #667085;
    --line: #e4e8f0;
    --danger: #b42318;
    --success: #027a48;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--primary); text-decoration: none; }

header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 18px 4%;
    background: rgba(255,255,255,.97);
    border-bottom: 1px solid #e5e9f2;
    backdrop-filter: blur(10px);
}
header h1 { margin: 0 0 5px; font-size: 21px; }
header p { margin: 0; color: var(--muted); font-size: 14px; }
main { max-width: 1400px; margin: 24px auto; padding: 0 18px 60px; }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-page main { margin: 0; }
.login-card {
    width: min(430px, 92vw);
    padding: 32px;
    background: var(--card);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(30,41,59,.10);
}
.login-card h1 { margin: 0 0 8px; font-size: 23px; line-height: 1.4; }
.login-card form > button { display: block; margin: 20px auto 0; }
.login-links { display: flex; flex-direction: column; gap: 14px; margin-top: 24px; }
.login-link-button {
    display: block;
    padding: 11px 16px;
    border: 1px solid #cfd6e4;
    border-radius: 9px;
    background: #f8fafc;
    color: var(--primary);
    font-weight: 700;
    text-align: center;
    transition: .15s ease;
}
.login-link-button:hover { background: var(--primary-soft); border-color: var(--primary); box-shadow: 0 4px 12px rgba(36,86,214,.12); }

label { display: block; margin: 14px 0; font-weight: 600; }
input, textarea, select, button { font: inherit; }
input, textarea, select {
    width: 100%;
    margin-top: 7px;
    padding: 10px 12px;
    border: 1px solid #cfd6e4;
    border-radius: 8px;
    background: #fff;
    outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(36,86,214,.12); }
textarea { min-height: 72px; resize: vertical; }
button, .button-link {
    display: inline-block;
    padding: 11px 18px;
    border: 0;
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}
button:hover, .button-link:hover { background: #1f49b8; }
.muted { color: var(--muted); font-size: 13px; }
.alert, .notice { margin-bottom: 18px; padding: 13px 15px; border-radius: 10px; background: var(--primary-soft); line-height: 1.7; }
.error { background: #fff0f0; color: var(--danger); }
.success { background: #ecfdf3; color: var(--success); }

.top-actions { display: flex; align-items: center; gap: 16px; }
.save-state { font-size: 13px; color: var(--success); }
.save-state.bad { color: var(--danger); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(520px, 1fr)); gap: 18px; }
.score-card, .panel, .individual-panel {
    padding: 20px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 5px 18px rgba(37,56,88,.05);
}
.score-card.submitted { border-color: #9fd0bf; }
.score-card.needs-attention { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(180,35,24,.12); }
.card-head, .person-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; }
.card-head h2, .person-head h2 { margin: 6px 0; font-size: 19px; }
.card-head h2 small, .person-head h2 small { color: var(--muted); font-size: 13px; font-weight: 500; }
.card-head p, .person-head p { margin: 0; color: var(--muted); font-size: 13px; }
.department { display: inline-block; padding: 3px 8px; border-radius: 6px; background: #f0f3f8; color: #475467; font-size: 12px; }
.total { white-space: nowrap; text-align: right; }
.total span, .total em { color: var(--muted); font-size: 12px; font-style: normal; }
.total strong { display: inline-block; margin: 0 4px; color: var(--primary); font-size: 28px; }
.summary-link, .summary-missing {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    vertical-align: middle;
    white-space: nowrap;
}
.summary-link { border: 1px solid #b9d7ff; background: #eef6ff; color: #1769aa; }
.summary-link:hover { background: #dceeff; }
.summary-missing { border: 1px solid #fecaca; background: #fff1f2; color: #dc2626; }

.legend-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0 18px; }
.legend-grid details, .score-item { border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.legend-grid details { padding: 12px; }
.legend-grid summary, .criterion-help summary { color: var(--primary); font-weight: 700; cursor: pointer; }
.legend-grid p { margin-bottom: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.progress-wrap { display: flex; align-items: center; gap: 18px; margin: 18px 0; }
.progress { height: 8px; flex: 1; overflow: hidden; border-radius: 99px; background: #e4e8f0; }
.progress span { display: block; width: 0; height: 100%; background: var(--primary); transition: width .3s; }

.score-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 18px; }
.score-item { min-width: 0; padding: 13px; background: #f8fafc; }
.score-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.score-title span { color: var(--muted); font-weight: 500; }
.criterion-help { margin-top: 9px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.criterion-help summary { padding: 8px 10px; font-size: 13px; }
.criterion-table { border-top: 1px solid var(--line); }
.criterion-row { display: grid; grid-template-columns: 44px 1fr 54px; gap: 8px; align-items: center; padding: 8px 9px; border-bottom: 1px solid var(--line); font-size: 12px; }
.criterion-row:last-child { border-bottom: 0; }
.criterion-row p { margin: 0; color: #475467; line-height: 1.55; }
.criterion-row em { color: var(--primary); font-style: normal; font-weight: 750; text-align: right; }
.slider-line { display: grid; grid-template-columns: 1fr 78px; gap: 12px; align-items: center; margin-top: 12px; }
.score-slider { height: 28px; margin: 0; padding: 0; border: 0; box-shadow: none; accent-color: var(--primary); cursor: pointer; touch-action: pan-y; }
.slider-line .score-input { margin: 0; padding: 9px 7px; text-align: center; }
.score-input.invalid { border-color: var(--danger); background: #fff7f6; }
.comment-label { margin-top: 14px; font-size: 14px; }
.card-foot { display: flex; justify-content: flex-end; margin-top: 10px; }
.row-status { color: var(--muted); font-size: 13px; }
.submitted .row-status { color: var(--success); font-weight: 700; }
.final-submit-panel { display: flex; position: sticky; bottom: 12px; z-index: 8; align-items: center; justify-content: space-between; gap: 20px; margin-top: 20px; padding: 16px 18px; border: 1px solid #b9c9ec; border-radius: 14px; background: rgba(255,255,255,.97); box-shadow: 0 10px 30px rgba(30,41,59,.14); backdrop-filter: blur(10px); }
.final-submit-panel p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.submit-all { margin: 0; padding: 13px 30px; white-space: nowrap; }
.submit-all:disabled { opacity: .65; cursor: wait; }

.admin-container > h2 { margin: 26px 0 12px; }
.table-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; min-width: 850px; border-collapse: collapse; }
th, td { padding: 11px; border-bottom: 1px solid #e8ebf1; text-align: left; vertical-align: top; }
th { background: #f8fafc; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.formula-cell { min-width: 360px; max-width: 620px; white-space: normal; color: #344054; font-size: 13px; line-height: 1.6; }
.comment-cell { min-width: 180px; max-width: 300px; white-space: normal; line-height: 1.5; }
.individual-panel { margin-top: 20px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.section-heading h2 { margin: 0 0 14px; }
.detail-link { font-weight: 700; }
.detail-toggle { padding: 8px 12px; font-size: 13px; white-space: nowrap; }
.scorer-summary { min-width: 960px; }
.scorer-summary-row:has(+ .scorer-detail-row:not([hidden])) > td { background: #f8fafc; }
.scorer-detail-row > td { padding: 16px; background: #f8fafc; }
.inline-detail-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.inline-detail-heading span { color: var(--muted); font-size: 13px; }
.score-detail { min-width: 1100px; }
.score-detail .comment-cell { white-space: pre-wrap; word-break: break-word; }
.status-pill { display: inline-block; padding: 3px 8px; border-radius: 99px; background: #edf1f0; color: var(--muted); font-size: 12px; }
.status-pill.ok { background: #ecfdf3; color: var(--success); }
.status-pill.draft { background: #fff5dc; color: #8a5a00; }

.ranking-chart { display: flex; flex-direction: column; gap: 9px; margin: 12px 0 28px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 5px 18px rgba(37,56,88,.05); }
.ranking-row { display: grid; grid-template-columns: 66px minmax(110px,170px) minmax(260px,1fr); align-items: center; gap: 12px; min-height: 42px; padding: 6px 0; }
.ranking-row + .ranking-row { border-top: 1px dashed #eef2f7; }
.ranking-rank { color: #64748b; font-weight: 700; text-align: center; white-space: nowrap; }
.ranking-name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ranking-note { padding: 2px 6px; border-radius: 999px; background: var(--primary-soft); color: #475569; font-size: 11px; white-space: nowrap; }
.ranking-bar-track { position: relative; height: 28px; overflow: hidden; border-radius: 7px; background: #eef2f7; }
.ranking-bar { height: 100%; min-width: 2px; border-radius: 7px; background: linear-gradient(90deg,#4f7cff,var(--primary)); }
.ranking-score { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); color: #0f172a; font-weight: 800; font-variant-numeric: tabular-nums; }
.empty-chart { margin: 12px 0 28px; padding: 28px; border: 1px dashed #cbd5e1; border-radius: 12px; background: #fff; color: var(--muted); text-align: center; }

@media (max-width: 900px) {
    .cards { grid-template-columns: 1fr; }
    .legend-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
    header { position: static; align-items: flex-start; padding: 15px 18px; }
    header h1 { font-size: 18px; }
    .top-actions { gap: 10px; }
    main { margin-top: 18px; padding: 0 10px 48px; }
    .login-card { padding: 22px; }
    .legend-grid, .score-grid { grid-template-columns: 1fr; }
    .person-head { display: block; }
    .total { margin-top: 10px; text-align: left; }
    .progress-wrap { display: block; }
    .progress { margin-top: 8px; }
    .final-submit-panel { align-items: stretch; flex-direction: column; }
    .submit-all { width: 100%; }
    .ranking-chart { padding: 12px; overflow-x: auto; }
    .ranking-row { grid-template-columns: 58px 100px minmax(220px,1fr); min-width: 470px; gap: 8px; }
    .ranking-note { display: none; }
}
