/* Shared button/status semantics. Existing page, text, menu and layout tokens stay intact. */
:root {
  --ui-primary: #6f5bff;
  --ui-primary-hover: #5e4ae3;
  --ui-primary-pressed: #503ccb;
  --ui-primary-ink: #ffffff;
  --ui-create-bg: #eee7ff;
  --ui-create-ink: #6245d8;
  --ui-view-bg: #e2ecff;
  --ui-view-ink: #315fc7;
  --ui-neutral-bg: #f3f5f9;
  --ui-neutral-ink: #43516a;
  --ui-neutral-line: #e4e8ee;
  --ui-danger-bg: #ffe2ef;
  --ui-danger-ink: #b52a68;
  --ui-disabled-bg: #e9edf4;
  --ui-disabled-ink: #a0abbb;
  --ui-status-ink: #213048;
  --ui-success-bg: #d8fbec;
  --ui-success: #19ba92;
  --ui-pending-bg: #eee7ff;
  --ui-pending: #8e6be8;
  --ui-running-bg: #e2ecff;
  --ui-running: #4f82fa;
  --ui-failed-bg: #ffe2ef;
  --ui-failed: #ea5d97;
  --ui-cancelled-bg: #edf0f5;
  --ui-cancelled: #929eb2;
}
:root[data-theme="dark"] {
  --ui-create-bg: #6f5bff;
  --ui-create-ink: #ffffff;
  --ui-view-bg: #315fc7;
  --ui-view-ink: #ffffff;
  --ui-neutral-bg: var(--surface);
  --ui-neutral-ink: var(--ink);
  --ui-neutral-line: var(--line);
  --ui-danger-bg: #c2387e;
  --ui-danger-ink: #ffffff;
  --ui-disabled-bg: #2b2b2b;
  --ui-disabled-ink: #858585;
}

/* New colors are limited to table actions and their filter toolbar. */
.app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button) {
  --ui-action-bg: var(--ui-neutral-bg);
  --ui-action-ink: var(--ui-neutral-ink);
  --ui-action-line: var(--ui-neutral-line);
  background: var(--ui-action-bg);
  color: var(--ui-action-ink);
  border-color: var(--ui-action-line);
}

.app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button):is([data-action-tone="view"], [data-action-tone="edit"], [data-action-tone="open"], .ledger-register-button, .ledger-link-button) {
  --ui-action-bg: var(--ui-view-bg);
  --ui-action-ink: var(--ui-view-ink);
  --ui-action-line: color-mix(in srgb, var(--ui-view-ink) 35%, var(--ui-view-bg));
}

.app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button)[data-ui-action="create"] {
  --ui-action-bg: var(--ui-create-bg);
  --ui-action-ink: var(--ui-create-ink);
  --ui-action-line: color-mix(in srgb, var(--ui-create-ink) 40%, var(--ui-create-bg));
}

.app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button):is(.primary, .ledger-primary, [data-action-tone="success"]) {
  --ui-action-bg: var(--ui-primary);
  --ui-action-ink: var(--ui-primary-ink);
  --ui-action-line: var(--ui-primary);
}

.app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button):is(.danger, [data-action-tone="danger"]) {
  --ui-action-bg: var(--ui-danger-bg);
  --ui-action-ink: var(--ui-danger-ink);
  --ui-action-line: color-mix(in srgb, var(--ui-danger-ink) 35%, var(--ui-danger-bg));
}

.app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button):hover:not(:disabled) {
  background: color-mix(in srgb, var(--ui-action-bg) 96%, var(--ui-action-ink));
  color: var(--ui-action-ink);
  border-color: var(--ui-action-ink);
  filter: none;
}

.app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button):is(.primary, .ledger-primary, [data-action-tone="success"]):hover:not(:disabled) {
  background: var(--ui-primary-hover);
  color: var(--ui-primary-ink);
  border-color: var(--ui-primary-hover);
}

.app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button):is(.primary, .ledger-primary, [data-action-tone="success"]):active:not(:disabled) {
  background: var(--ui-primary-pressed);
  border-color: var(--ui-primary-pressed);
}

.app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button):focus-visible {
  outline-color: var(--ui-primary);
}

.app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button):disabled {
  background: var(--ui-disabled-bg);
  border-color: var(--ui-disabled-bg);
  color: var(--ui-disabled-ink);
  opacity: 1;
  filter: none;
}

/* Fully opaque, white-text colored table buttons in the dark theme only. */
:root[data-theme="dark"] .app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button):is(.primary, .ledger-primary, .danger, [data-action-tone="view"], [data-action-tone="edit"], [data-action-tone="open"], [data-action-tone="success"], [data-action-tone="danger"], [data-ui-action="create"], .ledger-register-button, .ledger-link-button):not(:disabled) {
  background: var(--ui-action-bg);
  border-color: var(--ui-action-bg);
  color: #ffffff;
  opacity: 1;
}
:root[data-theme="dark"] .app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button):is(.primary, .ledger-primary, .danger, [data-action-tone="view"], [data-action-tone="edit"], [data-action-tone="open"], [data-action-tone="success"], [data-action-tone="danger"], [data-ui-action="create"], .ledger-register-button, .ledger-link-button):hover:not(:disabled) {
  background: color-mix(in srgb, var(--ui-action-bg) 90%, #000000);
  border-color: color-mix(in srgb, var(--ui-action-bg) 90%, #000000);
}
:root[data-theme="dark"] .app-shell :is(table :is(.record-actions, .capture-actions, .finance-actions) :is(button, .button), table button[data-action-tone], table .ledger-register-button, table .ledger-link-button, .record-filter-actions button, .ledger-filter-actions button, .finance-filter .finance-actions button):is(.primary, .ledger-primary, .danger, [data-action-tone="view"], [data-action-tone="edit"], [data-action-tone="open"], [data-action-tone="success"], [data-action-tone="danger"], [data-ui-action="create"], .ledger-register-button, .ledger-link-button):active:not(:disabled) {
  background: color-mix(in srgb, var(--ui-action-bg) 82%, #000000);
  border-color: color-mix(in srgb, var(--ui-action-bg) 82%, #000000);
}

/* Same status meaning and pastel fills in both themes. Only status text is recolored. */
.app-shell :is(.badge, .capture-status, .finance-state) {
  --ui-state-bg: var(--ui-cancelled-bg);
  --ui-state-mark: var(--ui-cancelled);
}
:root[data-theme="dark"] .app-shell table :is(.badge, .capture-status, .finance-state):not(.reference-badge),
:root[data-theme="light"] .app-shell :is(.badge, .capture-status, .finance-state):not(.reference-badge) {
  background: var(--ui-state-bg);
  color: var(--ui-status-ink);
  border-color: color-mix(in srgb, var(--ui-state-mark) 25%, var(--ui-state-bg));
}
:is(.app-shell, .modal) :is(.badge.approved, .badge.completed, .capture-status.status-已完成, .finance-state.settled) {
  --ui-state-bg: var(--ui-success-bg);
  --ui-state-mark: var(--ui-success);
}
:is(.app-shell, .modal) :is(.badge.draft, .badge.pending, .badge.queued, .badge.partial, .badge.reconcile,
  .capture-status.status-待制作, .capture-status.status-排队中, .capture-status.status-需核对,
  .finance-state.pending, .finance-state.partial, .finance-state.unpriced) {
  --ui-state-bg: var(--ui-pending-bg);
  --ui-state-mark: var(--ui-pending);
}
:is(.app-shell, .modal) :is(.badge.running, .capture-status.status-制作中, .capture-status.status-生成中) {
  --ui-state-bg: var(--ui-running-bg);
  --ui-state-mark: var(--ui-running);
}
:is(.app-shell, .modal) :is(.badge.failed, .badge.rejected, .capture-status.status-失败, .capture-status.status-异常) {
  --ui-state-bg: var(--ui-failed-bg);
  --ui-state-mark: var(--ui-failed);
}
:is(.app-shell, .modal) :is(.badge, .capture-status, .finance-state) svg { color: var(--ui-state-mark); }

.app-shell table .enterprise-lifecycle-status-cell.is-active { color: var(--ui-success); }
.app-shell table .enterprise-lifecycle-status-cell:is(.is-disabled, .is-deleted) { color: var(--ui-cancelled); }

/* Reuse the summary's established typography, layout, and motion. */
:root[data-theme="light"] .capture-generation-dashboard .capture-dashboard-card.success {
  --summary-card: var(--ui-success-bg);
  --summary-disc: #b9efdf;
  --summary-icon: var(--ui-success);
}
:root[data-theme="light"] .capture-generation-dashboard .capture-dashboard-card.failed {
  --summary-card: var(--ui-failed-bg);
  --summary-disc: #fac7dd;
  --summary-icon: var(--ui-failed);
}
:root[data-theme="light"] .capture-generation-dashboard .capture-dashboard-card.pending {
  --summary-card: var(--ui-pending-bg);
  --summary-disc: #dfd3fb;
  --summary-icon: var(--ui-pending);
}
:root[data-theme="light"] .capture-generation-dashboard .capture-dashboard-card.running {
  --summary-card: var(--ui-running-bg);
  --summary-disc: #ccddff;
  --summary-icon: var(--ui-running);
}
