/* Copyright (c) 2026 zenitudeserenity
   All rights reserved.
   两端共用组件（06 §四）。原生元素 + 一个类名，不做组件框架。
   🔴 颜色从不单独表达状态：每个状态都配图标或文字。动效只动 transform / opacity。 */

/* ---------------------------------------------------------------- 图标 */
.ico { display: inline-block; vertical-align: -0.22em; width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75;
       stroke-linecap: round; stroke-linejoin: round; }
.ico-sm { width: 16px; height: 16px; }
.ico-lg { width: 28px; height: 28px; }

/* ---------------------------------------------------------------- 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap); padding: 0 var(--sp-4); border-radius: var(--r-md);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background var(--dur-fast), transform var(--dur-fast);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--err); border-color: var(--err); background: var(--surface); }
.btn-danger:hover { background: var(--err-soft); }
.btn-sm { min-height: 28px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: var(--tap); }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }

/* ---------------------------------------------------------------- 表单 */
.field { display: grid; gap: var(--sp-1); margin-bottom: var(--sp-4); }
.field > label, .label { font-weight: 600; font-size: var(--fs-sm); }
.hint { color: var(--text-2); font-size: var(--fs-sm); }
.field-err { color: var(--err); font-size: var(--fs-sm); }
.field-err:empty { display: none; }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: 0 var(--sp-3);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); font-size: max(var(--fs-md), 16px);
}
:root[data-ui="admin"] .input, :root[data-ui="admin"] .select, :root[data-ui="admin"] .textarea { font-size: var(--fs-md); }
.textarea { padding: var(--sp-2) var(--sp-3); min-height: 96px; line-height: 1.5; resize: vertical; }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--err); }
.check { display: flex; width: fit-content; gap: var(--sp-2); align-items: center; min-height: var(--tap); cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 76px; }
.pw-wrap .btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); min-height: calc(var(--tap) - 8px); }

/* ---------------------------------------------------------------- 分段按钮（≤4 项的选择） */
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r-md); overflow: hidden; }
.seg button { border: 0; background: var(--surface); min-height: var(--tap); padding: 0 var(--sp-4); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button[aria-pressed="true"], .seg button[aria-checked="true"] { background: var(--primary); color: var(--on-primary); font-weight: 600; }

/* ---------------------------------------------------------------- 状态标签：圆点 + 文字 */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 2px solid currentColor; flex: none; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-ok::before, .badge-run::before { background: currentColor; }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-warn::before { border-radius: 2px; transform: rotate(45deg); background: currentColor; }
.badge-err { background: var(--err-soft); color: var(--err); }
.badge-err::before { border-radius: 1px; background: currentColor; }
.badge-run { background: var(--primary-soft); color: var(--primary); }
.badge-off::before { background: transparent; }          /* 空心圈 = 离线 / 没有 */
.badge-plain::before { display: none; }

/* ---------------------------------------------------------------- 卡片 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
        padding: var(--sp-4); box-shadow: var(--shadow-1); min-width: 0; }
.card-title { font-size: var(--fs-lg); font-weight: 650; margin-bottom: var(--sp-2);
              display: flex; align-items: center; gap: var(--sp-2); }
.card-title .sp { flex: 1; }
.card-sub { color: var(--text-2); font-size: var(--fs-sm); }
.card.off { opacity: .72; }
a.card { color: inherit; text-decoration: none; display: block; }
a.card:hover { border-color: var(--line-strong); }
.reading { font-size: var(--fs-num); font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; }
.reading small { font-size: var(--fs-md); color: var(--text-2); font-weight: 500; margin-left: 2px; }
.grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.stack { display: grid; gap: var(--sp-4); }
.row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.row .sp { flex: 1; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); font-size: var(--fs-sm); }
.err-text { color: var(--err); }
.ok-text { color: var(--ok); }
.section-title { font-size: var(--fs-lg); font-weight: 650; margin: var(--sp-5) 0 var(--sp-3);
                 display: flex; align-items: center; gap: var(--sp-2); }
.section-title .sp { flex: 1; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-1) var(--sp-4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-2); }
.kv dd { min-width: 0; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- 表格 */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.table { width: 100%; font-size: var(--fs-sm); }
.table th, .table td { padding: var(--sp-2) var(--sp-3); text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { background: var(--surface-2); color: var(--text-2); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr.clickable { cursor: pointer; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th button.sort { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.table th button.sort:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.table th[aria-sort="ascending"] button.sort::after { content: "▲"; font-size: 10px; }
.table th[aria-sort="descending"] button.sort::after { content: "▼"; font-size: 10px; }

/* ---------------------------------------------------------------- 对话框 / 抽屉 / 底部弹层（原生 <dialog>） */
dialog { border: 0; padding: 0; color: var(--text); background: var(--surface); box-shadow: var(--shadow-2); }
dialog::backdrop { background: var(--scrim); }
.dialog { border-radius: var(--r-lg); width: min(480px, calc(100vw - 32px)); }
.dialog-head { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-4) var(--sp-4) 0; }
.dialog-head h2 { font-size: var(--fs-lg); flex: 1; }
.dialog-body { padding: var(--sp-4); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: 0 var(--sp-4) var(--sp-4); flex-wrap: wrap; }
.drawer { margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: 480px; max-width: 100vw; border-radius: 0;
          display: flex; flex-direction: column; }
.drawer[open] { animation: slide-in var(--dur) var(--ease-out); }
.drawer .dialog-body { flex: 1; overflow-y: auto; }
.sheet { margin: auto auto 0; width: 100%; max-width: 640px; border-radius: var(--r-lg) var(--r-lg) 0 0;
         max-height: 90vh; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.sheet[open] { animation: slide-up var(--dur) var(--ease-out); }
.sheet .dialog-body { overflow-y: auto; }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } }

/* ---------------------------------------------------------------- 提示条 / 横幅 / 空状态 / 骨架 */
.toasts { position: fixed; z-index: var(--z-toast); left: 50%; transform: translateX(-50%);
          bottom: calc(var(--sp-5) + env(safe-area-inset-bottom)); display: grid; gap: var(--sp-2);
          width: min(440px, calc(100vw - 32px)); pointer-events: none; }
:root[data-ui="app"] .toasts { bottom: calc(88px + env(safe-area-inset-bottom)); }
.toast { pointer-events: auto; display: flex; gap: var(--sp-3); align-items: center; padding: var(--sp-3) var(--sp-4);
         border-radius: var(--r-md); background: var(--text); color: var(--bg); box-shadow: var(--shadow-2);
         animation: slide-up var(--dur) var(--ease-out); }
.toast .sp { flex: 1; }
.toast .btn { min-height: 32px; background: transparent; color: inherit; border-color: currentColor; }
.toast-err { background: var(--err); color: #fff; }
.banner { display: flex; gap: var(--sp-3); align-items: center; padding: var(--sp-3) var(--sp-4);
          border-radius: var(--r-md); border: 1px solid; font-size: var(--fs-sm); flex-wrap: wrap; }
.banner .sp { flex: 1; }
.banner-warn { background: var(--warn-soft); border-color: var(--warn); color: var(--text); }
.banner-err { background: var(--err-soft); border-color: var(--err); color: var(--text); }
.banner-info { background: var(--primary-soft); border-color: var(--primary); color: var(--text); }
.empty { text-align: center; padding: var(--sp-6) var(--sp-4); color: var(--text-2); display: grid; gap: var(--sp-3); justify-items: center; }
.empty .ico { width: 36px; height: 36px; color: var(--text-3); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%;
            animation: shimmer 1.2s infinite linear; border-radius: var(--r-sm); min-height: 1em; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------------------------------------------------------------- 开关（三态：开 / 关 / 等待设备确认，03 §4.4） */
.switch { position: relative; width: 52px; height: 32px; border-radius: var(--r-full); border: 2px solid var(--line-strong);
          background: var(--surface-2); cursor: pointer; flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%;
                 background: var(--text-2); transition: transform var(--dur) var(--ease-out); }
.switch[aria-checked="true"] { background: var(--primary); border-color: var(--primary); }
.switch[aria-checked="true"]::after { transform: translateX(20px); background: var(--on-primary); }
.switch[aria-busy="true"]::after { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------------------------------------------------------------- 曲线 / 像素图 / 页签 */
.spark { width: 100%; height: 56px; color: var(--primary); }
.spark path { fill: none; stroke: currentColor; stroke-width: 2; vector-effect: non-scaling-stroke; }
.pixel { image-rendering: pixelated; image-rendering: crisp-edges; background: #fff; border: 1px solid var(--line-strong);
         border-radius: var(--r-sm); }
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--line); margin-bottom: var(--sp-4); overflow-x: auto; }
.tabs [role="tab"] { all: unset; cursor: pointer; padding: var(--sp-2) var(--sp-3); border-bottom: 2px solid transparent;
                     color: var(--text-2); white-space: nowrap; }
.tabs [role="tab"][aria-selected="true"] { color: var(--text); border-bottom-color: var(--primary); font-weight: 650; }
.tabs [role="tab"]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.code { font-family: var(--font-mono); background: var(--surface-2); border-radius: var(--r-sm); padding: var(--sp-3);
        overflow: auto; font-size: 12px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 60vh; }
.copyline { display: flex; gap: var(--sp-2); align-items: center; }
.copyline code { flex: 1; min-width: 0; background: var(--surface-2); padding: var(--sp-2); border-radius: var(--r-sm);
                 overflow-wrap: anywhere; font-size: 13px; }

/* ---- 图表（db_upgrade_plan 05 §三 / §六）：两端共用。图容器必须有高度；空状态 / 出错是文字，不画一张空坐标 */
.chart { width: 100%; height: 240px; }
.chart-sm { height: 180px; }
.chart-heat { height: 210px; }
.chart-gauge { height: 190px; }
.chart.is-empty, .chart-err { height: auto; }
.chart-empty { display: grid; justify-items: center; gap: var(--sp-2); padding: var(--sp-5) var(--sp-3); color: var(--text-3); text-align: center; }
.chart-empty .ico { width: 28px; height: 28px; }
.chart-foot { display: flex; align-items: flex-start; gap: var(--sp-2); margin-top: var(--sp-1); }
.chart-sum { flex: 1; min-width: 0; font-size: var(--fs-xs); overflow-wrap: anywhere; }
.num-table { max-height: 320px; overflow: auto; margin-top: var(--sp-2); }
.num-table .table { font-size: var(--fs-xs); }
.tl-legend { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-xs); color: var(--text-2); margin-top: var(--sp-1); }
.tl-legend span { display: inline-flex; align-items: center; gap: 6px; }
.tl-legend i { display: inline-block; width: 22px; height: 10px; border-radius: 3px; }
.tl-legend .sw-auto { background: var(--c1); }
.tl-legend .sw-hand { border: 1px solid var(--c2); background: repeating-linear-gradient(135deg, var(--c2) 0 2px, transparent 2px 5px); }
.tl-say { font-size: var(--fs-sm); color: var(--text-2); margin-bottom: var(--sp-1); }
.seg-sm button { padding: 0 var(--sp-3); }
.data-tools { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; margin-bottom: var(--sp-3); }
.data-tools .custom-range { gap: var(--sp-2); flex-wrap: wrap; }
.data-tools .custom-range .input { width: auto; min-width: 0; }
/* 分段控件里的焦点环：.seg 有 overflow:hidden 圆角，外描边会被裁掉只剩一条缝（D6 键盘验收撞到）。
   改成内嵌双圈：外圈焦点色、内圈底色 —— 选中的那颗（底色就是主色）也看得见 */
.seg button:focus-visible, .seg a:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--focus), inset 0 0 0 4px var(--surface); }
.seg button[aria-pressed="true"]:focus-visible, .seg button[aria-checked="true"]:focus-visible, .seg a[aria-current="page"]:focus-visible {
  box-shadow: inset 0 0 0 2px var(--on-primary), inset 0 0 0 4px var(--focus); }
