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

.kpi-card {
  border: 1px solid var(--line-dark);
  background: var(--surface-tint);
  padding: 6px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-label {
  font-size: 8.5px;
  font-weight: 700;
  color: var(--ink-muted);
  letter-spacing: 0.4px;
}

.kpi-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
}

.kpi-sub {
  font-size: 9.5px;
  color: var(--ink-muted);
}

.toc-title-main {
  font-weight: 700;
  color: var(--ink);
}

.toc-title-sub {
  font-size: 9.5px;
  color: var(--ink-muted);
}

.open-link-btn {
  display: inline-block;
  border: 1px solid var(--line-dark);
  background: #f4f4f5;
  color: #18181b;
  text-decoration: none;
  font-size: 9.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  white-space: nowrap;
}

.open-link-btn:hover {
  background: #e4e4e7;
}

.badge-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 9.5px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.badge-active,
.badge-resolved {
  background: #A8B49A;
  color: #212b1e;
  border: 1px solid #8d9c7e;
}

.badge-pending,
.badge-open,
.badge-progress,
.badge-revision,
.badge-revise {
  background: #FCC963;
  color: #2e2c2a;
  border: 1px solid #dfb050;
}

.badge-obsolete {
  background: #C27C5E;
  color: #ffffff;
  border: 1px solid #a66346;
  text-decoration: line-through;
}

.badge-review {
  background: #ffe699;
  color: #111827;
  border: 1px solid #eab308;
}

.empty-row {
  text-align: center;
  color: var(--ink-muted);
  padding: 8px !important;
}

.data-table td {
  font-size: 10px;
}

.a4-sheet.is-hidden-sheet {
  display: none !important;
}

.summary-search-input {
  height: 28px;
  width: 210px;
  border: 1px solid var(--line-dark);
  border-radius: 5px;
  background: var(--surface-tint);
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  padding: 3px 8px;
}

.sum-paper-seg {
  display: inline-flex;
  align-items: center;
  background: #fafafa;
  border: 1px solid #d4d4d8;
  border-radius: 6px;
  padding: 1.5px;
  gap: 1px;
}

.sum-paper-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: #52525b;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2.5px 7px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.sum-paper-btn:hover {
  background: #f4f4f5;
  color: #18181b;
}

.sum-paper-btn.is-active {
  background: #18181b;
  color: #ffffff;
}

.summary-search-input:focus {
  outline: none;
  border-color: #27272a;
  background: #ffffff;
}

.summary-clear-btn {
  padding: 3px 8px !important;
  font-size: 11px !important;
}

.col-right {
  text-align: right;
}

/* Paper Size Switcher (A4 Portrait / A3 Landscape / A3 Portrait) */
body[data-summary-paper="a4p"] .a4-sheet {
  width: 210mm;
  min-height: 297mm;
  height: 297mm;
  overflow: hidden;
}

body[data-summary-paper="a3l"] .a4-sheet {
  width: 420mm;
  min-height: 297mm;
  height: 297mm;
  padding: 7mm 9mm;
  overflow: hidden;
}

body[data-summary-paper="a3l"] .data-table td {
  font-size: 10.5px;
}

body[data-summary-paper="a3l"] .kpi-grid {
  gap: 12px;
}

body[data-summary-paper="a3p"] .a4-sheet {
  width: 297mm;
  min-height: 420mm;
  height: 420mm;
  padding: 8mm 10mm;
  overflow: hidden;
}

#summaryPages.is-measuring .a4-sheet {
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
}

.summary-cont-sheet .a4-sheet-body-note {
  font-size: 10px;
}

#registerSummaryTable {
  width: 100%;
  table-layout: fixed;
}

#registerSummaryTable thead th[data-reg-col="code"] {
  text-align: center !important;
}

#registerSummaryTable tbody td[data-reg-col="code"],
.sum-code-td {
  text-align: right !important;
}

.sum-code-wrap {
  display: flex;
  align-items: center;
  gap: 3px;
  width: 100%;
}

.sum-code-tools {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0.72;
}

.sum-reg-row:hover .sum-code-tools,
.sum-code-tools:focus-within {
  opacity: 1;
}

.sum-code-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 3px;
  border: 1px solid #d4d4d8;
  background: #f4f4f5;
  color: #18181b;
  text-decoration: none;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.sum-code-link:hover {
  background: #e4e4e7;
}

.sum-code-link.is-linked {
  background: #eef2ff;
  border-color: #818cf8;
  color: #312e81;
}

.sum-code-input {
  flex: 1;
  min-width: 0;
  text-align: right !important;
  font-weight: 700;
}

.sum-row-icon-btn.is-mini {
  width: 17px;
  height: 17px;
  font-size: 10px;
}

.sum-status-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 100%;
}

.sum-row-del-inline {
  opacity: 0.25;
  transition: opacity 0.12s ease;
}

.sum-reg-row:hover .sum-row-del-inline,
.sum-row-del-inline:focus {
  opacity: 1;
}

@media print {
  body[data-summary-paper="a3l"] .a4-sheet {
    width: 100% !important;
    min-height: 0 !important;
  }

  body[data-summary-paper="a3p"] .a4-sheet {
    width: 100% !important;
    min-height: 0 !important;
  }

  .a4-sheet + .a4-sheet {
    break-before: auto;
    page-break-before: auto;
  }

  .a4-sheet:not(.is-hidden-sheet) ~ .a4-sheet:not(.is-hidden-sheet) {
    break-before: page;
    page-break-before: always;
  }
}

/* ==========================================================================
   Summary Inline Editing, Row Resize/Density, Table Config & Live Doc Linking
   ========================================================================== */
.sum-header-tools {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sum-mini-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid #d4d4d8;
  background: #ffffff;
  color: #18181b;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2.5px 8px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}

.sum-mini-btn:hover {
  background: #f4f4f5;
  border-color: #a1a1aa;
}

.sum-mini-btn.is-primary {
  background: #18181b;
  color: #ffffff;
  border-color: #18181b;
}

.sum-mini-btn.is-primary:hover {
  background: #27272a;
}

.sum-table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 8px;
  background: #fafafa;
  border-top: 1px solid #e4e4e7;
}

.sum-footer-left,
.sum-footer-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sum-footer-lbl {
  font-size: 10.5px;
  color: #52525b;
  font-weight: 600;
}

.sum-density-seg {
  display: inline-flex;
  border: 1px solid #d4d4d8;
  border-radius: 5px;
  background: #ffffff;
  padding: 1px;
  gap: 1px;
}

.sum-density-btn {
  border: none;
  background: transparent;
  color: #52525b;
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
}

.sum-density-btn.is-active {
  background: #18181b;
  color: #ffffff;
}

.data-table th {
  position: relative;
}

.sum-col-resizer {
  position: absolute;
  top: 0;
  right: -2px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 4;
}

.sum-col-resizer:hover::after,
.sum-col-resizer.is-dragging::after {
  content: "";
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: 2px;
  background: #3b82f6;
}

.data-table tbody tr {
  position: relative;
}

.data-table tbody td {
  padding: var(--sum-cell-pad-y, 4px) 6px;
  font-size: var(--sum-table-font-size, 10.5px);
  vertical-align: middle;
}

.sum-reg-row {
  height: var(--sum-row-min-h, 28px);
}

.sum-cell-input,
.sum-cell-area {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.32;
  padding: 2px 4px;
  margin: -1px -2px;
}

.sum-cell-area {
  resize: none;
  overflow: hidden;
  display: block;
  min-height: 20px;
}

.sum-cell-input.sum-bold {
  font-weight: 700;
}

.sum-cell-input.col-center {
  text-align: center;
}

.sum-cell-input:hover,
.sum-cell-area:hover {
  background: rgba(244, 244, 245, 0.85);
  border-color: #d4d4d8;
}

.sum-cell-input:focus,
.sum-cell-area:focus {
  outline: none;
  background: #ffffff;
  border-color: #2563eb;
  box-shadow: 0 0 0 1.5px rgba(37, 99, 235, 0.18);
}

.sum-status-select {
  cursor: pointer;
  font-family: inherit;
  font-size: 9.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  max-width: 100%;
  text-align: center;
}

.sum-status-select.badge-obsolete {
  text-decoration: line-through;
}

.sum-link-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex-wrap: nowrap;
}

.open-link-btn.is-linked {
  background: #eef2ff;
  border-color: #818cf8;
  color: #312e81;
}

.open-link-btn.is-linked:hover {
  background: #e0e7ff;
}

.sum-row-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid #d4d4d8;
  background: #ffffff;
  color: #52525b;
  border-radius: 3px;
  font-size: 11px;
  cursor: pointer;
}

.sum-row-icon-btn:hover {
  background: #f4f4f5;
  color: #18181b;
}

.sum-row-icon-btn.is-danger:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}

.sum-row-height-handle {
  display: block;
  width: 100%;
  height: 5px;
  margin-top: 2px;
  cursor: row-resize;
  border-radius: 2px;
}

.sum-row-height-handle:hover,
.sum-row-height-handle.is-dragging {
  background: rgba(59, 130, 246, 0.35);
}

body.sum-nowrap .sum-cell-area {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.sum-borders-soft .data-table th,
body.sum-borders-soft .data-table td {
  border-left-color: transparent;
  border-right-color: transparent;
}

/* Modal Styles */
.sum-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 24, 27, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  padding: 16px;
}

.sum-modal-backdrop[hidden] {
  display: none !important;
}

.sum-modal-card {
  background: #ffffff;
  border: 1px solid #d4d4d8;
  border-radius: 10px;
  width: 100%;
  max-width: 580px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.sum-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #e4e4e7;
  background: #fafafa;
}

.sum-modal-title {
  font-size: 14px;
  font-weight: 700;
  color: #18181b;
}

.sum-modal-sub {
  font-size: 11.5px;
  color: #52525b;
  margin-top: 2px;
}

.sum-modal-close {
  border: 1px solid #d4d4d8;
  background: #ffffff;
  color: #52525b;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}

.sum-modal-close:hover {
  background: #f4f4f5;
  color: #18181b;
}

.sum-modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sum-modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid #e4e4e7;
  background: #fafafa;
}

.sum-cfg-section {
  border: 1px solid #e4e4e7;
  border-radius: 8px;
  padding: 10px 12px;
}

.sum-cfg-title {
  font-size: 12px;
  font-weight: 700;
  color: #18181b;
  margin-bottom: 8px;
}

.sum-cfg-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.sum-cfg-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: #3f3f46;
  font-weight: 600;
}

.sum-cfg-field select,
.sum-cfg-field input[type="number"] {
  border: 1px solid #d4d4d8;
  border-radius: 5px;
  padding: 4px 6px;
  font-family: inherit;
  font-size: 11.5px;
}

.sum-cfg-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  font-size: 11.5px;
  color: #27272a;
}

.sum-cfg-checks label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.sum-col-cfg-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sum-col-cfg-item {
  display: grid;
  grid-template-columns: 1fr 90px 44px;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: #fafafa;
  border: 1px solid #e4e4e7;
  border-radius: 6px;
  font-size: 11.5px;
}

.sum-col-cfg-item input[type="number"] {
  border: 1px solid #d4d4d8;
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 11px;
  width: 72px;
}

.sum-link-options-list {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid #e4e4e7;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
}

.sum-link-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: none;
  border-bottom: 1px solid #f4f4f5;
  background: #ffffff;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.sum-link-opt:hover {
  background: #f4f4f5;
}

.sum-link-opt-main {
  font-size: 11.5px;
  font-weight: 700;
  color: #18181b;
}

.sum-link-opt-sub {
  font-size: 10.5px;
  color: #52525b;
}

@media print {
  .sum-col-resizer,
  .sum-row-height-handle,
  .sum-table-footer,
  .sum-excel-bar,
  .sum-header-tools .sum-mini-btn,
  .sum-row-icon-btn {
    display: none !important;
  }

  .sum-cell-input,
  .sum-cell-area,
  .sum-status-select {
    border-color: transparent !important;
    background-color: inherit;
    box-shadow: none !important;
    appearance: none;
    -webkit-appearance: none;
  }
}

/* ==========================================================================
   Inline Excel-style Table Size Bar (Row Height / Col Width Slider + Input)
   ========================================================================== */
.sum-excel-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 6px 8px;
  background: #f4f4f5;
  border-bottom: 1px solid #d4d4d8;
  font-size: 11px;
}

.sum-excel-bar[hidden] {
  display: none !important;
}

.sum-excel-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.sum-excel-lbl {
  font-weight: 700;
  color: #27272a;
  font-size: 10.5px;
  white-space: nowrap;
}

.sum-excel-sel {
  height: 23px;
  border: 1px solid #d4d4d8;
  border-radius: 4px;
  background: #ffffff;
  color: #18181b;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  padding: 0 5px;
}

.sum-excel-range {
  width: 84px;
  height: 16px;
  accent-color: #18181b;
  cursor: pointer;
}

.sum-excel-num {
  width: 50px;
  height: 23px;
  border: 1px solid #d4d4d8;
  border-radius: 4px;
  background: #ffffff;
  color: #18181b;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  padding: 0 3px;
  font-variant-numeric: tabular-nums;
}

.sum-excel-num.is-sm {
  width: 44px;
}

.sum-excel-num:focus {
  outline: none;
  border-color: #2563eb;
}

.sum-excel-unit {
  font-size: 10px;
  color: #71717a;
}

.sum-excel-sep {
  width: 1px;
  height: 18px;
  background: #d4d4d8;
}

.sum-excel-chk {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  color: #3f3f46;
  cursor: pointer;
  white-space: nowrap;
}

.sum-col-pills {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.sum-col-pill {
  border: 1px solid #d4d4d8;
  background: #ffffff;
  color: #71717a;
  font-family: inherit;
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  cursor: pointer;
}

.sum-col-pill.is-on {
  background: #18181b;
  border-color: #18181b;
  color: #ffffff;
}

.sum-reg-row.is-excel-focused td {
  background: #f8fafc;
}

.sum-reg-row.is-excel-focused td:first-child {
  box-shadow: inset 2.5px 0 0 #2563eb;
}
