:root {
  --content-max: 1360px;
  --page-pad: 24px;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e1ec;
  --panel: #ffffff;
  --bg: #f4f7fb;
  --blue: #1f4e79;
  --teal: #0f766e;
  --amber: #b45309;
  --red: #b91c1c;
  --green: #15803d;
  --emerald: #047857;
  --violet: #6d28d9;
  --shadow: 0 10px 28px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
}

header {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 18px var(--page-pad);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin: 0 auto;
  max-width: var(--content-max);
  width: 100%;
}

h1 {
  font-size: 22px;
  line-height: 1.25;
  margin: 0;
}

h1,
h2,
h3,
.link-section-title,
.list-count {
  overflow-wrap: normal;
  text-wrap: balance;
}

.subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

main {
  display: grid;
  gap: 14px;
  margin: 0 auto;
  max-width: var(--content-max);
  padding: 20px var(--page-pad) 48px;
  width: 100%;
}

.nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

a.button,
button {
  background: var(--blue);
  border: 0;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  font-weight: 700;
  gap: 8px;
  padding: 10px 14px;
  text-decoration: none;
}

button.secondary,
a.secondary {
  background: #eef3f8;
  color: var(--blue);
}

a.import-action {
  background: var(--emerald);
  color: #fff;
}

.grid {
  display: grid;
  gap: 14px;
}

.cards {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  padding: 16px;
}

.card > h2 {
  align-items: center;
  display: flex;
  font-size: 18px;
  line-height: 1.25;
  margin: 0 0 12px !important;
  min-height: 24px;
  white-space: nowrap;
}

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

.metric strong {
  color: var(--ink);
  display: block;
  font-size: 30px;
  margin-top: 6px;
}

.project-overview {
  align-items: stretch;
  background: linear-gradient(135deg, #ffffff 0%, #f7fbff 54%, #eef7f3 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(260px, 1.2fr) minmax(320px, 1fr);
  margin-bottom: 14px;
  padding: 18px;
}

.project-overview .project-kicker,
.project-breakdown span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.project-overview strong {
  color: var(--ink);
  display: block;
  font-size: 34px;
  line-height: 1;
  margin-top: 7px;
}

.project-overview p {
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.45;
  margin: 10px 0 0;
  max-width: 620px;
}

.project-breakdown {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.project-breakdown article {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(203, 213, 225, 0.82);
  border-radius: 8px;
  padding: 14px;
}

.project-breakdown strong {
  font-size: 30px;
}

.toolbar {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin: 18px 0 12px;
  min-width: 0;
}

.filters {
  display: flex;
  flex: 1 1 auto;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  min-height: 38px;
  padding: 8px 10px;
}

input[type="search"] {
  flex: 1 1 280px;
  min-width: min(280px, 100%);
}

.multi-filter {
  background: #fff;
  flex: 1 1 170px;
  min-height: 94px;
  min-width: 160px;
  padding: 6px;
}

.multi-filter option {
  border-radius: 4px;
  padding: 5px 7px;
}

.multi-filter option:checked {
  background: linear-gradient(0deg, #dbeafe, #dbeafe);
  color: #1f4e79;
  font-weight: 800;
}

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

#records,
#kpTable {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding-bottom: 2px;
}

#records table {
  min-width: 2240px;
}

#kpTable table {
  min-width: 1040px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #edf3f8;
  color: #203147;
  font-weight: 800;
  line-height: 1.18;
  position: sticky;
  top: 73px;
  vertical-align: middle;
  white-space: nowrap;
  z-index: 2;
}

#records th,
#kpTable th {
  position: static;
  top: auto;
  z-index: auto;
}

.status {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
}

.status.empty {
  background: #eef1f5;
  color: #667085;
}

.status.done {
  background: #d1fae5;
  color: var(--emerald);
}

.status.work {
  background: #dcfce7;
  color: var(--green);
}

.status.lost {
  background: #ede9fe;
  color: var(--violet);
}

.status.no {
  background: #fee2e2;
  color: var(--red);
}

.status.force {
  background: #fff1d6;
  color: var(--amber);
}

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

.list-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 10px;
}

.leader-analytics {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.section-heading {
  align-items: end;
  display: flex;
  justify-content: space-between;
}

.section-heading h2 {
  font-size: 18px;
  margin: 0;
}

.section-heading p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin: 4px 0 0;
}

.focus-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.distribution-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.focus-stat {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px;
  min-height: 104px;
  padding: 14px;
}

.distribution-card {
  background: #fff;
  border: 1px solid var(--line);
  border-top: 5px solid var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 14px;
}

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

.distribution-card strong {
  color: var(--ink);
  font-size: 32px;
  line-height: 1;
}

.distribution-card em {
  color: var(--accent);
  font-size: 13px;
  font-style: normal;
  font-weight: 900;
}

.distribution-strip {
  background: #e5e7eb;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  height: 28px;
  overflow: hidden;
}

.distribution-strip span {
  min-width: 2px;
}

.pie-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.pie-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.pie-panel h3 {
  font-size: 15px;
  margin: 0 0 12px;
}

.pie-content {
  align-items: center;
  display: grid;
  gap: 14px;
  grid-template-columns: 170px minmax(0, 1fr);
}

.pie-content-single {
  grid-template-columns: 1fr;
  justify-items: center;
}

.svg-donut-chart {
  align-items: center;
  display: grid;
  justify-items: center;
  max-width: 420px;
  position: relative;
  width: 100%;
}

.svg-donut-chart > div {
  display: grid;
  gap: 2px;
  justify-items: center;
  left: 50%;
  position: absolute;
  top: 46%;
  transform: translate(-50%, -50%);
  z-index: 1;
}

.svg-donut-chart strong {
  color: var(--ink);
  font-size: 30px;
  line-height: 1;
}

.svg-donut-chart span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.pie-svg,
.donut-svg {
  display: block;
  height: auto;
  max-width: 440px;
  overflow: visible;
  width: 100%;
}

.pie-label {
  cursor: pointer;
}

.pie-label line {
  opacity: 0.75;
}

.pie-label text {
  fill: #172033;
  font-family: inherit;
  paint-order: stroke;
  stroke: #fff;
  stroke-linejoin: round;
  stroke-width: 3px;
}

.pie-label-title {
  font-size: 6.4px;
  font-weight: 900;
}

.pie-label-value {
  font-size: 5.8px;
  font-weight: 800;
}

.pie-label.active text {
  fill: #075985;
}

.pie-label.muted-label {
  opacity: 0.4;
}

.pie-inline-status {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.pie-inline-status span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.donut-chart,
.pie-chart {
  aspect-ratio: 1;
  background: conic-gradient(var(--pie));
  border-radius: 50%;
  width: 170px;
}

.donut-chart {
  align-items: center;
  display: grid;
  justify-items: center;
  position: relative;
}

.donut-chart::after {
  background: #fff;
  border-radius: 50%;
  content: "";
  inset: 36px;
  position: absolute;
}

.donut-chart > div {
  display: grid;
  gap: 2px;
  justify-items: center;
  position: relative;
  z-index: 1;
}

.donut-chart strong {
  color: var(--ink);
  font-size: 34px;
  line-height: 1;
}

.donut-chart span,
.pie-note span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.pie-note {
  display: grid;
  gap: 4px;
}

.pie-note strong {
  color: var(--ink);
  font-size: 24px;
}

.pie-legend {
  display: grid;
  gap: 7px;
}

.pie-legend-row {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: inherit;
  cursor: pointer;
  display: grid;
  gap: 7px;
  grid-template-columns: 10px minmax(0, 1fr) auto auto;
  padding: 4px 6px;
  text-align: left;
}

.legend-dot {
  aspect-ratio: 1;
  border-radius: 50%;
  display: inline-block;
  width: 10px;
}

.pie-legend-row span {
  color: #203147;
  font-size: 13px;
  font-weight: 800;
}

.pie-legend-row strong,
.pie-legend-row em {
  font-size: 13px;
  white-space: nowrap;
}

.pie-legend-row em {
  color: var(--muted);
  font-style: normal;
  font-weight: 800;
}

.pie-legend-row.active {
  background: #e0f2fe;
  outline: 2px solid #7dd3fc;
}

.pie-slice {
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
  transform-origin: 90px 70px;
}

.pie-slice:hover,
.pie-slice.active {
  opacity: 1;
  transform: scale(1.025);
}

.pie-slice.muted-slice {
  opacity: 0.35;
}

.clear-distribution {
  justify-self: start;
  margin-top: 8px;
}

.active-filter-pill {
  background: #e0f2fe;
  border: 1px solid #7dd3fc;
  border-radius: 999px;
  color: #075985;
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  margin-left: 8px;
  padding: 4px 8px;
}

.focus-stat span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.focus-stat strong {
  color: var(--ink);
  font-size: 34px;
  line-height: 1;
}

.focus-stat em {
  color: var(--accent);
  font-size: 13px;
  font-style: normal;
  font-weight: 800;
}

.analytics-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(320px, 0.95fr) minmax(0, 1.35fr);
}

.analysis-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.analysis-panel h3 {
  font-size: 15px;
  margin: 0 0 14px;
}

.payout-panel {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.payout-panel-title {
  align-items: center;
  background: #fff;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.payout-panel-title h3 {
  flex: 1 1 auto;
  font-size: clamp(14px, 1.55vw, 17px);
  line-height: 1.25;
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.payout-panel-title span {
  background: #eef3f8;
  border-radius: 999px;
  color: var(--blue);
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 900;
  padding: 5px 9px;
  white-space: nowrap;
}

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

.payout-card {
  background: #f8fafc;
  border: 1px solid #dbe3ea;
  border-top: 4px solid #64748b;
  border-radius: 8px;
  padding: 12px;
}

.payout-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  min-height: 32px;
}

.payout-card strong {
  color: var(--ink);
  display: block;
  font-size: 28px;
  margin-top: 4px;
}

.payout-card small {
  color: var(--muted);
  font-weight: 800;
}

.payout-table th,
.payout-table td {
  position: static;
  top: auto;
  white-space: nowrap;
  z-index: auto;
}

.payout-table {
  position: relative;
  z-index: 0;
}

.payout-bar {
  background: #e2e8f0;
  border-radius: 999px;
  display: flex;
  height: 12px;
  min-width: 130px;
  overflow: hidden;
}

.payout-bar span {
  display: block;
  min-width: 0;
}

.payout-bar .paid {
  background: #047857;
}

.payout-bar .bank-pending {
  background: #2563eb;
}

.payout-bar .missing {
  background: #b45309;
}

.chart-stack {
  display: grid;
  gap: 12px;
}

.chart-bar-row {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 128px minmax(140px, 1fr) 76px;
}

.distribution-row {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 150px minmax(140px, 1fr) 86px;
}

.chart-bar-label {
  color: #203147;
  font-size: 13px;
  font-weight: 800;
}

.chart-track {
  background: #edf2f7;
  border-radius: 999px;
  height: 16px;
  overflow: hidden;
}

.chart-fill {
  border-radius: 999px;
  height: 100%;
}

.chart-bar-value {
  display: grid;
  gap: 2px;
  justify-items: end;
}

.chart-bar-value strong {
  font-size: 16px;
  line-height: 1;
}

.chart-bar-value span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.composition-bar {
  border-radius: 999px;
  display: flex;
  height: 12px;
  margin-top: 18px;
  overflow: hidden;
}

.composition-bar span {
  min-width: 2px;
}

.heatmap-wrap {
  overflow-x: auto;
}

.heatmap-table th,
.heatmap-table td {
  position: static;
  text-align: center;
  white-space: nowrap;
}

.heatmap-table th {
  line-height: 1.25;
  min-width: 78px;
  top: auto;
  vertical-align: middle;
  z-index: auto;
}

.heatmap-table th:first-child,
.heatmap-table td:first-child {
  text-align: left;
}

.heat-cell {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #172033;
  display: inline-flex;
  font-size: 13px;
  font-weight: 900;
  justify-content: center;
  min-width: 34px;
  padding: 6px 8px;
}

.team-list {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.team-card {
  align-items: start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 14px;
}

.leader-link {
  background: linear-gradient(180deg, #ffffff 0%, #f0f7ff 100%);
  border-color: #9fc5e8;
  grid-column: 1 / -1;
}

.officer-link {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border-color: #b7c7d8;
}

.link-section-title {
  color: var(--ink);
  font-size: 18px;
  grid-column: 1 / -1;
  margin: 14px 0 0;
}

.copy-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

.copy-row input {
  width: 100%;
}

.case-list {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.case-card {
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  padding: 16px;
}

.case-head {
  align-items: start;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

.case-title {
  font-size: 18px;
  font-weight: 800;
}

.case-code {
  background: #eef6ff;
  border-radius: 999px;
  color: var(--blue);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
  padding: 5px 9px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-top: 3px;
}

.info-grid {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 10px;
}

.info-item {
  font-size: 13px;
  line-height: 1.35;
}

.info-item span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 3px;
}

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

.status-buttons button {
  background: #eef3f8;
  color: var(--blue);
  justify-content: center;
  min-height: 46px;
  text-align: center;
  width: 100%;
}

.status-buttons button.active.done {
  background: var(--emerald);
  color: #fff;
}

.status-buttons button.active.work {
  background: var(--green);
  color: #fff;
}

.status-buttons button.active.lost {
  background: var(--violet);
  color: #fff;
}

.status-buttons button.active.no {
  background: var(--red);
  color: #fff;
}

.status-buttons button.active.force {
  background: var(--amber);
  color: #fff;
}

.note-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

.police-list {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.phone-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

.phone-row input {
  font-size: 16px;
}

.notice {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  color: #7c2d12;
  margin: 12px 0;
  padding: 12px 14px;
}

.decision-box {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  color: #7c2d12;
  font-size: 13px;
  line-height: 1.4;
  padding: 10px;
}

.admin-decision {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 130px 1fr auto;
  margin-top: 8px;
}

.admin-proposal {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(150px, 0.9fr) minmax(180px, 1.1fr) auto;
  margin-top: 8px;
}

.proposal-box {
  background: #f8fafc;
  border: 1px solid #dbe3ea;
  border-radius: 8px;
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
}

.proposal-box label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.proposal-box textarea {
  min-height: 72px;
}

.payout-inline {
  border-top: 1px solid var(--line);
  margin-top: 8px;
  padding-top: 8px;
}

.interaction-box {
  background: #ffffff;
  border: 1px solid #dbe3ea;
  border-radius: 8px;
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
}

.interaction-box h3 {
  font-size: 15px;
  margin: 0;
}

.interaction-history {
  display: grid;
  gap: 8px;
}

.interaction-item {
  border-left: 4px solid #1f4e79;
  background: #f8fafc;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.45;
  padding: 9px 10px;
}

.interaction-item.officer {
  border-left-color: #047857;
  background: #f0fdf4;
}

.interaction-item.history-item {
  border-left-color: #7c3aed;
  background: #faf7ff;
}

.interaction-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.update-history {
  min-width: 220px;
}

.history-change {
  font-size: 12px;
  line-height: 1.45;
  color: #334155;
}

.history-change span {
  color: #475569;
  font-weight: 700;
}

.interaction-box textarea {
  min-height: 82px;
}

.admin-update {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(180px, 1.2fr) minmax(150px, 1fr) 140px minmax(180px, 1.2fr) auto;
}

@media (max-width: 900px) {
  :root {
    --page-pad: 14px;
  }

  .topbar,
  .toolbar,
  .case-head {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .cards,
  .project-overview,
  .project-breakdown,
  .team-list,
  .info-grid,
  .status-buttons,
  .focus-grid,
  .distribution-grid,
  .pie-grid,
  .analytics-grid,
  .payout-grid,
  .admin-decision,
  .admin-proposal,
  .admin-update,
  .proposal-box,
  .note-row,
  .phone-row {
    grid-template-columns: 1fr;
  }

  input[type="search"] {
    min-width: 0;
    width: 100%;
  }

  .filters,
  .toolbar > button,
  .toolbar > .muted {
    width: 100%;
  }

  .filters select,
  .filters input {
    flex: 1 1 100%;
    width: 100%;
  }

  .chart-bar-row,
  .distribution-row {
    grid-template-columns: 1fr;
  }

  .chart-bar-value {
    justify-items: start;
  }

  .pie-content {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .payout-panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .pie-legend {
    justify-self: stretch;
    width: 100%;
  }

  th {
    top: 116px;
  }
}
