:root {
  --ink: #22302b;
  --paper: #f6f7f2;
  --jade: #2f7d63;
  --mint: #dcebe3;
  --amber: #d99a3d;
  --coral: #d96c5f;
  --muted: #63726b;
  --rule: #d8dfd7;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; font-variant-numeric: tabular-nums; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
button, input, select { min-height: 40px; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
button, input, select, textarea { border-radius: 5px; }
input, select, textarea { max-width: 100%; min-width: 0; border: 1px solid #b9c7bd; padding: 8px 10px; background: #fff; color: var(--ink); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--jade); outline-offset: 3px; }
button:hover:not(:disabled) { filter: brightness(.96); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: 28px; font-weight: 650; letter-spacing: -.04em; }
h2 { margin-bottom: 5px; font-size: 17px; font-weight: 650; }
p { max-width: 78ch; }

.shell { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 100vh; }
.login-panel { max-width: 440px; margin: 10vh auto; padding: 32px; border-top: 3px solid var(--jade); }
.login-panel .brand__mark { margin-bottom: 24px; }
.login-panel h1 { font-size: 26px; }
.login-panel p { font-size: 14px; }
.login-panel canvas { display: block; width: 240px; height: 240px; max-width: 100%; margin: 24px 0 12px; background: #fff; }
.credential-login-form { display: grid; gap: 16px; margin-top: 24px; }
.credential-login-form label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.credential-login-form input { width: 100%; min-height: 44px; }
.credential-login-form .primary-button { min-height: 44px; }
.login-pair-panel { margin: 24px 0; padding: 20px; background: var(--mint); border: 1px solid #b9d5c5; border-radius: 12px; }
.login-pair-label { color: var(--jade); font-size: 13px; font-weight: 650; }
.login-pair-code { display: block; margin: 10px 0 8px; color: var(--ink); font-size: clamp(28px, 7vw, 38px); font-weight: 700; letter-spacing: .16em; line-height: 1.2; font-variant-numeric: tabular-nums; user-select: all; overflow-wrap: anywhere; }
.login-pair-hint { margin: 0; color: var(--muted); }
.login-scan-label { margin: 20px 0 0; color: var(--muted); font-size: 13px; font-weight: 650; }
.login-help { color: var(--muted); margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--rule); }
@media (max-width: 600px) {
  .login-panel { margin: 3vh auto; padding: 24px 18px; }
  .login-pair-panel { padding: 20px 14px; }
  .login-scan-label, #login-qr { display: none !important; }
}
#logout-button { margin-top: 20px; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; padding: 32px 16px 24px; background: #eef1e9; border-right: 1px solid var(--rule); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 36px; }
.brand__mark { display: grid; place-items: center; width: 36px; height: 42px; flex: none; border: 1px solid var(--jade); border-radius: 5px 10px 10px 5px; color: var(--jade); background: var(--mint); font-weight: 700; font-size: 20px; }
.brand__name { font-size: 17px; font-weight: 650; white-space: nowrap; }
.brand__meta { margin-top: 2px; font-size: 10px; color: var(--muted); white-space: nowrap; }
.nav { display: grid; gap: 7px; }
.nav__item { padding: 11px 16px; width: 100%; border: 0; background: transparent; color: var(--muted); font-weight: 550; text-align: left; }
.nav__item--active { background: var(--mint); color: var(--jade); box-shadow: inset 3px 0 var(--jade); }
.sidebar__foot { display: flex; align-items: center; gap: 8px; margin-top: auto; padding: 24px 8px 0; color: var(--muted); font-size: 12px; }
.state-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.state-dot--ok { background: var(--jade); }
.workspace { min-width: 0; padding: 36px clamp(20px, 3vw, 48px) 48px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 26px; }
.topbar p { margin-bottom: 0; font-size: 13px; color: var(--muted); }
.refresh-button, .primary-button, .secondary-button, .status-button, .text-button { padding: 8px 15px; border: 1px solid transparent; font-size: 13px; font-weight: 550; white-space: nowrap; }
.primary-button { color: #fff; background: var(--jade); }
.refresh-button, .secondary-button { color: var(--ink); border-color: #b9c7bd; background: transparent; }
.text-button { color: var(--jade); background: transparent; }
.muted, .chart-note, .chart-key { color: var(--muted); font-size: 12px; }
.filter-rail { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; padding: 15px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.mode-label { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.mode-badge { display: inline-block; padding: 4px 8px; background: var(--mint); color: #24513e; font-size: 12px; font-weight: 650; }
.mode-badge[data-mode="fixture"] { color: #704712; background: #f6e7c9; border-left: 3px solid var(--amber); }
.mode-badge[data-mode="cloud-unavailable"] { color: #863d32; background: #f8e2dc; border-left: 3px solid var(--coral); }
.date-filter { display: flex; align-items: end; flex-wrap: wrap; gap: 8px; }
.date-filter label, .user-filters label { display: grid; gap: 4px; font-size: 11px; color: var(--muted); min-width: 0; }
.date-filter input { width: 143px; font-size: 12px; }
.notice { margin: 18px 0; padding: 16px 18px; background: #f6e7c9; border-left: 3px solid var(--amber); color: #664817; font-size: 13px; overflow-wrap: anywhere; }

.summary-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); padding: 28px 0 30px; }
.metric { min-width: 0; padding: 0 16px; border-right: 1px solid var(--rule); }
.metric:first-child { padding-left: 0; }
.metric:last-child { padding-right: 0; border: 0; }
.metric__label { color: var(--muted); font-size: 12px; }
.metric__value { margin-top: 10px; font-weight: 600; font-size: clamp(18px, 1.9vw, 28px); letter-spacing: -.04em; white-space: nowrap; }
.activity-sheet { padding: 26px 28px 15px; border: 1px solid #c7dacf; border-radius: 10px; background: #eaf1e9; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 19px; }
.section-heading p { color: var(--muted); font-size: 12px; margin: 5px 0 0; }
.chart-key { flex: none; }
.heatmap-scroll { overflow-x: auto; padding: 4px 0; }
.hourly-heatmap { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 4px; min-width: 530px; }
.hour-cell { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; height: 96px; border-radius: 3px; }
.heat-0 { background: #dce5db; color: #596c5e; }
.heat-1 { background: #bbd9c6; color: #294f39; }
.heat-2 { background: #8fc2a5; color: #234431; }
.heat-3 { background: #487c60; color: #fff; }
.heat-4 { background: var(--jade); color: #fff; }
.hour-cell__count { font-size: 14px; font-weight: 650; }
.hour-cell__label { font-size: 10px; }
.time-periods { display: grid; grid-template-columns: repeat(4, 1fr); margin: 9px 0 25px; font-size: 11px; color: var(--muted); }
.time-periods span:not(:first-child) { text-align: center; }
.time-periods span:last-child { text-align: right; }
.weekday-bars { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 18px; padding-top: 19px; border-top: 1px solid #c7dacf; }
.weekday { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; font-size: 11px; color: #52685a; }
.weekday__track { height: 4px; background: #d1dfd1; }
.weekday__track i { display: block; height: 100%; background: var(--jade); }
.weekday strong { font-weight: 600; }
.chart-note { margin: 12px 0 0; line-height: 1.6; }
.overview-ledger { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 28px; padding: 28px 0; margin-bottom: 22px; border-bottom: 1px solid var(--rule); }
.overview-ledger section { min-width: 0; }
.overview-ledger section + section { border-left: 1px solid var(--rule); padding-left: 28px; }
.overview-ledger .chart-note { margin-top: 2px; }
.daily-bars { display: flex; align-items: end; gap: 12px; overflow-x: auto; padding: 2px 2px 8px; }
.daily-bar { display: flex; flex: 1 0 78px; flex-direction: column; align-items: center; gap: 6px; font-size: 10px; white-space: nowrap; }
.daily-bar strong { font-weight: 550; font-size: 12px; }
.daily-bar__track { display: flex; align-items: end; width: 24px; height: 82px; border-bottom: 1px solid #a0baaa; background: #edf0e8; }
.daily-bar__track i { display: block; width: 100%; background: var(--jade); border-radius: 3px 3px 0 0; }
.ledger-summary { margin: 15px 0 0; font-size: 12px; }
.ledger-summary > div { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 5px 0; }
.ledger-summary dt { color: var(--muted); }
.ledger-summary dd { margin: 0; font-size: 15px; font-weight: 600; }
.ledger-link { min-height: 30px; padding: 0; border: 0; background: transparent; color: var(--jade); font-weight: 650; text-decoration: underline; text-underline-offset: 4px; }
.revenue-section .ledger-summary > div:first-child { display: block; padding-bottom: 12px; }
.revenue-section .ledger-summary > div:first-child dd { font-size: 30px; color: var(--jade); letter-spacing: -.035em; margin-top: 6px; }
.user-section { margin-top: 28px; }
.user-filters { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; padding-bottom: 22px; }
.user-filters input, .user-filters select { font-size: 12px; }
.user-filters .search-field { flex: 1 1 200px; }
.table-wrap { min-width: 0; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.drilldown-table { min-width: 610px; }
.data-table th, .data-table td { padding: 15px 10px; border-bottom: 1px solid var(--rule); font-size: 12px; text-align: left; vertical-align: top; word-break: break-word; }
.data-table th { border-top: 1px solid var(--rule); background: #edf0e8; color: var(--muted); font-size: 11px; font-weight: 500; }
.data-table th small { display: block; font-size: 10px; margin-top: 4px; }
.data-table th.numeric, .data-table td.numeric { text-align: right; }
.data-table td strong { font-weight: 550; }
.data-table tbody tr:hover { background: #eff3ea; }
.analytics-table th:first-child { width: 17%; }
.analytics-table th:nth-child(2) { width: 18%; }
.analytics-table th:nth-child(3) { width: 12%; }
.analytics-table th:nth-child(4) { width: 12%; }
.analytics-table th:nth-child(5) { width: 15%; }
.analytics-table th:nth-child(6) { width: 11%; }
.analytics-table th:nth-child(7) { width: 15%; }
.user-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-id { overflow-wrap: anywhere; }
.scope-label { display: none; }
.cell-note { display: block; font-size: 10px; color: var(--muted); margin-top: 5px; }
.tracking-note { display: block; font-size: 10px; color: #876223; margin-top: 5px; }
.membership-state { color: var(--muted); font-size: 11px; }
.membership-state--active { color: var(--jade); }
.data-table .empty-row { padding: 30px 12px; text-align: center; color: var(--muted); }
.empty-state { color: var(--muted); font-size: 12px; }
.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: end; gap: 10px; margin-top: 20px; font-size: 12px; color: var(--muted); }
.pagination > span { margin-right: auto; }
.pagination label { display: flex; align-items: center; gap: 6px; }
.pagination select { font-size: 12px; }

/* User detail continues the course ledger: ruled chapters and paired scopes. */
.user-open { min-height: 32px; max-width: 100%; border: 0; padding: 0; background: transparent; color: var(--jade); text-align: left; font-weight: 650; text-decoration: underline; text-underline-offset: 4px; }
.analytics-table tr[data-user-id] { cursor: pointer; }
.detail-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; padding: 14px 0; border-top: 1px solid var(--rule); }
.detail-toolbar label { display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--muted); min-width: 0; }
.detail-toolbar select { max-width: 240px; }
.detail-toolbar .mode-badge { margin-left: auto; }
.detail-heading { padding: 20px 0 8px; }
.detail-heading h2 { font-size: 30px; overflow-wrap: anywhere; }
.detail-nav { display: flex; flex-wrap: wrap; gap: 4px 16px; border-block: 1px solid var(--rule); background: var(--mint); padding: 8px 12px; }
.detail-nav a { display: inline-flex; align-items: center; min-height: 40px; color: var(--jade); font-size: 13px; font-weight: 600; text-decoration: none; }
.detail-nav a:focus-visible { outline: 3px solid var(--jade); outline-offset: 3px; }
.detail-nav a:hover { text-decoration: underline; text-underline-offset: 5px; }
.detail-chapter { border-bottom: 1px solid var(--rule); padding: 28px 0; scroll-margin-top: 18px; overflow-wrap: anywhere; }
.detail-chapter > h2 { color: var(--jade); margin-bottom: 16px; }
.detail-chapter h3 { font-size: 14px; font-weight: 600; margin: 24px 0 12px; }
.detail-chapter h4 { font-size: 13px; font-weight: 600; margin: 0 0 8px; }
.detail-ledger { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 32px; margin: 12px 0; font-size: 12px; }
.detail-ledger > div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--rule); min-width: 0; }
.detail-ledger dt { flex: 0 0 auto; max-width: 50%; color: var(--muted); }
.detail-ledger dd { margin: 0; text-align: right; min-width: 0; overflow-wrap: anywhere; }
.scope-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px; }
.scope-columns > section { min-width: 0; }
.scope-columns > section + section { border-left: 1px solid var(--rule); padding-left: 32px; }
.scope-columns .detail-ledger { grid-template-columns: minmax(0, 1fr); }
.detail-record { border-bottom: 1px solid var(--rule); padding: 18px 0; }
.detail-record:last-child { border-bottom: 0; }
.detail-record .detail-ledger { margin-bottom: 0; }
.detail-record .detail-ledger > div { border: 0; padding: 5px 0; }
.record-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.record-heading h4 { margin: 0; }
.child-heading { display: flex; align-items: center; gap: 12px; }
.child-heading h4 { margin: 0; }
.child-avatar { width: 40px; height: 40px; object-fit: cover; border-radius: 5px; flex: none; }
.child-avatar--placeholder { display: grid; place-items: center; background: var(--mint); color: var(--jade); font-size: 18px; }
.quality-badge, .payment-badge { font-size: 11px; padding: 3px 8px; background: #f6e7c9; color: #704712; }
.quality-badge[data-quality="exact"], .payment-badge--paid { color: #24513e; background: var(--mint); }
.detail-status { padding: 16px; font-size: 13px; background: #edf0e8; border-left: 3px solid var(--jade); }
.detail-status--error { background: #f8e2dc; border-color: var(--coral); }
.detail-status p { margin-bottom: 10px; }
.detail-activity { background: #e3ecdf; padding: 20px; margin: 18px 0; }
.detail-activity h4 { margin-top: 22px; }
.detail-activity h4:first-child { margin-top: 0; }
.detail-activity .weekday-bars { border: 0; padding-top: 4px; }

/* Existing management views retain their navigation, record details and actions. */
.work-area { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.list-panel, .detail-panel { min-width: 0; border: 1px solid var(--rule); background: #fff; border-radius: 6px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; }
.toolbar__title, .detail-panel__title { font-size: 15px; font-weight: 600; }
.toolbar__actions { display: flex; gap: 8px; }
.detail-panel { padding: 18px; }
.detail-content { margin-top: 14px; font-size: 12px; overflow-wrap: anywhere; }
.detail-row { display: grid; grid-template-columns: 85px minmax(0, 1fr); gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--rule); }
.detail-row__label { color: var(--muted); }
.status-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.status-button { background: var(--paper); }
.status-button--active { color: var(--jade); background: var(--mint); }
.announcement-form { display: none; gap: 12px; margin-top: 18px; }
.announcement-form--visible { display: grid; }
.announcement-form label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.announcement-form textarea { resize: vertical; width: 100%; }
.announcement-form .checkbox-line { display: flex; align-items: center; gap: 8px; }

@media (max-width: 1150px) {
  .workspace { padding: 26px 22px; }
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 24px; }
  .metric:nth-child(3) { border: 0; }
  .metric:nth-child(4) { padding-left: 0; }
  .metric__value { font-size: 24px; }
  .overview-ledger { grid-template-columns: 1.2fr 1fr; }
  .overview-ledger .trend-section { grid-column: 1 / -1; border-bottom: 1px solid var(--rule); padding-bottom: 22px; }
  .overview-ledger .conversion-section { padding-left: 0; border-left: 0; }
  .weekday-bars { gap: 10px; }
  .weekday { grid-template-columns: 1fr auto; gap: 6px; }
  .weekday__track { grid-column: 1 / -1; grid-row: 2; }
  .work-area { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { position: static; height: auto; padding: 16px 16px 0; border-right: 0; border-bottom: 1px solid var(--rule); }
  .brand { padding: 0 0 14px; }
  .brand__mark { width: 30px; height: 34px; font-size: 16px; }
  .brand__meta { font-size: 10px; }
  .sidebar__foot { display: none; }
  .nav { display: flex; overflow-x: auto; gap: 3px; padding-bottom: 8px; }
  .nav__item { flex: none; width: auto; padding: 9px 12px; font-size: 12px; }
  .nav__item--active { box-shadow: inset 0 -2px var(--jade); }
  .workspace { padding: 24px 16px 36px; }
  .topbar { gap: 12px; margin-bottom: 20px; }
  h1 { font-size: 24px; }
  .topbar p { font-size: 12px; }
  .filter-rail { gap: 14px; }
  .date-filter { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 9px; }
  .date-filter input { width: 100%; }
  .summary-grid { display: flex; overflow-x: auto; padding: 24px 0; }
  .metric { min-width: 130px; padding: 0 16px; flex: none; }
  .metric:nth-child(3) { border-right: 1px solid var(--rule); }
  .metric:nth-child(4) { padding-left: 16px; }
  .metric__value { font-size: 23px; }
  .activity-sheet { padding: 20px 14px 16px; }
  .section-heading { align-items: start; gap: 10px; }
  .activity-sheet .section-heading { display: block; }
  .chart-key { display: block; margin-top: 10px; font-size: 10px; }
  .hour-cell { height: 85px; }
  .time-periods { display: none; }
  .weekday-bars { margin-top: 18px; }
  .weekday { font-size: 10px; }
  .chart-note { font-size: 11px; }
  .overview-ledger { gap: 20px; grid-template-columns: minmax(0, 1fr); padding-bottom: 20px; }
  .overview-ledger section + section { border: 0; padding-left: 0; }
  .overview-ledger .conversion-section { padding-bottom: 20px; border-bottom: 1px solid var(--rule); }
  .ledger-summary > div { padding: 7px 0; }
  .user-filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .user-filters .search-field { grid-column: 1 / -1; }
  .user-filters button { grid-column: 1 / -1; }
  .analytics-table, .analytics-table tbody, .analytics-table tr, .analytics-table td { display: block; width: 100%; }
  .analytics-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .analytics-table tr { padding: 16px 0; border-top: 1px solid var(--rule); }
  .analytics-table td, .analytics-table td.numeric { display: grid; grid-template-columns: 95px minmax(0, 1fr); text-align: right; border: 0; padding: 6px 0; }
  .analytics-table td::before { content: attr(data-label); text-align: left; color: var(--muted); font-size: 11px; grid-column: 1; grid-row: 1 / span 5; }
  .analytics-table td > * { grid-column: 2; }
  .analytics-table td:first-child { margin-bottom: 7px; }
  .analytics-table .user-name { font-size: 16px; }
  .analytics-table .cell-note { font-size: 11px; }
  .analytics-table .scope-label { display: inline; }
  .analytics-table td.empty-row { display: block; padding: 24px 10px; text-align: center; }
  .analytics-table td.empty-row::before { content: none; }
  .pagination { gap: 8px; }
  .pagination > span { flex-basis: 100%; }
  .pagination label { margin-right: auto; }
  .pagination button { padding: 8px 10px; }
  .user-open { text-align: right; justify-self: end; }
  .detail-toolbar { gap: 12px; }
  .detail-toolbar label { order: 3; width: 100%; }
  .detail-toolbar select { flex: 1; min-width: 0; }
  .detail-heading h2 { font-size: 26px; }
  .detail-nav { gap: 2px 12px; padding: 7px 10px; }
  .detail-nav a { font-size: 12px; }
  .detail-chapter { padding: 24px 0; }
  .detail-ledger, .scope-columns { grid-template-columns: minmax(0, 1fr); }
  .scope-columns { gap: 4px; }
  .scope-columns > section + section { padding-left: 0; border-left: 0; border-top: 1px solid var(--rule); }
  .detail-ledger > div { gap: 10px; }
  .detail-activity { padding: 16px 10px; }
}

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