:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #69746d;
  --line: #dde4de;
  --paper: #f5f7f3;
  --white: #ffffff;
  --forest: #153f2d;
  --forest-2: #23533d;
  --mint: #bcf071;
  --mint-soft: #e8f8ce;
  --amber: #e6a239;
  --red: #ca5b4c;
  --blue: #5d7ec4;
  --shadow: 0 14px 40px rgba(21, 63, 45, 0.08);
  --radius: 20px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
[id] { scroll-margin-top: 118px; }
body { margin: 0; color: var(--ink); background: var(--paper); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 30px 22px 24px; display: flex; flex-direction: column; background: var(--forest); color: white; }
.brand { display: flex; gap: 12px; align-items: center; color: white; text-decoration: none; margin: 0 8px 40px; }
.brand-mark { width: 39px; height: 39px; display: grid; place-items: center; border-radius: 12px; color: var(--forest); background: var(--mint); font-weight: 900; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; letter-spacing: .01em; }
.brand small { margin-top: 2px; color: rgba(255,255,255,.54); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; }
.sidebar nav { display: grid; gap: 7px; }
.nav-link { display: flex; gap: 13px; align-items: center; padding: 12px 13px; border-radius: 12px; color: rgba(255,255,255,.68); text-decoration: none; font-size: 14px; transition: .2s ease; }
.nav-link:hover, .nav-link.active { color: white; background: rgba(255,255,255,.09); }
.nav-link.active { box-shadow: inset 3px 0 var(--mint); }
.nav-icon { width: 20px; color: var(--mint); font-size: 16px; text-align: center; }
.sidebar-note { margin-top: auto; padding: 15px; display: flex; gap: 11px; border: 1px solid rgba(255,255,255,.13); border-radius: 14px; background: rgba(0,0,0,.09); }
.sidebar-note strong { display: block; font-size: 12px; }
.sidebar-note p { margin: 5px 0 0; color: rgba(255,255,255,.53); font-size: 10px; line-height: 1.55; }
.live-dot { width: 8px; height: 8px; flex: 0 0 auto; margin-top: 3px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 5px rgba(188,240,113,.1); }

main { min-width: 0; }
.topbar { padding: 28px clamp(24px, 3.5vw, 52px) 24px; display: flex; justify-content: space-between; align-items: center; gap: 24px; background: rgba(245,247,243,.88); border-bottom: 1px solid rgba(221,228,222,.8); backdrop-filter: blur(15px); position: sticky; top: 0; z-index: 5; }
.topbar h1 { margin: 3px 0 0; font-size: clamp(20px, 2vw, 27px); letter-spacing: -.035em; }
.eyebrow { margin: 0; color: #7b877f; font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.mode-pill, .subtle-badge { display: inline-flex; align-items: center; gap: 7px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; color: #58655d; background: white; font-size: 11px; font-weight: 700; white-space: nowrap; }
.mode-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.primary-button, .small-button, .icon-button, .text-button { border: 0; cursor: pointer; transition: .18s ease; }
.primary-button { padding: 10px 15px; border-radius: 11px; color: white; background: var(--forest); font-weight: 750; font-size: 12px; box-shadow: 0 7px 18px rgba(21,63,45,.14); }
.primary-button:hover { background: var(--forest-2); transform: translateY(-1px); }
.icon-button { width: 37px; height: 37px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 11px; background: white; color: var(--ink); }
.icon-button:hover { border-color: #aab8ae; }
.small-button { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: white; font-size: 10px; font-weight: 800; }
.text-button { padding: 5px; color: var(--forest-2); background: transparent; text-decoration: none; font-size: 11px; font-weight: 800; }

.content { padding: 30px clamp(24px, 3.5vw, 52px) 60px; }
.hero-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; }
.metric-card { min-height: 154px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); box-shadow: var(--shadow); }
.accent-card { color: white; border-color: var(--forest); background: var(--forest); }
.metric-heading { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 11px; font-weight: 750; }
.accent-card .metric-heading { color: rgba(255,255,255,.68); }
.metric-icon { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 9px; color: var(--forest); background: var(--mint-soft); font-size: 12px; }
.metric-value { display: block; margin-top: 13px; font-size: clamp(27px, 3vw, 39px); letter-spacing: -.05em; line-height: 1; }
.metric-card p { margin: 12px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.accent-card p { color: rgba(255,255,255,.58); }
.accent-card p b { color: var(--mint); }

.flow-card, .panel { margin-top: 17px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); box-shadow: var(--shadow); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.section-heading h2 { margin: 4px 0 0; font-size: 16px; letter-spacing: -.02em; }
.section-heading.compact { align-items: flex-start; }
.flow-track { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr auto 1fr; align-items: center; gap: 12px; margin-top: 25px; }
.flow-step { min-width: 0; display: flex; gap: 10px; align-items: center; }
.flow-number { width: 33px; height: 33px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 10px; color: var(--forest); background: var(--mint-soft); font-size: 10px; font-weight: 900; }
.flow-step strong, .flow-step small { display: block; }
.flow-step strong { font-size: 12px; }
.flow-step small { overflow: hidden; margin-top: 3px; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.flow-arrow { color: #b3bdb6; }

.main-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(290px, .8fr); gap: 0 17px; align-items: start; }
.panel { min-width: 0; }
.wide-panel { grid-row: span 1; }
.full-panel { grid-column: 1 / -1; }
.health-pill { display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px; border-radius: 999px; color: #47633e; background: #edf8e4; font-size: 10px; font-weight: 800; }
.health-pill i { width: 7px; height: 7px; border-radius: 50%; background: #69a943; }
.health-pill.attention { color: #8c493d; background: #fff0ed; }
.health-pill.attention i { background: var(--red); }
.operations-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, .8fr); gap: 18px; margin-top: 18px; }
.queue-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.queue-stats article { padding: 12px; border: 1px solid #e6ebe7; border-radius: 12px; background: #fafbf9; }
.queue-stats span, .queue-stats strong { display: block; }
.queue-stats span { color: var(--muted); font-size: 9px; }
.queue-stats strong { margin-top: 5px; font-size: 18px; letter-spacing: -.03em; }
.alert-list { margin-top: 10px; display: grid; gap: 8px; }
.alert-item { padding: 10px 12px; display: grid; grid-template-columns: 8px 1fr; gap: 10px; border: 1px solid #e6ebe7; border-radius: 11px; }
.alert-item i { width: 8px; height: 8px; margin-top: 3px; border-radius: 50%; background: var(--amber); }
.alert-item.critical i { background: var(--red); }
.alert-item strong, .alert-item small { display: block; }
.alert-item strong { font-size: 10px; }
.alert-item small { margin-top: 3px; color: var(--muted); font-size: 9px; line-height: 1.45; }
.all-clear { padding: 11px 12px; border-radius: 11px; color: #45633d; background: #f1f9e9; font-size: 9px; }
.readiness-card { padding: 14px; border-radius: 15px; color: white; background: var(--forest); }
.readiness-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.readiness-head strong, .readiness-head small { display: block; }
.readiness-head strong { font-size: 11px; }
.readiness-head small { margin-top: 4px; color: rgba(255,255,255,.55); font-size: 9px; }
.readiness-head > span { color: var(--mint); font-size: 19px; font-weight: 900; letter-spacing: -.04em; }
.readiness-track { height: 5px; overflow: hidden; margin-top: 12px; border-radius: 999px; background: rgba(255,255,255,.13); }
.readiness-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--mint); transition: width .3s ease; }
.readiness-steps { margin-top: 12px; display: grid; gap: 6px; }
.readiness-step { display: grid; grid-template-columns: 17px 1fr auto; gap: 7px; align-items: center; padding: 7px 8px; border-radius: 9px; background: rgba(255,255,255,.055); }
.readiness-step i { width: 17px; height: 17px; display: grid; place-items: center; border-radius: 6px; color: var(--forest); background: var(--mint); font-style: normal; font-size: 8px; font-weight: 900; }
.readiness-step.pending i { color: rgba(255,255,255,.5); background: rgba(255,255,255,.11); }
.readiness-step span { font-size: 9px; }
.readiness-step small { color: rgba(255,255,255,.45); font-size: 8px; }
.table-wrap { overflow-x: auto; margin-top: 17px; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 10px; color: #8a958d; border-bottom: 1px solid var(--line); font-size: 9px; letter-spacing: .07em; text-align: left; text-transform: uppercase; }
td { padding: 13px 10px; border-bottom: 1px solid #edf0ed; font-size: 11px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
.customer-cell { display: flex; gap: 10px; align-items: center; }
.avatar { width: 31px; height: 31px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 10px; color: var(--forest); background: #eef2ed; font-size: 10px; font-weight: 900; }
.customer-cell strong, .customer-cell small { display: block; }
.customer-cell small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.source-tag, .stage-tag { display: inline-flex; padding: 5px 8px; border-radius: 999px; background: #f0f3ef; color: #5e6a62; font-size: 9px; font-weight: 750; white-space: nowrap; }
.stage-qualified, .stage-appointment, .stage-proposal, .stage-won { color: var(--forest); background: var(--mint-soft); }
.score-cell { display: flex; gap: 7px; align-items: center; }
.score-ring { width: 33px; height: 33px; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--forest) calc(var(--score) * 1%), #e9ede9 0); position: relative; }
.score-ring::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: white; }
.score-ring span { position: relative; z-index: 1; font-size: 8px; font-weight: 900; }
.loading-cell { padding: 34px; color: var(--muted); text-align: center; }

.funnel-list { margin-top: 20px; display: grid; gap: 12px; }
.funnel-row { display: grid; grid-template-columns: 68px 1fr 26px; gap: 9px; align-items: center; font-size: 10px; }
.funnel-row strong { font-size: 10px; text-align: right; }
.bar-track { height: 7px; overflow: hidden; border-radius: 999px; background: #edf1ed; }
.bar-fill { height: 100%; min-width: 4px; border-radius: inherit; background: var(--forest-2); }

.action-list, .message-list { margin-top: 16px; display: grid; gap: 9px; }
.action-item, .message-item { padding: 11px 12px; border: 1px solid #e7ece8; border-radius: 12px; background: #fafbf9; }
.action-item { display: grid; grid-template-columns: 28px 1fr; gap: 10px; }
.action-symbol { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 9px; color: var(--forest); background: var(--mint-soft); font-size: 11px; font-weight: 900; }
.action-item strong, .message-item strong { display: block; font-size: 10px; }
.action-item p, .message-item p { margin: 4px 0 0; color: var(--muted); font-size: 9px; line-height: 1.45; }
.message-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.message-head span { color: #929c95; font-size: 8px; }
.direction { color: var(--forest-2); }
.direction.outbound { color: var(--blue); }
.muted { color: var(--muted); font-size: 10px; line-height: 1.6; }

.simulator-panel form { margin-top: 16px; display: grid; gap: 11px; }
label { display: grid; gap: 6px; color: #4f5d54; font-size: 10px; font-weight: 750; }
input, textarea, select { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 10px; outline: none; color: var(--ink); background: white; font-size: 11px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: #78a487; box-shadow: 0 0 0 3px rgba(120,164,135,.12); }
.form-row { display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.simulation-result { margin-top: 13px; padding: 12px; border: 1px solid #cfe7ad; border-radius: 12px; background: #f3fae8; font-size: 10px; line-height: 1.55; }
.simulation-result strong { display: block; margin-bottom: 4px; }
.hidden { display: none !important; }

.integration-grid { margin-top: 18px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.integration-card { padding: 14px; border: 1px solid var(--line); border-radius: 14px; }
.integration-card-head { display: flex; align-items: center; justify-content: space-between; gap: 7px; }
.integration-card strong { font-size: 10px; }
.integration-card p { min-height: 30px; margin: 8px 0 0; color: var(--muted); font-size: 9px; line-height: 1.5; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 4px rgba(230,162,57,.12); }
.status-ready { background: #69a943; box-shadow: 0 0 0 4px rgba(105,169,67,.12); }
.status-rules_fallback { background: var(--blue); box-shadow: 0 0 0 4px rgba(93,126,196,.12); }
.status-needs_configuration { background: var(--red); box-shadow: 0 0 0 4px rgba(202,91,76,.12); }

dialog { width: min(430px, calc(100vw - 30px)); padding: 22px; border: 0; border-radius: 18px; box-shadow: 0 28px 90px rgba(15,35,24,.3); }
dialog::backdrop { background: rgba(13,31,21,.44); backdrop-filter: blur(4px); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; }
.dialog-heading h2 { margin: 4px 0 0; font-size: 19px; }
dialog form { display: grid; gap: 15px; }
.full-button { width: 100%; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: 360px; padding: 12px 15px; border-radius: 12px; color: white; background: var(--forest); box-shadow: 0 14px 40px rgba(21,63,45,.25); font-size: 11px; }
.toast.error { background: #923f34; }

@media (max-width: 1120px) {
  .hero-grid { grid-template-columns: repeat(2, 1fr); }
  .flow-track { grid-template-columns: 1fr; gap: 8px; }
  .flow-arrow { transform: rotate(90deg); justify-self: center; }
  .integration-grid { grid-template-columns: repeat(3, 1fr); }
  .operations-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  [id] { scroll-margin-top: 18px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; height: auto; padding: 18px 20px; }
  .brand { margin: 0 0 16px; }
  .sidebar nav { display: flex; overflow-x: auto; }
  .nav-link { flex: 0 0 auto; }
  .sidebar-note { display: none; }
  .topbar { position: static; }
  .main-grid { grid-template-columns: 1fr; }
  .full-panel { grid-column: auto; }
  .queue-stats { grid-template-columns: repeat(5, minmax(85px, 1fr)); overflow-x: auto; }
}

@media (max-width: 600px) {
  .topbar { align-items: flex-start; flex-direction: column; padding: 22px 18px; }
  .top-actions { width: 100%; }
  .top-actions .primary-button { margin-left: auto; }
  .content { padding: 20px 14px 45px; }
  .hero-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 130px; }
  .flow-card, .panel { padding: 17px; border-radius: 16px; }
  .integration-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; }
  th:nth-child(2), td:nth-child(2), th:nth-child(5), td:nth-child(5) { display: none; }
}

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