/* Shiny adaptations layered over the original dashboard mockup stylesheet. */

html { scroll-behavior: smooth; }

body > .container-fluid {
  margin: 0;
  padding: 0;
  width: 100%;
}

a, a:hover, a:focus { color: var(--accent); }

.skip-link {
  background: var(--pin);
  border-radius: 0 0 6px 0;
  color: #fff;
  font-weight: 700;
  left: 0;
  padding: 9px 14px;
  position: fixed;
  top: -60px;
  z-index: 1000;
}

.skip-link:focus {
  color: #fff;
  outline: 3px solid var(--accent);
  top: 0;
}

.form-group, .radio, .checkbox {
  margin-bottom: 0;
  margin-top: 0;
}

.seg-control > .form-group > .control-label {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.seg-control .shiny-options-group {
  border: 1px solid var(--control-border);
  border-radius: 6px;
  display: flex;
  overflow: hidden;
}

.seg-control .radio-inline {
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font: 600 12px/1 var(--f-body);
  margin: 0;
  padding: 0;
}

.seg-control .radio-inline + .radio-inline {
  border-left: 1px solid var(--border);
  margin-left: 0;
}

.seg-control .radio-inline label {
  cursor: pointer;
  display: block;
  font-weight: 600;
  margin: 0;
  padding: 9px 13px;
}

.seg-control label.radio-inline {
  padding: 9px 13px;
}

.seg-control label.radio-inline span {
  display: block;
}

.seg-control .radio-inline input {
  height: 1px;
  margin: 0;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.seg-control .radio-inline:has(input:checked) {
  background: var(--accent);
  color: #fff;
}

.seg-control .radio-inline:has(input:focus-visible) {
  box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px var(--accent);
}

.year-control .radio-inline label {
  padding-left: 10px;
  padding-right: 10px;
}

.year-control label.radio-inline {
  padding-left: 10px;
  padding-right: 10px;
}

.finder .selectize-control { margin: 0; }

.finder .selectize-input {
  height: 34px;
  max-height: 34px;
  overflow: hidden;
  white-space: nowrap;
}

.finder .selectize-input > .item {
  display: inline-block;
  max-width: calc(100% - 12px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.finder .selectize-input.focus > .item {
  display: none;
}

.finder .selectize-input.focus > input {
  display: inline-block !important;
  min-width: 100% !important;
  width: 100% !important;
}

.finder .selectize-input,
.subgroup-control .selectize-input,
.subgroup-control select.form-control {
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  box-shadow: none;
  color: var(--text);
  font: 400 13px/1.35 var(--f-body);
  min-height: 34px;
  padding: 8px 34px 8px 10px;
}

.finder .selectize-input.focus,
.subgroup-control .selectize-input.focus,
.subgroup-control select.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
  outline: 0;
}

.selectize-dropdown {
  background: var(--surface);
  border-color: var(--control-border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(10, 20, 40, .16);
  color: var(--text);
  font-family: var(--f-body);
  line-height: 1.35;
  margin-top: 4px;
}

.selectize-dropdown .option {
  border-bottom: 1px solid var(--grid);
  padding: 8px 10px;
}

.selectize-dropdown .active {
  background: var(--accent-soft);
  color: var(--text);
}

.topbar .btn {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  line-height: 1.2;
  min-height: 34px;
  text-decoration: none;
}

.topbar .export-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.topbar .export-btn:hover,
.topbar .export-btn:focus {
  background: color-mix(in srgb, var(--accent) 88%, #000);
  color: #fff;
}

.left-column, .right-column { min-width: 0; }
.indicator-card > header { align-items: center; }

.subgroup-control {
  align-items: center;
  display: flex;
  gap: 8px;
}

.subgroup-control label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
}

.subgroup-control .form-group { min-width: 175px; }
.subgroup-control .selectize-control { margin-bottom: 0; }

.badge {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
  white-space: nowrap;
}

.scorebox { min-width: 285px; }

.status-note {
  color: var(--text);
  max-width: 430px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  background: var(--accent-soft);
  line-height: 1.45;
  text-align: left;
}

.next-divider {
  color: var(--border);
  margin: 0 5px;
}

details.ind > summary { list-style: none; }
details.ind > summary::-webkit-details-marker { display: none; }
details.ind > .ind-b { display: none; }
details.ind[open] > .ind-b { display: block; }

details.ind > .ind-h::after {
  border-bottom: 2px solid var(--muted);
  border-right: 2px solid var(--muted);
  content: "";
  height: 9px;
  margin: 0 3px 4px 4px;
  transform: rotate(45deg);
  transition: transform .15s ease;
  width: 9px;
}

details.ind[open] > .ind-h::after {
  margin-bottom: -2px;
  transform: rotate(225deg);
}

.years-pill, .restriction-pill {
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--muted);
  display: inline-block;
  font-size: 9.5px;
  line-height: 1.2;
  margin-left: 5px;
  padding: 2px 6px;
  vertical-align: 1px;
  white-space: nowrap;
}

.restriction-pill {
  border-color: color-mix(in srgb, var(--D) 45%, var(--border));
  color: var(--D);
}

.rank-1 { background: color-mix(in srgb, var(--F) 12%, var(--surface)); border-color: color-mix(in srgb, var(--F) 35%, var(--border)); }
.rank-2 { background: color-mix(in srgb, var(--D) 12%, var(--surface)); border-color: color-mix(in srgb, var(--D) 35%, var(--border)); }
.rank-3 { background: color-mix(in srgb, var(--C) 12%, var(--surface)); border-color: color-mix(in srgb, var(--C) 35%, var(--border)); }
.rank-4 { background: color-mix(in srgb, var(--B) 12%, var(--surface)); border-color: color-mix(in srgb, var(--B) 35%, var(--border)); }
.rank-5 { background: color-mix(in srgb, var(--A) 12%, var(--surface)); border-color: color-mix(in srgb, var(--A) 35%, var(--border)); }

.empty-cell, .empty-state {
  color: var(--muted);
  font-size: 12.5px;
  padding: 18px 16px;
}

.chart-body {
  min-height: 285px;
  padding: 4px 12px 0 !important;
}

.shiny-plot-output { max-width: 100%; }
.shiny-plot-output img {
  display: block;
  max-width: 100%;
}

.grade-legend {
  align-items: center;
  border-top: 1px solid var(--grid);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 11.5px;
  gap: 13px;
  padding: 5px 16px 10px;
}

.grade-legend span {
  align-items: center;
  display: inline-flex;
  gap: 5px;
}

.grade-legend i:not(.u-legend-pin) {
  border-radius: 2px;
  display: inline-block;
  height: 4px;
  width: 18px;
}

.grade-legend .u-legend-pin {
  display: inline-block;
  margin-left: 5px;
}

.composition-total-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  margin-bottom: 7px;
  text-transform: uppercase;
}

.composition-total-track {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  display: flex;
  height: 30px;
  overflow: visible;
  position: relative;
}

.composition-segment:first-child { border-radius: 4px 0 0 4px; }
.composition-segment {
  display: block;
  height: 100%;
  min-width: 0;
}

.cut-marker {
  border-left: 1px dashed currentColor;
  bottom: -18px;
  color: var(--muted);
  height: 46px;
  position: absolute;
  transform: translateX(-.5px);
  z-index: 2;
}

.cut-marker b, .cut-marker small {
  background: var(--surface);
  display: block;
  font-size: 11px;
  line-height: 1.05;
  padding: 1px 3px;
}

.cut-marker b { color: #fff; font-weight: 800; }
.cut-marker small { color: var(--text); font-size: 10.5px; }
.cut-A { color: var(--grade-label-A); }
.cut-B { color: var(--grade-label-B); }
.cut-C { color: var(--grade-label-C); }
.cut-D { color: var(--grade-label-D); }
.cut-F { color: var(--grade-label-F); }
.cut-A b { background: var(--A); }
.cut-B b { background: var(--B); }
.cut-C b { background: var(--C); }
.cut-D b { background: var(--D); }
.cut-F b { background: var(--F); }

.composition-rows { margin-top: 36px; }

.composition-row {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(115px, 1fr) minmax(130px, 2fr) auto;
  margin: 8px 0;
}

.composition-label { font-size: 12px; }

.composition-track {
  background: var(--surface-2);
  border-radius: 5px;
  height: 8px;
  overflow: hidden;
}

.composition-earned {
  border-radius: 5px;
  display: block;
  height: 100%;
}

.composition-segment.is-estimated,
.composition-earned.is-estimated {
  background-image: repeating-linear-gradient(
    135deg,
    rgba(255, 255, 255, .28) 0,
    rgba(255, 255, 255, .28) 4px,
    transparent 4px,
    transparent 8px
  ) !important;
}

.composition-value {
  color: var(--muted);
  font-size: 11.5px;
  min-width: 82px;
  text-align: right;
}

.composition-footnote {
  color: var(--muted);
  font-size: 11px;
  margin: 14px 0 0;
}

.trend-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(280px, .8fr) minmax(420px, 1.4fr);
}

.trend-grid h3 {
  font-size: 12px;
  letter-spacing: .02em;
  margin: 0 0 4px;
}

.trend-lead, .trend-small {
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 6px;
  min-width: 0;
  padding: 10px 10px 2px;
}

.trend-lead { background: var(--surface-2); }

.methodology-card details > summary {
  cursor: pointer;
  font-family: var(--f-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .04em;
  list-style-position: inside;
  padding: 13px 16px;
  text-transform: uppercase;
}

.methodology-card details[open] > summary {
  border-bottom: 1px solid var(--border);
}

.methodology-card .shiny-html-output {
  padding: 14px 16px 18px;
}

.method-grid {
  display: grid;
  gap: 28px;
  grid-template-columns: minmax(220px, .65fr) minmax(300px, 1.35fr);
}

.method-grid h3 {
  font-size: 13px;
  margin-bottom: 6px;
}

.method-grid p {
  color: var(--muted);
  font-size: 12px;
  margin: 5px 0 10px;
}

.cut-table {
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 10px;
  width: 100%;
}

.cut-table th, .cut-table td {
  border-bottom: 1px solid var(--grid);
  padding: 5px 7px;
  text-align: left;
}

.cut-table th:last-child, .cut-table td:last-child { text-align: right; }

.shiny-output-error, .shiny-output-error-validation {
  color: var(--muted);
  font-family: var(--f-body);
  font-size: 12px;
  padding: 16px;
}

.recalculating {
  opacity: .58;
  transition: opacity .12s ease;
}

@media (prefers-color-scheme: dark) {
  /* ggplot output is rasterized server-side; keep the whole app light and legible. */
  :root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef2f7;
    --border: #d5dde7;
    --text: #16202e;
    --muted: #5b6b80;
    --accent: #1b4b8f;
    --accent-soft: #e7eefa;
    --A: #1f6f5c;
    --B: #23733b;
    --C: #765600;
    --D: #99440e;
    --F: #a3282b;
    --grid: #e3e9f0;
    --pin: #12233b;
    --i0: #1b4b8f;
    --i1: #3d76bd;
    --i2: #7aa5d8;
    --i3: #b9cfe9;
  }
}

@media (max-width: 1180px) {
  .topbar { gap: 10px; }
  .brand { flex-basis: 100%; }
  .finder { max-width: none; }
}

@media (max-width: 1080px) {
  .left-column, .right-column, .card.full { grid-column: auto; }
  .trend-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .topbar { padding: 10px 12px; }
  .brand-agency-logo { width: min(100%, 310px); }
  .entity-type-control, .year-control { flex: 1 1 auto; }

  .seg-control .shiny-options-group,
  .seg-control .form-group { width: 100%; }

  .seg-control .radio-inline {
    flex: 1 1 auto;
    text-align: center;
  }

  .finder {
    flex-basis: 100%;
    min-width: 100%;
    order: 4;
  }

  .print-btn, .export-btn { flex: 1 1 auto; }
  .mast { padding: 15px 14px 17px; }

  .mast-in {
    gap: 13px;
    grid-template-columns: auto 1fr;
  }

  .badge {
    font-size: 40px;
    height: 72px;
    width: 72px;
  }

  .scorebox {
    border-left: 0;
    border-top: 1px solid var(--border);
    grid-column: 1 / -1;
    min-width: 0;
    padding: 13px 0 0;
    text-align: left;
  }

  .wrap { padding: 13px 10px 28px; }

  .card > header, .indicator-card > header {
    align-items: flex-start;
    flex-direction: column;
  }

  .subgroup-control {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .subgroup-control .form-group { width: 100%; }
  .ind-h { gap: 9px; grid-template-columns: 1fr auto auto; }
  .ind-h .q { display: none; }
  table.meas { font-size: 11.5px; }

  table.meas th, table.meas td {
    padding-left: 4px;
    padding-right: 4px;
  }

  .composition-row { grid-template-columns: 1fr auto; }

  .composition-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .method-grid { grid-template-columns: 1fr; }
}

@media print {
  details.ind > .ind-b,
  .methodology-card details > .shiny-html-output {
    display: block !important;
  }

  .left-column, .right-column, .card.full { grid-column: auto; }
  .trend-grid, .method-grid { grid-template-columns: 1fr; }
  .shiny-plot-output { break-inside: avoid; }
}
