:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d7dee8;
  --line-strong: #b8c3d2;
  --text: #172033;
  --muted: #667085;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --primary-soft: #e0f2f1;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --warning: #9a6700;
  --warning-soft: #fff7df;
  --ok: #14804a;
  --ok-soft: #e7f6ed;
  --focus: #2563eb;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.09);
  --ledger-row-height: 34px;
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #f8fafc 0%, var(--bg) 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
input,
select,
textarea,
.summary-card,
.status-dot,
.workflow-cell,
.pill,
.filter-menu,
.workflow-dialog,
.recipient-table th,
.recipient-table td {
  transition:
    background 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease,
    color 150ms ease,
    opacity 150ms ease,
    transform 150ms ease;
}

button {
  cursor: pointer;
}

svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(340px, 100%);
  padding: 24px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.login-panel:focus-within {
  transform: translateY(-1px);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.12);
}

.field-label {
  display: block;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.login-panel input,
.search-box input,
.workflow-dialog input,
.workflow-dialog select,
.workflow-dialog textarea,
.summary-controls select {
  min-height: 36px;
  padding: 7px 9px;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.primary-button,
.secondary-button,
.icon-button,
.icon-only,
.small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 36px;
  padding: 7px 10px;
  font-weight: 700;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.icon-button {
  min-width: 78px;
  white-space: nowrap;
}

.primary-button {
  width: 100%;
  margin-top: 14px;
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.icon-button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

.secondary-button:hover,
.icon-only:hover,
.small-button:hover {
  border-color: var(--line-strong);
  background: var(--panel-soft);
  transform: translateY(-1px);
}

.icon-only {
  width: 36px;
  flex: 0 0 36px;
  padding: 0;
}

.is-loading {
  position: relative;
  pointer-events: none;
}

button.is-loading,
.status-dot.is-loading {
  color: transparent !important;
}

button.is-loading svg,
button.is-loading span {
  opacity: 0;
}

.is-loading::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(15, 118, 110, 0.22);
  border-top-color: var(--primary);
  border-radius: 999px;
  animation: spin 760ms linear infinite;
}

.table-region.is-loading::after {
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 0 0 9999px rgba(255, 255, 255, 0.36);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.danger {
  color: var(--danger);
}

.danger:hover {
  border-color: #f0b8b3;
  background: var(--danger-soft);
}

.form-message {
  min-height: 20px;
  margin: 9px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.app-shell {
  height: 100vh;
  min-height: 100vh;
  min-width: 1280px;
  padding: 10px;
  overflow: hidden;
}

.summary-controls,
.summary-card,
.topbar,
.table-region {
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 50px;
  padding: 7px;
}

.summary-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 6px;
}

.summary-controls select {
  width: auto;
  min-width: max-content;
}

.summary-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  width: 132px;
  min-height: 46px;
  padding: 7px 9px;
  color: var(--text);
  text-align: left;
}

.summary-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-card strong {
  min-width: 34px;
  text-align: right;
  font-size: 22px;
  line-height: 1;
}

.summary-card.active {
  border-color: rgba(15, 118, 110, 0.34);
  background: var(--primary-soft);
}

.summary-card:hover {
  border-color: rgba(15, 118, 110, 0.26);
  transform: translateY(-1px);
}

#addRowBtn {
  margin-left: auto;
}

.search-box {
  display: flex;
  align-items: center;
  width: 330px;
  flex: 0 0 330px;
}

.search-box input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.search-box .icon-only {
  border-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.status-dot {
  width: 11px;
  height: 11px;
  margin: 0 8px;
  border-radius: 999px;
  box-shadow: 0 0 0 4px rgba(102, 112, 133, 0.12);
}

.status-dot.online {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(20, 128, 74, 0.14);
}

.status-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(180, 35, 24, 0.12);
}

.table-region {
  position: relative;
  margin-top: 8px;
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
  overflow-y: auto;
  min-height: 320px;
  max-height: calc(100vh - 78px);
}

.ledger-table {
  width: max-content;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.ledger-table th,
.ledger-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.ledger-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 40px;
  padding: 0;
  background: #e8eef6;
  color: #2d3748;
  font-size: 14px;
  text-align: center;
  white-space: nowrap;
}

.th-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 12px;
}

.filterable .th-inner {
  cursor: pointer;
}

.filterable .th-inner span:first-child::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid #667085;
  vertical-align: middle;
}

.filterable.active-filter .th-inner {
  color: var(--primary);
  background: rgba(15, 118, 110, 0.08);
}

.resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}

.resize-handle::after {
  content: "";
  position: absolute;
  top: 9px;
  right: 3px;
  width: 1px;
  height: 22px;
  background: transparent;
  transition: background 140ms ease;
}

.resize-handle:hover::after,
body.resizing .resize-handle::after {
  background: var(--primary);
}

.ledger-table tr {
  position: relative;
  transition: background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.ledger-table tbody tr:hover td {
  background: #f8fbff;
  box-shadow: inset 0 1px 0 rgba(37, 99, 235, 0.08), inset 0 -1px 0 rgba(37, 99, 235, 0.08);
}

.ledger-table tr.new-row {
  animation: newRowIn 460ms ease;
}

.ledger-table tr.selected td {
  background: #eef8f7;
}

.ledger-table tr.draft-row td {
  background: #fbfcfe;
}

.ledger-table td {
  position: relative;
  height: var(--row-height, var(--ledger-row-height));
  padding: 0;
  background: #fff;
  transition: background 140ms ease, box-shadow 140ms ease;
}

.ledger-table td:focus-within {
  background: #f7fbff;
}

.cell-editor,
.workflow-cell {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
  min-height: var(--row-height, var(--ledger-row-height));
  padding: 0 9px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

textarea.cell-editor {
  resize: none;
  padding-top: 10px;
  padding-bottom: 8px;
  line-height: 1.35;
}

@keyframes newRowIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
}

.cell-editor:focus {
  box-shadow: inset 0 0 0 2px var(--focus);
}

.readonly-cell {
  background: #f7f8fb;
  color: #475467;
  font-weight: 700;
}

.code-needs-prefix {
  background: #fff7df;
  animation: codePulse 1.1s ease-in-out infinite;
}

@keyframes codePulse {
  0%, 100% {
    box-shadow: inset 0 0 0 2px rgba(154, 103, 0, 0.2);
  }
  50% {
    box-shadow: inset 0 0 0 2px rgba(154, 103, 0, 0.68);
  }
}

.center-cell,
.text-center {
  text-align: center;
}

.workflow-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-height: calc(var(--row-height, var(--ledger-row-height)) + 2px);
  height: auto;
  color: var(--text);
  text-align: left;
  line-height: 1.35;
}

.row-resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -3px;
  z-index: 4;
  width: 100%;
  height: 6px;
  cursor: row-resize;
}

.row-resize-handle::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2px;
  height: 1px;
  background: transparent;
}

.row-resize-handle:hover::after,
body.row-resizing .row-resize-handle::after {
  background: rgba(37, 99, 235, 0.46);
}

.workflow-cell.empty {
  place-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}

.workflow-empty-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 24px;
  color: var(--muted);
  font-weight: 700;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475467;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill.ok {
  background: #edf8f2;
  color: #2f7a55;
}

.pill.warn {
  background: #fff8e8;
  color: #8a6a22;
}

.pill.bad {
  background: #fff0ef;
  color: #a45049;
}

.status-list {
  display: grid;
  width: 100%;
  gap: 10px;
  overflow: hidden;
  padding: 4px 0;
}

.status-row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.status-label {
  min-width: 28px;
  max-width: 160px;
  overflow: visible;
  color: #475467;
  font-size: 12px;
  font-weight: 700;
  text-overflow: clip;
  white-space: nowrap;
}

.period-strip {
  display: grid;
  grid-auto-columns: minmax(max-content, 1fr);
  grid-auto-flow: column;
  gap: 3px;
  width: 100%;
  min-width: 0;
}

.period-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 20px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: #667085;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  overflow: hidden;
  white-space: nowrap;
}

.period-segment.done {
  border-color: rgba(20, 128, 74, 0.24);
  background: #dff3e8;
  color: #20734a;
}

.period-segment.sent {
  border-color: rgba(177, 122, 32, 0.22);
  background: #fff8e8;
  color: #8a6a22;
}

.period-segment.unsigned {
  border-color: rgba(177, 122, 32, 0.22);
  background: #fff8e8;
  color: #8a6a22;
}

.period-segment.due {
  border-color: rgba(180, 35, 24, 0.22);
  background: #fff0ee;
  color: #a33a32;
}

.period-segment.future,
.period-segment.empty {
  background: #fff;
  color: #98a2b3;
}

.period-segment:hover {
  transform: translateY(-1px);
}

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

.filter-menu {
  position: fixed;
  z-index: 30;
  min-width: 160px;
  max-height: 280px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.filter-menu button {
  display: block;
  width: 100%;
  min-height: 30px;
  padding: 6px 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.filter-menu button:hover,
.filter-menu button.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.workflow-dialog {
  width: min(1240px, calc(100vw - 32px));
  max-height: min(860px, calc(100vh - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  box-shadow: var(--shadow);
}

.workflow-dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.workflow-dialog form {
  display: flex;
  flex-direction: column;
  max-height: min(860px, calc(100vh - 24px));
  padding: 0 10px 10px;
  overflow: hidden;
}

.dialog-header,
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dialog-header {
  flex: 0 0 auto;
  z-index: 5;
  min-height: 38px;
  padding: 10px 0 8px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.dialog-scroll-area {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-bottom: 2px;
}

.dialog-header h2,
.dialog-section h3 {
  margin: 0;
  letter-spacing: 0;
}

.dialog-header h2 {
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dialog-title-actions .secondary-button,
.dialog-title-actions .primary-button {
  width: auto;
  min-width: 72px;
  margin: 0;
}

.danger-soft {
  border-color: #f2c9c5;
  background: #fff3f2;
  color: #9f3a33;
}

.soft-blue {
  border-color: #bcd2ff;
  background: #edf4ff;
  color: #245ea8;
}

.switch-grid {
  display: grid;
  grid-template-columns: 188px 144px 188px 188px 1fr auto;
  gap: 14px;
  margin: 12px 0;
  align-items: stretch;
}

.switch-field {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.switch-field > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.segmented {
  position: relative;
  display: block;
  width: 104px;
  height: 30px;
  border: 1px solid #cfd7e3;
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
  cursor: pointer;
}

.segmented::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #d7dee8;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.18);
  transition: transform 150ms ease, background 150ms ease;
}

.segmented:has(button[data-value="true"].active) {
  border-color: rgba(47, 122, 85, 0.32);
  background: #edf8f2;
}

.segmented:has(button[data-value="true"].active)::before {
  transform: translateX(74px);
  background: #75c596;
}

.segmented button {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  min-height: 28px;
  border: 0;
  background: transparent;
  color: transparent;
  font-size: 0;
  pointer-events: none;
}

.segmented button.active::after {
  content: "不需要";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 18px;
  color: #667085;
  font-size: 12px;
  font-weight: 800;
}

.segmented button[data-value="true"].active::after {
  content: "需要";
  padding-left: 0;
  padding-right: 18px;
  color: #2f7a55;
}

.frequency-field select {
  min-height: 30px;
  padding: 4px 7px;
}

.add-recipient-top {
  align-self: stretch;
  grid-column: 6;
  justify-self: end;
  min-width: 104px;
  padding-inline: 9px;
  border-color: #d6dce6;
  background: #f4f6f9;
  color: #475467;
  white-space: nowrap;
}

.dialog-section {
  margin-top: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.dialog-section h3 {
  font-size: 15px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.form-grid.compact label,
.notes-field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-grid .span-2 {
  grid-column: span 2;
}

.recipient-table-wrap {
  overflow-x: hidden;
  overflow-y: auto;
}

.recipient-table {
  width: 100%;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.detail-row .recipient-table {
  width: 100%;
  min-width: 0;
}

.recipient-table th,
.recipient-table td {
  height: 34px;
  padding: 4px 5px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  vertical-align: middle;
  text-align: center;
}

.recipient-table th {
  background: #eef2f7;
  color: #475467;
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
}

.recipient-table input {
  min-height: 30px;
  padding: 5px 7px;
  text-align: center;
}

.recipient-table input[type="text"] {
  min-width: 0;
}

.recipient-table .idx-col { width: 38px; }
.recipient-table .name-col { width: 150px; }
.recipient-table .copies-col { width: 58px; }
.recipient-table .writer-col { width: 126px; }
.recipient-table .status-col { width: 88px; }
.recipient-table .date-col { width: 154px; }
.recipient-table .remarks-col { width: auto; }
.recipient-table .detail-col { width: 54px; }
.recipient-table .edit-col { width: 44px; }
.recipient-table .action-col { width: 54px; }
.recipient-table .period-col { width: 56px; }

.period-name {
  color: #475467;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.detail-row td {
  background: #fbfcfe;
}

.period-detail-table {
  margin: 3px 0;
  border: 1px solid var(--line);
  border-bottom: 0;
}

.recipient-table .icon-only {
  margin: 0 auto;
}

.detail-toggle {
  min-height: 30px;
  padding: 4px 8px;
  margin: 0 auto;
}

.check-field {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 78px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.check-field input {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.check-field.done {
  border-color: rgba(20, 128, 74, 0.24);
  background: #edf8f2;
  color: #2f7a55;
}

.check-field.pending {
  border-color: rgba(154, 103, 0, 0.24);
  background: #fff8e8;
  color: #8a6a22;
}

.recipient-index {
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.notes-field {
  margin-top: 8px;
}

.notes-field textarea {
  resize: vertical;
}

.detail-notes-input {
  min-height: 30px;
  height: 30px;
  resize: vertical;
  text-align: left !important;
  vertical-align: top;
  line-height: 1.35;
}

.period-tooltip {
  position: fixed;
  z-index: 60;
  min-width: 210px;
  max-width: 300px;
  padding: 9px 10px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
  line-height: 1.55;
  opacity: 1;
  transform: translateY(0);
  animation: tooltipIn 140ms ease;
  pointer-events: none;
}

.period-tooltip .tooltip-title {
  margin-bottom: 4px;
  color: #475467;
  font-weight: 800;
}

.period-tooltip .tooltip-title.tooltip-ok {
  color: #2f7a55;
}

.period-tooltip .tooltip-title.tooltip-warn {
  color: #b17a20;
}

.period-tooltip .tooltip-row {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 6px;
}

.period-tooltip span {
  color: var(--muted);
}

.period-tooltip strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.tooltip-ok {
  color: #2f7a55;
}

.tooltip-info {
  color: #3d73b8;
}

.tooltip-warn {
  color: #b17a20;
}

.tooltip-danger {
  color: #b14c45;
}

.tooltip-muted {
  color: #98a2b3;
}

.tooltip-normal {
  color: var(--text);
}

@keyframes tooltipIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}
