:root {
  --navy: #0b2143;
  --navy-deep: #071528;
  --navy-soft: #18365d;
  --gold: #ad8740;
  --gold-soft: #f4ecd8;
  --cyan: #188b99;
  --green: #2d7c5a;
  --red: #b0544b;
  --ink: #172238;
  --ink-soft: #5b687a;
  --faint: #8a94a2;
  --line: #dfe4e8;
  --line-soft: #edf0f2;
  --surface: #fff;
  --canvas: #f4f6f7;
  --sidebar-width: 242px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; color: var(--ink); background: var(--canvas); font-family: Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(280px, .72fr) minmax(520px, 1.28fr); background: #f4f6f7; }
.login-brand { padding: 38px; display: flex; align-items: flex-start; gap: 12px; color: #fff; background: var(--navy-deep); }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; flex: 0 0 36px; color: var(--navy-deep); background: #c7a75f; font-family: Georgia, serif; font-size: 12px; font-weight: 700; }
.login-brand strong, .sidebar-brand strong { display: block; font-size: 17px; }
.login-brand small, .sidebar-brand small { display: block; margin-top: 3px; color: #96a2b6; font-size: 10px; }
.login-panel { width: min(420px, calc(100% - 40px)); margin: auto; padding: 34px; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 22px 60px rgba(9, 26, 48, .08); }
.login-panel .eyebrow, .page-heading > div > span, .panel-heading .eyebrow { color: var(--gold); font-size: 10px; font-weight: 700; letter-spacing: .12em; }
.login-panel h1 { margin: 10px 0 8px; font-size: 25px; }
.login-panel p { margin: 0 0 25px; color: var(--ink-soft); font-size: 13px; line-height: 1.7; }
.login-panel label { display: grid; gap: 7px; margin-top: 15px; color: #475468; font-size: 12px; font-weight: 600; }
.login-panel input { width: 100%; height: 43px; padding: 0 12px; border: 1px solid #ccd4dc; border-radius: 4px; outline: 0; }
.login-panel input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(173, 135, 64, .12); }
.primary-button, .secondary-button { min-height: 38px; border: 0; border-radius: 4px; font-weight: 600; }
.primary-button { width: 100%; margin-top: 22px; color: #fff; background: var(--navy); }
.primary-button:hover { background: var(--navy-soft); }
.secondary-button { padding: 0 16px; color: #fff; background: var(--navy-soft); }
.form-status { display: block; min-height: 18px; margin-top: 11px; color: var(--red); font-size: 12px; }

.admin-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: var(--sidebar-width); display: flex; flex-direction: column; color: #d7dfeb; background: var(--navy-deep); }
.sidebar-brand { height: 63px; display: flex; align-items: center; gap: 11px; padding: 0 16px; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar nav { min-height: 0; flex: 1; overflow: auto; padding: 12px 9px; }
.nav-group { display: block; padding: 13px 10px 6px; color: #6f7c91; font-size: 9px; font-weight: 700; letter-spacing: .1em; }
.nav-item { width: 100%; height: 39px; display: flex; align-items: center; gap: 11px; padding: 0 12px; color: #aeb8c7; background: transparent; border: 0; border-radius: 4px; text-align: left; font-size: 13px; }
.nav-item i { width: 13px; height: 13px; border: 1.5px solid currentColor; border-radius: 2px; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-item.active { color: #fff; background: #1b355b; box-shadow: inset 3px 0 #c4a35c; }
.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer > a { display: block; padding: 7px 4px 13px; color: #9ba8ba; font-size: 12px; text-decoration: none; }
.admin-user { display: flex; align-items: center; gap: 9px; padding: 10px; background: rgba(255,255,255,.04); }
.admin-user > span { width: 30px; height: 30px; display: grid; place-items: center; color: var(--navy-deep); background: #c7a75f; font-size: 12px; font-weight: 700; }
.admin-user strong, .admin-user small { display: block; }
.admin-user strong { font-size: 12px; }
.admin-user small { margin-top: 2px; color: #8795a9; font-size: 9px; }
.text-button { margin: 8px 0 0; padding: 4px 9px; color: #8795a9; background: transparent; border: 0; font-size: 11px; }

.workspace { grid-column: 2; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; height: 63px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
.topbar > div:first-of-type { display: flex; align-items: center; gap: 10px; color: #8893a1; font-size: 11px; }
.topbar > div:first-of-type strong { color: #28364b; font-size: 13px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.env-label { color: #667386; font-size: 10px; }
.env-label i { width: 7px; height: 7px; display: inline-block; margin-right: 5px; border-radius: 50%; background: #3aa876; box-shadow: 0 0 0 3px rgba(58,168,118,.1); }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; color: #596678; background: #fff; border: 1px solid var(--line); border-radius: 4px; font-size: 18px; }
#menu-button { display: none; }
main { padding: 26px 24px 48px; }
.view { display: none; }
.view.active { display: block; }
.page-heading { min-height: 78px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.page-heading h1 { margin: 7px 0 5px; color: #172439; font-size: 27px; line-height: 1.1; letter-spacing: 0; }
.page-heading p { margin: 0; color: #758193; font-size: 12px; }
.period-switch { display: flex; padding: 3px; background: #e9edef; border-radius: 5px; }
.period-switch button { min-width: 52px; height: 31px; padding: 0 10px; color: #697688; background: transparent; border: 0; border-radius: 3px; font-size: 11px; }
.period-switch button.active { color: #20314a; background: #fff; box-shadow: 0 1px 5px rgba(10,31,61,.1); font-weight: 700; }
.date-filter, .lead-filters { display: flex; align-items: end; gap: 10px; margin-bottom: 14px; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 5px; }
.date-filter label { display: grid; gap: 5px; color: #788496; font-size: 9px; }
.date-filter input, .lead-filters input, .lead-filters select, .lead-row input, .lead-row select, .member-row input, .member-row select, .application-table input, .application-table select { height: 34px; padding: 0 10px; color: #334157; background: #fff; border: 1px solid #d6dde3; border-radius: 4px; font-size: 11px; }
.date-filter > span { align-self: center; color: #9aa3af; font-size: 10px; }
.date-filter small { margin-left: auto; align-self: center; color: #8a94a2; font-size: 10px; }
.lead-filters input { width: min(360px, 50%); }
.lead-filters select { width: 150px; }

.loading-block, .empty-block, .error-block { min-height: 220px; display: grid; place-items: center; color: #8994a2; background: #fff; border: 1px solid var(--line); border-radius: 5px; font-size: 12px; }
.error-block { color: var(--red); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; margin-bottom: 13px; }
.metric-card { min-width: 0; min-height: 116px; padding: 16px; background: #fff; border: 1px solid var(--line); border-radius: 5px; }
.metric-card > span { display: block; color: #6f7b8d; font-size: 10px; }
.metric-card > strong { display: block; margin-top: 12px; color: #172439; font-size: 27px; line-height: 1; letter-spacing: 0; white-space: nowrap; }
.metric-card footer { display: flex; justify-content: space-between; gap: 6px; margin-top: 13px; color: #8b95a3; font-size: 9px; }
.delta { color: var(--green); font-weight: 700; }
.delta.down { color: var(--red); }
.delta.neutral { color: #8993a1; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(270px, .72fr); gap: 13px; margin-bottom: 13px; }
.triple-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; margin-bottom: 13px; }
.double-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; margin-bottom: 13px; }
.panel { min-width: 0; padding: 16px; background: #fff; border: 1px solid var(--line); border-radius: 5px; }
.panel-heading { min-height: 38px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.panel-heading h2 { margin: 4px 0 0; color: #26354a; font-size: 14px; letter-spacing: 0; }
.panel-heading > span { color: #8a94a2; font-size: 9px; }
.trend-chart { width: 100%; height: 245px; display: block; overflow: visible; }
.trend-chart .grid { stroke: #edf0f2; stroke-width: 1; }
.trend-chart .axis-label { fill: #8993a1; font-size: 9px; }
.trend-chart .pv { fill: none; stroke: #ad8740; stroke-width: 2.5; }
.trend-chart .uv { fill: none; stroke: #188b99; stroke-width: 2.2; }
.chart-legend { display: flex; gap: 14px; color: #687588; font-size: 9px; }
.chart-legend i { width: 12px; height: 2px; display: inline-block; margin-right: 4px; vertical-align: middle; }
.realtime-number { padding: 13px 0 17px; text-align: center; border-bottom: 1px solid var(--line-soft); }
.realtime-number strong { display: block; color: var(--cyan); font-size: 38px; }
.realtime-number span { color: #8a94a2; font-size: 9px; }
.mini-metrics { display: grid; grid-template-columns: repeat(2, 1fr); }
.mini-metrics div { padding: 12px; text-align: center; border-right: 1px solid var(--line-soft); }
.mini-metrics div:last-child { border: 0; }
.mini-metrics span, .mini-metrics strong { display: block; }
.mini-metrics span { color: #8a94a2; font-size: 9px; }
.mini-metrics strong { margin-top: 5px; font-size: 15px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.data-table th { padding: 8px; color: #7b8797; background: #f7f8f9; border-bottom: 1px solid var(--line); text-align: left; font-weight: 600; }
.data-table td { padding: 9px 8px; color: #3d4a5e; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table strong { color: #26364c; }
.data-table small { display: block; margin-top: 3px; color: #8993a1; }
.data-table .number { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow: auto; }
.bar-list { display: grid; gap: 11px; }
.bar-item header { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; color: #5f6c7e; font-size: 10px; }
.bar-track { height: 7px; overflow: hidden; background: #edf0f2; border-radius: 2px; }
.bar-track i { display: block; height: 100%; background: var(--cyan); border-radius: 2px; }
.bar-item:nth-child(2n) .bar-track i { background: #6d7f96; }
.funnel-list .bar-track { height: 9px; }
.funnel-list .bar-track i { background: var(--gold); }
.device-summary { display: grid; grid-template-columns: 118px minmax(0, 1fr); align-items: center; gap: 18px; }
.donut { width: 106px; height: 106px; position: relative; border-radius: 50%; background: conic-gradient(var(--cyan) 0 var(--p1), var(--gold) var(--p1) var(--p2), #7d8ca0 var(--p2)); }
.donut::after { content: ""; position: absolute; inset: 27px; border-radius: 50%; background: #fff; }
.legend-list { display: grid; gap: 8px; color: #647184; font-size: 10px; }
.legend-list span { display: flex; justify-content: space-between; gap: 8px; }
.legend-list i { width: 7px; height: 7px; display: inline-block; margin-right: 6px; border-radius: 50%; background: var(--cyan); }
.legend-list span:nth-child(2) i { background: var(--gold); }
.legend-list span:nth-child(3) i { background: #7d8ca0; }

.insight-list { display: grid; gap: 9px; }
.insight { padding: 11px 12px; border-left: 3px solid var(--cyan); background: #f6f8f9; }
.insight.attention { border-left-color: var(--gold); }
.insight.risk { border-left-color: var(--red); }
.insight.ok { border-left-color: var(--green); }
.insight strong { display: block; color: #314056; font-size: 11px; }
.insight p { margin: 4px 0 0; color: #6c7889; font-size: 10px; line-height: 1.55; }
.service-list { display: grid; gap: 8px; }
.service-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 10px; }
.service-row:last-child { border: 0; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(45,124,90,.1); }
.status-dot.bad { background: var(--red); box-shadow: 0 0 0 3px rgba(176,84,75,.1); }
.service-row strong { color: #3a485d; font-size: 10px; }
.service-row span:last-child { color: #8993a1; }

.summary-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 13px; background: #fff; border: 1px solid var(--line); border-radius: 5px; }
.summary-strip > div { padding: 15px; border-right: 1px solid var(--line-soft); }
.summary-strip > div:last-child { border: 0; }
.summary-strip span, .summary-strip strong { display: block; }
.summary-strip span { color: #7d8999; font-size: 9px; }
.summary-strip strong { margin-top: 8px; font-size: 21px; }
.source-error { color: var(--red); }
.source-ok { color: var(--green); }
.lead-card-list { display: grid; gap: 10px; }
.lead-row { display: grid; grid-template-columns: 1.1fr .9fr 1.4fr .75fr; gap: 12px; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 5px; }
.lead-row h3 { margin: 0; font-size: 13px; }
.lead-row p { margin: 5px 0 0; color: #687587; font-size: 10px; line-height: 1.5; overflow-wrap: anywhere; }
.lead-row label { display: grid; gap: 5px; color: #7c8796; font-size: 9px; }
.lead-row textarea { min-height: 64px; padding: 8px; resize: vertical; border: 1px solid #d6dde3; border-radius: 4px; font-size: 10px; }
.lead-row .lead-actions { display: grid; gap: 7px; align-content: start; }
.lead-row .secondary-button { min-height: 32px; font-size: 10px; }
.member-row { display: grid; grid-template-columns: 1.1fr .75fr 1fr 1.2fr; gap: 12px; margin-bottom: 10px; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 5px; }
.member-row h3 { margin: 8px 0 0; color: #26364c; font-size: 13px; }
.member-row p { margin: 5px 0 0; color: #687587; font-size: 10px; line-height: 1.5; overflow-wrap: anywhere; }
.member-row small { display: block; margin-top: 6px; color: #8993a1; font-size: 9px; line-height: 1.5; }
.member-row label { display: grid; gap: 5px; margin-bottom: 8px; color: #7c8796; font-size: 9px; }
.member-row textarea { min-height: 54px; padding: 8px; resize: vertical; border: 1px solid #d6dde3; border-radius: 4px; font-size: 10px; }
.member-row .secondary-button { width: 100%; min-height: 32px; font-size: 10px; }
.application-table td:last-child { min-width: 270px; }
.application-table td:last-child { display: grid; grid-template-columns: 100px 90px minmax(120px, 1fr) 58px; gap: 5px; }
.application-table .secondary-button { min-height: 34px; padding-inline: 8px; font-size: 10px; }
.badge { display: inline-flex; align-items: center; min-height: 20px; padding: 0 7px; color: #5d6878; background: #edf0f2; border-radius: 3px; font-size: 9px; }
.badge.new { color: #8a6521; background: #f5ecd7; }
.badge.contacted { color: #176b78; background: #dff0f2; }
.badge.qualified, .badge.converted { color: #24674c; background: #dfeee7; }
.data-note { margin-top: 12px; padding: 10px 12px; color: #718093; background: #eef2f4; border-radius: 4px; font-size: 10px; line-height: 1.6; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 80; max-width: 330px; padding: 11px 15px; color: #fff; background: #263850; border-radius: 4px; box-shadow: 0 12px 35px rgba(0,0,0,.16); font-size: 11px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .18s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }
.sidebar-backdrop { display: none; }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .triple-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .triple-grid > :last-child { grid-column: 1 / -1; }
  .lead-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .member-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .admin-shell { display: block; }
  .workspace { min-height: 100vh; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 25; display: block; background: rgba(5,17,34,.5); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  #menu-button { display: grid; }
  .topbar { padding: 0 14px; }
  main { padding: 20px 14px 40px; }
  .dashboard-grid, .double-grid { grid-template-columns: 1fr; }
  .summary-strip { grid-template-columns: repeat(2, 1fr); }
  .summary-strip > div { border-bottom: 1px solid var(--line-soft); }
}
@media (max-width: 560px) {
  .login-shell { display: block; padding: 0 0 30px; }
  .login-brand { height: 72px; padding: 18px; }
  .login-panel { margin: 52px auto 0; padding: 25px 20px; }
  .env-label { display: none; }
  .topbar > div:first-of-type > span { display: none; }
  .page-heading { min-height: 104px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .page-heading h1 { font-size: 23px; }
  .page-heading p { max-width: 220px; line-height: 1.5; }
  .period-switch button { min-width: 40px; padding: 0 6px; }
  .metric-grid { gap: 8px; }
  .metric-card { min-height: 110px; padding: 13px; }
  .metric-card > strong { font-size: 23px; }
  .triple-grid { grid-template-columns: 1fr; }
  .triple-grid > :last-child { grid-column: auto; }
  .date-filter { display: grid; grid-template-columns: 1fr 18px 1fr; align-items: end; }
  .date-filter input { width: 100%; min-width: 0; }
  .date-filter .secondary-button { width: 64px; }
  .date-filter small { grid-column: 1 / -1; margin: 0; }
  .lead-filters { display: grid; grid-template-columns: 1fr 120px; }
  .lead-filters input, .lead-filters select { width: 100%; min-width: 0; }
  .lead-filters .secondary-button { width: 64px; }
  .summary-strip { grid-template-columns: repeat(2, 1fr); }
  .lead-row { grid-template-columns: 1fr; }
  .member-row { grid-template-columns: 1fr; }
  .device-summary { grid-template-columns: 98px 1fr; }
  .donut { width: 88px; height: 88px; }
  .donut::after { inset: 23px; }
  .panel { padding: 13px; }
  .table-scroll { margin-inline: -13px; padding-inline: 13px; }
}
