:root {
    --brand: #1f5fbf;
    --brand-dark: #17498f;
    --brand-light: #eaf1fc;
    --bg: #f4f6fa;
    --card: #ffffff;
    --text: #1f2d3d;
    --text-muted: #6b7a90;
    --line: #e3e8f0;
    --done: #2f9e6e;
    --doing: #e8a33d;
    --undo: #e05a4f;
    --radius: 10px;
    --shadow: 0 2px 10px rgba(23, 58, 110, .07);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

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

/* ---------------- 顶栏与导航 ---------------- */

.topbar {
    background: linear-gradient(135deg, #17498f 0%, #1f5fbf 55%, #2a74d6 100%);
    color: #fff;
    box-shadow: 0 2px 12px rgba(23, 58, 110, .18);
}

.topbar-inner,
.nav-inner,
.container,
.footer .container-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 22px;
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 14px;
    padding-bottom: 12px;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .16);
    border: 1px solid rgba(255, 255, 255, .35);
    border-radius: 9px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 1px;
}

.brand-text strong { display: block; font-size: 17px; letter-spacing: .5px; }
.brand-text small { display: block; font-size: 11px; color: rgba(255, 255, 255, .7); letter-spacing: .6px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.user-chip {
    padding: 4px 12px;
    background: rgba(255, 255, 255, .16);
    border-radius: 20px;
    font-size: 13px;
}

.nav { border-top: 1px solid rgba(255, 255, 255, .16); }

.nav-inner { display: flex; gap: 4px; overflow-x: auto; }

.nav-link {
    padding: 10px 18px;
    color: rgba(255, 255, 255, .86);
    font-size: 14px;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}

.nav-link:hover { color: #fff; text-decoration: none; background: rgba(255, 255, 255, .08); }
.nav-link.active { color: #fff; font-weight: 600; border-bottom-color: #ffd66b; }

/* ---------------- 布局 ---------------- */

main.container { padding-top: 22px; padding-bottom: 36px; min-height: calc(100vh - 190px); }

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.page-head h1 { margin: 0; font-size: 20px; letter-spacing: .5px; }
.page-head .sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    margin-bottom: 18px;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.card-title { margin: 0; font-size: 15px; font-weight: 700; color: #17325c; }
.card-title small { font-weight: 400; color: var(--text-muted); margin-left: 8px; font-size: 12px; }

/* ---------------- 概览指标 ---------------- */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 18px;
}

.kpi {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    position: relative;
    overflow: hidden;
}

.kpi::after {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: var(--brand);
}

.kpi .label { color: var(--text-muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; color: #17325c; line-height: 1.25; }
.kpi .value small { font-size: 13px; font-weight: 400; color: var(--text-muted); margin-left: 4px; }
.kpi .foot { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.kpi.green::after { background: var(--done); }
.kpi.orange::after { background: var(--doing); }
.kpi.red::after { background: var(--undo); }

/* ---------------- 图表 ---------------- */

.pie-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 18px;
}

.pie-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px 12px;
}

.pie-card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    border-bottom: 1px dashed var(--line);
    padding-bottom: 10px;
    margin-bottom: 6px;
}

.pie-card-head h3 { margin: 0; font-size: 15px; color: #17325c; }
.pie-card-head .range { font-size: 11px; color: var(--text-muted); }
.pie-card-head .total { font-size: 12px; color: var(--text-muted); }

.pie-body {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 6px 0 4px;
}

.pie-body canvas { flex: 0 0 auto; }

.legend { list-style: none; margin: 0; padding: 0; flex: 1 1 auto; min-width: 120px; }

.legend li {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    padding: 3px 0;
    color: var(--text-muted);
}

.legend .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.legend .name { flex: 1 1 auto; color: var(--text); }
.legend .count { font-variant-numeric: tabular-nums; }
.legend .pct { width: 46px; text-align: right; font-weight: 700; color: #17325c; font-variant-numeric: tabular-nums; }

.rate-bar {
    height: 6px;
    background: #eef2f8;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
}

.rate-bar > i {
    display: block;
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, #2f9e6e, #4fc48d);
}

/* ---------------- 表格 ---------------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

table.data thead th {
    background: #f2f6fc;
    color: #3a4f6e;
    font-weight: 600;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

table.data tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid #f0f3f8;
    vertical-align: middle;
}

table.data tbody tr:hover { background: #fafcff; }
table.data tbody tr:last-child td { border-bottom: none; }

.cell-title { font-weight: 600; color: #17325c; }
.cell-content {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 2px;
    max-width: 380px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    line-height: 1.7;
    white-space: nowrap;
}

.badge.st-done { background: #e7f5ee; color: #1f7d55; }
.badge.st-doing { background: #fdf3e1; color: #a86c0b; }
.badge.st-undo { background: #fdeceb; color: #b8402f; }

.due { font-variant-numeric: tabular-nums; white-space: nowrap; }
.due .left { display: block; font-size: 11px; color: var(--text-muted); }
.due.overdue .left { color: var(--undo); font-weight: 600; }
.due.soon .left { color: var(--doing); font-weight: 600; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid transparent;
    font-size: 13px;
    cursor: pointer;
    background: #fff;
    color: var(--text);
    font-family: inherit;
    transition: all .15s ease;
    text-decoration: none !important;
    white-space: nowrap;
}

.btn:hover { filter: brightness(.97); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; border-color: var(--line); color: #3a4f6e; }
.btn-ghost:hover { border-color: #c3d2e8; color: var(--brand); }
.btn-danger { background: #fff; border-color: #f0c6c1; color: #b8402f; }
.btn-danger:hover { background: #fdeceb; }
.btn-inline { padding: 4px 10px; font-size: 12px; }
.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.ops { display: flex; gap: 6px; white-space: nowrap; }

/* ---------------- 表单 ---------------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 22px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; color: #3a4f6e; font-weight: 600; }
.field label .req { color: var(--undo); margin-left: 3px; }
.field .hint { font-size: 11.5px; color: var(--text-muted); }

input[type="text"], input[type="date"], input[type="number"], input[type="password"], input[type="email"],
select, textarea {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid #dbe3ee;
    border-radius: 6px;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #7aa8e8;
    box-shadow: 0 0 0 3px rgba(31, 95, 191, .12);
}

textarea { resize: vertical; min-height: 92px; line-height: 1.7; }

.radio-group { display: flex; gap: 10px; flex-wrap: wrap; }

.radio-card {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border: 1px solid #dbe3ee;
    border-radius: 7px;
    cursor: pointer;
    background: #fff;
    font-size: 13px;
    transition: all .15s;
}

.radio-card:hover { border-color: #a9c4e8; }
.radio-card input { margin: 0; }
.radio-card.checked { border-color: var(--brand); background: var(--brand-light); }
.radio-card.checked.st-done { border-color: var(--done); background: #e7f5ee; }
.radio-card.checked.st-doing { border-color: var(--doing); background: #fdf3e1; }
.radio-card.checked.st-undo { border-color: var(--undo); background: #fdeceb; }

.form-actions {
    display: flex;
    gap: 10px;
    padding-top: 16px;
    margin-top: 18px;
    border-top: 1px dashed var(--line);
}

.form-section-title {
    font-size: 13px;
    font-weight: 700;
    color: #17325c;
    padding-left: 9px;
    border-left: 3px solid var(--brand);
    margin: 4px 0 2px;
    grid-column: 1 / -1;
}

/* ---------------- 筛选栏 ---------------- */

.filter-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 14px;
}

.filter-bar .item { display: flex; flex-direction: column; gap: 4px; }
.filter-bar .item label { font-size: 12px; color: var(--text-muted); }
.filter-bar .item input, .filter-bar .item select { min-width: 130px; padding: 6px 10px; }
.filter-bar .item.grow { flex: 1 1 200px; }
.filter-bar .item.grow input { width: 100%; }
.filter-bar .btns { display: flex; gap: 8px; }

/* ---------------- 提示 ---------------- */

.alert {
    padding: 11px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13.5px;
    border: 1px solid transparent;
}

.alert-success { background: #e9f7f0; border-color: #bfe6d3; color: #1f7d55; }
.alert-error { background: #fdeceb; border-color: #f4ccc7; color: #a93a2b; }
.alert-warn { background: #fdf5e5; border-color: #f3ddb0; color: #8a5a08; }
.alert-info { background: var(--brand-light); border-color: #c9dcf6; color: #17498f; }

.empty {
    text-align: center;
    padding: 34px 10px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ---------------- 分页 ---------------- */

.pager { display: flex; gap: 6px; justify-content: flex-end; align-items: center; padding-top: 14px; flex-wrap: wrap; }
.pager .info { color: var(--text-muted); font-size: 12px; margin-right: auto; }
.pager a, .pager span.page {
    padding: 5px 11px;
    border: 1px solid var(--line);
    border-radius: 5px;
    font-size: 12.5px;
    color: #3a4f6e;
    background: #fff;
}
.pager a:hover { border-color: #c3d2e8; text-decoration: none; }
.pager .current { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pager .disabled { opacity: .45; pointer-events: none; }

/* ---------------- 设置页 ---------------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button {
    background: none;
    border: none;
    padding: 9px 16px;
    font-size: 13.5px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    font-family: inherit;
}
.tabs button.active { color: var(--brand); font-weight: 700; border-bottom-color: var(--brand); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1 1 240px; }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12.5px;
    background: #f1f4f9;
    color: #5a6b85;
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa8bb; }
.status-pill.on { background: #e7f5ee; color: #1f7d55; }
.status-pill.on .dot { background: var(--done); }
.status-pill.off { background: #fdeceb; color: #b8402f; }
.status-pill.off .dot { background: var(--undo); }

.code-box {
    background: #f7f9fc;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 10px 14px;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 12.5px;
    color: #3a4f6e;
    overflow-x: auto;
    white-space: pre;
    line-height: 1.7;
}

/* ---------------- 登录页 ---------------- */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #17325c 0%, #1f5fbf 60%, #3d86e0 100%);
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 18px 46px rgba(10, 30, 60, .32);
    padding: 32px 30px 26px;
}

.login-card .logo {
    width: 48px; height: 48px;
    margin: 0 auto 14px;
    border-radius: 12px;
    background: linear-gradient(135deg, #17498f, #2a74d6);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 700;
}

.login-card h1 { margin: 0; text-align: center; font-size: 18px; color: #17325c; }
.login-card .sub { text-align: center; color: var(--text-muted); font-size: 12.5px; margin: 4px 0 22px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; padding: 10px; font-size: 14px; margin-top: 4px; }
.login-card .foot { text-align: center; color: #94a3b8; font-size: 11.5px; margin-top: 18px; }

/* ---------------- 页脚 ---------------- */

.footer {
    border-top: 1px solid var(--line);
    background: #fff;
    color: var(--text-muted);
    font-size: 12px;
    padding: 14px 0;
}

.footer .container-inner { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ---------------- 响应式 ---------------- */

@media (max-width: 1100px) {
    .pie-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .topbar-inner { padding-top: 10px; padding-bottom: 10px; gap: 8px; }
    .brand-text strong { font-size: 15px; letter-spacing: 0; }
    .brand-text small { display: none; }
    .brand-mark { width: 32px; height: 32px; font-size: 16px; }
    .user-chip { display: none; }
    .nav-link { padding: 9px 13px; font-size: 13.5px; }
    .page-head h1 { font-size: 17px; }
    .pie-body { flex-direction: column; align-items: center; }
    .legend { width: 100%; }
    .filter-bar .item, .filter-bar .item input, .filter-bar .item select { width: 100%; min-width: 0; }
    .filter-bar .btns { width: 100%; }
    .filter-bar .btns .btn { flex: 1; }
}

@media print {
    .topbar, .footer, .ops, .page-head .actions, .filter-bar { display: none !important; }
    body { background: #fff; }
    .card, .pie-card { box-shadow: none; }
}

/* 操作列内的删除表单需去除默认外边距 */
.ops form { margin: 0; }
.ops form .btn { width: 100%; }

/* 已配置 / 未配置 凭据标记 */
.cred-tag {
    display: inline-block;
    margin-left: 7px;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 400;
    background: #fdeceb;
    color: #b8402f;
    vertical-align: middle;
}

.cred-tag.set { background: #e7f5ee; color: #1f7d55; }

/* ---------- 批量操作 ---------- */
.bulk-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 0 0 12px;
    margin-bottom: 4px;
    border-bottom: 1px dashed var(--line);
}

.bulk-all {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
}

.check-all,
.row-check {
    width: 15px;
    height: 15px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--brand);
}

.bulk-bar .muted { color: var(--text-muted); font-size: 13px; }
.bulk-bar form { margin: 0; }
.bulk-bar .bulk-del[disabled] { opacity: .5; cursor: not-allowed; }

.cell-sub {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 3px;
    line-height: 1.5;
}

.card-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.tips {
    margin: 0;
    padding-left: 20px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.9;
}

.tips code {
    background: #f3f6fb;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
}

.unit-input { display: flex; align-items: center; gap: 8px; }
.unit-input input { flex: 1; min-width: 0; }
.unit { color: var(--text-muted); font-size: 13px; white-space: nowrap; }
