:root {
  color-scheme: light;
  --ink: #15221c;
  --muted: #718078;
  --line: #dfe6e1;
  --paper: #f6f8f5;
  --card: #ffffff;
  --green: #167c54;
  --green-dark: #0f5f40;
  --green-soft: #e5f3ec;
  --amber: #c98127;
  --shadow: 0 18px 45px rgba(30, 54, 42, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 95% 5%, rgba(22, 124, 84, .09), transparent 27rem),
    var(--paper);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid rgba(22, 124, 84, .28);
  outline-offset: 2px;
}
.hidden { display: none !important; }

.topbar {
  height: 94px;
  padding: 19px 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .8);
  backdrop-filter: blur(18px);
}

.topbar h1 { margin: 2px 0 0; font-size: 24px; letter-spacing: -.02em; }
.eyebrow { margin: 0; color: var(--green); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.local-badge { padding: 9px 13px; color: var(--green-dark); background: var(--green-soft); border-radius: 999px; font-size: 13px; font-weight: 700; }
.local-badge i { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #20a56e; box-shadow: 0 0 0 4px rgba(32, 165, 110, .13); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.logout-form { margin: 0; }
.logout-form button { min-height: 38px; }
.nav-link { display: inline-flex; align-items: center; justify-content: center; padding: 9px 13px; border: 1px solid #bdd3c7; border-radius: 10px; color: var(--green-dark); background: white; font-size: 12px; font-weight: 750; text-decoration: none; }
.nav-link:hover { border-color: var(--green); background: var(--green-soft); }

.login-body { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-shell { width: min(420px, 100%); }
.login-brand { margin-bottom: 18px; text-align: center; }
.login-brand h1 { margin: 5px 0 0; font-size: clamp(24px, 6vw, 32px); letter-spacing: -.03em; }
.login-card { padding: 28px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255, 255, 255, .94); box-shadow: var(--shadow); }
.login-card h2 { margin: 0; font-size: 18px; }
.login-copy { margin: 7px 0 22px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.login-field { display: block; margin-top: 14px; color: var(--ink); font-size: 12px; font-weight: 750; }
.login-field input { width: 100%; min-height: 46px; margin-top: 7px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fafcf9; outline: none; }
.login-field input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 124, 84, .12); }
.login-button { min-height: 46px; }
.login-error { margin: 0 0 14px; padding: 10px 12px; border: 1px solid #efc5c5; border-radius: 10px; color: #9e2929; background: #fff4f4; font-size: 12px; }
.login-footnote { margin: 15px 0 0; color: var(--muted); font-size: 11px; text-align: center; }

.workspace { height: calc(100vh - 94px); display: grid; grid-template-columns: 380px 1fr; }
.sidebar { overflow-y: auto; padding: 22px; border-right: 1px solid var(--line); background: rgba(250, 252, 249, .74); }
.sidebar section { margin-bottom: 16px; }
.import-card, .job-card, .conversation-panel { padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }

.section-heading { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.section-heading.compact { margin-bottom: 13px; }
.section-heading h2 { margin: 0; font-size: 16px; }
.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.step { display: grid; place-items: center; width: 34px; height: 34px; color: var(--green); background: var(--green-soft); border-radius: 10px; font-size: 11px; font-weight: 800; }

.drop-zone { min-height: 145px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; padding: 18px; text-align: center; border: 1.5px dashed #b8c8bf; border-radius: 14px; background: #fafcf9; transition: .2s ease; cursor: pointer; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--green); background: var(--green-soft); }
.drop-zone input { display: none; }
.drop-zone strong { font-size: 14px; }
.drop-zone span:last-child { max-width: 240px; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.upload-icon { display: grid; place-items: center; width: 38px; height: 38px; color: white; background: var(--green); border-radius: 12px; font-size: 23px; font-weight: 300; }

.primary-button, .download-button { width: 100%; margin-top: 12px; padding: 12px 16px; border: 0; border-radius: 11px; color: white; background: var(--green); font-weight: 750; text-align: center; text-decoration: none; }
.primary-button:hover, .download-button:hover { background: var(--green-dark); }
.primary-button:disabled { cursor: not-allowed; background: #b8c4bd; }

.path-import { margin-top: 13px; color: var(--muted); font-size: 12px; }
.path-import summary { cursor: pointer; user-select: none; }
.path-import form { display: flex; gap: 6px; margin-top: 10px; }
.path-import input { min-width: 0; flex: 1; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; outline: none; }
.path-import button { padding: 8px 10px; border: 0; border-radius: 9px; color: var(--green-dark); background: var(--green-soft); font-weight: 700; }

.job-status-row { display: flex; justify-content: space-between; align-items: center; }
.status-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 5px rgba(201, 129, 39, .13); }
.status-dot.completed { background: var(--green); box-shadow: 0 0 0 5px rgba(22, 124, 84, .13); }
.status-dot.failed { background: #c84444; box-shadow: 0 0 0 5px rgba(200, 68, 68, .12); }
.progress-track { height: 7px; margin-top: 17px; overflow: hidden; border-radius: 999px; background: #edf1ee; }
.progress-track span { display: block; width: 4%; height: 100%; border-radius: inherit; background: var(--green); transition: width .3s ease; }
.progress-track span.indeterminate { width: 35%; animation: progress 1.3s ease-in-out infinite; }
.job-card p { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
@keyframes progress { from { transform: translateX(-110%); } to { transform: translateX(300%); } }

.search-box { height: 39px; display: flex; align-items: center; gap: 7px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: #fafcf9; }
.search-box span { color: var(--muted); font-size: 20px; transform: rotate(-18deg); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; font-size: 12px; }
.conversation-list { max-height: calc(100vh - 505px); min-height: 80px; margin: 10px -8px -8px; overflow-y: auto; }
.query-sidebar { display: flex; flex-direction: column; }
.catalog-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.catalog-summary span { padding: 13px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: white; font-size: 11px; text-align: center; }
.catalog-summary strong { display: block; margin-bottom: 3px; color: var(--green-dark); font-size: 20px; }
.query-panel { flex: 1; min-height: 0; }
.query-list { max-height: calc(100vh - 300px); }
.owner-group { margin: 10px 0 15px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.owner-group:last-child { border-bottom: 0; }
.owner-group-heading { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 11px; color: var(--green-dark); background: var(--green-soft); }
.owner-group-toggle { min-width: 0; min-height: 46px; flex: 1; display: flex; align-items: center; gap: 10px; padding: 5px 3px; border: 0; color: inherit; text-align: left; background: transparent; }
.owner-group-toggle:hover .owner-group-copy strong { text-decoration: underline; text-underline-offset: 3px; }
.owner-chevron { width: 9px; height: 9px; flex: 0 0 9px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .18s ease; }
.owner-group.collapsed .owner-chevron { transform: rotate(-45deg); }
.owner-group-copy { min-width: 0; }
.owner-group-heading small, .owner-group-heading strong, .owner-note-preview { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.owner-group-heading small { margin-bottom: 2px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .08em; }
.owner-group-heading strong { font-size: 13px; }
.owner-note-preview { max-width: 220px; margin-top: 3px; color: #4e6d5e; font-size: 10px; }
.owner-note-preview.empty { color: var(--muted); font-style: italic; }
.owner-group-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 5px; }
.owner-group-count { flex: 0 0 auto; padding: 4px 8px; border-radius: 999px; color: var(--green-dark); background: rgba(255, 255, 255, .72); font-size: 10px; font-weight: 750; }
.owner-note-button { min-height: 44px; padding: 7px 8px; border: 1px solid #bed7c9; border-radius: 8px; color: var(--green-dark); background: rgba(255, 255, 255, .84); font-size: 10px; font-weight: 750; }
.owner-note-button:hover { border-color: var(--green); background: white; }
.owner-note-editor { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; align-items: end; padding: 9px 7px 5px; }
.owner-note-editor label { color: var(--muted); font-size: 10px; font-weight: 750; }
.owner-note-editor input { width: 100%; min-height: 44px; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; outline: 0; background: white; }
.owner-note-editor input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 124, 84, .1); }
.owner-note-editor button { min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--green-dark); background: white; font-size: 10px; font-weight: 750; }
.owner-note-editor button[type="submit"] { color: white; border-color: var(--green); background: var(--green); }
.owner-note-editor button:disabled { cursor: wait; opacity: .55; }
.owner-group-content[hidden] { display: none; }
.conversation-item { width: 100%; display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; padding: 10px 8px; border: 0; border-radius: 11px; text-align: left; background: transparent; }
.conversation-item:hover, .conversation-item.active { background: var(--green-soft); }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: var(--green-dark); background: #d7ebe1; font-size: 12px; font-weight: 800; }
.conversation-copy { min-width: 0; }
.conversation-copy strong, .conversation-copy span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conversation-copy strong { font-size: 13px; }
.conversation-copy span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.conversation-meta { color: var(--muted); font-size: 10px; text-align: right; }

.chat-pane { min-width: 0; position: relative; overflow: hidden; }
.empty-state { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 35px; text-align: center; }
.archive-mark { display: grid; place-items: center; width: 72px; height: 72px; color: var(--green); border: 1px solid #cfe0d6; border-radius: 22px; background: rgba(255, 255, 255, .8); box-shadow: var(--shadow); font-family: Georgia, serif; font-size: 24px; font-weight: bold; }
.empty-state h2 { margin: 22px 0 8px; font-size: 20px; }
.empty-state p { max-width: 470px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.chat-content { height: 100%; display: flex; flex-direction: column; }
.chat-header { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 17px 28px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .7); }
.chat-header h2 { margin: 0; font-size: 18px; }
.conversation-detail-row { display: flex; flex-wrap: wrap; align-items: center; gap: 7px 10px; margin-top: 5px; }
.conversation-route { margin: 0; color: var(--muted); font-size: 11px; }
.transaction-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.transaction-pill, .transaction-unmatched { display: inline-flex; align-items: center; min-height: 24px; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 750; line-height: 1.2; }
.transaction-pill.deposit { color: #0f6543; background: #e1f3e9; }
.transaction-pill.withdrawal { color: #8a5517; background: #f8ead7; }
.transaction-unmatched { color: #755e44; background: #f2eee7; }
.message-search { width: min(320px, 42vw); background: white; }
.chat-tools { display: flex; align-items: center; gap: 9px; }
.chat-tools select { height: 39px; max-width: 230px; padding: 0 30px 0 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: white; outline: none; }
.message-scroll { flex: 1; overflow-y: auto; padding: 20px 6vw 36px; }
.message-list { display: flex; flex-direction: column; gap: 13px; }
.message-row { display: flex; flex-direction: column; align-items: flex-start; }
.message-row.outgoing { align-items: flex-end; }
.message-bubble { max-width: min(660px, 78%); padding: 11px 14px; border: 1px solid var(--line); border-radius: 4px 16px 16px; background: white; box-shadow: 0 7px 20px rgba(30, 54, 42, .05); }
.outgoing .message-bubble { color: #f7fffa; border-color: var(--green); border-radius: 16px 4px 16px 16px; background: var(--green); }
.message-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.58; }
.message-time { margin: 5px 5px 0; color: var(--muted); font-size: 10px; }
.owner-badge { margin: 0 5px 5px; padding: 4px 8px; border-radius: 999px; color: var(--green-dark); background: var(--green-soft); font-size: 9px; font-weight: 750; }
.outgoing .owner-badge { color: #785015; background: #f7ead7; }
.older-button { display: block; margin: 0 auto 18px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 999px; color: var(--green-dark); background: white; font-size: 11px; }
.no-results { padding: 28px 10px; color: var(--muted); text-align: center; font-size: 13px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; max-width: 420px; padding: 13px 16px; color: white; border-radius: 11px; background: #b53f3f; box-shadow: var(--shadow); font-size: 13px; }
.toast.success { background: var(--green-dark); }
.empty-action { margin-top: 18px; }
.import-page { width: min(1020px, calc(100% - 36px)); margin: 32px auto; display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
.server-inbox { grid-column: 1 / -1; }
.server-path { display: flex; align-items: center; gap: 12px; margin: 18px 0 4px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 11px; background: var(--green-soft); }
.server-path span { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.server-path code { color: var(--green-dark); font-weight: 750; overflow-wrap: anywhere; }
.scan-summary, .inbox-empty { margin: 13px 0 0; color: var(--muted); font-size: 12px; }
.inbox-jobs { display: grid; gap: 7px; margin-top: 12px; }
.inbox-job { display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: 10px; background: #f4f7f5; color: var(--muted); font-size: 12px; }
.inbox-job i { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: #a8b4ad; }
.inbox-job.running i, .inbox-job.queued i { background: #e3a52b; box-shadow: 0 0 0 4px #fff0c9; }
.inbox-job.completed i { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.inbox-job.failed { color: #a22; background: #fff2f1; }
.inbox-job.failed i { background: #d14c43; }
.import-main { margin: 0; padding: 25px; }
.import-step { margin-top: 28px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid label { color: var(--muted); font-size: 11px; font-weight: 700; }
.field-grid input { width: 100%; margin-top: 6px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fafcf9; outline: none; }
.field-grid input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 124, 84, .09); }
.import-side { display: flex; flex-direction: column; gap: 16px; }
.import-side .job-card { margin: 0; }
.result-link { width: 100%; margin-top: 9px; }
.help-card { padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: var(--shadow); }
.help-card h3 { margin: 0 0 10px; font-size: 15px; }
.help-card p { color: var(--muted); font-size: 11px; line-height: 1.6; }
.help-card code { display: block; padding: 10px; border-radius: 9px; color: var(--green-dark); background: var(--green-soft); font-size: 10px; overflow-wrap: anywhere; }

@media (max-width: 820px) {
  .topbar { height: 78px; padding: 14px 18px; }
  .topbar h1 { font-size: 18px; }
  .eyebrow { display: none; }
  .workspace { height: auto; min-height: calc(100vh - 78px); grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .conversation-list { max-height: 360px; }
  .chat-pane { min-height: 650px; border-top: 1px solid var(--line); }
  .chat-header { align-items: stretch; flex-direction: column; }
  .message-search { width: 100%; }
  .chat-tools { align-items: stretch; flex-direction: column; }
  .chat-tools select { width: 100%; max-width: none; }
  .message-scroll { padding: 18px; }
  .message-bubble { max-width: 88%; }
  .import-page { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: 1fr; }
  .owner-group-heading { align-items: stretch; }
  .owner-group-actions { flex-direction: column; justify-content: center; }
  .owner-note-editor { grid-template-columns: 1fr 1fr; }
  .owner-note-editor label { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
