:root {
  color-scheme: light;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-soft: #f8f8fb;
  --surface-strong: #eeeff4;
  --text: #20212a;
  --muted: #6f7280;
  --line: #e0e2e9;
  --brand: #673bd1;
  --brand-strong: #5327bd;
  --brand-soft: #eee9fb;
  --brand-on: #ffffff;
  --green: #16805b;
  --green-soft: #e5f4ed;
  --orange: #9a6408;
  --orange-soft: #fff3d7;
  --red: #b63a45;
  --red-soft: #fae9eb;
  --shadow: 0 16px 42px rgba(30, 35, 50, 0.08);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--brand); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.nowrap { white-space: nowrap; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(420px, 1.05fr);
  background: var(--surface);
}
.auth-brand {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(34px, 7vw, 82px);
  color: #ffffff;
  background: linear-gradient(145deg, #2e174f, #5e35c2 58%, #aa8dff);
}
.auth-brand::after {
  content: "";
  position: absolute;
  right: -80px;
  bottom: -120px;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
}
.brand-lockup { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; font-size: 1.18rem; font-weight: 650; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: rgba(255,255,255,.18); }
.auth-copy { position: relative; z-index: 1; max-width: 520px; }
.auth-copy h1 { margin: 0 0 18px; font-size: clamp(2rem, 4vw, 3.5rem); line-height: 1.08; font-weight: 650; }
.auth-copy p { margin: 0; color: rgba(255,255,255,.78); font-size: 1.04rem; line-height: 1.7; }
.auth-panel { display: grid; place-items: center; padding: 28px; }
.auth-card { width: min(430px, 100%); }
.auth-card h2 { margin: 0 0 8px; font-size: 1.7rem; }
.auth-card > p { margin: 0 0 28px; color: var(--muted); }

.app-shell { min-height: 100vh; display: grid; grid-template-rows: 64px 1fr; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(14px);
}
.topbar .brand-lockup { color: var(--text); }
.topbar .brand-mark { color: var(--brand-on); background: var(--brand); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: var(--brand); background: var(--brand-soft); font-weight: 650; }
.app-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.nav-label { padding: 8px 11px; color: var(--muted); font-size: .82rem; }
.nav-button {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 3px;
  border: 0;
  border-radius: 9px;
  color: var(--text);
  background: transparent;
  text-align: left;
}
.nav-button:hover { background: var(--surface-soft); }
.nav-button.active { color: var(--brand); background: var(--brand-soft); }
.sidebar-foot { margin-top: auto; padding: 12px; }
.main { min-width: 0; padding: 26px clamp(18px, 3vw, 38px) 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.page-head h1 { margin: 0 0 6px; font-size: 1.6rem; }
.page-head p { margin: 0; color: var(--muted); }
.page-actions, .inline-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 39px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
}
.button:hover { border-color: #c6c8d2; background: var(--surface-soft); }
.button.primary { border-color: var(--brand); color: var(--brand-on); background: var(--brand); }
.button.primary:hover { background: var(--brand-strong); }
.button.danger { border-color: var(--red); color: var(--red); background: var(--surface); }
.button.ghost { border-color: transparent; background: transparent; }
.button.small-button { min-height: 32px; padding: 5px 9px; font-size: .86rem; }
.button:disabled { cursor: not-allowed; opacity: .58; }
.icon-button { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }

.card { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: 0 1px 2px rgba(30,35,50,.02); }
.card-body { padding: 18px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { padding: 17px; }
.stat-label { color: var(--muted); }
.stat-value { margin-top: 9px; font-size: 1.85rem; font-weight: 650; }
.stat-context { margin-top: 5px; color: var(--muted); font-size: .83rem; }
.grid-2 { display: grid; grid-template-columns: 1.15fr .85fr; gap: 16px; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.section-title h2, .section-title h3 { margin: 0; font-size: 1.04rem; }
.empty { padding: 38px 20px; color: var(--muted); text-align: center; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: grid; gap: 7px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { color: var(--muted); font-size: .88rem; }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-soft);
  outline: none;
}
.input, .select { height: 40px; padding: 8px 10px; }
.textarea { min-height: 92px; padding: 10px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 17px; }
.form-error { min-height: 20px; margin-top: 8px; color: var(--red); font-size: .86rem; }

.search-panel { padding: 17px; }
.search-grid { display: grid; grid-template-columns: 1fr 1fr 1.2fr .55fr auto; gap: 12px; align-items: end; }
.mode-banner { display: flex; align-items: center; gap: 10px; padding: 11px 13px; margin-bottom: 14px; border-radius: 9px; color: var(--orange); background: var(--orange-soft); }
.mode-banner.live { color: var(--green); background: var(--green-soft); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 20px 0 10px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-input { width: min(260px, 100%); }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 780px; }
.data-table th, .data-table td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.data-table th { color: var(--muted); background: var(--surface-soft); font-size: .84rem; font-weight: 550; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--brand-soft); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.company-cell { display: grid; gap: 3px; }
.company-name { font-weight: 620; }
.score { color: var(--green); font-weight: 650; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 999px; color: var(--brand); background: var(--brand-soft); font-size: .82rem; }
.pill.green { color: var(--green); background: var(--green-soft); }
.pill.orange { color: var(--orange); background: var(--orange-soft); }
.pill.red { color: var(--red); background: var(--red-soft); }
.tag-list { display: flex; gap: 5px; flex-wrap: wrap; }

.pipeline { display: grid; grid-template-columns: repeat(5, minmax(140px, 1fr)); gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.pipeline-stage { min-width: 145px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.pipeline-stage strong { display: block; font-size: 1.5rem; margin-top: 8px; }
.progress-track { height: 7px; margin-top: 12px; border-radius: 999px; background: var(--surface-strong); overflow: hidden; }
.progress-bar { height: 100%; border-radius: inherit; background: var(--brand); }

.kanban { display: grid; grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 14px; }
.kanban-column { min-width: 0; }
.kanban-head { display: flex; justify-content: space-between; padding: 0 3px 10px; }
.task { padding: 14px; margin-bottom: 9px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.task h3 { margin: 0 0 7px; font-size: .98rem; }
.task p { margin: 4px 0; color: var(--muted); font-size: .86rem; }
.task-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 11px; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(19, 20, 29, .4); }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 90;
  width: min(720px, 100%);
  height: 100vh;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--bg);
  box-shadow: -18px 0 48px rgba(20,22,31,.13);
}
.drawer-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 17px 20px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.drawer-head h2 { margin: 0; font-size: 1.2rem; }
.drawer-body { display: grid; gap: 14px; padding: 18px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.detail-fact { padding: 12px; border-radius: 9px; background: var(--surface-soft); }
.detail-fact span { display: block; margin-bottom: 4px; color: var(--muted); font-size: .82rem; }
.badge { display: inline-flex; align-items: center; margin-left: 6px; padding: 2px 7px; border-radius: 999px; background: #e8f7ef; color: #177245; font-size: .72rem; font-weight: 600; }
.reason-box { padding: 13px; border-left: 3px solid var(--brand); background: var(--brand-soft); line-height: 1.55; }
.timeline { display: grid; gap: 11px; }
.timeline-item { display: grid; grid-template-columns: 10px 1fr; gap: 10px; }
.timeline-dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--brand); }
.timeline-content { padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.message-box { padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); white-space: pre-wrap; line-height: 1.58; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; background: rgba(19,20,29,.48); }
.modal { width: min(620px, 100%); max-height: calc(100vh - 36px); overflow-y: auto; border-radius: 13px; background: var(--surface); box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 17px 19px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-body { padding: 18px; }

#toast-root { position: fixed; top: 76px; right: 20px; z-index: 200; display: grid; gap: 8px; }
.toast { min-width: 260px; max-width: 420px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); box-shadow: var(--shadow); }
.toast.success { border-color: #8dcdb5; }
.toast.error { border-color: #e3a3a9; color: var(--red); }
.spinner { width: 17px; height: 17px; border: 2px solid rgba(255,255,255,.4); border-top-color: currentColor; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1050px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .search-grid, .form-grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .search-grid .button { grid-column: 1 / -1; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { min-height: 260px; padding: 32px; }
  .auth-copy h1 { font-size: 2.1rem; }
  .app-layout { grid-template-columns: 70px minmax(0,1fr); }
  .sidebar .nav-label, .sidebar .nav-button span, .sidebar-foot { display: none; }
  .sidebar .nav-button { justify-content: center; }
  .main { padding-inline: 16px; }
  .kanban { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .topbar { padding-inline: 14px; }
  .top-actions .user-name { display: none; }
  .app-layout { display: block; }
  .sidebar { position: sticky; top: 64px; z-index: 20; width: 100%; height: auto; flex-direction: row; overflow-x: auto; padding: 7px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar .nav-button { min-width: 45px; margin: 0; }
  .stats, .form-grid, .search-grid, .detail-grid { grid-template-columns: 1fr; }
  .field.full, .search-grid .button { grid-column: auto; }
  .page-head { align-items: stretch; flex-direction: column; }
  .toolbar { align-items: stretch; flex-direction: column; }
  #toast-root { left: 14px; right: 14px; }
  .toast { min-width: 0; }
}
