:root {
  --ink: #18201d;
  --muted: #65706a;
  --line: #d9ded9;
  --paper: #f6f5f1;
  --surface: #ffffff;
  --jade: #0f766e;
  --jade-dark: #0b5c56;
  --jade-pale: #e3f4f0;
  --vermilion: #b7483b;
  --gold: #b48a3c;
  --sidebar: #15201d;
  --sidebar-soft: #21302c;
  --shadow: 0 10px 28px rgba(24, 32, 29, 0.08);
  --radius: 6px;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--paper); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.62; }
input, textarea, select {
  width: 100%;
  border: 1px solid #cfd6d1;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}
textarea { resize: vertical; line-height: 1.65; }
input:focus, textarea:focus, select:focus { border-color: var(--jade); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1); }
label { display: grid; gap: 7px; color: #39433e; font-size: 13px; font-weight: 700; }
[hidden] { display: none !important; }

.app-shell { display: grid; grid-template-columns: 284px minmax(0, 1fr); width: 100%; height: 100dvh; }
.sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
  color: #f5f7f6;
  background: var(--sidebar);
  border-right: 1px solid #25332f;
  transition: width .2s ease;
}
.brand-row { display: flex; align-items: center; gap: 11px; min-height: 72px; padding: 13px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { display: grid; place-items: center; flex: 0 0 39px; height: 39px; border: 1px solid rgba(255,255,255,.2); background: #0f766e; color: #fff; font: 700 20px/1 Georgia, serif; }
.brand-copy { min-width: 0; display: grid; gap: 3px; }
.brand-copy strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
.brand-copy span { color: #9caaa5; font-size: 12px; }
.brand-row .icon-btn { margin-left: auto; }
.sidebar-actions { display: grid; grid-template-columns: minmax(0,1fr) 42px; gap: 8px; padding: 12px 14px; }
.search-box { position: relative; display: block; }
.search-box span { position: absolute; left: 11px; top: 9px; color: #9eaaa6; font-size: 18px; }
.search-box input { height: 42px; padding-left: 34px; border-color: #3c4945; background: var(--sidebar-soft); color: #fff; font-weight: 400; }
.search-box input::placeholder { color: #9eaaa6; }
.customer-list { flex: 1; min-height: 0; overflow: auto; padding: 0 9px 12px; }
.customer-item { width: 100%; display: grid; grid-template-columns: 42px minmax(0,1fr) auto; gap: 9px; align-items: center; min-height: 68px; padding: 10px; margin-bottom: 7px; border: 1px solid transparent; border-radius: var(--radius); color: #eef3f1; background: transparent; text-align: left; }
.customer-item:hover { background: rgba(255,255,255,.05); }
.customer-item.active { border-color: #2cb5a8; background: #173936; }
.avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 5px; background: #e5f4ed; color: #176357; font-weight: 800; }
.customer-copy { min-width: 0; display: grid; gap: 5px; }
.customer-copy strong, .customer-copy span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.customer-copy span { color: #afbbb7; font-size: 12px; }
.customer-count { min-width: 22px; height: 22px; display: grid; place-items: center; border: 1px solid #54625e; border-radius: 11px; color: #cbd4d1; font-size: 11px; }
.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); color: #9eaaa6; font-size: 12px; line-height: 1.5; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #d0a953; }

.app-shell.sidebar-collapsed { grid-template-columns: 68px minmax(0, 1fr); }
.sidebar-collapsed .brand-row { padding-inline: 14px; }
.sidebar-collapsed .brand-copy, .sidebar-collapsed .search-box, .sidebar-collapsed .customer-copy, .sidebar-collapsed .sidebar-foot, .sidebar-collapsed .customer-count { display: none; }
.sidebar-collapsed .brand-row .icon-btn { position: absolute; left: 42px; top: 48px; width: 22px; height: 22px; border-radius: 11px; font-size: 14px; }
.sidebar-collapsed .sidebar-actions { display: block; padding-inline: 13px; }
.sidebar-collapsed .customer-list { padding-inline: 8px; }
.sidebar-collapsed .customer-item { grid-template-columns: 40px; min-height: 54px; padding: 7px 5px; justify-content: center; }

.main-shell { min-width: 0; height: 100dvh; display: grid; grid-template-rows: 62px minmax(0,1fr); overflow: hidden; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; padding: 0 18px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.topbar-left { min-width: 0; display: flex; align-items: center; gap: 10px; }
.tabs { display: flex; align-items: center; gap: 4px; min-width: 0; }
.tab-btn { min-height: 40px; padding: 0 14px; border: 0; border-radius: 5px; background: transparent; color: #66716c; white-space: nowrap; }
.tab-btn:hover { color: var(--ink); background: #f0f3f1; }
.tab-btn.active { color: var(--jade-dark); background: var(--jade-pale); font-weight: 800; }
.topbar-meta { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.api-status { color: var(--muted); font-size: 12px; }
.api-status.ok .status-dot { background: #1b9a74; }
.api-status.error .status-dot { background: #c34a3d; }

.view { min-width: 0; min-height: 0; height: 100%; overflow: auto; padding: 18px; }
.view.active { display: block; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; max-width: 1480px; margin: 0 auto 14px; }
.section-heading h1, .plain-section h1, .customer-head h1 { margin: 2px 0 0; font-size: 20px; line-height: 1.3; }
.eyebrow { margin: 0; color: var(--jade); font-size: 12px; font-weight: 800; }
.segmented { display: inline-grid; grid-auto-flow: column; grid-auto-columns: minmax(110px, auto); border: 1px solid #cfd6d1; border-radius: 6px; overflow: hidden; background: #fff; }
.segmented.compact { width: 100%; grid-template-columns: 1fr 1fr; grid-auto-flow: row; grid-auto-columns: auto; }
.segment-btn { min-height: 40px; padding: 0 15px; border: 0; border-right: 1px solid #dfe4e1; background: #fff; color: #606b66; }
.segment-btn:last-child { border-right: 0; }
.segment-btn.active { background: var(--jade); color: #fff; font-weight: 800; }

.chart-workspace { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0,1fr); gap: 14px; max-width: 1480px; min-height: calc(100% - 72px); margin: 0 auto; }
.chart-form-panel, .chart-result-panel, .plain-section, .chat-layout { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.chart-form-panel { align-self: start; }
.chart-form { display: grid; gap: 15px; padding: 18px; }
.form-intro { display: grid; gap: 5px; padding-bottom: 14px; border-bottom: 1px solid #e3e7e4; }
.form-intro strong { font-size: 16px; }
.form-intro span { color: var(--muted); font-size: 12px; line-height: 1.6; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: 16px; height: 16px; }
.field-note { margin: -5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.chart-result-panel { min-width: 0; min-height: 590px; overflow: hidden; }
.empty-state { min-height: 590px; display: grid; align-content: center; justify-items: center; gap: 8px; padding: 32px; text-align: center; }
.empty-symbol { display: grid; place-items: center; width: 82px; height: 82px; border: 1px solid #cad5cf; color: var(--jade); background: #eff7f4; font-size: 45px; }
.empty-state h2 { margin: 8px 0 0; font-size: 19px; }
.empty-state p { max-width: 480px; margin: 0; color: var(--muted); line-height: 1.7; }
.result-head { min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.result-head h2, .interpretation-panel h2 { margin: 3px 0 0; font-size: 19px; }
.chart-visualization { padding: 18px; overflow-x: auto; }
.chart-summary { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 11px 13px; margin-bottom: 16px; border-left: 3px solid var(--gold); background: #faf7ed; color: #4b534f; font-size: 13px; }
.pillar-table { display: grid; grid-template-columns: 82px repeat(4, minmax(105px, 1fr)); min-width: 560px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.pillar-cell { min-height: 42px; display: grid; place-items: center; padding: 8px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; font-size: 12px; }
.pillar-cell.label { justify-items: start; color: var(--muted); background: #f7f8f6; font-weight: 800; }
.pillar-cell.head { background: #f0f5f2; color: var(--jade-dark); font-weight: 800; }
.pillar-cell.ganzhi { min-height: 66px; font: 700 25px/1.2 Georgia, "STKaiti", serif; }
.five-elements { display: grid; grid-template-columns: repeat(5, minmax(80px,1fr)); gap: 8px; margin: 16px 0; }
.element-meter { padding: 10px; border: 1px solid var(--line); background: #fbfbfa; }
.element-meter strong { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 13px; }
.element-bar { height: 5px; background: #e1e6e3; overflow: hidden; }
.element-bar i { display: block; height: 100%; background: var(--jade); }
.data-table { width: 100%; min-width: 620px; border-collapse: collapse; font-size: 12px; }
.data-table th, .data-table td { padding: 9px 10px; border: 1px solid var(--line); text-align: left; white-space: nowrap; }
.data-table th { background: #f4f6f4; color: #4f5a55; }
.hexagram-flow { display: grid; grid-template-columns: repeat(3, minmax(190px,1fr)); gap: 10px; min-width: 620px; }
.hexagram-block { padding: 14px; border: 1px solid var(--line); background: #fbfbf9; }
.hexagram-block.current { border-top: 3px solid var(--jade); }
.hexagram-block h3 { margin: 4px 0 12px; font-size: 17px; }
.hexagram-lines { display: grid; gap: 6px; width: 88px; margin: 8px 0 14px; }
.hex-line { position: relative; height: 7px; }
.hex-line::before, .hex-line::after { content: ""; position: absolute; top: 0; height: 7px; background: #222c28; }
.hex-line.yang::before { left: 0; width: 100%; }
.hex-line.yin::before { left: 0; width: 41%; }
.hex-line.yin::after { right: 0; width: 41%; }
.hex-line.moving::before, .hex-line.moving::after { background: var(--vermilion); }
.hexagram-meta { display: grid; gap: 5px; color: #59645e; font-size: 12px; line-height: 1.5; }
.body-use { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 14px; padding: 12px; border-left: 3px solid var(--vermilion); background: #faf2f0; font-size: 13px; }
.calculation { margin-top: 12px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.interpretation-panel { margin: 0 18px 18px; padding-top: 15px; border-top: 1px solid var(--line); }
.interpretation-panel > header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 13px; }
.interpretation-summary { padding: 13px; border-left: 3px solid var(--jade); background: #eff7f4; line-height: 1.75; }
.interpretation-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin-top: 12px; }
.interpretation-section { padding: 12px 0; border-bottom: 1px solid #e1e5e2; }
.interpretation-section h3 { margin: 0 0 7px; font-size: 14px; }
.interpretation-section p, .interpretation-section li { color: #4e5954; font-size: 13px; line-height: 1.75; }
.interpretation-section ul { margin: 0; padding-left: 18px; }
.customer-reply-box { margin-top: 14px; padding: 14px; border: 1px solid #cbd8d2; background: #fff; white-space: pre-wrap; line-height: 1.8; }

.chat-layout { height: 100%; max-width: 1420px; margin: 0 auto; display: grid; grid-template-rows: auto minmax(0,1fr) auto; overflow: hidden; }
.customer-head { min-height: 76px; display: flex; align-items: center; gap: 11px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.customer-avatar { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 5px; background: #def1e8; color: #16665a; font-weight: 800; }
.customer-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.push-right { margin-left: auto; }
.chat-log { min-height: 0; overflow: auto; padding: 20px 24px; background: #f2f4f1; }
.chat-empty { min-height: 100%; display: grid; place-content: center; text-align: center; color: var(--muted); }
.message-row { display: flex; margin-bottom: 15px; }
.message-row.assistant { justify-content: flex-end; }
.message { max-width: min(760px, 78%); }
.message-meta { margin: 0 0 5px; color: #7d8782; font-size: 11px; }
.assistant .message-meta { text-align: right; }
.message-bubble { padding: 11px 13px; border: 1px solid #dfe4e1; border-radius: 5px; background: #fff; white-space: pre-wrap; line-height: 1.72; }
.assistant .message-bubble { border-color: #b8ded2; background: #dff4e8; }
.message.chart-note .message-bubble { border-left: 3px solid var(--gold); background: #faf7ed; }
.chat-composer { padding: 13px 16px 14px; border-top: 1px solid var(--line); background: #fff; }
.chat-composer label { margin-bottom: 7px; }
.chat-composer textarea { max-height: 150px; }
.composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 9px; }
.composer-foot > span { color: var(--muted); font-size: 12px; }

.settings-grid { display: grid; grid-template-columns: minmax(300px, .85fr) minmax(420px, 1.15fr); gap: 14px; max-width: 1450px; margin: 0 auto; }
.compact-settings { grid-template-columns: repeat(2, minmax(300px,1fr)); }
.plain-section { min-width: 0; padding: 18px; }
.plain-section > header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.form-stack { display: grid; gap: 15px; margin-top: 16px; }
.notice { padding: 11px 12px; margin-top: 14px; border-left: 3px solid var(--gold); background: #fbf7e9; color: #5f5848; font-size: 12px; line-height: 1.7; }
.knowledge-editor { min-height: 600px; margin-top: 12px; font-family: Consolas, "Microsoft YaHei", sans-serif; font-size: 13px; }
.section-copy { color: var(--muted); line-height: 1.75; }

.icon-btn { flex: 0 0 auto; display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 1px solid #d1d7d3; border-radius: 5px; background: #fff; color: var(--ink); font-size: 20px; }
.icon-btn.dark { border-color: #40504b; background: #22302c; color: #fff; }
.icon-btn.teal { border-color: var(--jade); background: var(--jade); color: #fff; }
.primary-btn, .secondary-btn, .danger-btn, .file-btn { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; padding: 0 14px; border-radius: 5px; font-weight: 700; white-space: nowrap; }
.primary-btn { border: 1px solid var(--jade); background: var(--jade); color: #fff; }
.primary-btn:hover { background: var(--jade-dark); }
.secondary-btn, .file-btn { border: 1px solid #cfd6d1; background: #fff; color: #38423d; }
.danger-btn { border: 1px solid #e0aaa4; background: #fff7f6; color: #a53c31; }
.full { width: 100%; min-height: 44px; }
.button-row { display: flex; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; }
.button-row.left { justify-content: flex-start; }
.file-btn { cursor: pointer; }
.file-btn input { display: none; }
.mobile-only { display: none; }

.dialog { width: min(480px, calc(100vw - 24px)); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 24px 80px rgba(0,0,0,.22); }
.dialog::backdrop { background: rgba(20,30,27,.48); }
.dialog form { padding: 18px; }
.dialog header, .dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog header { padding-bottom: 13px; border-bottom: 1px solid var(--line); }
.dialog header h2 { margin: 0; font-size: 18px; }
.dialog footer { justify-content: flex-end; padding-top: 16px; }
.dialog .form-stack { margin-top: 15px; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 26px; transform: translate(-50%, 18px); max-width: min(520px, calc(100vw - 28px)); padding: 10px 14px; border-radius: 5px; background: #1c2925; color: #fff; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; font-size: 13px; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.toast.error { background: #8e352c; }
.mobile-overlay { position: fixed; z-index: 15; inset: 0; background: rgba(20,30,27,.42); }

@media (max-width: 1040px) {
  .chart-workspace { grid-template-columns: 330px minmax(0,1fr); }
  .settings-grid { grid-template-columns: 1fr; }
  .interpretation-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  html, body { overflow: hidden; }
  .app-shell, .app-shell.sidebar-collapsed { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; width: min(84vw, 310px); transform: translateX(-102%); box-shadow: 12px 0 34px rgba(0,0,0,.22); transition: transform .22s ease; }
  .app-shell.mobile-sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-collapsed .brand-copy, .sidebar-collapsed .search-box, .sidebar-collapsed .customer-copy, .sidebar-collapsed .sidebar-foot, .sidebar-collapsed .customer-count { display: grid; }
  .sidebar-collapsed .search-box { display: block; }
  .sidebar-collapsed .sidebar-actions { display: grid; padding-inline: 14px; }
  .sidebar-collapsed .customer-item { grid-template-columns: 42px minmax(0,1fr) auto; min-height: 68px; padding: 10px; justify-content: initial; }
  .sidebar-collapsed .brand-row .icon-btn { position: static; width: 38px; height: 38px; margin-left: auto; border-radius: 5px; font-size: 20px; }
  .main-shell { width: 100%; grid-template-rows: 58px minmax(0,1fr); }
  .topbar { padding: 0 10px; gap: 7px; }
  .topbar-left { flex: 1; overflow: hidden; }
  .mobile-only { display: inline-grid; }
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn { min-height: 38px; padding: 0 11px; }
  .topbar-meta { display: none; }
  .view { padding: 10px; }
  .section-heading { align-items: flex-start; gap: 10px; }
  .section-heading > div:first-child { min-width: 84px; }
  .section-heading h1 { font-size: 17px; overflow-wrap: anywhere; }
  .segmented { grid-auto-columns: minmax(96px, auto); }
  .chart-workspace { display: block; min-height: 0; }
  .chart-form-panel { margin-bottom: 10px; }
  .chart-form { padding: 14px; }
  .chart-result-panel { min-height: 460px; }
  .empty-state { min-height: 460px; }
  .result-head { align-items: flex-start; flex-direction: column; padding: 13px; }
  .result-head .button-row { width: 100%; justify-content: flex-start; }
  .chart-visualization { padding: 13px; }
  .interpretation-panel { margin: 0 13px 13px; }
  .settings-grid, .compact-settings { display: block; }
  .plain-section { margin-bottom: 10px; padding: 14px; }
  .knowledge-editor { min-height: 480px; }
  .chat-log { padding: 16px 12px; }
  .message { max-width: 88%; }
  .chat-composer { padding: 11px; }
  .composer-foot { align-items: flex-end; }
  .composer-foot > span { display: none; }
  .composer-foot .button-row { margin-left: auto; }
}

@media (max-width: 520px) {
  .topbar-left { gap: 6px; }
  .tabs { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); overflow: visible; }
  .tab-btn { min-width: 0; padding: 0 4px; font-size: 13px; }
  .two-col { grid-template-columns: 1fr; }
  .section-heading { display: grid; }
  .section-heading .segmented { width: 100%; grid-template-columns: 1fr 1fr; grid-auto-flow: row; grid-auto-columns: auto; }
  .five-elements { grid-template-columns: repeat(5, minmax(54px,1fr)); }
  .element-meter { padding: 8px 6px; }
  .element-meter strong { font-size: 11px; }
  .result-head .button-row { display: grid; grid-template-columns: 1fr 1fr; }
  .result-head .button-row .primary-btn { grid-column: 1 / -1; }
  .interpretation-panel > header { align-items: flex-start; }
  .customer-head { padding: 10px; }
  .customer-head h1 { font-size: 17px; }
  .chat-composer .button-row { display: grid; grid-template-columns: auto 1fr; width: 100%; }
}
