:root {
  --score-add: #078c82;
  --score-add-soft: #e8f7f3;
  --score-deduct: #d94b55;
  --score-deduct-soft: #fff0f1;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

.positive-text { color: var(--score-add) !important; }
.negative-text { color: var(--score-deduct) !important; }

.score-badge.add {
  background: var(--score-add-soft);
  color: var(--score-add);
}

.score-badge.deduct {
  background: var(--score-deduct-soft);
  color: var(--score-deduct);
}

.identity-pair,
.organization-pair {
  max-width: 100%;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.identity-pair > span,
.organization-pair > span {
  max-width: 100%;
}

.pair-separator {
  white-space: pre;
}

.action-pair {
  max-width: 100%;
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  overflow-wrap: anywhere;
}

.action-pair code {
  color: #185f9b;
  font-family: ui-monospace, "Cascadia Mono", "Microsoft YaHei UI", monospace;
  font-size: inherit;
  font-weight: 750;
  white-space: normal;
  overflow-wrap: anywhere;
}

.action-pair > span {
  color: #596b7f;
}

.metric em {
  display: block;
  margin-top: 7px;
  color: #8290a0;
  font-size: 10px;
  font-style: normal;
}

.score-mode-switch {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(54px, 1fr));
  padding: 3px;
  border: 1px solid #d8e3eb;
  border-radius: 10px;
  background: #f4f8fb;
}

.score-mode-switch button {
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #66788b;
  font-weight: 700;
}

.score-mode-switch button.active {
  background: #fff;
  color: #0769b3;
  box-shadow: 0 2px 9px rgba(22, 77, 117, .13);
}

.chart-controls,
.chart-legend {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chart-legend {
  justify-content: flex-end;
  margin: -5px 0 10px;
  color: #7c8b9b;
  font-size: 10px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-legend i {
  width: 9px;
  height: 9px;
  display: inline-block;
  border-radius: 3px;
}

.legend-add { background: linear-gradient(180deg, #16b5aa, #078c82); }
.legend-deduct { background: linear-gradient(180deg, #f06b73, #d33f49); }

.score-chart {
  min-width: max(100%, 590px);
  height: 330px;
  display: flex;
  align-items: stretch;
  gap: 18px;
  padding: 12px 22px 18px;
  border-left: 1px solid #d5e0e8;
  border-bottom: 1px solid #d5e0e8;
  background: repeating-linear-gradient(to top, #eef3f7 0, #eef3f7 1px, transparent 1px, transparent 58px);
}

.score-column {
  min-width: 62px;
  max-width: 105px;
  flex: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  align-items: stretch;
  gap: 5px;
  text-align: center;
}

.score-column > strong {
  color: #243d55;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.score-column > small {
  color: #8a97a6;
  font-size: 9px;
  overflow-wrap: anywhere;
}

.score-plot {
  position: relative;
  min-height: 240px;
}

.score-plot::after {
  content: "";
  position: absolute;
  z-index: 0;
  right: -9px;
  bottom: 50%;
  left: -9px;
  border-top: 1px solid #9eb0bf;
}

.score-plot.positive-only::after {
  bottom: 0;
}

.score-bar {
  position: absolute;
  z-index: 1;
  left: 50%;
  width: 38px;
  min-height: 2px;
  transform: translateX(-50%);
  box-shadow: 0 5px 13px rgba(24, 75, 107, .16);
}

.score-bar.positive {
  border-radius: 7px 7px 2px 2px;
  background: linear-gradient(180deg, #16b5aa, #078c82);
}

.score-bar.negative {
  border-radius: 2px 2px 7px 7px;
  background: linear-gradient(180deg, #d33f49, #f06b73);
}

.deduct-chart .score-bar.negative {
  border-radius: 7px 7px 2px 2px;
  background: linear-gradient(180deg, #f06b73, #d33f49);
}

.score-value {
  position: absolute;
  z-index: 2;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  white-space: nowrap;
}

.score-value.positive { color: #067c74; }
.score-value.negative { color: #c93641; }

.zero-dot {
  position: absolute;
  z-index: 2;
  left: 50%;
  width: 6px;
  height: 6px;
  transform: translate(-50%, 50%);
  border: 2px solid #8295a6;
  border-radius: 50%;
  background: #fff;
}

.draft-totals {
  min-width: 290px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.draft-totals > span {
  display: grid;
  gap: 3px;
}

.draft-totals small {
  color: #78889a;
  font-size: 10px;
}

.draft-totals b {
  font-size: 14px;
}

.draft-totals .net-total {
  padding-left: 16px;
  border-left: 1px solid #dae3ea;
}

.draft-totals strong {
  font-size: 22px;
}

.draft-totals i {
  color: #778697;
  font-size: 10px;
  font-style: normal;
}

.score-summary {
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
}

.query-range {
  padding: 11px 16px;
  border-bottom: 1px solid #edf2f6;
  color: #7c8999;
  font-size: 11px;
}

.score-cell {
  display: grid;
  gap: 2px;
  white-space: nowrap;
}

.score-cell small {
  margin: 0 !important;
}

.mobile-score-line {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 11px;
}

.mobile-score-line i {
  color: #68798a;
  font-style: normal;
}

.formal-score-totals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.formal-score-totals > span {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.formal-score-totals small {
  color: #7d8c9b;
}

.formal-score-totals b,
.formal-score-totals strong {
  overflow-wrap: anywhere;
}

body.drawer-open {
  overflow: hidden;
  touch-action: none;
}

.drawer-backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
}

.drawer {
  max-width: 100vw;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-x: none;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}

.drawer *,
.drawer-head > div,
.detail-grid > div,
.detail-block {
  min-width: 0;
  max-width: 100%;
}

.drawer h3,
.drawer h4,
.drawer p,
.drawer dd,
.drawer small,
.drawer span {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.import-zone {
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.import-zone > * {
  max-width: 100%;
  min-width: 0;
}

.import-zone input[type="file"] {
  width: min(100%, 520px);
  min-height: 46px;
  padding: 6px;
  border: 1px solid #d6e0e8;
  border-radius: 9px;
  background: #fff;
  color: #536679;
}

.import-zone input[type="file"]::file-selector-button {
  min-height: 32px;
  margin-right: 8px;
  padding: 0 11px;
  border: 0;
  border-radius: 7px;
  background: #eaf4fa;
  color: #0769b3;
  font-weight: 700;
}

@media (max-width: 760px) {
  .chart-heading {
    display: grid !important;
    gap: 12px;
  }

  .chart-controls {
    justify-content: space-between;
  }

  .score-mode-switch {
    flex: 1;
  }

  .score-mode-switch button {
    padding: 0 7px;
  }

  .chart-legend {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .score-chart {
    min-width: max(100%, 520px);
    height: 305px;
    gap: 13px;
    padding: 10px 16px 15px;
  }

  .score-column {
    min-width: 58px;
  }

  .score-plot {
    min-height: 218px;
  }

  .score-bar {
    width: 31px;
  }

  .draft-totals {
    min-width: 0;
    display: grid;
    grid-template-columns: auto auto minmax(74px, 1fr);
    gap: 8px;
  }

  .draft-totals .net-total {
    padding-left: 8px;
  }

  .draft-totals strong {
    font-size: 18px;
  }

  .entry-footer {
    grid-template-columns: minmax(0, 1fr);
  }

  .footer-actions {
    width: 100%;
  }

  .score-summary {
    grid-template-columns: 1fr 1fr;
  }

  .score-summary > div {
    border-bottom: 1px solid #edf2f6;
  }

  .score-summary p {
    display: none;
  }

  .formal-score-totals {
    grid-template-columns: 1fr 1fr;
  }

  .formal-score-totals > span:last-child {
    grid-column: 1 / -1;
    padding-top: 10px;
    border-top: 1px solid #e4ebf0;
  }

  .drawer {
    right: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
  }

  .drawer .detail-grid {
    width: 100%;
    grid-template-columns: minmax(0, 1fr);
  }

  .tabs,
  .card-pad,
  .import-zone,
  #import-result {
    min-width: 0;
    max-width: 100%;
  }

  .import-zone {
    min-height: 0;
    place-items: stretch;
    padding: 20px 12px;
    text-align: left;
  }

  .import-zone .btn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: normal;
  }

  .error-table {
    width: auto;
    margin-right: 0;
    margin-left: 0;
  }

  .responsive-table td .identity-pair,
  .responsive-table td .organization-pair,
  .responsive-table td .action-pair {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .chart-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .chart-controls > .pill {
    align-self: flex-start;
  }

  .draft-totals {
    grid-template-columns: 1fr 1fr;
  }

  .draft-totals .net-total {
    grid-column: 1 / -1;
    grid-template-columns: auto 1fr;
    align-items: baseline;
    padding: 8px 0 0;
    border-top: 1px solid #dae3ea;
    border-left: 0;
  }

  .draft-totals .net-total strong {
    justify-self: end;
  }

  .identity-pair,
  .organization-pair {
    font-size: inherit;
  }
}
