:root {
  color-scheme: light;
  --ink: #17201f;
  --muted: #65706e;
  --line: #d9dfdd;
  --soft: #f5f7f4;
  --paper: #ffffff;
  --green: #0d7c66;
  --blue: #285f9e;
  --gold: #b27b16;
  --red: #b8453d;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1;
}

h2 {
  font-size: 17px;
}

.actions {
  display: flex;
  gap: 10px;
}

button,
.file-btn {
  border: 1px solid #203a36;
  border-radius: 7px;
  background: #203a36;
  color: white;
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 750;
}

#exportBtn {
  background: var(--paper);
  color: #203a36;
}

.main-tabs {
  display: inline-flex;
  gap: 6px;
  margin: 0 0 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.tab-btn {
  min-width: 128px;
  border-color: transparent;
  background: transparent;
  color: #203a36;
}

.tab-btn.active {
  border-color: #203a36;
  background: #203a36;
  color: white;
}

.file-btn input {
  display: none;
}

.filters {
  display: grid;
  grid-template-columns: repeat(10, minmax(96px, 1fr));
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 10px 9px;
}

.search-field {
  grid-column: span 1;
}

.reset-field button {
  width: 100%;
  min-height: 40px;
  border-color: #203a36;
  background: #203a36;
}

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

.kpis article,
.inventory-kpis article,
.panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.kpis article,
.inventory-kpis article {
  padding: 16px;
}

.kpis span,
.inventory-kpis span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.kpis strong,
.inventory-kpis strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
  line-height: 1;
}

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

.inventory-view {
  margin-top: 14px;
}

.inventory-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.inventory-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 12px;
}

.inventory-editor {
  min-height: 0;
}

.inventory-form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.inventory-table-panel {
  min-height: 0;
}

.inventory-grid {
  margin-top: 16px;
  overflow-x: auto;
}

.inventory-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.inventory-table th,
.inventory-table td {
  border-bottom: 1px solid #e8ecea;
  padding: 12px;
  text-align: left;
  vertical-align: middle;
}

.stock-cell strong {
  display: block;
  font-size: 22px;
}

.stock-cell span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stock-cell.low strong {
  color: var(--red);
}

.stock-total {
  font-size: 18px;
  font-weight: 850;
}

.save-status {
  min-height: 18px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.panel {
  min-height: 260px;
  padding: 16px;
}

body[data-mode="all"] .order-panel,
body[data-mode="compare"] .confirm-detail-panel {
  display: none;
}

.panel.wide {
  grid-column: span 4;
}

.map-panel,
.district-map-panel {
  grid-column: span 2;
  min-height: 520px;
}

.province-panel,
.district-panel {
  grid-column: span 2;
  min-height: 520px;
}

.bars {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(72px, 132px) 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 13px;
  padding: 0;
  text-align: left;
}

.clickable-bar {
  cursor: pointer;
}

.clickable-bar:hover .bar-label,
.clickable-bar:focus-visible .bar-label {
  color: var(--green);
}

.clickable-bar:hover .bar-track,
.clickable-bar:focus-visible .bar-track {
  outline: 2px solid rgba(13, 124, 102, 0.25);
  outline-offset: 2px;
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 24px;
}

.two-col .bar-row {
  break-inside: avoid;
}

.bar-label {
  overflow: hidden;
  color: #2f3d3a;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-label {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 5px;
  white-space: nowrap;
}

.color-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border: 1px solid rgba(23, 32, 31, 0.18);
  border-radius: 999px;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.35);
}

.color-dot.black {
  background: radial-gradient(circle at 30% 25%, #5d5669, #24202d 70%);
}

.color-dot.white {
  background: radial-gradient(circle at 30% 25%, #ffffff, #d7c8ec 75%);
}

.color-dot.beige {
  background: radial-gradient(circle at 30% 25%, #a8786c, #6f4843 75%);
}

.color-dot.maroon {
  background: radial-gradient(circle at 30% 25%, #ff6483, #d71f49 75%);
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8ece9;
}

.compare-track {
  display: grid;
  gap: 4px;
  background: transparent;
}

.compare-rail {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8ece9;
}

.compare-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.compare-fill.all {
  background: var(--green);
}

.compare-fill.confirmed {
  background: var(--gold);
}

.compare-value {
  color: #34413f;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.bar-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.percent-row {
  grid-template-columns: minmax(120px, 170px) 1fr minmax(74px, auto);
}

.metric-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.metric-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #edf0ee;
}

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

.metric-list strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.province-map {
  margin-top: 12px;
}

.district-map-panel {
  min-height: 680px;
}

.district-panel {
  min-height: 680px;
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(210px, 1fr);
  align-items: center;
  gap: 16px;
}

.district-map-layout {
  display: grid;
  place-items: center;
}

.sri-lanka-svg {
  width: 100%;
  max-height: 435px;
  overflow: visible;
}

.district-svg {
  max-height: 610px;
}

.province-shape,
.district-shape {
  cursor: pointer;
  outline: none;
}

.province-shape path,
.district-shape path {
  stroke: #ffffff;
  stroke-width: 5;
  filter: drop-shadow(0 2px 5px rgba(23, 32, 31, 0.12));
  transition: fill 160ms ease, transform 160ms ease;
}

.province-shape:hover path,
.province-shape:focus-visible path,
.district-shape:hover path,
.district-shape:focus-visible path {
  stroke: #173f36;
  stroke-width: 7;
  transform: translateY(-2px);
}

.province-shape text,
.district-shape text {
  fill: #17201f;
  font-size: 22px;
  font-weight: 850;
  pointer-events: none;
  text-anchor: middle;
}

.district-shape text {
  font-size: 18px;
}

.province-shape .province-percent,
.district-shape .province-percent {
  fill: #51605d;
  font-size: 18px;
  font-weight: 800;
}

.district-shape .province-percent {
  font-size: 15px;
}

.map-legend {
  display: grid;
  gap: 8px;
}

.map-legend-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfb;
  color: var(--ink);
  cursor: pointer;
  padding: 9px;
  text-align: left;
}

.map-legend-row:hover,
.map-legend-row:focus-visible {
  border-color: rgba(13, 124, 102, 0.55);
  outline: 2px solid rgba(13, 124, 102, 0.16);
}

.map-legend-row span {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(23, 32, 31, 0.1);
  border-radius: 4px;
}

.map-legend-row strong {
  font-size: 13px;
}

.map-legend-row em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 850;
}

.table-panel {
  margin-top: 14px;
}

#leadsView.table-panel {
  margin-top: 14px;
}

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

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

.table-status {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

#editSaveStatus {
  color: var(--green);
}

.table-wrap {
  max-height: 560px;
  overflow: auto;
}

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

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #edf0ee;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f9faf8;
  color: #3e4a47;
  font-size: 12px;
}

td.address {
  min-width: 260px;
  max-width: 380px;
}

.edit-cell-input {
  min-width: 96px;
  padding: 7px 8px;
  font-size: 12px;
}

.edit-cell-select {
  cursor: pointer;
}

.save-row-btn {
  min-width: 64px;
  padding: 8px 10px;
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef4f1;
  color: #1d4e43;
  font-size: 12px;
  font-weight: 850;
}

.low {
  background: #fff0e8;
  color: #8b3d16;
}

.medium {
  background: #fff8da;
  color: #6a4a00;
}

.high {
  background: #e8f6ed;
  color: #11613d;
}

@media (max-width: 1100px) {
  .filters,
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel.wide {
    grid-column: span 2;
  }

  .map-panel,
  .province-panel,
  .district-map-panel,
  .district-panel {
    grid-column: span 2;
  }

  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .shell {
    width: min(100% - 20px, 1480px);
    padding-top: 14px;
  }

  .topbar,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .filters,
  .grid,
  .kpis,
  .two-col {
    grid-template-columns: 1fr;
  }

  .panel.wide {
    grid-column: span 1;
  }

  .map-panel,
  .province-panel,
  .district-map-panel,
  .district-panel {
    grid-column: span 1;
    min-height: 0;
  }

  .map-layout {
    grid-template-columns: 1fr;
  }
}
