/* D：状态栏、历史、账号、登录、toast、对话框、横幅。只使用 base.css 的令牌。 */

/* ---------- 通用 ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.ui-view { padding-bottom: calc(32px + var(--safe-bottom)); }

.ui-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 12px;
}

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
}
.view-head .btn-plain { margin-right: -8px; }
.view-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-title { font-size: 17px; font-weight: 600; }
.card-note { font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* 表单 */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; color: var(--text-2); }
.form-error { font-size: 14px; color: var(--bad); }
.form-error.is-ok { color: var(--ok); }

/* 键值行 */
.kv { display: flex; flex-direction: column; padding-top: 6px; padding-bottom: 6px; }
.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
}
.kv-row:last-child { border-bottom: 0; }
.kv-label { color: var(--text-2); font-size: 15px; flex: none; }
.kv-value { font-size: 15px; text-align: right; overflow-wrap: anywhere; }
.kv-value-group { display: inline-flex; align-items: center; gap: 4px; }
.kv-action { min-height: 32px; font-size: 14px; margin-right: -8px; }
.kv-value[data-status="error"], .kv-value[data-status="auth-lost"] { color: var(--bad); }
.kv-value[data-status="offline"], .kv-value[data-status="pending"] { color: var(--text-2); }
.kv .btn-block { margin: 12px 0 6px; }

/* ---------- 状态栏 ---------- */
#statusbar.statusbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}

.sb-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 4px var(--gutter) 6px;
}

.sb-main {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
}

.sb-day {
  flex: none;
  min-width: 8.6em; /* 题数、时长变化时不推动右边的元素 */
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.sb-sep { color: var(--text-3); }
.sb-time { color: var(--text-2); }

.sb-goal {
  flex: 1 1 auto;
  min-width: 32px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
}
.sb-goal-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.sb-goal.is-done .sb-goal-fill { background: var(--ok); }

.sb-end {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.sb-sync {
  width: 8px;
  height: 8px;
  margin: 0 6px;
  border-radius: 50%;
  background: var(--ok);
  flex: none;
}
.sb-sync[data-status="syncing"] { background: var(--accent); animation: sb-pulse 1.2s var(--ease) infinite; }
.sb-sync[data-status="offline"] { background: var(--text-3); }
.sb-sync[data-status="error"] { background: var(--warn); }
.sb-sync[data-status="auth-lost"] { background: var(--bad); }
@keyframes sb-pulse { 50% { opacity: 0.35; } }

.sb-guest {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  padding: 0 6px;
  min-height: 40px;
  margin: -3px 0;
  border-radius: var(--r-sm);
  white-space: nowrap;
}

.sb-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: -3px 0; /* 触控区 40px，不撑高 34px 的行 */
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sb-icon[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.sb-icon:active { opacity: 0.6; }

.icon { display: block; }
.icon-fill { fill: currentColor; }
.icon-stroke { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.sb-ops {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 2px;
}

.sb-op {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  line-height: 32px;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sb-op::after {
  /* 视觉 32px，点击区上下各扩 4px（≥ 40px） */
  content: "";
  position: absolute;
  inset: -4px -3px;
}
.sb-op-name { font-size: 13px; color: var(--text-2); }
.sb-op-level { font-size: 15px; font-weight: 600; min-width: 2.1em; text-align: center; }
.sb-op-dot {
  display: inline-block;
  visibility: hidden; /* 始终占位：定级结束时按钮宽度不变 */
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-3);
  align-self: center;
  margin-left: -1px;
}
.sb-op.is-placing .sb-op-dot { visibility: visible; }
.sb-op[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.sb-op[aria-pressed="true"] .sb-op-name { color: var(--accent); }
.sb-op[aria-pressed="true"] .sb-op-dot { background: var(--accent); }
.sb-op:active { opacity: 0.7; }

/* 很窄的屏幕：短名自带运算符时省掉前缀，保证定级圆点不被截断 */
@media (max-width: 359px) {
  .sb-ops { gap: 4px; }
  .sb-op { padding: 0 4px; gap: 3px; }
  .sb-op.has-symbol .sb-op-name { display: none; }
}

@media (min-width: 600px) {
  .sb-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 52px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .sb-main { display: contents; }
  .sb-day { order: 1; }
  .sb-goal { order: 2; flex: 0 1 120px; }
  .sb-ops {
    order: 3;
    display: flex;
    gap: 4px;
    margin: 0 auto;
  }
  .sb-op { background: transparent; padding: 0 10px; }
  .sb-op:hover { background: var(--surface-2); }
  .sb-op[aria-pressed="true"]:hover { background: var(--accent-soft); }
  .sb-end { order: 4; }
}

@media (min-width: 600px) and (max-width: 720px) {
  .sb-inner { gap: 8px; }
  .sb-ops { gap: 0; }
  .sb-op { padding: 0 6px; }
  .sb-goal { min-width: 24px; }
}

/* ---------- 横幅 ---------- */
#banner {
  width: 100%;
  max-width: var(--content-max);
  margin: 6px auto 0;
  padding: 0 var(--gutter);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#banner[hidden] { display: none; }
.banner-item {
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: var(--r);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 14px;
  text-align: left;
}
.banner-item[data-kind="auth"], .banner-item[data-kind="auth-lost"] { background: var(--bad-soft); }
.banner-item.is-action { cursor: pointer; }
.banner-item.is-action:active { opacity: 0.7; }

/* ---------- toast ---------- */
#toast.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 84px);
  z-index: 60;
  max-width: calc(100vw - 2 * var(--gutter));
  padding: 7px 16px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 88%, transparent);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -4px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
#toast.toast:empty { display: none; }
#toast.toast.is-long { width: max-content; white-space: normal; text-align: center; border-radius: 16px; line-height: 1.4; }
#toast.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 600px) {
  #toast.toast { top: calc(var(--safe-top) + 62px); }
}

/* ---------- 对话框 ---------- */
html.has-dialog, html.has-dialog body { overflow: hidden; }

.dlg-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
  padding-bottom: calc(var(--gutter) + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.dlg-panel {
  width: 100%;
  max-width: 360px;
  padding: 24px 20px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  outline: none;
}
.dlg-title { font-size: 18px; font-weight: 600; }
.dlg-message { margin-top: 8px; color: var(--text-2); font-size: 15px; }
.dlg-field { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.dlg-field-label { font-size: 13px; color: var(--text-2); }
.dlg-actions { display: flex; gap: 10px; margin-top: 20px; }
.dlg-actions > .btn { flex: 1; }
.dlg-actions-alt + .dlg-actions { margin-top: 10px; }

/* ---------- 登录 ---------- */
.view-login { justify-content: center; }
.lg-wrap {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  padding: 40px 0 calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 20px;
}
.lg-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.lg-mark {
  width: 60px;
  height: 60px;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 600;
  line-height: 60px;
  text-align: center;
}
.lg-title { font-family: var(--font-display); font-size: 30px; font-weight: 700; letter-spacing: -0.01em; }
.lg-sub { font-size: 15px; }
.lg-tabs { align-self: center; }
.lg-tabs > button { min-width: 96px; }
.lg-offline { font-size: 14px; color: var(--text-2); text-align: center; }
.lg-foot { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.lg-note { font-size: 13px; text-align: center; }

/* ---------- 账号 ---------- */
.ac-notice {
  padding: 10px 14px;
  border-radius: var(--r);
  background: var(--ok-soft);
  font-size: 14px;
}
.ac-notice[data-kind="warn"] { background: var(--accent-soft); }
.ac-notice[data-kind="bad"] { background: var(--bad-soft); color: var(--bad); }
.ac-guest-note { font-size: 14px; padding: 8px 0 0; }
.ac-rejected-note { font-size: 13px; padding: 0 0 10px; border-bottom: 1px solid var(--line); }
.ac-logout { color: var(--bad); }

/* ---------- 历史 ---------- */
.hi-loading, .hi-op-empty { font-size: 14px; padding: 8px 0; }
.hi-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.hi-empty-title { font-size: 17px; font-weight: 600; }
.hi-empty .btn { margin-top: 6px; }

.hi-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.hi-tile { display: flex; flex-direction: column; gap: 2px; padding: 14px; min-width: 0; }
.hi-tile-label { font-size: 13px; }
.hi-tile-value { display: inline-flex; align-items: baseline; gap: 3px; }
.hi-tile-num { font-family: var(--font-display); font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.hi-tile-unit { font-size: 13px; color: var(--text-2); }
.hi-tile-sub { font-size: 12px; line-height: 1.35; word-break: keep-all; overflow-wrap: anywhere; }

.hi-card { display: flex; flex-direction: column; gap: 8px; }
.hi-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hi-op-current { font-size: 14px; }
.hi-legend { font-size: 12px; }
.hi-readout { font-size: 14px; color: var(--text-2); min-height: 21px; }
.hi-trend { font-size: 15px; font-weight: 500; }
.hi-chart-cap { font-size: 13px; font-weight: 500; margin-top: 4px; }
.hi-chart-cap-level { margin-top: 10px; }

/* 数据不足 3 天时的摘要 */
.hi-brief { display: flex; flex-direction: column; gap: 6px; }
.hi-brief-total { display: flex; align-items: baseline; gap: 4px; }
.hi-brief-sep { margin: 0 4px; color: var(--text-3); }
.hi-brief-time { font-size: 15px; color: var(--text-2); }
.hi-brief-rows { display: flex; flex-direction: column; margin-top: 4px; }
.hi-brief-row { padding: 10px 0; border-top: 1px solid var(--line); }
.hi-brief-op { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.hi-brief-detail { font-size: 14px; margin-top: 2px; }

.hi-chart { width: 100%; overflow: hidden; margin: 4px 0 0; }
.hi-chart svg { display: block; max-width: 100%; height: auto; }

.hi-legend-row { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; }
.hi-key { display: inline-flex; align-items: center; gap: 6px; }
.hi-key::before { content: ""; flex: none; }
/* 折线 + 圆点 */
.hi-key-line::before {
  width: 16px; height: 8px;
  background: radial-gradient(circle, var(--accent) 3px, transparent 3.5px) center / 8px 8px no-repeat,
    linear-gradient(var(--accent), var(--accent)) center / 16px 2px no-repeat;
}
.hi-key-over::before { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.hi-key-zone::before {
  width: 16px; height: 8px;
  border-top: 1.5px dashed var(--text-2);
  background: var(--ok-soft);
}

.hi-details summary {
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  width: max-content;
  padding: 4px 0;
}
.hi-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; }
.hi-table th, .hi-table td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.hi-table th:first-child, .hi-table td:first-child { text-align: left; }
.hi-table th { color: var(--text-2); font-weight: 500; }

/* SVG 图表（颜色全部来自令牌） */
.chart { font-family: var(--font); user-select: none; -webkit-user-select: none; touch-action: pan-y; }
.chart text { font-size: 11px; fill: var(--text-3); font-variant-numeric: tabular-nums; }
.chart .chart-bar-label { font-size: 10px; fill: var(--text-2); }
.chart-axis { stroke: var(--line); stroke-width: 1; }
.chart-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-baseline { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 4 4; }
.chart-ref-line { stroke: var(--text-2); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart-zone-ok { fill: var(--ok-soft); fill-opacity: 0.6; }
.chart .chart-y.is-ref { fill: var(--text-2); font-weight: 600; }
/* 分段控件按内容收窄，不拉满整行 */
.hi-range { align-self: flex-start; margin: 4px 0 4px; }
.chart-bar-fill { fill: var(--accent); fill-opacity: 0.45; transition: fill-opacity var(--dur) var(--ease); }
.chart-bar.is-today .chart-bar-fill { fill-opacity: 0.75; }
.chart-bar.is-active .chart-bar-fill { fill-opacity: 1; }
.chart-bar-empty { fill: var(--surface-2); }
.chart-level-line { fill: none; stroke: var(--text-2); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-pct-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-step-mark { fill: var(--text-2); stroke: var(--surface); stroke-width: 2; opacity: 0; }
.chart-step.is-active .chart-step-mark { opacity: 1; }
.chart-dot-mark { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-dot.is-over .chart-dot-mark { fill: var(--warn); }
.chart-dot.is-active .chart-dot-mark { stroke: var(--accent-soft); stroke-width: 7; }
.chart-dot.is-over.is-active .chart-dot-mark { stroke: var(--bad-soft); }
.chart-cursor { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 2 2; }
.chart-hit { fill: transparent; pointer-events: all; cursor: pointer; }

@media (max-width: 380px) {
  .hi-tile { padding: 12px 10px; }
  .hi-tile-num { font-size: 22px; }
}
