:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #1c1d1b;
  --muted: #686a64;
  --soft: #ece9e2;
  --line: rgba(31, 33, 29, 0.1);
  --green: #148a5d;
  --green-2: #22b47b;
  --blue: #3366cc;
  --blue-2: #79a7e8;
  --amber: #d99319;
  --red: #cc4b37;
  --shadow: 0 1px 4px rgba(31, 33, 29, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 24px;
  background: rgba(246, 245, 241, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.1;
}

.brand p,
.panel p,
.section-heading p,
.metric-panel p {
  color: var(--muted);
}

.brand p {
  margin-top: 3px;
  font-size: 12px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

button:hover {
  border-color: rgba(20, 138, 93, 0.32);
}

.status-pill {
  min-width: 102px;
  border-radius: 999px;
  padding: 7px 11px;
  background: rgba(217, 147, 25, 0.13);
  color: #8a5a07;
  font-size: 12px;
  font-weight: 650;
  text-align: center;
}

.status-pill.ok {
  background: rgba(20, 138, 93, 0.12);
  color: var(--green);
}

.status-pill.error {
  background: rgba(204, 75, 55, 0.12);
  color: var(--red);
}

main {
  width: min(1320px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

.hidden {
  display: none;
}

.alert {
  margin-bottom: 14px;
  padding: 13px 15px;
  border-radius: 8px;
  border: 1px solid rgba(204, 75, 55, 0.22);
  border-left: 4px solid var(--red);
  background: #fff;
  color: var(--red);
  font-size: 13px;
  line-height: 1.45;
}

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

.kpi-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi-card {
  padding: 18px;
}

.kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.kpi-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1;
}

.kpi-card small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 28px 2px 14px;
}

.section-heading h2 {
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.section-heading::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--soft);
}

.section-heading p {
  font-size: 11px;
}

.dashboard-grid {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

.two-col {
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.9fr);
}

.wide-left {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.8fr);
}

.narrow-right {
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.7fr);
}

.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel h3 {
  font-size: 14px;
}

.panel p {
  margin-top: 4px;
  font-size: 12px;
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.bar-list {
  display: grid;
  gap: 13px;
}

.bar-row {
  display: grid;
  gap: 5px;
}

.bar-row-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.bar-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 750;
}

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

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--soft);
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
}

.metric-panel strong {
  display: block;
  margin-top: 8px;
  color: var(--green);
  font-size: 32px;
  line-height: 1;
}

.metric-panel p {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.45;
}

.mini-metric + .mini-metric {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--soft);
}

.metric-track {
  height: 11px;
  overflow: hidden;
  margin-top: 14px;
  border-radius: 999px;
  background: var(--soft);
}

.metric-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.metric-track.amber {
  background: rgba(242, 161, 28, 0.12);
}

.metric-track.amber span {
  background: var(--amber);
}

.split-bar {
  display: flex;
  height: 10px;
  overflow: hidden;
  margin-top: 14px;
  border-radius: 999px;
  background: var(--soft);
}

#pipelineWonBar {
  background: var(--green);
}

#pipelineLostBar {
  background: var(--amber);
}

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

table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  padding: 0 10px 10px;
  border-bottom: 1.5px solid var(--soft);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--soft);
  vertical-align: top;
}

.num {
  text-align: right;
  white-space: nowrap;
}

.sku-cell {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 750;
}

.status {
  display: inline-block;
  min-width: 72px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 750;
  text-align: center;
}

.status.ok {
  background: rgba(20, 138, 93, 0.12);
  color: var(--green);
}

.status.warn {
  background: rgba(217, 147, 25, 0.14);
  color: #9a6409;
}

.status.danger {
  background: rgba(204, 75, 55, 0.13);
  color: var(--red);
}

.lost-list {
  display: grid;
  gap: 10px;
}

.lost-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--soft);
}

.lost-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.lost-item strong {
  display: block;
  font-size: 13px;
}

.lost-item span,
.lost-item p {
  color: var(--muted);
  font-size: 12px;
}

.debug-panel {
  margin-top: 18px;
}

.settlement-panel {
  margin-bottom: 14px;
}

.settlement-section {
  margin-bottom: 14px;
}

.settlement-panel table {
  min-width: 1120px;
  table-layout: auto;
}

.settlement-panel th,
.settlement-panel td {
  white-space: nowrap;
}

.settlement-panel td:first-child,
.settlement-panel th:first-child {
  white-space: normal;
  min-width: 74px;
}

.cumulative-panel,
.cash-panel,
.water-alert {
  margin-bottom: 14px;
}

.insight-note,
.panel-note {
  margin-top: 16px;
  border-radius: 8px;
  background: rgba(25, 169, 116, 0.12);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.45;
}

.client-rank {
  display: grid;
  gap: 13px;
}

.client-line {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 15px;
}

.client-meta,
.muted {
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
}

.city-tag {
  display: inline-block;
  margin-left: 5px;
  border-radius: 999px;
  background: rgba(25, 169, 116, 0.11);
  color: var(--green);
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
}

.city-tag.province {
  background: rgba(242, 161, 28, 0.14);
  color: #b36d00;
}

.client-track {
  height: 10px;
  overflow: hidden;
  margin-top: 7px;
  border-radius: 999px;
  background: var(--soft);
}

.client-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green-2);
}

.client-track span.province {
  background: var(--amber);
}

.client-legend {
  display: flex;
  gap: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

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

.client-legend i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--green-2);
}

.client-legend i.province {
  background: var(--amber);
}

.header-metric {
  text-align: right;
  min-width: 150px;
}

.header-metric span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.header-metric strong {
  display: block;
  margin-top: 5px;
  color: var(--red);
  font-size: 24px;
}

.cash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr minmax(280px, 1.5fr);
  gap: 22px;
  align-items: center;
}

.cash-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.cash-grid strong {
  display: block;
  font-size: 28px;
}

.cash-grid > div:nth-child(2) strong {
  color: var(--green);
}

.cash-note {
  border-radius: 8px;
  background: rgba(242, 161, 28, 0.14);
  padding: 16px;
  font-size: 13px;
  line-height: 1.5;
}

.water-alert {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(0, 1.4fr);
  gap: 22px;
  align-items: center;
  border: 1px solid rgba(204, 75, 55, 0.2);
  border-left: 4px solid var(--red);
  border-radius: 8px;
  background: #fff;
  padding: 20px 24px;
  box-shadow: var(--shadow);
}

.water-alert h3 {
  color: var(--red);
  font-size: 15px;
  margin-bottom: 16px;
}

.water-alert p {
  font-size: 14px;
  line-height: 1.55;
}

.water-metrics {
  display: flex;
  align-items: center;
  gap: 22px;
}

.water-metrics strong {
  font-size: 30px;
  line-height: 1;
}

.water-metrics strong span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.water-metrics em {
  color: var(--muted);
  font-size: 22px;
  font-style: normal;
}

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

summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

pre {
  max-height: 360px;
  overflow: auto;
  margin: 14px 0 0;
  padding: 12px;
  border-radius: 7px;
  background: #1f211d;
  color: #f3f2ed;
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .kpi-grid,
  .two-col,
  .wide-left,
  .narrow-right,
  .three-col {
    grid-template-columns: 1fr;
  }

  .cash-grid,
  .water-alert {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .section-heading::after {
    display: none;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .actions {
    width: 100%;
  }

  .actions button,
  .status-pill {
    flex: 1;
  }

  main {
    width: min(100% - 20px, 1320px);
  }

  .panel,
  .kpi-card {
    padding: 14px;
  }
}
