/* Ablemate 奥博迈特 · components v1.0 — uses tokens.css variables only. Class prefix: am- */
*, *::before, *::after { box-sizing: border-box; }
body.am { margin: 0; background: var(--am-paper); color: var(--am-text); font: var(--am-text-m)/1.6 var(--am-font-sans); -webkit-font-smoothing: antialiased; }
.am :focus-visible { outline: 2px solid var(--am-focus); outline-offset: 2px; border-radius: 4px; }
.am-muted { color: var(--am-muted); font-size: var(--am-text-s); }
.am-num { font-variant-numeric: tabular-nums; }
.am-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.am-hidden { display: none !important; }
.am-row { display: flex; gap: var(--am-space-2); align-items: center; flex-wrap: wrap; }
.am-stack { display: grid; gap: var(--am-space-3); }

/* Buttons */
.am-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 6px 14px;
  border-radius: var(--am-radius-s); border: 1px solid transparent; font: 600 var(--am-text-s)/1.2 var(--am-font-sans); cursor: pointer;
  background: var(--am-primary); color: var(--am-on-primary); transition: background var(--am-motion-fast), border-color var(--am-motion-fast); text-decoration: none; white-space: nowrap; }
.am-btn:hover { background: var(--am-primary-hover); }
.am-btn--accent { background: var(--am-amber); color: var(--am-on-amber); }
.am-btn--accent:hover { background: var(--am-amber-600); }
.am-btn--secondary { background: var(--am-surface); color: var(--am-primary); border-color: var(--am-primary); }
.am-btn--secondary:hover { background: var(--am-ink-50); }
.am-btn--ghost { background: transparent; color: var(--am-primary); }
.am-btn--ghost:hover { background: var(--am-ink-50); }
.am-btn--danger { background: var(--am-surface); color: var(--am-danger); border-color: var(--am-danger); }
.am-btn--danger:hover { background: var(--am-danger-bg); }
.am-btn--sm { min-height: 28px; padding: 3px 10px; font-size: var(--am-text-xs); }
.am-btn[disabled], .am-btn[aria-busy="true"] { opacity: .5; cursor: not-allowed; }

/* Status tag: icon + text, never color alone */
.am-tag { display: inline-flex; align-items: center; gap: 5px; padding: 1px 10px; border-radius: var(--am-radius-pill);
  font-size: var(--am-text-xs); font-weight: 600; white-space: nowrap; background: var(--am-idle-bg); color: var(--am-idle); }
.am-tag--ok { background: var(--am-ok-bg); color: var(--am-ok); }
.am-tag--pending { background: var(--am-pending-bg); color: var(--am-pending); }
.am-tag--danger { background: var(--am-danger-bg); color: var(--am-danger); }
.am-tag--info { background: var(--am-ink-50); color: var(--am-primary); }
.am-count { display: inline-grid; place-items: center; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 9px;
  background: var(--am-amber); color: var(--am-on-amber); font-size: 11px; font-weight: 700; }

/* Card & layout */
.am-card { background: var(--am-surface); border: 1px solid var(--am-line); border-radius: var(--am-radius-l); }
.am-card__head { display: flex; justify-content: space-between; align-items: center; gap: var(--am-space-3); flex-wrap: wrap;
  padding: var(--am-space-3) var(--am-space-4); border-bottom: 1px solid var(--am-line); }
.am-card__body { padding: var(--am-space-4); }
.am-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--am-space-3); }
.am-kpi { background: var(--am-surface); border: 1px solid var(--am-line); border-radius: var(--am-radius-m); padding: var(--am-space-3) var(--am-space-4); }
.am-kpi__label { color: var(--am-muted); font-size: var(--am-text-xs); }
.am-kpi__value { font-size: var(--am-text-2xl); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; }

/* Form */
.am-field { display: grid; gap: 4px; }
.am-field > label { font-size: var(--am-text-xs); color: var(--am-muted); font-weight: 500; }
.am-input, .am-select, .am-textarea { width: 100%; min-height: 34px; padding: 6px 12px; border: 1px solid var(--am-line); border-radius: var(--am-radius-s);
  background: var(--am-surface); color: var(--am-text); font: var(--am-text-m)/1.5 var(--am-font-sans); }
.am-textarea { min-height: 140px; resize: vertical; }
.am-input:focus, .am-select:focus, .am-textarea:focus { outline: none; border-color: var(--am-focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--am-focus) 22%, transparent); }
.am-input[aria-invalid="true"] { border-color: var(--am-danger); }
.am-field__error { color: var(--am-danger); font-size: var(--am-text-xs); }
.am-field__hint { color: var(--am-muted); font-size: var(--am-text-xs); }
.am-seg { display: inline-flex; border: 1px solid var(--am-line); border-radius: var(--am-radius-s); overflow: hidden; }
.am-seg button { white-space: nowrap; border: 0; background: var(--am-surface); color: var(--am-muted); padding: 6px 14px; font: inherit; cursor: pointer; }
.am-seg button[aria-pressed="true"] { background: var(--am-primary); color: var(--am-on-primary); font-weight: 600; }

/* Table: stacks into cards below 720px */
.am-table-wrap { width: 100%; overflow-x: auto; }
.am-table { width: 100%; border-collapse: collapse; font-size: var(--am-text-s); }
.am-table th { text-align: left; font-weight: 500; color: var(--am-muted); padding: 10px var(--am-space-4); background: var(--am-surface-2); white-space: nowrap; }
.am-table td { padding: 12px var(--am-space-4); border-top: 1px solid var(--am-line); vertical-align: middle; }
.am-table td.am-num, .am-table th.am-num { text-align: right; }
.am-table tbody tr:hover td { background: var(--am-surface-2); }
@media (max-width: 720px) {
  .am-table--stack thead { display: none; }
  .am-table--stack tr { display: block; border-top: 1px solid var(--am-line); padding: var(--am-space-2) 0; }
  .am-table--stack td { display: flex; justify-content: space-between; gap: var(--am-space-3); border: 0; padding: 4px var(--am-space-4); }
  .am-table--stack td::before { content: attr(data-label); color: var(--am-muted); font-size: var(--am-text-xs); flex: none; white-space: nowrap; }
  .am-table--stack td > * { min-width: 0; text-align: right; }
  .am-table--stack .am-who { justify-content: flex-end; }
  .am-table--stack .am-who__name { white-space: normal; overflow-wrap: anywhere; }
  .am-table--stack td.am-num { text-align: right; }
}

/* Badge (工牌) & avatar */
.am-avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: var(--am-primary); color: var(--am-on-primary); font-weight: 700; font-size: var(--am-text-s); }
.am-avatar--amber { background: var(--am-amber); color: var(--am-on-amber); }
.am-avatar--lg { width: 56px; height: 56px; font-size: var(--am-text-xl); }
.am-who { display: flex; gap: var(--am-space-3); align-items: center; min-width: 0; }
.am-who__name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.am-badge { width: 200px; background: var(--am-surface); border: 1px solid var(--am-line); border-radius: var(--am-radius-l);
  padding: 8px 14px 14px; text-align: center; box-shadow: var(--am-shadow-card); }
.am-badge__slot { width: 38px; height: 7px; border-radius: 4px; background: var(--am-paper); border: 1px solid var(--am-line); margin: 0 auto 10px; }
.am-badge .am-avatar { margin: 0 auto 6px; }

/* Seal (印章): approvals only */
.am-seal { display: inline-grid; place-items: center; width: 92px; height: 92px; border: 3px solid currentColor; border-radius: 50%;
  color: var(--am-primary); text-align: center; font-weight: 700; line-height: 1.2; transform: rotate(-12deg);
  box-shadow: inset 0 0 0 3px var(--am-surface), inset 0 0 0 5px currentColor; }
.am-seal small { display: block; font-size: 9px; letter-spacing: .12em; }
.am-seal--pending { color: var(--am-pending); }
.am-seal--declined { color: var(--am-danger); }
.am-seal--stamp { animation: am-stamp var(--am-motion-base) ease-out; }
@keyframes am-stamp { from { transform: rotate(-12deg) scale(1.35); opacity: 0; } 70% { transform: rotate(-12deg) scale(.95); opacity: 1; } to { transform: rotate(-12deg) scale(1); } }

/* Dialog (danger confirm) */
.am-dialog { border: 1px solid var(--am-line); border-radius: var(--am-radius-l); padding: 0; width: min(440px, 94vw);
  background: var(--am-surface); color: var(--am-text); box-shadow: var(--am-shadow-pop); }
.am-dialog::backdrop { background: rgba(15, 22, 32, .45); }
.am-dialog__body { padding: var(--am-space-5); display: grid; gap: var(--am-space-3); }
.am-dialog__title { margin: 0; font-size: var(--am-text-l); }
.am-dialog__impact { background: var(--am-surface-2); border-left: 3px solid var(--am-amber); padding: var(--am-space-2) var(--am-space-3); border-radius: var(--am-radius-s); font-size: var(--am-text-s); }
.am-dialog__actions { display: flex; justify-content: flex-end; gap: var(--am-space-2); padding: var(--am-space-3) var(--am-space-5); border-top: 1px solid var(--am-line); }

/* Drawer */
.am-drawer { position: fixed; inset: 0 0 0 auto; width: min(560px, 100vw); margin: 0; max-height: none; height: 100%; border: 0; border-left: 1px solid var(--am-line);
  padding: 0; background: var(--am-surface); color: var(--am-text); box-shadow: var(--am-shadow-pop); }
.am-drawer::backdrop { background: rgba(15, 22, 32, .35); }
.am-drawer__head { display: flex; justify-content: space-between; align-items: center; padding: var(--am-space-4) var(--am-space-5); border-bottom: 1px solid var(--am-line); }
.am-drawer__body { padding: var(--am-space-5); overflow-y: auto; height: calc(100% - 64px); }

/* Toast */
.am-toasts { position: fixed; right: var(--am-space-6); bottom: var(--am-space-6); display: grid; gap: var(--am-space-2); z-index: 1000; }
.am-toast { min-width: 260px; max-width: 420px; background: var(--am-surface); border: 1px solid var(--am-line); border-left: 4px solid var(--am-ok);
  border-radius: var(--am-radius-m); padding: 10px 14px; box-shadow: var(--am-shadow-card); display: flex; gap: var(--am-space-3); align-items: center; justify-content: space-between; }
.am-toast--error { border-left-color: var(--am-danger); }
.am-toast--info { border-left-color: var(--am-primary); }

/* Command palette */
.am-cmdk { border: 1px solid var(--am-line); border-radius: var(--am-radius-l); width: min(620px, 94vw); padding: 0; margin-top: 12vh;
  background: var(--am-surface); color: var(--am-text); box-shadow: var(--am-shadow-pop); }
.am-cmdk::backdrop { background: rgba(15, 22, 32, .4); }
.am-cmdk__input { border: 0; border-bottom: 1px solid var(--am-line); border-radius: 0; min-height: 48px; padding: 0 var(--am-space-4); }
.am-cmdk__list { list-style: none; margin: 0; padding: var(--am-space-2); max-height: 360px; overflow-y: auto; }
.am-cmdk__item { display: flex; justify-content: space-between; gap: var(--am-space-3); padding: 9px 12px; border-radius: var(--am-radius-s); cursor: pointer; }
.am-cmdk__item[aria-selected="true"] { background: var(--am-ink-50); }
.am-cmdk__empty { padding: 10px 12px; }
.am-kbd { font: 11px var(--am-font-mono); border: 1px solid var(--am-line); border-radius: 4px; padding: 0 5px; color: var(--am-muted); }

/* Empty state */
.am-empty { text-align: center; padding: var(--am-space-8) var(--am-space-4); color: var(--am-muted); }
.am-empty__desk { width: 120px; height: 56px; margin: 0 auto var(--am-space-3); border-bottom: 4px solid var(--am-line); position: relative; }
.am-empty__desk::before { content: ""; position: absolute; left: 40px; top: 8px; width: 40px; height: 40px; border: 2px dashed var(--am-idle); border-radius: 50%; }
.am-empty__title { color: var(--am-text); font-weight: 600; margin-bottom: 4px; }

/* Skeleton */
.am-skeleton { background: linear-gradient(90deg, var(--am-line), var(--am-surface-2), var(--am-line)); background-size: 200% 100%;
  animation: am-shimmer 1.2s linear infinite; border-radius: var(--am-radius-s); min-height: 14px; }
@keyframes am-shimmer { to { background-position: -200% 0; } }

/* App shell */
.am-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.am-sidebar { background: var(--am-ink); color: #C9D3E3; padding: var(--am-space-4) var(--am-space-3); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
:root[data-theme="dark"] .am-sidebar { background: var(--am-surface-2); color: var(--am-muted); border-right: 1px solid var(--am-line); }
.am-sidebar__brand { display: flex; align-items: center; gap: var(--am-space-2); color: #fff; font-weight: 700; margin: 0 6px var(--am-space-5); }
:root[data-theme="dark"] .am-sidebar__brand { color: var(--am-text); }
.am-sidebar__brand img { width: 26px; height: 26px; }
.am-nav { display: grid; gap: 2px; }
.am-nav__group { font-size: var(--am-text-xs); opacity: .65; padding: var(--am-space-3) var(--am-space-3) 4px; }
.am-nav__item { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-radius: var(--am-radius-s);
  color: inherit; text-decoration: none; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.am-nav__item:hover { background: rgba(255, 255, 255, .08); }
.am-nav__item[aria-current="page"] { background: rgba(255, 255, 255, .14); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--am-amber); }
:root[data-theme="dark"] .am-nav__item[aria-current="page"] { color: var(--am-text); background: var(--am-ink-50); }
.am-topbar { display: flex; justify-content: space-between; align-items: center; gap: var(--am-space-3); padding: 10px var(--am-space-6);
  background: var(--am-surface); border-bottom: 1px solid var(--am-line); position: sticky; top: 0; z-index: 10; }
.am-search { display: inline-flex; align-items: center; gap: var(--am-space-2); min-width: 280px; padding: 6px 12px; border: 1px solid var(--am-line);
  border-radius: var(--am-radius-s); background: var(--am-paper); color: var(--am-muted); cursor: pointer; font: inherit; }
.am-main { padding: var(--am-space-6); max-width: 1320px; width: 100%; margin: 0 auto; }
.am-page-title { margin: 0; font-size: var(--am-text-xl); }
@media (max-width: 860px) {
  .am-shell { grid-template-columns: 1fr; }
  .am-sidebar { position: static; height: auto; display: flex; gap: var(--am-space-2); overflow-x: auto; padding: var(--am-space-2); }
  .am-sidebar__brand, .am-nav__group { display: none; }
  .am-nav { display: flex; }
  .am-topbar { flex-wrap: wrap; padding: var(--am-space-2) var(--am-space-4); }
  .am-search { min-width: 0; flex: 1 1 100%; order: 2; }
  .am-main { padding: var(--am-space-4); }
}

/* Shell content column must be allowed to shrink below its content's min-width (grid 1fr + min-width:auto overflow) */
.am-shell > * { min-width: 0; }
@media (max-width: 860px) {
  .am-nav__item { white-space: nowrap; }
}
/* Stacks/forms are grids: their implicit column must not size to the widest child's min-content */
.am-stack { grid-template-columns: minmax(0, 1fr); }
.am-stack > *, .am-field > * { min-width: 0; }

/* Chart (single series). Text wears text tokens; the mark wears the validated chart token. */
.am-chart { margin: 0; display: grid; gap: var(--am-space-2); }
.am-chart__title { font-weight: 600; font-size: var(--am-text-s); }
.am-chart svg { width: 100%; height: auto; display: block; }
.am-chart__bar { fill: var(--am-chart-1); }
.am-chart__hit { fill: transparent; }
.am-chart__slot:hover .am-chart__bar { fill-opacity: .72; }
.am-chart__grid { stroke: var(--am-chart-grid); stroke-width: 1; }
.am-chart__base { stroke: var(--am-line); stroke-width: 1; }
.am-chart__peak { fill: var(--am-text); font: 600 12px var(--am-font-sans); font-variant-numeric: tabular-nums; }
.am-chart__tick { fill: var(--am-muted); font: 11px var(--am-font-sans); }
.am-chart__table summary { cursor: pointer; color: var(--am-muted); font-size: var(--am-text-xs); }
