:root {
  --ink: #12313a;
  --muted: #668087;
  --line: #d8e5e3;
  --paper: #ffffff;
  --wash: #f3f8f7;
  --teal: #3370ff;
  --teal-dark: #245bdb;
  --teal-soft: #edf3ff;
  --amber: #d99417;
  --amber-soft: #fff2d6;
  --purple: #6956d8;
  --purple-soft: #ebe8ff;
  --danger: #bc4b45;
  --shadow: 0 16px 42px rgba(31, 35, 41, .11);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: #f5f7f8;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #f5f6f8; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; color: inherit; }

.topbar { height: 64px; display: grid; grid-template-columns: 236px minmax(300px, 720px) 1fr; align-items: center; gap: 20px; padding: 0 28px; background: rgba(255,255,255,.96); border-bottom: 1px solid #e5e6eb; position: sticky; top: 0; z-index: 30; backdrop-filter: blur(16px); }
.brand { display: flex; gap: 10px; align-items: center; text-decoration: none; color: var(--ink); }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; background: linear-gradient(145deg, #3370ff, #5b8cff); color: #fff; font-weight: 800; border-radius: 10px; box-shadow: 0 6px 16px rgba(51,112,255,.25); }
.brand b, .brand small { display: block; }
.brand small { color: var(--muted); font-size: 9px; letter-spacing: .08em; margin-top: 2px; }
.global-search { height: 42px; display: flex; align-items: center; gap: 10px; padding: 0 14px; border: 1px solid #d9dce3; border-radius: 9px; background: #f7f8fa; }
.global-search:focus-within { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,143,134,.12); }
.global-search input { flex: 1; min-width: 0; border: 0; outline: 0; color: var(--ink); }
kbd { border: 1px solid var(--line); padding: 2px 6px; border-radius: 5px; color: var(--muted); background: var(--wash); font-size: 11px; }
.identity { justify-self: end; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.identity button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 10px; }
.data-status { display: flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 999px; background: #f2f3f5; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.data-status[data-status="live"] { color: #16815c; background: #e8f8f1; }
.data-status[data-status="live"] .status-dot { background: #22a06b; }
.data-status[data-status="error"] { color: #c43b3b; background: #fff0f0; }
.data-status[data-status="error"] .status-dot { background: #f54a45; }
.reload-button { font-size: 16px; padding: 5px 8px !important; }

.view-tabs { display: flex; justify-content: center; gap: 5px; padding: 8px 20px; background: #fff; border-bottom: 1px solid #e5e6eb; position: sticky; top: 64px; z-index: 25; }
.view-tabs button { border: 0; background: transparent; padding: 9px 22px; border-radius: 8px; font-weight: 700; color: var(--muted); }
.view-tabs button.active { color: var(--teal-dark); background: var(--teal-soft); }

#app { width: min(1380px, calc(100% - 40px)); margin: 20px auto 70px; }
.hero { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; margin-bottom: 14px; }
.hero-main, .hero-aside, .panel { background: rgba(255,255,255,.96); border: 1px solid #e5e6eb; border-radius: 14px; box-shadow: 0 4px 16px rgba(31,35,41,.04); }
.hero-main { padding: 22px 26px; background: linear-gradient(120deg, #f5f8ff, #fff 66%); color: var(--ink); display: flex; align-items: end; justify-content: space-between; gap: 24px; overflow: hidden; position: relative; }
.hero-main::after { content: ""; position: absolute; width: 210px; height: 210px; background: radial-gradient(circle, rgba(51,112,255,.1), transparent 68%); right: -30px; top: -100px; }
.eyebrow { color: #3ec9ba; font-size: 11px; letter-spacing: .16em; font-weight: 800; }
.hero h1, .page-title h1 { margin: 6px 0 8px; font-size: clamp(25px, 2.5vw, 38px); letter-spacing: -.035em; }
.hero p { max-width: 720px; color: var(--muted); line-height: 1.7; margin: 0; }
.scenario-row { display: grid; grid-template-columns: repeat(2, minmax(110px,1fr)); gap: 8px; position: relative; z-index: 1; min-width: 270px; }
.scenario-row button { display: flex; justify-content: space-between; border: 1px solid #d6e2ff; background: #fff; color: var(--teal-dark); border-radius: 8px; padding: 9px 11px; }
.hero-aside { padding: 18px; }
.overview-title { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.overview-title small { color: #16815c; font-weight: 500; }
.hero-aside h2, .panel h2 { margin: 0; font-size: 17px; }
.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 16px; }
.metric { background: #f7f8fa; border-radius: 9px; padding: 12px; }
.metric b { display: block; font-size: 24px; }
.metric span { color: var(--muted); font-size: 12px; }

.layout { display: grid; grid-template-columns: 260px minmax(0,1fr); gap: 18px; }
.filter-panel { align-self: start; position: sticky; top: 136px; padding: 18px; }
.filter-panel h3 { margin: 0 0 14px; font-size: 14px; }
.filter-group { margin-bottom: 20px; }
.filter-group label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.filter-group select { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px; background: #fff; }
.business-menu { display: grid; gap: 5px; }
.business-menu button { text-align: left; border: 0; background: transparent; padding: 10px; border-radius: 9px; }
.business-menu button.active { background: var(--teal-soft); color: var(--teal-dark); font-weight: 700; }
.business-menu small { display: block; margin-top: 3px; color: var(--muted); font-weight: 400; }

.content-stack { display: grid; gap: 18px; min-width: 0; }
.panel { padding: 20px; }
.panel-heading { display: flex; justify-content: space-between; align-items: end; gap: 14px; margin-bottom: 16px; }
.panel-heading p, .page-title p { margin: 5px 0 0; color: var(--muted); line-height: 1.55; }
.panel-heading small { color: var(--muted); white-space: nowrap; }
.page-title { margin: 4px 0 20px; }
.page-title h1 { font-size: 34px; }

.stage-grid { display: grid; grid-template-columns: repeat(5, minmax(170px,1fr)); gap: 9px; }
.stage-card { min-height: 210px; text-align: left; border: 1px solid var(--line); border-top: 4px solid var(--teal); background: #fff; padding: 15px; border-radius: 4px 4px 10px 10px; display: flex; flex-direction: column; gap: 9px; }
.stage-card:hover, .stage-card.active { border-color: var(--teal); box-shadow: 0 9px 24px rgba(0,103,98,.1); transform: translateY(-2px); }
.stage-status { align-self: flex-end; background: var(--teal-soft); color: var(--teal-dark); font-size: 11px; padding: 3px 7px; border-radius: 5px; }
.stage-card strong { font-size: 16px; }
.stage-card p { margin: 0; color: #48666c; font-size: 13px; line-height: 1.65; flex: 1; }
.stage-owner { font-size: 12px; font-weight: 700; color: var(--teal-dark); }
.stage-card small { color: var(--muted); }

.result-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.chip-row, .tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 11px; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.department-filters { padding-bottom: 16px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.department-section + .department-section { margin-top: 24px; }
.department-heading { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 10px; }
.department-heading h3 { margin: 0; font-size: 16px; }
.department-heading span { color: var(--muted); font-size: 12px; }
.people-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.person-card { background: #fff; border: 1px solid #e5e6eb; border-radius: 12px; padding: 16px; min-width: 0; transition: .16s ease; }
.person-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.person-head { display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 11px; }
.avatar { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; background: linear-gradient(145deg, #3370ff, #70a0ff); color: #fff; font-weight: 800; object-fit: cover; }
.person-name strong, .person-name small { display: block; }
.person-name small { color: var(--muted); margin-top: 3px; font-size: 11px; }
.role-badge { padding: 5px 8px; border-radius: 5px; background: var(--amber-soft); color: #936000; font-size: 11px; font-weight: 700; }
.role-owner { background: var(--teal-soft); color: var(--teal-dark); }
.role-consulted { background: var(--purple-soft); color: #5142b2; }
.role-related { background: #edf2f2; color: #567077; }
.person-context { color: #51565d; font-size: 12px; font-weight: 600; margin: 14px 0 7px; }
.business-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; }
.business-tags span { color: #245bdb; background: #edf3ff; font-size: 10px; padding: 3px 6px; border-radius: 4px; }
.quick-fields { margin: 0; display: grid; gap: 9px; }
.quick-fields div { min-width: 0; }
.quick-fields dt { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.quick-fields dd { margin: 0; font-size: 13px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.is-empty { color: #a28242 !important; font-style: italic; }
.tag-row { margin-top: 11px; min-height: 22px; }
.tag-row span { background: var(--wash); color: var(--muted); padding: 3px 6px; border-radius: 4px; font-size: 10px; }
.card-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 13px; border-top: 1px solid #edf2f1; padding-top: 10px; }
.card-actions button, .drawer-actions button, .section-title button, .section-controls button, .edit-footer button { border: 1px solid var(--line); border-radius: 7px; background: #fff; padding: 7px 9px; font-size: 12px; }
.chat-button, .primary-button { background: var(--teal) !important; color: #fff !important; border-color: var(--teal) !important; box-shadow: 0 4px 10px rgba(51,112,255,.16); }
.mobile-navigation { display: none; }

.matrix-scroll { overflow: auto; }
.responsibility-matrix { width: 100%; min-width: 900px; border-collapse: separate; border-spacing: 0; }
.responsibility-matrix th, .responsibility-matrix td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 10px; vertical-align: top; background: #fff; }
.responsibility-matrix thead th { position: sticky; top: 0; z-index: 2; background: #eaf5f3; }
.responsibility-matrix th:first-child { position: sticky; left: 0; z-index: 3; min-width: 150px; background: #f4f8f7; }
.responsibility-matrix button { width: 100%; border: 0; text-align: left; background: var(--wash); border-radius: 6px; margin-bottom: 5px; padding: 7px; }
.responsibility-matrix button b, .responsibility-matrix button small { display: block; }
.responsibility-matrix button small { color: var(--teal-dark); margin-top: 3px; }
.matrix-empty { color: #9aa9ac; font-size: 12px; }

.goal-grid, .agent-grid, .gap-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.goal-card, .agent-card, .gap-card { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 16px; }
.goal-card h3 { margin: 0 0 8px; }
.goal-card p { color: var(--muted); line-height: 1.55; }
.agent-head { display: flex; gap: 10px; align-items: center; }
.agent-head strong, .agent-head small { display: block; }
.agent-head small { color: var(--muted); margin-top: 3px; }
.agent-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--purple-soft); color: var(--purple); font-weight: 900; }
.agent-fields { display: grid; gap: 10px; margin: 16px 0 0; }
.agent-fields dt { color: var(--muted); font-size: 11px; }
.agent-fields dd { margin: 3px 0 0; line-height: 1.5; }
.gap-card b { font-size: 24px; display: block; margin-bottom: 4px; }
.gap-card span { color: var(--muted); font-size: 12px; }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(9,34,39,.42); z-index: 50; }
.person-drawer { position: fixed; z-index: 51; right: 0; top: 0; width: min(620px, 100%); height: 100vh; background: #fff; box-shadow: -20px 0 60px rgba(0,0,0,.18); overflow: auto; padding: 26px; }
.drawer-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.drawer-person { display: flex; align-items: center; gap: 13px; }
.drawer-avatar { width: 58px; height: 58px; border-radius: 14px; object-fit: cover; flex: 0 0 auto; }
.drawer-head h2 { margin: 7px 0 3px; font-size: 30px; }
.drawer-head p { margin: 0; color: var(--muted); }
.icon-button { border: 0; background: var(--wash); border-radius: 50%; width: 36px; height: 36px; font-size: 24px; }
.drawer-actions { display: flex; gap: 8px; margin: 20px 0; }
.detail-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.detail-grid label, .custom-section { display: block; border: 1px solid var(--line); border-radius: 10px; padding: 11px; }
.detail-grid label span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 5px; }
.detail-grid textarea, .custom-section textarea, .custom-section input { width: 100%; border: 0; resize: vertical; outline: 0; background: transparent; color: var(--ink); line-height: 1.5; }
.detail-grid textarea { min-height: 62px; }
.custom-section-list { margin-top: 22px; }
.section-title { display: flex; justify-content: space-between; align-items: center; }
.custom-section { margin-top: 9px; }
.custom-section input { font-weight: 700; margin-bottom: 7px; }
.section-controls { display: none; gap: 5px; margin-top: 7px; }
.editing textarea, .editing input { background: #f6faf9; padding: 7px; border-radius: 6px; }
.editing .section-controls { display: flex; }
.edit-footer { position: sticky; bottom: -26px; background: #fff; padding: 14px 0 0; margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }
.edit-footer[hidden] { display: none; }
.empty-note { color: var(--muted); border: 1px dashed var(--line); padding: 16px; border-radius: 10px; }
#toast { position: fixed; right: 22px; bottom: 22px; z-index: 80; padding: 12px 16px; background: var(--ink); color: #fff; border-radius: 9px; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
#toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1000px) {
  .topbar { grid-template-columns: auto 1fr; }
  .identity { display: none; }
  .hero { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 220px minmax(0,1fr); }
  .people-grid, .goal-grid, .agent-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .stage-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 720px) {
  .topbar { height: auto; grid-template-columns: 1fr; gap: 10px; padding: 12px 14px; position: static; }
  .brand small, kbd { display: none; }
  .global-search { width: 100%; }
  .view-tabs { display: none; }
  .mobile-navigation { display: grid; grid-template-columns: repeat(5,1fr); position: fixed; z-index: 45; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.98); border-top: 1px solid #e5e6eb; padding: 6px 8px max(6px, env(safe-area-inset-bottom)); }
  .mobile-navigation button { border: 0; background: transparent; display: grid; place-items: center; gap: 2px; color: #8f959e; font-size: 10px; padding: 3px; }
  .mobile-navigation button span { display: grid; place-items: center; width: 28px; height: 24px; border-radius: 8px; font-size: 12px; font-weight: 700; }
  .mobile-navigation button.active { color: #245bdb; }
  .mobile-navigation button.active span { background: #edf3ff; }
  #app { width: calc(100% - 20px); margin-top: 10px; margin-bottom: 92px; }
  .hero { display: block; }
  .hero-main { padding: 22px 18px; }
  .hero-main { display: block; }
  .scenario-row { margin-top: 18px; min-width: 0; }
  .hero-aside { margin-top: 12px; }
  .layout { display: block; }
  .filter-panel { position: static; margin-bottom: 12px; }
  .business-menu { display: flex; overflow-x: auto; }
  .business-menu button { min-width: 180px; }
  .stage-grid, .people-grid, .goal-grid, .agent-grid, .gap-grid { grid-template-columns: 1fr; }
  .stage-card { min-height: 0; }
  .panel { padding: 14px; border-radius: 12px; }
  .panel-heading { align-items: start; }
  .detail-grid { grid-template-columns: 1fr; }
  .person-drawer { padding: 20px 15px; }
  .person-head { grid-template-columns: 40px 1fr; }
  .role-badge { grid-column: 2; justify-self: start; }
}
