:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #1f2a44;
  --muted: #6b7890;
  --line: #e4eaf3;
  --brand: #155eef;
  --brand-dark: #0b2a4a;
  --brand-soft: #eaf1ff;
  --green: #0f9d58;
  --green-soft: #e8f7ef;
  --orange: #d97706;
  --orange-soft: #fff4e5;
  --red: #d93025;
  --red-soft: #fdecea;
  --purple: #7c3aed;
  --purple-soft: #f2ecff;
  --shadow: 0 8px 24px rgba(21, 45, 85, .07);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  font-size: 13px;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--brand); text-decoration: none; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 22px;
  background: linear-gradient(120deg, #0b2a4a, #123b66 62%, #155eef);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 300px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: transparent;
  display: block; object-fit: cover;
}
.brand-title { font-size: 16px; font-weight: 700; line-height: 1.2; }
.brand-sub { font-size: 11px; color: rgba(255,255,255,.68); margin-top: 2px; }
.global-search { flex: 1; display: flex; max-width: 720px; }
.global-search input {
  flex: 1; height: 36px; border: 0; border-radius: 8px 0 0 8px;
  padding: 0 14px; outline: none; color: var(--text);
}
.global-search .btn { border-radius: 0 8px 8px 0; height: 36px; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 13px;
  font-weight: 600;
  transition: .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #b9c8e2; background: #f8fbff; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #0d4ed4; }
.btn.ghost { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.25); color: #fff; }
.btn.ghost:hover { background: rgba(255,255,255,.18); }
.btn.danger { color: var(--red); border-color: #f3c5c1; background: #fff7f6; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.layout { display: flex; min-height: calc(100vh - 64px); }
.sidebar {
  width: 190px; flex: 0 0 190px;
  background: #fff; border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 16px 10px 12px;
  position: sticky; top: 64px; height: calc(100vh - 64px);
}
#nav { display: flex; flex-direction: column; gap: 4px; }
.nav {
  border: 0; background: transparent; text-align: left;
  padding: 10px 12px; border-radius: 9px; color: #4b5a73;
  display: flex; align-items: center; gap: 10px; font-weight: 600;
}
.nav span { width: 18px; text-align: center; color: #8a99b3; font-size: 15px; }
.nav:hover { background: #f3f7ff; color: var(--brand); }
.nav.active { background: var(--brand-soft); color: var(--brand); }
.nav.active span { color: var(--brand); }
.side-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.health { font-size: 11px; color: var(--muted); line-height: 1.6; margin-bottom: 6px; }
.health.ok { color: var(--green); }
.health.bad { color: var(--red); }
.link { border: 0; background: transparent; color: var(--brand); padding: 4px 0; font-size: 12px; }

#main { flex: 1; min-width: 0; padding: 20px 22px 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-title { font-size: 20px; font-weight: 800; margin: 0; }
.page-sub { color: var(--muted); font-size: 12px; margin-top: 5px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.card-title { font-weight: 700; font-size: 14px; }
.card-body { padding: 14px 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, "Courier New", monospace; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat::after { content: ""; position: absolute; right: -18px; top: -18px; width: 64px; height: 64px; border-radius: 50%; background: var(--brand-soft); opacity: .7; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 8px; letter-spacing: .3px; }
.stat-value.red { color: var(--red); }
.stat-value.green { color: var(--green); }
.stat-value.orange { color: var(--orange); }
.stat-value.purple { color: var(--purple); }
.stat-note { font-size: 11px; color: var(--muted); margin-top: 3px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #edf1f7; vertical-align: middle; }
th { font-size: 11px; color: #7a879e; font-weight: 700; background: #fafcff; position: sticky; top: 0; z-index: 1; }
tbody tr { transition: .12s; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #f7faff; }
tbody tr.overdue { background: #fff8f7; }
td .sub { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }
.empty b { display: block; color: #4b5a73; margin-bottom: 6px; }

.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.st-pending { background: var(--orange-soft); color: var(--orange); }
.st-progress { background: var(--brand-soft); color: var(--brand); }
.st-waiting { background: #fff8e1; color: #a16207; }
.st-done { background: var(--green-soft); color: var(--green); }
.st-closed { background: #eef1f5; color: #667085; }
.p-high { background: var(--red-soft); color: var(--red); }
.p-mid { background: #fff4e5; color: var(--orange); }
.p-low { background: #eef2f7; color: #5b6b82; }
.tag { display: inline-block; background: #f1f4f9; color: #51617a; padding: 2px 7px; border-radius: 5px; font-size: 11px; margin: 1px 3px 1px 0; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line); background: #fff; border-radius: 12px 12px 0 0; }
.toolbar input, .toolbar select { height: 32px; border: 1px solid var(--line); border-radius: 7px; padding: 0 9px; background: #fff; outline: none; color: var(--text); }
.toolbar input:focus, .toolbar select:focus { border-color: #9ab8f8; box-shadow: 0 0 0 3px #eaf1ff; }
.toolbar .spacer { flex: 1; }
.table-wrap { overflow: auto; max-height: calc(100vh - 240px); }
.table-wrap table { min-width: 980px; }
.table-wrap::-webkit-scrollbar, .modal-body::-webkit-scrollbar, .ocr-messages::-webkit-scrollbar { width: 8px; height: 8px; }
.table-wrap::-webkit-scrollbar-thumb, .modal-body::-webkit-scrollbar-thumb, .ocr-messages::-webkit-scrollbar-thumb { background: #cfd8e6; border-radius: 8px; }

.detail-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.detail-title { font-size: 20px; font-weight: 800; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-sub { color: var(--muted); font-size: 12px; margin-top: 6px; }
.detail-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr); gap: 14px; align-items: start; }
.kv { display: grid; grid-template-columns: 78px minmax(0, 1fr); gap: 7px 10px; line-height: 1.55; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; word-break: break-all; }
.section { margin-top: 14px; }
.section-title { font-weight: 700; font-size: 13px; margin: 0 0 9px; display: flex; align-items: center; gap: 8px; }
.section-title::before { content: ""; width: 3px; height: 14px; border-radius: 2px; background: var(--brand); }
.desc { white-space: pre-wrap; line-height: 1.7; background: #fafcff; border: 1px solid var(--line); border-radius: 9px; padding: 12px; min-height: 54px; }
.money { font-weight: 800; font-variant-numeric: tabular-nums; }
.money.big { font-size: 22px; }

.timeline { position: relative; margin: 4px 0 0 6px; padding-left: 18px; border-left: 2px solid #e3ebf7; }
.tl-item { position: relative; padding: 0 0 14px 0; }
.tl-item::before { content: ""; position: absolute; left: -25px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--brand); }
.tl-item.status::before { border-color: var(--green); }
.tl-meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.tl-text { line-height: 1.6; white-space: pre-wrap; }
.note-box { display: flex; gap: 8px; margin-top: 10px; }
.note-box input { flex: 1; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; outline: none; }
.note-box input:focus { border-color: #9ab8f8; box-shadow: 0 0 0 3px #eaf1ff; }

.chat-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow: auto; padding-right: 4px; }
.chat-msg { max-width: 86%; padding: 8px 11px; border-radius: 10px; line-height: 1.55; white-space: pre-wrap; font-size: 12px; }
.chat-msg.customer { align-self: flex-start; background: #f2f4f7; }
.chat-msg.self { align-self: flex-end; background: var(--brand-soft); }
.chat-msg.unknown { align-self: flex-start; background: #f7f7f7; }
.chat-msg .who { display: block; font-size: 10px; color: var(--muted); margin-bottom: 3px; }

.attach-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.attach-grid img { width: 118px; height: 86px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; }
.attach-grid a { font-size: 12px; }
.attach-drop { border: 1.5px dashed #b9c8e2; border-radius: 10px; padding: 18px 14px; text-align: center; color: #667085; background: #fafcff; cursor: pointer; transition: border-color .15s, background .15s; }
.attach-drop:hover, .attach-drop.drag { border-color: var(--brand); background: var(--brand-soft); }
.attach-drop .link { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 76px minmax(0, 1fr) 42px; gap: 8px; align-items: center; font-size: 12px; }
.bar { height: 8px; border-radius: 999px; background: #eef2f8; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #5b8def, #155eef); }
.bar-row b { text-align: right; color: #51617a; font-variant-numeric: tabular-nums; }

.search-hero { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.search-hero .row { display: flex; gap: 8px; }
.search-hero input { flex: 1; height: 42px; border: 1px solid var(--line); border-radius: 9px; padding: 0 14px; outline: none; font-size: 14px; }
.search-hero input:focus { border-color: #9ab8f8; box-shadow: 0 0 0 4px #eaf1ff; }
.search-hero .cloud-type { height: 42px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; outline: none; font-size: 14px; background: #fff; color: var(--text); min-width: 132px; }
.search-hero .cloud-type:focus { border-color: #9ab8f8; box-shadow: 0 0 0 4px #eaf1ff; }
.result-group { margin-top: 14px; }
.result-title { font-weight: 700; margin: 0 0 8px; font-size: 13px; color: #4b5a73; }
.result-item { background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; margin-bottom: 7px; cursor: pointer; }
.result-item:hover { border-color: #b9c8e2; background: #fafcff; }
.result-item .line1 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-weight: 600; }
.result-item .line2 { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.5; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(14, 28, 51, .46); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 32px 18px; overflow: auto; scrollbar-gutter: stable both-edges; }
.modal { width: 760px; max-width: 100%; background: #fff; border-radius: 14px; box-shadow: 0 24px 80px rgba(8, 24, 48, .28); overflow: hidden; }
.modal.wide { width: 1080px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.icon-btn { border: 0; background: transparent; font-size: 22px; line-height: 1; color: #7a879e; padding: 0 4px; }
.icon-btn:hover { color: var(--text); }
.tabs { display: flex; gap: 4px; padding: 10px 16px 0; border-bottom: 1px solid var(--line); background: #fbfcff; }
.tab { border: 0; background: transparent; padding: 9px 13px; border-radius: 8px 8px 0 0; color: #667085; font-weight: 600; }
.tab.active { background: #fff; color: var(--brand); box-shadow: 0 -1px 0 var(--line) inset; }
.modal-body { max-height: calc(100vh - 220px); overflow: auto; padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: #fbfcff; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: #5a6981; }
.form-grid label.wide { grid-column: span 2; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  outline: none; color: var(--text); background: #fff; min-height: 35px;
}
.form-grid textarea { min-height: 92px; resize: vertical; line-height: 1.55; }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { border-color: #9ab8f8; box-shadow: 0 0 0 3px #eaf1ff; }
.form-grid .req::after { content: " *"; color: var(--red); }
.form-note { grid-column: 1 / -1; font-size: 12px; color: var(--muted); background: #f7faff; border: 1px dashed #d7e3f8; border-radius: 8px; padding: 8px 10px; }
.form-note.ok { color: var(--green); background: #f4fbf7; border-color: #c9ecd8; }
.form-note.bad { color: var(--red); background: #fff8f7; border-color: #f3c5c1; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.paste-area { width: 100%; min-height: 220px; border: 1px solid var(--line); border-radius: 9px; padding: 11px; outline: none; line-height: 1.6; resize: vertical; }
.paste-area:focus { border-color: #9ab8f8; box-shadow: 0 0 0 3px #eaf1ff; }
.parse-preview { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.preview-msg { background: #f7f9fc; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 12px; white-space: pre-wrap; }
.preview-msg.self { background: var(--brand-soft); }
.preview-msg .who { color: var(--muted); font-size: 10px; display: block; margin-bottom: 2px; }

.ocr-wrap { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: 14px; }
.ocr-shot { background: #f4f7fb; border: 1px solid var(--line); border-radius: 10px; padding: 8px; min-height: 220px; display: flex; align-items: flex-start; justify-content: center; }
.ocr-shot img { max-width: 100%; max-height: 480px; border-radius: 6px; }
.ocr-right { min-width: 0; }
.ocr-toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.ocr-messages { max-height: 380px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; padding: 8px; background: #fbfcff; }
.ocr-msg { display: flex; gap: 7px; padding: 6px 5px; border-bottom: 1px dashed #e7edf6; line-height: 1.5; font-size: 12px; }
.ocr-msg:last-child { border-bottom: 0; }
.ocr-msg input { margin-top: 3px; }
.ocr-msg .who { font-size: 10px; color: var(--muted); display: block; margin-bottom: 2px; }
.ocr-msg.self .txt { color: #35507a; }
.ocr-msg.customer .txt { color: #1f2a44; }
.ocr-empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.warn { color: var(--orange); font-size: 12px; line-height: 1.6; margin-top: 7px; }

.toast { position: fixed; right: 20px; bottom: 20px; background: #1f2a44; color: #fff; padding: 10px 14px; border-radius: 9px; font-size: 12px; opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; z-index: 80; max-width: 420px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: #b42318; }
.toast.ok { background: #087443; }

.logi-modal .modal-body { height: min(58vh, 540px); min-height: 240px; overflow: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.logi-refreshing { opacity: .45; transition: opacity .15s ease; pointer-events: none; }
.logi-placeholder { min-height: 200px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.quick-stats { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.quick-stats b { color: var(--text); font-size: 15px; margin-left: 4px; }
.hidden { display: none !important; }
.link.light { color: rgba(255,255,255,.82); font-size: 11px; }
.link.light:hover { color: #fff; }
.user-box { display: flex; align-items: center; gap: 8px; padding-left: 10px; margin-left: 4px; border-left: 1px solid rgba(255,255,255,.2); white-space: nowrap; }
.user-name { font-size: 12px; font-weight: 700; max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
.user-box .badge { background: rgba(255,255,255,.16); color: #fff; }

.boot-screen {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 15%, #1b4f86 0, #0b2a4a 42%, #071a30 100%);
  color: rgba(255,255,255,.78); font-size: 13px; letter-spacing: .5px;
}
.boot-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.boot-inner img { width: 54px; height: 54px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.35); }

.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 15%, #1b4f86 0, #0b2a4a 42%, #071a30 100%);
  padding: 24px;
}
.login-card {
  width: 380px; max-width: 100%; background: #fff; border-radius: 18px;
  padding: 30px 30px 24px; box-shadow: 0 28px 90px rgba(0, 0, 0, .35);
}
.login-logo {
  width: 46px; height: 46px; border-radius: 13px; background: transparent;
  display: block; object-fit: cover;
  margin-bottom: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; letter-spacing: .5px; }
.login-sub { color: var(--muted); font-size: 12px; margin: 6px 0 22px; }
.login-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 13px; font-size: 12px; color: #5a6981; }
.login-field input {
  height: 42px; border: 1px solid var(--line); border-radius: 9px; padding: 0 12px;
  outline: none; font-size: 14px; color: var(--text);
}
.login-field input:focus { border-color: #9ab8f8; box-shadow: 0 0 0 3px #eaf1ff; }
.login-btn { width: 100%; height: 43px; font-size: 14px; border-radius: 9px; margin-top: 4px; }
.login-msg { min-height: 20px; color: var(--red); font-size: 12px; margin-top: 10px; text-align: center; }
.login-hint { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 13px; color: var(--muted); font-size: 11px; line-height: 1.7; text-align: center; }
.login-hint b { color: #4b5a73; }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .detail-grid, .ocr-wrap { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 12px; gap: 10px; }
  .brand { min-width: 0; }
  .global-search { order: 3; flex-basis: 100%; max-width: none; }
  .layout { display: block; }
  .sidebar { width: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); }
  #nav { flex-direction: row; overflow: auto; }
  .side-foot { display: none; }
  #main { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid label.wide { grid-column: auto; }
  .detail-head { flex-wrap: wrap; }
  .detail-actions { margin-left: 0; }
}

.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.tracking-link { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.tracking-link:hover { color: var(--brand-dark); }
