:root {
    --navy: #14243b;
    --blue: #246bfd;
    --blue-dark: #1854cf;
    --blue-soft: #edf3ff;
    --ink: #182230;
    --muted: #667085;
    --line: #e4e9f0;
    --surface: #ffffff;
    --background: #f4f6fa;
    --danger: #c4323b;
    --danger-soft: #fff0f1;
    --warning: #9b5c00;
    --warning-soft: #fff6df;
    --success: #157347;
    --success-soft: #eaf8f0;
    --radius: 14px;
    --shadow: 0 8px 28px rgba(20, 36, 59, 0.07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
    margin: 0;
    color: var(--ink);
    background: var(--background);
    font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.6;
}
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-dark); }
button, input, select, textarea { font: inherit; }
button, summary { -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: 30px; line-height: 1.25; letter-spacing: -0.02em; }
h2 { margin-bottom: 0; font-size: 20px; line-height: 1.35; }
strong { font-weight: 650; }

.topbar { background: var(--navy); color: #fff; box-shadow: 0 2px 12px rgba(10, 24, 43, 0.16); }
.topbar-inner {
    width: min(1400px, calc(100% - 48px));
    min-height: 68px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 34px;
}
.brand { display: flex; align-items: center; gap: 11px; color: #fff; font-weight: 700; white-space: nowrap; }
.brand:hover { color: #fff; }
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 47px;
    height: 34px;
    border-radius: 9px;
    background: var(--blue);
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.04em;
}
.main-nav { align-self: stretch; display: flex; gap: 6px; }
.main-nav a { display: flex; align-items: center; padding: 0 16px; color: #c8d2e2; border-bottom: 3px solid transparent; }
.main-nav a:hover, .main-nav a.active { color: #fff; background: rgba(255,255,255,0.04); border-bottom-color: #5d91ff; }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 16px; color: #c8d2e2; }
.user-menu a, .user-menu .link-button { color: #dbe3ef; font-size: 14px; }
.user-name { color: #fff; font-weight: 600; }
.user-name small { margin-left: 7px; padding: 2px 6px; border-radius: 4px; background: rgba(255,255,255,0.12); font-size: 11px; }
.user-menu form { margin: 0; }

.container { width: min(1400px, calc(100% - 48px)); margin: 34px auto 60px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-heading p { margin-bottom: 0; }
.heading-actions { display: flex; gap: 10px; align-items: center; }
.eyebrow { display: block; margin-bottom: 5px; color: var(--blue); font-size: 12px; font-weight: 750; letter-spacing: 0.12em; }
.muted { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.narrow-card { max-width: 560px; padding: 28px; }
.breadcrumb { display: flex; gap: 9px; margin-bottom: 18px; color: var(--muted); font-size: 14px; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 17px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 650;
    line-height: 1.4;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.button:active { transform: translateY(1px); }
.button.primary { background: var(--blue); color: #fff; }
.button.primary:hover { background: var(--blue-dark); color: #fff; }
.button.secondary { background: #fff; color: #344054; border-color: #cfd7e3; }
.button.secondary:hover { background: #f8faff; border-color: #aebbd0; color: var(--ink); }
.button.ghost { color: var(--muted); background: transparent; }
.button.danger-outline { color: var(--danger); background: #fff; border-color: #efb7bc; }
.button.full { width: 100%; }
.link-button { padding: 0; border: 0; background: transparent; cursor: pointer; color: var(--blue); }
.danger-text { color: var(--danger); }
.form-actions { display: flex; gap: 10px; margin-top: 24px; }

.flash-stack { display: grid; gap: 8px; margin-bottom: 20px; }
.flash { padding: 12px 16px; border-radius: 9px; border: 1px solid; }
.flash.success { color: var(--success); background: var(--success-soft); border-color: #bfe7d0; }
.flash.error { color: var(--danger); background: var(--danger-soft); border-color: #f1c4c8; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card { position: relative; padding: 20px 24px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.stat-card:hover { border-color: #b8c9ed; color: var(--ink); }
.stat-card span { display: block; color: var(--muted); }
.stat-card strong { display: block; margin-top: 3px; font-size: 30px; line-height: 1.3; }
.stat-card.today { border-left: 4px solid #e4a429; }
.stat-card.overdue { border-left: 4px solid #d84a53; }
.stat-card.won { border-left: 4px solid var(--success); }
.deal-badge { margin: 5px 0 2px; }

.list-card { overflow: hidden; }
.filter-bar { display: flex; gap: 10px; padding: 18px; border-bottom: 1px solid var(--line); }
.bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: #f8faff; }
.bulk-bar select { width: auto; min-width: 160px; }
.bulk-bar .button { min-height: 38px; }
.bulk-select { display: inline-flex; align-items: center; gap: 8px; padding: 0; font-weight: 600; }
.bulk-select input, .check-col input { width: 16px; height: 16px; min-height: 0; cursor: pointer; }
.check-col { width: 44px; padding-right: 0; text-align: center; }
.search-field { flex: 1; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 18px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); background: #fafbfc; font-size: 13px; font-weight: 650; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcff; }
.customer-link { display: block; color: var(--ink); font-weight: 700; }
.table-subtext { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.badge { display: inline-flex; align-items: center; width: fit-content; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.badge.neutral { color: #5b6675; background: #eef1f5; }
.badge.success { color: var(--success); background: var(--success-soft); }
.badge.warning { color: var(--warning); background: var(--warning-soft); }
.badge.danger { color: var(--danger); background: var(--danger-soft); }
.count-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 30px; padding: 0 9px; border-radius: 999px; background: var(--blue-soft); color: var(--blue); font-weight: 700; }
.empty-state { padding: 60px 24px; text-align: center; }
.empty-state h2 { margin-bottom: 8px; }
.empty-state p { color: var(--muted); }
.empty-state.compact { padding: 40px 24px; }

.form-card { max-width: 960px; padding: 28px; }
fieldset { min-width: 0; margin: 0 0 28px; padding: 0 0 28px; border: 0; border-bottom: 1px solid var(--line); }
legend { margin-bottom: 18px; padding: 0; font-size: 18px; font-weight: 700; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 22px; }
.span-two { grid-column: span 2; }
label { display: grid; gap: 7px; color: #344054; font-weight: 600; }
label small { color: var(--muted); font-size: 12px; font-weight: 400; }
input, select, textarea {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid #ccd4df;
    border-radius: 8px;
    outline: none;
    background: #fff;
    color: var(--ink);
    font-weight: 400;
}
textarea { resize: vertical; line-height: 1.65; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36, 107, 253, 0.12); }
.required { color: var(--danger); font-size: 12px; }
.form-hint { margin: 18px 0 0; padding: 11px 14px; border-radius: 8px; background: var(--blue-soft); color: #34507d; }
.stack-form { display: grid; gap: 17px; }

.customer-summary { margin-bottom: 22px; padding: 24px; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.summary-grid div { display: grid; gap: 3px; }
.summary-grid span { color: var(--muted); font-size: 13px; }
.summary-grid strong { font-size: 16px; }
.assign-box { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.assign-box label { display: grid; gap: 4px; min-width: 200px; }
.summary-status { display: flex; align-items: center; gap: 12px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.summary-notes { margin-top: 16px; padding: 14px 16px; border-radius: 9px; background: #f8f9fb; }
.summary-notes p { margin-bottom: 6px; }
.summary-notes p:last-child { margin-bottom: 0; }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.record-meta { margin-top: 16px; color: var(--muted); font-size: 12px; }
#commercial-summary, #quote-documents, #contract-documents { margin-bottom: 22px; }
#quote-documents details, #contract-documents details { margin-top: 18px; }
#quote-documents details .stack-form, #contract-documents details .stack-form { margin-top: 16px; }
.detail-layout { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 22px; align-items: start; }
.follow-form-card { position: sticky; top: 20px; padding: 22px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.timeline { display: grid; gap: 16px; }
.timeline-heading-actions { display: flex; align-items: center; gap: 12px; }
.follow-card { padding: 22px; }
.follow-details > summary { list-style: none; cursor: pointer; }
.follow-details > summary::-webkit-details-marker { display: none; }
.follow-heading { display: flex; align-items: center; gap: 12px; }
.follow-heading-main { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.follow-heading a { font-size: 13px; flex: none; }
.follow-details > summary::after { content: "▾"; flex: none; color: var(--muted); font-size: 12px; transition: transform 0.15s; }
.follow-details[open] > summary::after { transform: rotate(180deg); }
.method-tag { padding: 3px 8px; border-radius: 6px; color: var(--blue); background: var(--blue-soft); font-size: 12px; font-weight: 700; }
.follow-content { margin: 16px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.annotation-box { margin-top: 18px; padding: 16px; border-left: 3px solid #7b61c9; border-radius: 0 9px 9px 0; background: #f7f4ff; }
.annotation-box > strong { display: block; margin-bottom: 12px; color: #59429b; }
.annotation-box .stack-form { gap: 10px; }
.annotation-box.readonly p { margin: 8px 0; }
.annotation-box.readonly small { color: var(--muted); }
.annotation-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 10px; color: var(--muted); }

.user-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.user-card { padding: 22px; }
.user-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 20px; }
.user-card-heading strong { display: block; font-size: 18px; }
.account-name { display: block; color: var(--muted); font-family: Consolas, monospace; }
.inline-edit-form { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; }
.user-actions { display: flex; align-items: flex-start; gap: 10px; margin-top: 18px; }
.user-actions details { position: relative; }
.user-actions summary { list-style: none; }
.user-actions summary::-webkit-details-marker { display: none; }
.reset-form { position: absolute; z-index: 5; top: 48px; left: 0; width: 260px; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: var(--shadow); }

.login-main { min-height: 100vh; margin: 0; width: 100%; display: grid; place-items: center; padding: 30px 18px; background: radial-gradient(circle at 50% 10%, #e7efff, var(--background) 55%); }
.login-card { width: min(430px, 100%); padding: 38px; border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: 0 20px 60px rgba(20, 36, 59, 0.12); }
.login-card h1 { margin-bottom: 8px; }
.login-brand { margin-bottom: 26px; }
.login-brand .brand-mark { width: 58px; height: 42px; font-size: 16px; }
.login-card form { margin-top: 26px; }
.login-help { margin: 22px 0 0; color: var(--muted); font-size: 12px; text-align: center; }
.error-card { max-width: 560px; margin: 60px auto; padding: 38px; text-align: center; }
.error-code { display: block; color: var(--blue); font-size: 54px; font-weight: 800; }

.modal-backdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(12, 24, 41, 0.62); backdrop-filter: blur(3px); }
.reminder-modal { width: min(660px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; padding: 28px; border-radius: 16px; background: #fff; box-shadow: 0 24px 80px rgba(0,0,0,0.25); }
.reminder-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.reminder-list { display: grid; gap: 10px; max-height: 390px; margin: 20px 0; overflow-y: auto; }
.reminder-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fafbfc; }
.reminder-item:hover { border-color: #b7c9ed; color: var(--ink); background: var(--blue-soft); }
.reminder-item-content { display: grid; }
.reminder-item-content small { color: var(--muted); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.customer-lookup-modal { width: min(720px, 100%); }
.lookup-form { display: flex; gap: 10px; margin-top: 18px; }
.lookup-form .search-field { flex: 1; }
.lookup-results { display: grid; gap: 10px; max-height: 390px; margin: 14px 0 20px; overflow-y: auto; }
.lookup-item { display: grid; gap: 6px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; }
.lookup-item-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lookup-item p { margin: 0; }
.lookup-item > small { color: var(--muted); }
.lookup-item .button { margin-top: 4px; justify-self: start; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1000px) {
    .topbar-inner { flex-wrap: wrap; gap: 12px 24px; padding: 12px 0; }
    .main-nav { min-height: 42px; }
    .detail-layout { grid-template-columns: 1fr; }
    .follow-form-card { position: static; }
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
    .container, .topbar-inner { width: min(100% - 28px, 1400px); }
    .container { margin-top: 24px; }
    .topbar-inner { gap: 10px; }
    .main-nav { order: 3; width: 100%; }
    .user-menu { gap: 10px; }
    .user-name small, .user-menu > a { display: none; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .stats-grid, .user-grid { grid-template-columns: 1fr; }
    .filter-bar { flex-wrap: wrap; }
    .search-field { flex-basis: 100%; }
    .form-grid { grid-template-columns: 1fr; }
    .span-two { grid-column: auto; }
    .form-card, .customer-summary { padding: 20px; }
    .summary-grid { grid-template-columns: 1fr 1fr; gap: 16px 10px; }
    .inline-edit-form { grid-template-columns: 1fr; }
    .follow-heading { align-items: flex-start; }
    .follow-heading-main { align-items: flex-start; flex-direction: column; gap: 6px; }
    .modal-actions { flex-direction: column; }
    .login-card { padding: 28px 22px; }
    .contacts-card, #commercial-summary, #quote-documents, #contract-documents { padding: 16px; }
    .customer-summary { grid-template-columns: 1fr; gap: 12px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .document-uploader { flex-direction: column; align-items: stretch; }
}

/* 页头操作按钮组 */
.heading-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.heading-actions .button { white-space: nowrap; }

/* 联系人区块 */
.contacts-card { padding: 24px; margin-bottom: 22px; }

/* 报价统计 / 报价单 / 合同订单卡片 */
#commercial-summary, #quote-documents, #contract-documents {
    padding: 24px;
    margin-bottom: 22px;
}
#commercial-summary .summary-grid { margin-bottom: 18px; }
#commercial-summary h3 { margin: 18px 0 10px; font-size: 15px; }
.document-section .table-wrap { margin-bottom: 14px; }
.contacts-table th, .contacts-table td { padding: 12px 14px; }
.contact-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.contact-actions details { position: relative; }
.contact-actions summary { list-style: none; cursor: pointer; }
.contact-actions summary::-webkit-details-marker { display: none; }
.contact-edit-form { position: absolute; z-index: 6; top: 32px; left: 0; width: 360px; max-width: 90vw; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: var(--shadow); display: grid; gap: 10px; }
.add-contact { margin-top: 16px; }
.add-contact summary { list-style: none; cursor: pointer; display: inline-flex; }
.add-contact summary::-webkit-details-marker { display: none; }
.add-contact[open] summary { margin-bottom: 16px; }

/* OCR 识别面板 */
.ocr-card { padding: 22px 24px; margin-bottom: 22px; }
.ocr-uploader { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.ocr-uploader input[type="file"] { width: auto; min-height: auto; padding: 6px; }
.ocr-raw { margin-top: 14px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 10px; background: #f8faff; }
.ocr-raw pre { margin: 8px 0 0; white-space: pre-wrap; word-break: break-word; max-height: 180px; overflow: auto; font-family: inherit; line-height: 1.7; }

/* 日报 */
.report-heading .date-pick { display: flex; gap: 8px; align-items: center; }
.report-heading .date-pick input { width: auto; min-width: 150px; }
.import-tips { margin: 0; padding-left: 20px; line-height: 1.9; }

/* 打印 */
@media print {
    .topbar, .no-print, .flash-stack { display: none !important; }
    .container { width: 100%; margin: 0; }
    body { background: #fff; }
    a { color: inherit; text-decoration: none; }
}
