/* ========== 基础 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --green: #1a7f4b;
    --green-dark: #14663b;
    --green-light: #e8f5ee;
    --ink: #1f2933;
    --gray: #6b7280;
    --line: #e5e7eb;
    --bg: #f4f6f8;
    --red: #d64545;
    --amber: #c9881f;
    --blue: #2563eb;
    --radius: 8px;
}
body {
    font-family: "Microsoft YaHei", "PingFang SC", -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
}
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted, small.muted { color: var(--gray); }

/* ========== 顶栏 ========== */
.topbar {
    display: flex; align-items: center; gap: 16px;
    background: #fff; padding: 0 20px; min-height: 56px;
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 50;
    flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; color: var(--green-dark); white-space: nowrap; flex-shrink: 0; }
.brand .logo { color: var(--green); margin-right: 4px; }
.mainnav { display: flex; gap: 4px; flex: 1 1 auto; overflow-x: auto; min-width: 200px; scrollbar-width: none; }
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a {
    padding: 6px 14px; border-radius: 6px; color: var(--ink);
    font-weight: 500; white-space: nowrap; flex-shrink: 0;
}
.mainnav a:hover { background: var(--green-light); text-decoration: none; }
.mainnav a.active { background: var(--green); color: #fff; }
.userbox { display: flex; align-items: center; gap: 12px; white-space: nowrap; flex-shrink: 0; }
.userbox .who small { color: var(--gray); font-weight: 400; margin-left: 4px; }
.btn-logout { color: var(--gray); font-size: 13px; }

.container { max-width: 1440px; margin: 20px auto; padding: 0 20px; }

/* ========== 提示 ========== */
.flash {
    padding: 10px 16px; margin: 12px 20px 0; border-radius: var(--radius);
    font-size: 14px;
}
.flash-success { background: var(--green-light); color: var(--green-dark); border: 1px solid #bfe3cf; }
.flash-error { background: #fdeaea; color: var(--red); border: 1px solid #f5c6c6; }

/* ========== 卡片/统计 ========== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card {
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px 18px;
}
.card .label { color: var(--gray); font-size: 13px; margin-bottom: 8px; }
.card .num { font-size: 26px; font-weight: 700; }
.card .num small { font-size: 13px; color: var(--gray); font-weight: 400; margin-left: 4px; }
.card.accent-green .num { color: var(--green); }
.card.accent-blue .num { color: var(--blue); }
.card.accent-amber .num { color: var(--amber); }
.card.accent-red .num { color: var(--red); }

.panel {
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px; margin-bottom: 18px;
}
.panel h2 { font-size: 16px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.panel h2 .sub-font { font-size: 13px; color: var(--gray); font-weight: 400; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ========== 按钮/表单 ========== */
.btn {
    display: inline-block; padding: 7px 16px; border-radius: 6px; border: 1px solid var(--line);
    background: #fff; color: var(--ink); cursor: pointer; font-size: 14px;
    font-family: inherit; line-height: 1.4;
}
.btn:hover { border-color: var(--green); color: var(--green); text-decoration: none; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); color: #fff; }
.btn-sm { padding: 3px 10px; font-size: 13px; }
.btn-danger:hover { border-color: var(--red); color: var(--red); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
    font-family: inherit; font-size: 14px; padding: 7px 10px;
    border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 2px rgba(26,127,75,.12); }
label.fld { display: block; margin-bottom: 12px; }
label.fld > span { display: block; font-size: 13px; color: var(--gray); margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }
@media (max-width: 800px) { .form-grid { grid-template-columns: 1fr; } }

/* ========== 筛选栏 ========== */
.toolbar {
    display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
    margin-bottom: 14px;
}
.toolbar .spacer { flex: 1; }
.toolbar input, .toolbar select { padding: 6px 10px; }
.search-box { min-width: 220px; }

/* ========== 表格 ========== */
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table.grid { width: 100%; border-collapse: collapse; white-space: nowrap; }
table.grid th, table.grid td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; }
table.grid th {
    background: #f8faf9; font-weight: 600; font-size: 13px; color: #374151;
    position: sticky; top: 0; user-select: none;
}
table.grid th.sortable { cursor: pointer; }
table.grid th.sortable:hover { color: var(--green); }
table.grid tbody tr:hover { background: #f6faf8; }
table.grid tbody tr.overdue { background: #fdf6ec; }
table.grid td.num, table.grid th.num { text-align: right; }
table.grid .editable { cursor: text; border-radius: 4px; min-width: 40px; display: inline-block; }
table.grid .editable:hover { background: var(--green-light); outline: 1px dashed #9ccfb3; }
.cell-status, .tag {
    display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px;
    background: #eef1f4; color: #4b5563;
}
.tag-green { background: var(--green-light); color: var(--green-dark); }
.tag-red { background: #fdeaea; color: var(--red); }
.tag-amber { background: #fdf3e0; color: var(--amber); }
.tag-blue { background: #e8f0fe; color: var(--blue); }
.empty { text-align: center; color: var(--gray); padding: 40px; }
.pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 12px; }
.pager .info { color: var(--gray); margin-right: 10px; }

/* ========== 客户详情抽屉 ========== */
.drawer-mask {
    position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 100;
    display: none;
}
.drawer-mask.open { display: block; }
.drawer {
    position: fixed; top: 0; right: -680px; width: 680px; max-width: 96vw; height: 100%;
    background: #fff; z-index: 101; transition: right .22s; overflow-y: auto;
    box-shadow: -4px 0 18px rgba(0,0,0,.12);
}
.drawer.open { right: 0; }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: #fff; }
.drawer-body { padding: 20px; }
.close-x { font-size: 22px; color: var(--gray); cursor: pointer; background: none; border: none; }

/* 时间线 */
.timeline { list-style: none; margin-top: 10px; }
.timeline li { position: relative; padding: 0 0 18px 22px; border-left: 2px solid var(--line); }
.timeline li::before {
    content: ''; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px;
    border-radius: 50%; background: var(--green); border: 2px solid #fff;
}
.timeline .t-time { color: var(--gray); font-size: 12px; }
.timeline .t-content { margin-top: 3px; white-space: pre-wrap; }
.timeline .t-meta { font-size: 12px; color: var(--green-dark); margin-top: 2px; }

/* ========== 登录页 ========== */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #0f5132 0%, #1a7f4b 60%, #2e9d63 100%); }
.login-card {
    background: #fff; border-radius: 14px; padding: 36px 34px; width: 360px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-card h1 { font-size: 22px; color: var(--green-dark); text-align: center; }
.login-card .sub { text-align: center; color: var(--gray); margin: 6px 0 22px; font-size: 13px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--gray); }
.login-card input { width: 100%; margin-top: 4px; padding: 10px 12px; }
.login-card .btn { padding: 10px; margin-top: 6px; font-size: 15px; }

/* ========== 表格快速录入 ========== */
.quick-grid { font-size: 13px; min-width: 1640px; }
.quick-grid th { white-space: nowrap; }
.quick-grid td { padding: 0; border: 1px solid var(--line); vertical-align: middle; }
.quick-grid td.rownum { text-align: center; color: var(--gray); background: #fafbfc; padding: 0 6px; user-select: none; }
.quick-grid .cell {
    width: 100%; min-width: 0; border: none !important; border-radius: 0;
    padding: 7px 8px; background: transparent; font-size: 13px; height: 34px;
    box-shadow: none !important;
}
.quick-grid .cell:focus { background: #eef7f1; }
.quick-grid select.cell { appearance: auto; cursor: pointer; }

/* ========== 图表 ========== */
.chart { width: 100%; height: 300px; }

/* ========== 设置页 Tabs ========== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a { padding: 8px 16px; color: var(--gray); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--green); border-bottom-color: var(--green); font-weight: 600; }

.dict-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
table.simple { width: 100%; border-collapse: collapse; }
table.simple th, table.simple td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.simple th { background: #f8faf9; font-size: 13px; color: #374151; }

.inline-edit-input { padding: 3px 6px !important; font-size: 13px; width: 100%; }

/* 工作台列表 */
.simple-list { list-style: none; }
.simple-list li { padding: 8px 4px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.simple-list li:last-child { border-bottom: none; }
.simple-list .overdue-li a { color: var(--red); }
