:root {
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f5f7;
  color: #172033;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { min-width: 320px; min-height: 100vh; margin: 0; background: #f4f5f7; }
a { color: inherit; }
button, input, select { font: inherit; }

.admin-shell { display: grid; grid-template-columns: 226px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 26px 18px 20px;
  background: #121b2b; color: #dce4f1; display: flex; flex-direction: column;
}
.brand-mark { display: flex; align-items: center; gap: 11px; padding: 0 8px 26px; }
.brand-mark > span { display: grid; place-items: center; width: 35px; height: 35px; border-radius: 9px; background: #f2a93b; color: #182033; font-size: 12px; font-weight: 900; letter-spacing: -.02em; }
.brand-mark div { display: grid; gap: 2px; }
.brand-mark strong { color: #fff; font-size: 14px; }
.brand-mark small { color: #8290a7; font-size: 11px; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav a { display: flex; align-items: center; gap: 11px; border-radius: 8px; padding: 10px 11px; color: #95a2b7; font-size: 13px; font-weight: 650; text-decoration: none; transition: .16s ease; }
.sidebar nav a span { width: 19px; color: #65758e; text-align: center; font-size: 15px; }
.sidebar nav a:hover, .sidebar nav a.active { background: #1d2a3e; color: #fff; }
.sidebar nav a.active span { color: #f2a93b; }
.sidebar-status { display: flex; align-items: flex-start; gap: 9px; margin-top: auto; border: 1px solid #29364b; border-radius: 9px; padding: 12px; background: #172236; }
.sidebar-status div { display: grid; gap: 3px; }
.sidebar-status strong { color: #d8e0eb; font-size: 11px; }
.sidebar-status small { color: #7f8da3; font-size: 10px; }
.live-dot { width: 7px; height: 7px; margin-top: 3px; border-radius: 50%; background: #4bc18a; box-shadow: 0 0 0 4px rgba(75,193,138,.12); }
.logout { display: block; margin-top: 13px; padding: 8px; color: #78869c; font-size: 11px; text-align: center; text-decoration: none; }
.logout:hover { color: #fff; }

.admin-content { min-width: 0; }
.topbar { padding: 32px clamp(24px, 4vw, 58px) 24px; background: #fff; border-bottom: 1px solid #e5e8ed; }
.eyebrow, .section-kicker { margin: 0 0 7px; color: #c57b14; font-size: 10px; font-weight: 850; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; color: #141d2d; font-size: clamp(26px, 3vw, 34px); line-height: 1.12; letter-spacing: -.035em; }
h2 { margin-bottom: 0; color: #172033; font-size: 21px; letter-spacing: -.02em; }
h3 { margin-bottom: 0; color: #1a2435; font-size: 14px; }
.page-summary { max-width: 720px; margin-bottom: 22px; color: #6d7788; font-size: 13px; line-height: 1.65; }
.global-filter { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 9px; }
.global-filter label { display: grid; gap: 5px; }
.global-filter label > span { color: #7a8494; font-size: 10px; font-weight: 700; }
.global-filter select, .global-filter input { height: 36px; min-width: 122px; border: 1px solid #dfe3e9; border-radius: 7px; background: #fafbfc; color: #263247; padding: 0 10px; outline: none; font-size: 12px; }
.global-filter input { width: 160px; }
.global-filter select:focus, .global-filter input:focus { border-color: #d39a43; box-shadow: 0 0 0 3px rgba(211,154,67,.12); }
.global-filter button { height: 36px; margin: 0; border: 0; border-radius: 7px; background: #18253a; color: #fff; padding: 0 17px; font-size: 12px; font-weight: 750; cursor: pointer; }
.clear-filter { height: 36px; display: inline-flex; align-items: center; color: #8a6470; padding: 0 6px; font-size: 11px; text-decoration: none; }
.is-hidden { visibility: hidden; }

.dashboard-main { padding: 7px clamp(24px, 4vw, 58px) 52px; }
.section-block { padding-top: 34px; scroll-margin-top: 10px; }
.section-title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 15px; }
.section-title-row p:not(.section-kicker) { max-width: 680px; margin: 6px 0 0; color: #7a8494; font-size: 12px; line-height: 1.55; }
.scope-chip { border: 1px solid #dfe3e9; border-radius: 999px; background: #fff; color: #687386; padding: 6px 10px; font-size: 10px; white-space: nowrap; }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.metric, .panel { border: 1px solid #e1e4e9; border-radius: 10px; background: #fff; box-shadow: 0 2px 8px rgba(20,32,52,.025); }
.metric { min-height: 127px; padding: 16px; }
.metric-primary { background: #18253a; border-color: #18253a; }
.metric-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.metric-label span { color: #737e90; font-size: 11px; font-weight: 700; }
.metric-label i { color: #9aa4b3; font-size: 11px; font-style: normal; }
.metric-label .tone-good { color: #34b27b; font-size: 8px; }
.metric strong { display: block; margin-top: 18px; color: #172033; font-size: 27px; line-height: 1; letter-spacing: -.035em; }
.metric small { display: block; margin-top: 10px; overflow: hidden; color: #929aa8; font-size: 10px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.metric-primary .metric-label span, .metric-primary small { color: #94a2b7; }
.metric-primary .metric-label i { color: #f2a93b; }
.metric-primary strong { color: #fff; }

.analysis-grid { display: grid; grid-template-columns: 1.35fr 1fr 1fr; gap: 10px; margin-top: 10px; }
.panel { min-width: 0; padding: 17px; }
.panel-wide { min-width: 0; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.panel-heading p { margin: 4px 0 0; color: #8a93a1; font-size: 10px; line-height: 1.45; }
.legend { display: flex; gap: 10px; color: #8b94a3; font-size: 9px; }
.legend span { display: flex; align-items: center; gap: 4px; }
.legend i { width: 6px; height: 6px; border-radius: 50%; background: #d3a04d; }
.legend i.legend-fail { background: #d25e5e; }

.trend-chart { height: 190px; display: flex; align-items: stretch; gap: 5px; padding-top: 10px; }
.trend-column { min-width: 0; flex: 1; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.trend-value { height: 17px; color: #7e8795; font-size: 8px; }
.trend-bar { position: relative; width: min(22px, 65%); min-height: 2px; border-radius: 3px 3px 1px 1px; background: linear-gradient(180deg, #edb55a, #d7942b); overflow: hidden; }
.trend-bar i { position: absolute; right: 0; bottom: 0; left: 0; background: #cf5b5b; }
.trend-label { margin-top: 7px; color: #9aa2af; font-size: 8px; white-space: nowrap; }

.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 10px; border-bottom: 1px solid #edf0f3; color: #3d485a; font-size: 11px; text-align: left; vertical-align: middle; }
th { color: #8b94a3; font-size: 9px; font-weight: 800; letter-spacing: .02em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfbfc; }
.compact-table th, .compact-table td { padding-right: 6px; padding-left: 6px; }
.number-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.operation-dot { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: #8291a6; }
.operation-dot--search_items { background: #cf963e; }
.operation-dot--get_item { background: #4e84b3; }
.operation-dot--oauth_token { background: #8a6ca9; }
.status-text { font-weight: 800; }
.status-text--good { color: #249363; }
.status-text--warn { color: #be7d17; }
.status-text--bad { color: #bd4b4b; }

.rank-list { display: grid; gap: 11px; margin: 0; padding: 0; list-style: none; counter-reset: rank; }
.rank-list li { display: grid; grid-template-columns: minmax(70px, 1fr) minmax(55px, 1.1fr) 24px; align-items: center; gap: 8px; counter-increment: rank; }
.rank-label { overflow: hidden; color: #455165; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.rank-label::before { content: counter(rank) "."; display: inline-block; width: 16px; color: #a3aab5; font-size: 8px; }
.rank-bar { height: 4px; border-radius: 999px; background: #eef0f3; overflow: hidden; }
.rank-bar i { display: block; height: 100%; border-radius: inherit; background: #d59c43; }
.rank-list strong { color: #697486; font-size: 10px; text-align: right; }
.empty-state { min-height: 80px; display: grid; place-items: center; color: #a0a7b2; font-size: 11px; text-align: center; }
.chart-empty { height: 190px; }

.tracking-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 34px; }
.tracking-columns > section + section { border-left: 1px solid #eaedf0; padding-left: 34px; }
.mini-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 5px; }
.mini-heading h3 { font-size: 12px; }
.mini-heading span { color: #9aa2ad; font-size: 9px; }
.tracking-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid #edf0f3; }
.tracking-row:last-child { border-bottom: 0; }
.tracking-row > div:first-child { min-width: 0; }
.tracking-row strong { display: block; overflow: hidden; color: #354154; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.tracking-row small { display: block; margin-top: 4px; color: #949ca8; font-size: 9px; }
.tracking-value { flex: 0 0 auto; text-align: right; }
.tracking-value strong { color: #455168; font-variant-numeric: tabular-nums; }

.user-analysis-grid { display: grid; grid-template-columns: .8fr 1.7fr; gap: 10px; }
.funnel { display: grid; gap: 13px; }
.funnel-step { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 5px 10px; }
.funnel-step span { color: #566176; font-size: 10px; }
.funnel-step strong { color: #293549; font-size: 12px; }
.funnel-step i { grid-column: 1 / -1; display: block; height: 5px; border-radius: 999px; background: linear-gradient(90deg, #daa349, #efc276); }
.funnel-step small { position: absolute; right: 0; bottom: -9px; color: #a0a7b2; font-size: 8px; }
.segment-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.segment-card { min-width: 0; border: 1px solid #e7e9ed; border-radius: 8px; padding: 13px 11px; background: #fafbfc; }
.segment-card strong { display: block; color: #233047; font-size: 23px; }
.segment-card span { display: block; margin-top: 8px; color: #4f5b6e; font-size: 10px; font-weight: 750; }
.segment-card small { display: block; margin-top: 4px; color: #9aa1ac; font-size: 8px; line-height: 1.4; }
.audience-panel { margin-top: 10px; }
.table-note { color: #9aa2ae; font-size: 9px; }
.user-name { display: block; max-width: 150px; overflow: hidden; color: #354154; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.muted-line { display: block; margin-top: 3px; color: #9ba3ae; font-size: 8px; }
.plan-pill, .segment-pill { display: inline-block; border-radius: 999px; background: #eef2f7; color: #526179; padding: 3px 7px; font-size: 8px; font-weight: 750; white-space: nowrap; }
.segment-pill { background: #fff3df; color: #986117; }

.marketing-section { border-radius: 14px; }
.opportunity-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.opportunity-card { min-height: 180px; border: 1px solid #27354b; border-radius: 10px; background: #18253a; padding: 18px; color: #fff; }
.opportunity-card > div { display: flex; align-items: flex-start; justify-content: space-between; }
.opportunity-card > div strong { color: #f1b653; font-size: 30px; line-height: 1; }
.opportunity-type { border: 1px solid #415068; border-radius: 999px; color: #9cacc2; padding: 4px 7px; font-size: 8px; letter-spacing: .08em; }
.opportunity-card h3 { margin-top: 30px; color: #fff; font-size: 13px; }
.opportunity-card p { margin: 8px 0 0; color: #9eacc0; font-size: 9px; line-height: 1.65; }

.disclosure-panel { padding: 0; }
.disclosure-panel > summary { display: flex; align-items: center; justify-content: space-between; padding: 17px; cursor: pointer; list-style: none; }
.disclosure-panel > summary::-webkit-details-marker { display: none; }
.disclosure-panel > summary span { display: grid; gap: 4px; }
.disclosure-panel > summary strong { color: #253146; font-size: 12px; }
.disclosure-panel > summary small { color: #929aa7; font-size: 9px; }
.disclosure-panel > summary i { color: #9aa2ae; font-size: 9px; font-style: normal; }
.disclosure-panel[open] > summary i { visibility: hidden; }
.disclosure-content { border-top: 1px solid #edf0f3; padding: 8px 17px 17px; }
.log-panel { padding: 0 17px; }
.log-table { min-width: 850px; }
.time-cell { white-space: nowrap; }
.request-subject { max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ok, .fail { display: inline-block; border-radius: 999px; padding: 3px 7px; font-size: 8px; font-weight: 850; }
.ok { background: #e7f6ee; color: #208458; }
.fail { background: #fbeaea; color: #b74343; }
details summary { color: #68768b; font-size: 9px; cursor: pointer; white-space: nowrap; }
details code { display: block; width: min(420px, 70vw); max-height: 260px; margin-top: 8px; overflow: auto; border-radius: 6px; background: #151f30; color: #dbe4f1; padding: 10px; font-family: "SFMono-Regular", Consolas, monospace; font-size: 9px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }

.site-records { display: flex; justify-content: center; padding: 0 20px 24px; background: #f4f5f7; }
.site-records__pill { display: inline-flex; align-items: center; gap: 10px; max-width: 100%; overflow-x: auto; color: #9aa1ac; font-size: 9px; white-space: nowrap; scrollbar-width: none; }
.site-records__pill::-webkit-scrollbar { display: none; }
.site-records a { display: inline-flex; align-items: center; gap: 4px; color: inherit; text-decoration: none; }
.site-records__police img { width: 13px; height: 14px; object-fit: contain; }

/* Login */
.login-shell { width: min(980px, calc(100% - 36px)); min-height: calc(100vh - 80px); margin: 0 auto; display: grid; grid-template-columns: 1.1fr minmax(320px, .7fr); align-items: center; gap: 60px; }
.login-intro h1 { font-size: 42px; }
.lede { max-width: 560px; color: #697487; font-size: 15px; line-height: 1.8; }
.login-highlights { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.login-highlights span { border: 1px solid #dfe3e9; border-radius: 999px; background: #fff; color: #5b6678; padding: 7px 11px; font-size: 10px; }
.login-card { padding: 28px; box-shadow: 0 18px 55px rgba(20,32,52,.08); }
.card-heading { margin-bottom: 20px; }
.login-card label { display: block; margin: 13px 0 6px; color: #596578; font-size: 11px; font-weight: 700; }
.login-card input { width: 100%; height: 42px; border: 1px solid #d9dee6; border-radius: 7px; background: #fafbfc; padding: 0 11px; outline: none; }
.login-card input:focus { border-color: #d39a43; box-shadow: 0 0 0 3px rgba(211,154,67,.12); }
.login-card button { width: 100%; height: 42px; margin-top: 18px; border: 0; border-radius: 7px; background: #18253a; color: #fff; font-weight: 750; cursor: pointer; }
.error { border-radius: 6px; background: #fbeaea; color: #b74343; margin: 12px 0 0; padding: 8px 10px; font-size: 10px; }

@media (max-width: 1220px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .analysis-grid { grid-template-columns: 1fr 1fr; }
  .analysis-grid .panel-wide { grid-column: 1 / -1; }
  .segment-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .admin-shell { grid-template-columns: 70px minmax(0, 1fr); }
  .sidebar { padding: 20px 10px; align-items: center; }
  .brand-mark { padding: 0 0 22px; }
  .brand-mark div, .sidebar nav a:not(.active) { }
  .brand-mark div, .sidebar nav a { font-size: 0; }
  .sidebar nav a { justify-content: center; width: 42px; padding: 10px; }
  .sidebar nav a span { font-size: 15px; }
  .sidebar-status, .sidebar .logout { display: none; }
  .tracking-columns { grid-template-columns: 1fr; gap: 12px; }
  .tracking-columns > section + section { border-top: 1px solid #eaedf0; border-left: 0; padding-top: 18px; padding-left: 0; }
  .user-analysis-grid { grid-template-columns: 1fr; }
  .opportunity-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .admin-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; flex-direction: row; justify-content: space-between; padding: 12px 16px; }
  .brand-mark { padding: 0; }
  .brand-mark div { display: grid; }
  .sidebar nav { display: flex; }
  .sidebar nav a { display: none; }
  .sidebar nav a.active { display: flex; }
  .topbar, .dashboard-main { padding-right: 16px; padding-left: 16px; }
  .global-filter label { flex: 1 1 42%; }
  .global-filter select, .global-filter input { width: 100%; min-width: 0; }
  .global-filter button { flex: 1; }
  .metric-grid, .analysis-grid { grid-template-columns: 1fr 1fr; }
  .analysis-grid .panel-wide { grid-column: 1 / -1; }
  .metric { min-height: 116px; }
  .segment-grid { grid-template-columns: 1fr 1fr; }
  .opportunity-grid { grid-template-columns: 1fr; }
  .opportunity-card { min-height: 150px; }
  .section-title-row { align-items: flex-start; flex-direction: column; }
  .login-shell { min-height: auto; grid-template-columns: 1fr; gap: 28px; padding: 60px 0 20px; }
  .login-intro h1 { font-size: 32px; }
}

/* User analytics page */
.activity-panel { margin-top: 10px; }
.conversion-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 620px; }
.legend i.legend-new { background: #4e84b3; }
.trend-bar--split { display: flex; flex-direction: column; background: transparent; overflow: hidden; }
.trend-bar--split .seg { display: block; width: 100%; }
.trend-bar--split .seg--returning { background: linear-gradient(180deg, #edb55a, #d7942b); }
.trend-bar--split .seg--new { background: #4e84b3; }

.risk-badge { display: inline-block; border-radius: 999px; padding: 3px 7px; font-size: 8px; font-weight: 850; white-space: nowrap; }
.risk-badge--active { background: #e7f6ee; color: #208458; }
.risk-badge--cooling { background: #fdf3e2; color: #b07a1a; }
.risk-badge--silent { background: #f6e9d8; color: #a35c14; }
.risk-badge--churned { background: #fbeaea; color: #b74343; }
.row-highlight td { background: #fff8ec; }
.row-highlight:hover td { background: #fff4e0; }
.expiry-soon { color: #b74343; font-size: 10px; font-weight: 750; white-space: nowrap; }
.muted-cell { color: #9ba3ae; font-size: 10px; }

.kw-trend { color: #8b94a3; font-size: 9px; font-weight: 750; white-space: nowrap; }
.kw-trend--up { color: #208458; }
.kw-trend--down { color: #b74343; }
.kw-trend--new { color: #4e84b3; }
.kw-opportunity { display: inline-block; border-radius: 999px; background: #fff3df; color: #986117; padding: 3px 7px; font-size: 8px; font-weight: 850; white-space: nowrap; }

.conversion-summary { display: grid; place-items: center; min-height: 160px; text-align: center; }
.conversion-summary strong { color: #172033; font-size: 38px; letter-spacing: -.03em; }
.conversion-summary p { max-width: 240px; margin: 10px auto 0; color: #8a93a1; font-size: 10px; line-height: 1.6; }

@media (max-width: 640px) {
  .conversion-metrics { grid-template-columns: 1fr 1fr; }
}
