:root {
  /* 兼容现有页面命名；实际值只在 ui-system.css 维护。 */
  --bg: var(--ui-bg);
  --panel: var(--ui-panel);
  --border: var(--ui-border);
  --border-strong: var(--ui-border-strong);
  --text: var(--ui-text);
  --muted: var(--ui-text-muted);
  --subtle: var(--ui-text-subtle);
  --blue: var(--ui-accent);
  --blue-dark: var(--ui-accent-hover);
  --blue-soft: var(--ui-accent-soft);
  --red: var(--ui-danger);
  --red-soft: var(--ui-danger-soft);
  --amber: var(--ui-warning);
  --amber-soft: var(--ui-warning-soft);
  --green: var(--ui-success);
  --green-soft: var(--ui-success-soft);
  --radius: var(--ui-radius);
  --font: var(--ui-font-sans);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font: 12px/1.5 var(--font);
  font-feature-settings: "tnum";
}

button,
input {
  color: inherit;
  font: inherit;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.rw-shell {
  width: 100%;
  padding: 12px 20px 20px;
}

.rw-page-head {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.rw-title-line {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 18px;
}

.rw-page-head h1 {
  flex: 0 0 auto;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.rw-page-head p {
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.rw-head-actions,
.rw-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rw-btn {
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--panel);
  cursor: pointer;
  white-space: nowrap;
}

.rw-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.rw-btn:hover:not(:disabled) {
  border-color: var(--blue);
  color: var(--blue);
}

.rw-btn.primary {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}

.rw-btn.primary:hover:not(:disabled) {
  color: #fff;
  background: var(--blue-dark);
}

.rw-btn.small {
  min-height: 26px;
  padding: 2px 8px;
}

.rw-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
}

.rw-metrics article {
  min-width: 0;
  padding: 8px 12px;
  border-right: 1px solid var(--border);
}

.rw-metrics article:last-child {
  border-right: 0;
}

.rw-metrics span {
  display: block;
  color: var(--muted);
}

.rw-metrics strong {
  display: inline-block;
  margin-top: 1px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
}

.rw-metrics small {
  display: block;
  overflow: hidden;
  color: var(--subtle);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.rw-metrics .upcoming small {
  color: #8a6d1a;
}

.rw-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 10px;
  align-items: start;
}

.rw-main,
.rw-side {
  display: grid;
  gap: 10px;
}

.rw-panel {
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--panel);
}

.rw-panel-head {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.rw-panel-head.compact {
  min-height: 40px;
}

.rw-panel-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
}

.rw-panel-head p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.rw-panel-body {
  padding: 10px;
}

.rw-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.rw-toolbar label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  white-space: nowrap;
}

.rw-panel-actions select,
.rw-toolbar input[type="date"] {
  min-height: 30px;
  padding: 3px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--panel);
}

.rw-batch-summary {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.rw-batch-summary p {
  margin: 0;
  padding: 8px 10px;
  color: var(--muted);
}

.rw-table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

#receivables table,
#documents table,
#contract-expiry table {
  min-width: 720px;
}

#contract-expiry .rw-row-action {
  width: 96px;
  text-align: right;
}

#contract-expiry .rw-expiry-tag {
  padding: 1px 6px;
  border-radius: var(--radius);
}

#batch-billing table {
  min-width: 760px;
}

th,
td {
  padding: 6px 9px;
  border-bottom: 1px solid #e4e4e4;
  text-align: left;
  vertical-align: middle;
}

th {
  color: #444;
  background: #f7f7f7;
  font-size: inherit;
  font-weight: 600;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: #f7faff;
}

.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.check {
  width: 36px;
  text-align: center;
}

.secondary {
  display: block;
  color: var(--muted);
  font-size: inherit;
}

.empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.tag {
  color: var(--text-2);
  background: #f0f0f0;
}

.tag.warning {
  color: var(--amber);
  background: var(--amber-soft);
}

.tag.danger {
  color: var(--red);
  background: var(--red-soft);
}

.tag.ok {
  color: var(--green);
  background: var(--green-soft);
}

.rw-list {
  display: grid;
}

.rw-list-item {
  padding: 8px 10px;
  border-bottom: 1px solid #e4e4e4;
}

.rw-list-item:last-child {
  border-bottom: 0;
}

.rw-list-item .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.rw-list-item strong {
  display: block;
  font-size: inherit;
}

.rw-list-item p {
  margin: 3px 0 6px;
  color: var(--muted);
}

.rw-list-item time {
  color: var(--subtle);
  font-size: inherit;
  white-space: nowrap;
}

.rw-list-item.alert-critical {
  border-left: 3px solid var(--red);
}

.rw-list-item.alert-warning {
  border-left: 3px solid #d49b00;
}

.rw-note {
  padding: 10px;
  border: 1px solid #b8d5f5;
  background: var(--blue-soft);
}

.rw-note strong {
  color: var(--blue-dark);
}

.rw-metrics .risk strong {
  color: var(--red);
}

.rw-metrics .upcoming strong {
  color: #b8860b;
}

.rw-note p {
  margin: 4px 0 0;
  color: #39536f;
}

#rw-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: 360px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: #fff;
  background: #243244;
  box-shadow: 0 6px 20px #1822302b;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition:
    opacity 0.15s ease,
    transform 0.15s ease;
}

#rw-toast.show {
  opacity: 1;
  transform: translateY(0);
}

#rw-toast.error {
  background: var(--red);
}

@media (max-width: 1100px) {
  .rw-layout {
    grid-template-columns: 1fr;
  }

  .rw-side {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rw-note {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .rw-shell {
    padding: 10px 8px 16px;
  }

  .rw-page-head {
    align-items: flex-start;
  }

  .rw-title-line {
    display: block;
  }

  .rw-page-head p {
    margin-top: 2px;
    white-space: normal;
  }

  .rw-metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .rw-metrics article {
    border-top: 1px solid var(--border);
  }

  .rw-metrics article:nth-child(odd) {
    border-right: 1px solid var(--border);
  }

  .rw-metrics article:nth-child(even) {
    border-right: 0;
  }

  .rw-metrics article:first-child,
  .rw-metrics article:nth-child(2) {
    border-top: 0;
  }

  .rw-side {
    grid-template-columns: 1fr;
  }

  .rw-note {
    grid-column: auto;
  }

  .rw-panel-head {
    align-items: flex-start;
  }

  .rw-panel-actions {
    flex-direction: column;
    align-items: flex-end;
  }
}

#operations {
  margin-bottom: 20px;
}
#op-dialog {
  width: min(760px, 92vw);
  max-height: 88vh;
  overflow: auto;
  border: 1px solid #d7dde5;
  border-radius: 12px;
  padding: 24px;
  color: #172b42;
}
#op-dialog::backdrop {
  background: rgb(15 23 42 / 45%);
}
.op-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 20px 0;
}
.op-fields label {
  display: grid;
  gap: 6px;
}
.op-fields input,
.op-fields select,
.op-fields textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 36px;
  padding: 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font: inherit;
}
.op-fields .op-wide {
  grid-column: 1 / -1;
}
#op-error {
  color: #b42318;
}
#op-table td {
  max-width: 320px;
  white-space: normal;
  overflow-wrap: anywhere;
}
#op-table .rw-btn {
  margin: 3px;
}
