:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #152033;
  --muted: #718096;
  --line: #e5eaf2;
  --navy: #18345f;
  --blue: #2f6df6;
  --blue-soft: #eaf1ff;
  --green: #159b72;
  --green-soft: #e7f8f2;
  --amber: #d98715;
  --amber-soft: #fff5df;
  --violet: #7757d9;
  --violet-soft: #f0ebff;
  --rose: #d94b67;
  --rose-soft: #fff0f3;
  --shadow: 0 12px 34px rgba(25, 46, 79, .07);
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select { font: inherit; }

.topbar {
  height: 72px;
  padding: 0 36px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand > div:last-child { display: grid; gap: 2px; }
.brand strong { font-size: 17px; letter-spacing: -.02em; }
.brand span { color: #8a96a9; font-size: 9px; letter-spacing: .14em; font-weight: 700; }
.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(145deg, #244e87, #16345e);
  box-shadow: 0 12px 24px rgba(28,61,105,.22);
  color: white;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
}
.brand-mark.small { width: 38px; height: 38px; border-radius: 11px; font-size: 17px; }
.sync-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #f4f6f9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.sync-status i { width: 7px; height: 7px; border-radius: 50%; background: #9aa5b4; }
.sync-status.online { background: var(--green-soft); color: #087a58; }
.sync-status.online i { background: var(--green); box-shadow: 0 0 0 4px rgba(21,155,114,.1); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.sync-now-button {
  height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid #d8e1ed;
  border-radius: 10px;
  background: #fff;
  color: var(--navy);
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(24,52,95,.05);
  transition: .18s ease;
}
.sync-now-button:hover { color: var(--blue); border-color: #aebfe0; transform: translateY(-1px); }
.sync-now-button:disabled { cursor: wait; opacity: .72; transform: none; }
.sync-icon { font-size: 18px; line-height: 1; }
.sync-now-button.loading .sync-icon { animation: sync-spin .8s linear infinite; }
@keyframes sync-spin { to { transform: rotate(360deg); } }
.page-toast {
  position: fixed;
  left: 50%;
  top: 86px;
  z-index: 100;
  max-width: min(520px, calc(100vw - 30px));
  padding: 12px 18px;
  border-radius: 11px;
  background: #173b68;
  color: #fff;
  box-shadow: 0 14px 38px rgba(15,35,62,.24);
  font-weight: 650;
  opacity: 0;
  transform: translate(-50%, -12px);
  transition: .22s ease;
}
.page-toast.visible { opacity: 1; transform: translate(-50%, 0); }
.page-toast.error { background: #ad2f48; }

.page-shell { max-width: 1560px; margin: 0 auto; padding: 34px 30px 60px; }
.hero-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 8px; color: var(--blue); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.eyebrow.green { color: var(--green); }
.hero-row h1 { margin: 0; font-size: clamp(28px, 3vw, 42px); letter-spacing: -.045em; line-height: 1.1; }
.hero-row p:last-child { margin: 10px 0 0; color: var(--muted); }
.hero-actions { display: flex; gap: 8px; }
.ghost-button, .clear-button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 13px;
  text-decoration: none;
  color: #4b5a70;
  font-weight: 600;
  font-size: 13px;
  transition: .18s ease;
}
.ghost-button:hover, .clear-button:hover { border-color: #bcc9dc; color: var(--blue); transform: translateY(-1px); }

.alert { padding: 13px 16px; border-radius: 12px; margin: 0 0 18px; line-height: 1.55; border: 1px solid; }
.alert strong { margin-right: 6px; }
.alert.error { background: #fff1f2; border-color: #fecdd3; color: #a51c36; }
.alert.warning { background: var(--amber-soft); border-color: #f5d89a; color: #87530a; }
.alert.info { background: var(--blue-soft); border-color: #cddcff; color: #244d9b; }
.alert code { background: rgba(255,255,255,.72); padding: 2px 5px; border-radius: 4px; }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.metric-card {
  min-height: 132px;
  padding: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 5px 18px rgba(24,52,95,.035);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.metric-card::after { content: ""; position: absolute; right: -32px; top: -44px; width: 112px; height: 112px; border-radius: 50%; background: #f2f5fa; }
.metric-card.primary { background: linear-gradient(145deg, #204a81, #17355f); color: white; border-color: transparent; box-shadow: 0 16px 32px rgba(24,52,95,.18); }
.metric-card.primary::after { background: rgba(255,255,255,.07); }
.metric-card.danger { border-color: #f5d2d9; }
.metric-card.danger::after { background: var(--rose-soft); }
.metric-card span { color: var(--muted); font-weight: 650; position: relative; z-index: 1; }
.metric-card.primary span, .metric-card.primary small { color: rgba(255,255,255,.76); }
.metric-card strong { font-size: 34px; line-height: 1; letter-spacing: -.04em; position: relative; z-index: 1; }
.metric-card strong.compact { font-size: 25px; }
.metric-card.danger strong { color: var(--rose); }
.metric-card small { color: #98a3b3; position: relative; z-index: 1; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 20px; align-items: start; }
.main-panel, .side-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.main-panel { min-width: 0; overflow: hidden; }
.filter-bar { padding: 16px; background: var(--surface-soft); border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.filter-field { display: grid; gap: 5px; min-width: 138px; }
.filter-field.date-filter { min-width: 150px; }
.filter-field.search-field { flex: 1; min-width: 170px; }
.filter-field label { color: #7a8799; font-size: 11px; font-weight: 700; }
.filter-field input, .filter-field select, .install-form input, .install-form select {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  color: var(--ink);
  background: white;
  border: 1px solid #dce3ec;
  border-radius: 9px;
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
.filter-field input:focus, .filter-field select:focus, .install-form input:focus, .install-form select:focus { border-color: #8dadf8; box-shadow: 0 0 0 3px rgba(47,109,246,.1); }
.risk-toggle { height: 40px; display: flex; align-items: center; gap: 7px; white-space: nowrap; color: #59687d; font-weight: 600; cursor: pointer; }
.risk-toggle input { width: 16px; height: 16px; accent-color: var(--rose); }
.filter-button, .primary-button {
  border: 0;
  border-radius: 9px;
  min-height: 40px;
  padding: 9px 18px;
  background: var(--navy);
  color: white;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 7px 14px rgba(24,52,95,.15);
  transition: .18s ease;
}
.filter-button:hover, .primary-button:hover { background: #254f86; transform: translateY(-1px); }
.primary-button:disabled { opacity: .7; cursor: wait; transform: none; }
.clear-button { height: 40px; display: inline-flex; align-items: center; }
.primary-button.full { width: 100%; display: flex; justify-content: center; align-items: center; text-decoration: none; min-height: 46px; }

.table-heading { display: flex; align-items: center; justify-content: space-between; padding: 22px 22px 12px; }
.table-heading h2 { margin: 0; font-size: 19px; }
.table-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 11px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.system { background: var(--blue); }
.dot.manual { background: var(--rose); }

.flow-list { padding: 0 12px 14px; }
.flow-row { border: 1px solid transparent; border-top-color: #edf0f5; transition: .18s ease; }
.flow-row:first-child { border-top-color: transparent; }
.flow-row[open], .flow-row:hover { border-color: #dce4ef; border-radius: 12px; background: #fbfcfe; margin: 4px 0; }
.flow-row.high { border-left: 3px solid var(--rose); }
.flow-row.medium { border-left: 3px solid var(--amber); }
.flow-row summary { list-style: none; display: grid; grid-template-columns: 70px minmax(210px, 1.55fr) minmax(130px, .9fr) minmax(86px,.65fr) 22px minmax(86px,.65fr) 94px 18px; gap: 12px; align-items: center; min-height: 78px; padding: 10px 12px; cursor: pointer; }
.flow-row summary::-webkit-details-marker { display: none; }
.time-cell, .company-cell, .person-cell { display: grid; gap: 4px; }
.time-cell strong { font-size: 16px; }
.time-cell span, .company-cell span, .person-cell span { color: #96a0af; font-size: 11px; }
.company-cell { min-width: 0; }
.company-cell strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reason-cell { display: grid; gap: 5px; justify-items: start; }
.reason-cell small { color: #9aa4b2; font-size: 10px; }
.reason-badge { display: inline-flex; padding: 5px 8px; border-radius: 7px; font-size: 11px; font-weight: 750; white-space: nowrap; }
.reason-badge.blue { color: #2457bd; background: var(--blue-soft); }
.reason-badge.amber { color: #9a5e09; background: var(--amber-soft); }
.reason-badge.violet { color: #6444c5; background: var(--violet-soft); }
.reason-badge.rose { color: #b72f4a; background: var(--rose-soft); }
.reason-badge.gray { color: #657388; background: #eef1f5; }
.person-cell strong { font-size: 13px; }
.person-cell.claim strong { color: var(--green); }
.flow-arrow { color: #c0c8d3; font-size: 17px; }
.duration-cell { justify-self: end; display: grid; justify-items: end; gap: 5px; color: #546278; font-size: 12px; font-weight: 700; }
.duration-cell b { padding: 3px 6px; border-radius: 5px; background: var(--rose-soft); color: var(--rose); font-size: 9px; }
.duration-cell b.medium { background: var(--amber-soft); color: var(--amber); }
.chevron { color: #9aa5b3; transition: transform .18s; }
.flow-row[open] .chevron { transform: rotate(180deg); }
.flow-details { margin: 0 12px 12px; padding: 14px 16px; border-radius: 10px; background: #f4f7fb; display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; }
.flow-details > div { display: grid; gap: 5px; }
.flow-details span { color: #8b96a7; font-size: 10px; font-weight: 650; }
.flow-details strong { font-size: 12px; }
.flow-details .flags { grid-column: 1 / -1; }
.flags p { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.flags em { font-style: normal; background: var(--rose-soft); color: #af314a; border: 1px solid #f5d2da; border-radius: 6px; padding: 4px 7px; font-size: 11px; font-weight: 650; }

.side-panel { display: grid; gap: 16px; }
.side-card { padding: 20px; }
.side-title { display: flex; justify-content: space-between; align-items: start; margin-bottom: 18px; }
.side-title h3 { margin: 0; font-size: 16px; }
.side-title > span { color: var(--muted); background: #f1f4f8; padding: 5px 8px; border-radius: 7px; font-size: 11px; font-weight: 700; }
.chart-item { margin-bottom: 16px; }
.chart-item:last-child { margin-bottom: 0; }
.chart-item > div:first-child { display: flex; justify-content: space-between; margin-bottom: 7px; color: #5b687a; font-size: 12px; }
.chart-item strong { color: var(--ink); }
.bar { height: 7px; background: #eef1f5; border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: inherit; background: #a7b3c4; }
.bar i.blue { background: var(--blue); }
.bar i.amber { background: #e7a23c; }
.bar i.violet { background: var(--violet); }
.bar i.rose { background: var(--rose); }
.rule-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 16px; }
.rule-list li { display: flex; gap: 11px; align-items: center; }
.rule-list div { display: grid; gap: 3px; }
.rule-list strong { font-size: 12px; }
.rule-list span { color: var(--muted); font-size: 11px; }
.rule-dot { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto; }
.rule-dot.blue { background: var(--blue); }
.rule-dot.amber { background: #e7a23c; }
.rule-dot.violet { background: var(--violet); }
.rule-dot.rose { background: var(--rose); }
.sync-card dl { margin: 0; display: grid; gap: 11px; }
.sync-card dl div { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line); padding-bottom: 10px; }
.sync-card dl div:last-child { border: 0; padding: 0; }
.sync-card dt { color: var(--muted); }
.sync-card dd { margin: 0; font-weight: 700; }
.empty-state { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty-state > div { width: 48px; height: 48px; margin: 0 auto 14px; display: grid; place-items: center; border-radius: 14px; background: #eef3fa; color: #7890b1; font-size: 24px; }
.empty-state h3 { margin: 0 0 6px; color: #526176; font-size: 15px; }
.empty-state p, .muted { color: var(--muted); }

/* Installer */
.install-body { min-height: 100vh; background: radial-gradient(circle at 15% 15%, #254f87 0, #18365f 28%, #102949 62%, #0c213d 100%); }
.install-shell { min-height: 100vh; width: min(1120px, calc(100% - 40px)); margin: 0 auto; display: grid; grid-template-columns: .85fr 1.15fr; gap: 80px; align-items: center; padding: 50px 0; }
.install-brand { color: white; }
.install-brand .eyebrow { color: #8db4ff; margin-top: 26px; }
.install-brand h1 { font-size: 46px; margin: 0; letter-spacing: -.05em; }
.install-lead { color: rgba(255,255,255,.7); font-size: 16px; line-height: 1.85; margin: 20px 0 28px; }
.install-points { display: grid; gap: 13px; }
.install-points span { color: rgba(255,255,255,.8); display: flex; align-items: center; gap: 10px; }
.install-points span::before { content: "✓"; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; background: rgba(87,208,164,.14); color: #62d4aa; font-weight: 800; }
.install-card { background: white; border-radius: 22px; padding: 34px; box-shadow: 0 28px 70px rgba(0,0,0,.24); }
.install-card h2 { font-size: 26px; margin: 4px 0 8px; letter-spacing: -.03em; }
.step-label { margin: 0; color: var(--blue); font-weight: 750; font-size: 12px; }
.install-form { margin-top: 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.install-form .field { display: grid; gap: 6px; }
.install-form .small-field { min-width: 100px; }
.install-form .full-field, .section-divider { grid-column: 1 / -1; }
.install-form label { color: #56647a; font-size: 12px; font-weight: 700; }
.install-form small { color: #95a0af; line-height: 1.5; }
.section-divider { position: relative; margin: 7px 0 0; color: #8995a6; font-size: 11px; font-weight: 750; letter-spacing: .08em; }
.section-divider::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--line); }
.section-divider span { position: relative; z-index: 1; background: white; padding-right: 10px; }
.check-row { display: flex; gap: 8px; align-items: start; cursor: pointer; }
.check-row input { width: 16px; height: 16px; min-height: 0; margin-top: 1px; accent-color: var(--blue); }
.success-icon { width: 60px; height: 60px; border-radius: 18px; background: var(--green-soft); color: var(--green); display: grid; place-items: center; font-size: 28px; font-weight: 800; margin-bottom: 22px; }

@media (max-width: 1250px) {
  .content-grid { grid-template-columns: 1fr; }
  .side-panel { grid-template-columns: repeat(3, 1fr); }
  .flow-row summary { grid-template-columns: 64px minmax(190px,1.5fr) minmax(125px,.9fr) 80px 18px 80px 82px 14px; gap: 9px; }
}
@media (max-width: 980px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .flow-row summary { grid-template-columns: 58px minmax(180px,1fr) 125px 82px 18px; }
  .flow-row .person-cell:first-of-type, .flow-arrow, .duration-cell { display: none; }
  .side-panel { grid-template-columns: 1fr; }
  .install-shell { grid-template-columns: 1fr; gap: 34px; padding: 40px 0; }
  .install-brand { max-width: 620px; }
}
@media (max-width: 720px) {
  .topbar { height: 62px; padding: 0 16px; }
  .brand span { display: none; }
  .sync-status { display: none; }
  .sync-now-button { height: 36px; padding: 0 11px; }
  .page-shell { padding: 24px 12px 40px; }
  .hero-row { align-items: start; flex-direction: column; gap: 18px; }
  .hero-actions { width: 100%; }
  .ghost-button { flex: 1; text-align: center; padding: 8px 5px; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .metric-card { min-height: 115px; padding: 16px; }
  .metric-card strong { font-size: 28px; }
  .metric-card strong.compact { font-size: 20px; }
  .filter-bar { display: grid; grid-template-columns: 1fr 1fr; }
  .filter-field, .filter-field.date-filter, .filter-field.search-field { min-width: 0; }
  .search-field { grid-column: 1 / -1; }
  .filter-button, .clear-button { justify-content: center; text-align: center; }
  .table-heading { padding: 18px 16px 9px; }
  .legend { display: none; }
  .flow-list { padding: 0 7px 10px; }
  .flow-row summary { grid-template-columns: 50px minmax(0,1fr) 98px 12px; gap: 8px; padding: 10px 8px; }
  .flow-row .reason-cell { display: none; }
  .flow-row .person-cell.claim { justify-items: end; }
  .flow-details { grid-template-columns: 1fr 1fr; }
  .install-shell { width: min(100% - 24px, 620px); padding: 26px 0; }
  .install-brand h1 { font-size: 34px; }
  .install-card { padding: 23px 18px; border-radius: 17px; }
  .install-form { grid-template-columns: 1fr; }
  .install-form .full-field, .section-divider { grid-column: auto; }
}
@media (max-width: 430px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { min-height: 108px; }
  .filter-bar { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .flow-row summary { grid-template-columns: 46px minmax(0,1fr) 76px 10px; }
  .company-cell span { display: none; }
  .flow-details { grid-template-columns: 1fr; }
}
