/* ==========================================================================
   澄清南北 · 共享组件层
   依赖：tokens.css、base.css。类名统一 cq- 前缀，仅引用 token。
   触控目标：可交互控件最小高度 40px（小尺寸变体除外，且不用于触屏主操作）。
   ========================================================================== */

/* ==========================================================================
   按钮 .cq-btn
   变体：--primary（默认）/ --secondary / --danger / --ghost / --icon
   状态：:disabled、.is-loading
   ========================================================================== */
.cq-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--cqnb-space-2);
  min-height: var(--cqnb-button-h); min-width: var(--cqnb-button-h);
  padding: 0 var(--cqnb-space-4);
  border: 1px solid transparent; border-radius: var(--cqnb-radius);
  background: var(--cqnb-accent); color: var(--cqnb-on-accent);
  font-size: var(--cqnb-text-md); font-weight: 600; letter-spacing: .02em;
  text-decoration: none; white-space: nowrap; user-select: none;
  transition: background var(--cqnb-motion-fast), box-shadow var(--cqnb-motion-fast),
              transform var(--cqnb-motion-fast), border-color var(--cqnb-motion-fast);
}
.cq-btn:hover:not(:disabled):not(.is-loading) { background: var(--cqnb-accent-strong); box-shadow: var(--cqnb-shadow-sm); text-decoration: none; }
.cq-btn:active:not(:disabled):not(.is-loading) { transform: translateY(1px); }
.cq-btn:disabled { opacity: .5; box-shadow: none; }
.cq-btn--secondary {
  background: var(--cqnb-panel); color: var(--cqnb-ink-soft);
  border-color: var(--cqnb-line-strong);
}
.cq-btn--secondary:hover:not(:disabled):not(.is-loading) { background: var(--cqnb-bg-soft); color: var(--cqnb-ink); }
.cq-btn--danger { background: var(--cqnb-danger); color: var(--cqnb-on-accent); }
.cq-btn--danger:hover:not(:disabled):not(.is-loading) { background: var(--cqnb-danger-strong); }
.cq-btn--ghost { background: transparent; color: var(--cqnb-accent); border-color: transparent; }
.cq-btn--ghost:hover:not(:disabled):not(.is-loading) { background: var(--cqnb-accent-faint); box-shadow: none; }
.cq-btn--icon { padding: 0 var(--cqnb-space-2); background: transparent; color: var(--cqnb-ink-soft); border-color: var(--cqnb-line); }
.cq-btn--icon:hover:not(:disabled):not(.is-loading) { background: var(--cqnb-bg-soft); color: var(--cqnb-ink); }
.cq-btn--sm { min-height: var(--cqnb-button-h-sm); min-width: var(--cqnb-button-h-sm); padding: 0 var(--cqnb-space-3); font-size: var(--cqnb-text-sm); }

/* 加载态：文字保留，前置转圈，禁止重复点击 */
.cq-btn.is-loading { pointer-events: none; opacity: .75; }
.cq-btn.is-loading::before {
  content: ""; width: 14px; height: 14px; flex: none;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  animation: cq-spin .8s linear infinite;
}

/* 按钮组 */
.cq-actions { display: flex; flex-wrap: wrap; gap: var(--cqnb-space-2); align-items: center; }

/* ==========================================================================
   朝廷案牍卡片（业务 DOM 可逐步采用，不改变现有交互）
   ========================================================================== */
.court-card { background: var(--court-paper); border: 1px solid var(--court-line); border-left: 3px solid var(--court-office-accent, var(--court-vermilion)); border-radius: var(--cqnb-radius); box-shadow: var(--court-shadow); }
.court-card--primary { border-left-width: 4px; }
.court-card--document { background: var(--court-paper-deep); }
.court-card--warning { border-left-color: var(--court-vermilion); }

/* ==========================================================================
   卡片 .cq-card
   ========================================================================== */
.cq-card {
  background: var(--cqnb-panel);
  border: 1px solid var(--cqnb-line);
  border-radius: var(--cqnb-radius-lg);
  box-shadow: var(--cqnb-shadow-sm);
  overflow-wrap: anywhere;
}
.cq-card__head {
  display: flex; align-items: baseline; gap: var(--cqnb-space-3); flex-wrap: wrap;
  padding: var(--cqnb-space-3) var(--cqnb-space-4);
  border-bottom: 1px solid var(--cqnb-line-faint);
}
.cq-card__title { font-family: var(--cqnb-font-title); font-size: var(--cqnb-text-lg); font-weight: 700; letter-spacing: .03em; }
.cq-card__subtitle { font-size: var(--cqnb-text-sm); color: var(--cqnb-muted); }
.cq-card__head .cq-actions { margin-left: auto; }
.cq-card__body { padding: var(--cqnb-space-4); }
.cq-card__body > :first-child { margin-top: 0; }
.cq-card__body > :last-child { margin-bottom: 0; }
.cq-card__foot {
  padding: var(--cqnb-space-3) var(--cqnb-space-4);
  border-top: 1px solid var(--cqnb-line-faint);
  background: var(--cqnb-bg-soft);
  border-radius: 0 0 var(--cqnb-radius-lg) var(--cqnb-radius-lg);
}
/* 卡片空状态 */
.cq-card__empty {
  padding: var(--cqnb-space-6) var(--cqnb-space-4);
  color: var(--cqnb-muted); font-size: var(--cqnb-text-md); text-align: center;
}

/* ==========================================================================
   状态签 chip .cq-chip
   色调：--neutral / --info / --success / --warning / --danger / --muted
   每个色调配不同小形状标识（.cq-chip__mark），不只靠颜色区分。
   形状语义：info●圆形 success✓对勾 warning▲三角 danger✕叉 neutral◆菱形 muted○空心
   ========================================================================== */
.cq-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; max-width: 100%;
  border: 1px solid var(--cqnb-line-strong); border-radius: var(--cqnb-radius-pill);
  background: var(--cqnb-neutral-soft); color: var(--cqnb-neutral);
  font-size: var(--cqnb-text-xs); font-weight: 600; line-height: 18px;
  white-space: nowrap;
}
.cq-chip__mark { flex: none; display: inline-grid; place-items: center; width: 12px; height: 12px; font-size: 9px; line-height: 1; font-style: normal; }
.cq-chip--info    { background: var(--cqnb-info-soft);    border-color: var(--cqnb-info);    color: var(--cqnb-info); }
.cq-chip--success { background: var(--cqnb-success-soft); border-color: var(--cqnb-success); color: var(--cqnb-success); }
.cq-chip--warning { background: var(--cqnb-warning-soft); border-color: var(--cqnb-warning); color: var(--cqnb-warning); }
.cq-chip--danger  { background: var(--cqnb-danger-soft);  border-color: var(--cqnb-danger);  color: var(--cqnb-danger); }
.cq-chip--muted   { background: transparent;              border-color: var(--cqnb-line);    color: var(--cqnb-muted); }
/* 形状标识（字符即形状，兼顾读屏隐藏与打印） */
.cq-chip--info .cq-chip__mark::before    { content: "●"; }
.cq-chip--success .cq-chip__mark::before { content: "✓"; font-weight: 900; }
.cq-chip--warning .cq-chip__mark::before { content: "▲"; }
.cq-chip--danger .cq-chip__mark::before  { content: "✕"; font-weight: 900; }
.cq-chip--neutral .cq-chip__mark::before { content: "◆"; }
.cq-chip--muted .cq-chip__mark::before   { content: "○"; }

/* ==========================================================================
   徽标 .cq-badge（计数/标记，非状态语义）
   ========================================================================== */
.cq-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--cqnb-radius-pill);
  background: var(--cqnb-accent); color: var(--cqnb-on-accent);
  font-size: var(--cqnb-text-xs); font-weight: 700; line-height: 1;
}
.cq-badge--gold { background: var(--cqnb-gold); }
.cq-badge--muted { background: var(--cqnb-neutral-soft); color: var(--cqnb-muted); border: 1px solid var(--cqnb-line); }

/* ==========================================================================
   表单
   .cq-field > .cq-field__label + (input.cq-input | select.cq-select | textarea.cq-textarea)
             + (.cq-field__help | .cq-field__error)
   错误态：.cq-field--error 或 input[aria-invalid="true"]，与 .cq-field__error 关联
   ========================================================================== */
.cq-field { display: flex; flex-direction: column; gap: var(--cqnb-space-1); margin-bottom: var(--cqnb-space-3); }
.cq-field__label { font-size: var(--cqnb-text-sm); font-weight: 700; color: var(--cqnb-ink-soft); }
.cq-field__label .cq-req { color: var(--cqnb-danger); margin-left: 2px; }
.cq-input, .cq-select, .cq-textarea {
  width: 100%; min-height: var(--cqnb-control-h);
  padding: 8px 10px;
  border: 1px solid var(--cqnb-line-strong); border-radius: var(--cqnb-radius);
  background: var(--cqnb-panel-raised); color: var(--cqnb-ink);
  transition: border-color var(--cqnb-motion-fast), box-shadow var(--cqnb-motion-fast);
}
.cq-textarea { min-height: 88px; resize: vertical; line-height: 1.6; }
.cq-input::placeholder, .cq-textarea::placeholder { color: var(--cqnb-faint); }
.cq-input:focus-visible, .cq-select:focus-visible, .cq-textarea:focus-visible {
  outline: 2px solid var(--cqnb-focus); outline-offset: 1px; border-color: var(--cqnb-focus);
}
.cq-input:disabled, .cq-select:disabled, .cq-textarea:disabled {
  background: var(--cqnb-bg-soft); color: var(--cqnb-muted); cursor: not-allowed;
}
.cq-field__help { font-size: var(--cqnb-text-xs); color: var(--cqnb-muted); line-height: 1.5; }
.cq-field__error {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--cqnb-text-xs); color: var(--cqnb-danger); line-height: 1.5;
}
.cq-field__error::before { content: "✕"; font-size: 9px; font-weight: 900; }
.cq-field--error .cq-input, .cq-field--error .cq-select, .cq-field--error .cq-textarea,
.cq-input[aria-invalid="true"], .cq-select[aria-invalid="true"], .cq-textarea[aria-invalid="true"] {
  border-color: var(--cqnb-danger);
}
.cq-field--error .cq-input:focus-visible, .cq-input[aria-invalid="true"]:focus-visible,
.cq-field--error .cq-textarea:focus-visible, .cq-textarea[aria-invalid="true"]:focus-visible {
  outline-color: var(--cqnb-danger); border-color: var(--cqnb-danger);
}
/* 勾选行 */
.cq-check { display: flex; align-items: center; gap: var(--cqnb-space-2); min-height: var(--cqnb-control-h); font-size: var(--cqnb-text-md); }
.cq-check input { width: 18px; height: 18px; accent-color: var(--cqnb-accent); margin: 0; }
/* 横向表单行 */
.cq-form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--cqnb-space-3); }

/* ==========================================================================
   表格 .cq-table（外层包 .cq-table-wrap 提供横滚）
   修饰：--sticky 首列固定；行展开 .cq-table__row--expanded；
   长文本折叠 .cq-cell-clamp；三态 .cq-table__empty/__loading/__error
   ========================================================================== */
.cq-table-wrap { overflow-x: auto; border: 1px solid var(--cqnb-line); border-radius: var(--cqnb-radius-lg); background: var(--cqnb-panel); }
.cq-table { width: 100%; border-collapse: collapse; font-size: var(--cqnb-text-md); font-variant-numeric: tabular-nums; }
.cq-table th, .cq-table td {
  padding: 9px var(--cqnb-space-3); text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--cqnb-line-faint);
  overflow-wrap: anywhere;
}
.cq-table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--cqnb-bg-soft); color: var(--cqnb-ink-soft);
  font-size: var(--cqnb-text-sm); font-weight: 700; white-space: nowrap;
  border-bottom: 1px solid var(--cqnb-line-strong);
}
.cq-table tbody tr:last-child td { border-bottom: 0; }
.cq-table tbody tr:hover { background: var(--cqnb-accent-faint); }
.cq-table__row--expanded { background: var(--cqnb-bg-soft); }
.cq-table__row-detail td { background: var(--cqnb-bg-soft); font-size: var(--cqnb-text-sm); color: var(--cqnb-ink-soft); }
/* 首列固定 */
.cq-table--sticky th:first-child, .cq-table--sticky td:first-child {
  position: sticky; left: 0; z-index: 2;
  background: var(--cqnb-panel); border-right: 1px solid var(--cqnb-line);
}
.cq-table--sticky thead th:first-child { background: var(--cqnb-bg-soft); z-index: 3; }
/* 长文本折叠（默认两行，配合 title 或行展开看全文） */
.cq-cell-clamp {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  overflow: hidden; max-width: 32em;
}
/* 表格三态 */
.cq-table__empty, .cq-table__loading, .cq-table__error {
  padding: var(--cqnb-space-6) var(--cqnb-space-4); text-align: center; font-size: var(--cqnb-text-md);
}
.cq-table__empty { color: var(--cqnb-muted); }
.cq-table__loading { color: var(--cqnb-muted); }
.cq-table__error { color: var(--cqnb-danger); background: var(--cqnb-danger-soft); }

/* ==========================================================================
   空状态 / 加载 / 错误（通用）
   ========================================================================== */
.cq-empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--cqnb-space-2);
  padding: var(--cqnb-space-6) var(--cqnb-space-4);
  border: 1px dashed var(--cqnb-line-strong); border-radius: var(--cqnb-radius-lg);
  background: var(--cqnb-bg-soft);
  color: var(--cqnb-muted); font-size: var(--cqnb-text-md); text-align: center;
}
.cq-empty__title { font-family: var(--cqnb-font-title); font-size: var(--cqnb-text-lg); color: var(--cqnb-ink-soft); }
.cq-loading { display: inline-flex; align-items: center; gap: var(--cqnb-space-2); color: var(--cqnb-muted); font-size: var(--cqnb-text-md); }
.cq-loading::before {
  content: ""; width: 14px; height: 14px; flex: none;
  border: 2px solid var(--cqnb-line-strong); border-top-color: var(--cqnb-accent);
  border-radius: 50%; animation: cq-spin .8s linear infinite;
}
.cq-spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--cqnb-line-strong); border-top-color: var(--cqnb-accent);
  border-radius: 50%; animation: cq-spin .8s linear infinite;
}
@keyframes cq-spin { to { transform: rotate(360deg); } }
/* 骨架屏 */
.cq-skeleton {
  border-radius: var(--cqnb-radius);
  background: linear-gradient(90deg, var(--cqnb-bg-soft) 25%, var(--cqnb-panel) 50%, var(--cqnb-bg-soft) 75%);
  background-size: 200% 100%;
  animation: cq-skeleton 1.2s ease-in-out infinite;
  min-height: 1em;
}
@keyframes cq-skeleton { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.cq-error-box {
  padding: var(--cqnb-space-3) var(--cqnb-space-4);
  border: 1px solid var(--cqnb-danger); border-left-width: 4px; border-radius: var(--cqnb-radius);
  background: var(--cqnb-danger-soft); color: var(--cqnb-danger); font-size: var(--cqnb-text-md);
}

/* ==========================================================================
   抽屉 / 浮层
   ========================================================================== */
.cq-overlay {
  position: fixed; inset: 0; z-index: var(--cqnb-z-overlay);
  background: rgba(43, 38, 32, .45);
  opacity: 0; pointer-events: none;
  transition: opacity var(--cqnb-motion);
}
.cq-overlay.is-open { opacity: 1; pointer-events: auto; }
.cq-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: var(--cqnb-z-modal);
  width: min(420px, 92vw);
  display: flex; flex-direction: column;
  background: var(--cqnb-panel); border-left: 1px solid var(--cqnb-line-strong);
  box-shadow: var(--cqnb-shadow-lg);
  transform: translateX(100%);
  transition: transform var(--cqnb-motion-slow);
}
.cq-drawer.is-open { transform: translateX(0); }
.cq-drawer__head {
  display: flex; align-items: center; gap: var(--cqnb-space-3);
  padding: var(--cqnb-space-3) var(--cqnb-space-4);
  border-bottom: 1px solid var(--cqnb-line);
}
.cq-drawer__title { font-family: var(--cqnb-font-title); font-size: var(--cqnb-text-lg); font-weight: 700; }
.cq-drawer__close { margin-left: auto; }
.cq-drawer__body { flex: 1; overflow-y: auto; padding: var(--cqnb-space-4); overscroll-behavior: contain; }

/* ==========================================================================
   分段控件 .cq-segmented
   ========================================================================== */
.cq-segmented {
  display: inline-flex; gap: 2px; padding: 2px;
  border: 1px solid var(--cqnb-line-strong); border-radius: var(--cqnb-radius-lg);
  background: var(--cqnb-bg-soft);
}
.cq-segmented button {
  min-height: 32px; padding: 0 var(--cqnb-space-3);
  border: 0; border-radius: var(--cqnb-radius); background: transparent;
  color: var(--cqnb-muted); font-size: var(--cqnb-text-sm); font-weight: 600;
  transition: background var(--cqnb-motion-fast), color var(--cqnb-motion-fast);
}
.cq-segmented button:hover { color: var(--cqnb-ink); }
.cq-segmented button[aria-selected="true"], .cq-segmented button.is-active {
  background: var(--cqnb-panel); color: var(--cqnb-accent-strong);
  box-shadow: var(--cqnb-shadow-sm);
}

/* ==========================================================================
   工具条 .cq-toolbar
   ========================================================================== */
.cq-toolbar {
  display: flex; align-items: center; gap: var(--cqnb-space-2); flex-wrap: wrap;
  padding: var(--cqnb-space-2) var(--cqnb-space-3);
  border: 1px solid var(--cqnb-line); border-radius: var(--cqnb-radius-lg);
  background: var(--cqnb-panel);
}
.cq-toolbar__group { display: flex; align-items: center; gap: var(--cqnb-space-2); }
.cq-toolbar__spacer { flex: 1; }
.cq-toolbar__label { font-size: var(--cqnb-text-sm); color: var(--cqnb-muted); font-weight: 600; }

/* ==========================================================================
   移动端规则（断点 1024 / 768 / 480）
   ========================================================================== */
@media (max-width: 768px) {
  .cq-drawer { width: 100vw; border-left: 0; }
  .cq-toolbar { padding: var(--cqnb-space-2); }
}
@media (max-width: 480px) {
  .cq-actions .cq-btn { flex: 1 1 auto; }
  .cq-form-row { grid-template-columns: 1fr; }
}

/* 动效降级（token 已归零，这里兜底关键帧） */
@media (prefers-reduced-motion: reduce) {
  .cq-btn.is-loading::before, .cq-loading::before, .cq-spinner { animation: none; border-top-color: currentColor; }
  .cq-skeleton { animation: none; }
  .cq-overlay, .cq-drawer, .cq-btn, .cq-segmented button { transition: none; }
}
