:root {
  --ink: #17202a;
  --muted: #607080;
  --line: #d9e1e8;
  --paper: #ffffff;
  --page: #f4f7f9;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --blue: #2459a6;
  --amber: #a35a00;
  --red: #b42318;
  --green: #177245;
  --shadow: 0 10px 30px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button,
.button-link {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

button:focus-visible,
.button-link:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(36, 89, 166, 0.22);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px) 20px;
  color: #fff;
  background:
    linear-gradient(130deg, rgba(23, 32, 42, 0.94), rgba(15, 118, 110, 0.88)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='260' viewBox='0 0 600 260'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='0.12'%3E%3Cpath d='M38 218 C120 140 190 238 276 145 S432 78 560 144'/%3E%3Cpath d='M24 76 C94 18 182 108 252 72 S386 8 580 58'/%3E%3Cpath d='M80 256 C198 184 232 244 334 190 S488 98 620 176'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 56px);
  line-height: 1;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: currentColor;
  opacity: 0.72;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.topbar-metrics {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  max-width: 540px;
}

.topbar-metrics span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.09);
  white-space: nowrap;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px clamp(12px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(244, 247, 249, 0.94);
  backdrop-filter: blur(12px);
}

.tab {
  flex: 0 0 auto;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
}

.tab.is-active {
  color: #fff;
  background: var(--teal);
}

main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px clamp(14px, 4vw, 48px) 56px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.section-heading h2 {
  margin: 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.1;
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.primary {
  color: #fff;
  background: var(--teal);
}

.primary:hover {
  background: var(--teal-dark);
}

.secondary {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.secondary:hover {
  border-color: #a9bac8;
}

code {
  border-radius: 5px;
  padding: 2px 5px;
  color: var(--teal-dark);
  background: #eef6f4;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92em;
}

.compact {
  min-height: 34px;
  padding: 0 10px;
}

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

.order-metrics {
  margin-bottom: 18px;
}

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

.metric-card {
  padding: 18px;
  min-height: 148px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.metric-card strong {
  display: block;
  margin: 10px 0 6px;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0;
}

.metric-card p,
.item-card p {
  margin: 0;
  color: var(--muted);
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.76fr);
  gap: 18px;
  margin-top: 18px;
}

.orders-layout {
  grid-template-columns: minmax(360px, 0.78fr) minmax(420px, 1fr);
}

.panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-header h3 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
}

textarea {
  resize: vertical;
}

.wide {
  grid-column: span 2;
}

.helper-text {
  margin: 12px 0;
  color: var(--muted);
  font-size: 14px;
}

.compact-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 14px 0 4px;
}

.subheader {
  margin-top: 18px;
}

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

.list-stack {
  margin-top: 18px;
}

.compact-list {
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.item-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 16px;
}

.item-card h3 {
  margin: 0 0 7px;
  font-size: 18px;
  letter-spacing: 0;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  color: var(--blue);
  background: #e7f0ff;
  font-size: 12px;
  font-weight: 800;
}

.badge.warning {
  color: var(--amber);
  background: #fff2d7;
}

.badge.danger {
  color: var(--red);
  background: #ffe7e4;
}

.badge.good {
  color: var(--green);
  background: #e6f4ed;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-content: start;
  justify-content: flex-end;
  gap: 8px;
}

.action-list {
  margin: 0;
  padding-left: 20px;
}

.action-list li + li {
  margin-top: 10px;
}

pre {
  min-height: 360px;
  margin: 0;
  white-space: pre-wrap;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
}

.output-panel {
  min-height: 460px;
}

.margin-output {
  display: grid;
  gap: 12px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.result-row strong {
  text-align: right;
}

.file-drop {
  display: block;
  border: 1px dashed #9fb1bf;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  background: #f9fbfc;
}

.file-drop input {
  margin-bottom: 8px;
}

.document-output {
  display: grid;
  gap: 14px;
}

.analysis-block h4 {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.analysis-block ul {
  margin: 0;
  padding-left: 18px;
}

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

.map-panel {
  min-height: 720px;
}

.sales-map {
  width: 100%;
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #e7eef4;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

.legend-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.legend-dot.customer-active {
  background: var(--green);
}

.legend-dot.customer-inactive {
  background: var(--red);
}

.legend-dot.prospect {
  background: var(--blue);
}

.weak-zones {
  margin-top: 12px;
}

.checklist-group {
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.checklist-group h3 {
  margin: 0 0 14px;
  font-size: 18px;
}

.check-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding: 11px 0;
}

.check-item:first-of-type {
  border-top: 0;
}

.check-item input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
}

.check-item span {
  color: var(--ink);
}

.check-item small {
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 36px));
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

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

  .topbar-metrics {
    justify-content: flex-start;
  }

  .metric-grid,
  .checklist-grid,
  .two-column,
  .orders-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }

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

@media (max-width: 620px) {
  .topbar {
    padding-top: 22px;
  }

  .topbar-metrics span,
  .toolbar,
  .section-heading > .toolbar {
    width: 100%;
  }

  .toolbar button,
  .toolbar select {
    flex: 1 1 auto;
  }

  .item-card {
    grid-template-columns: 1fr;
  }

  .mapper-grid,
  .compact-form {
    grid-template-columns: 1fr;
  }

  .sales-map {
    min-height: 420px;
  }

  .card-actions {
    justify-content: flex-start;
  }
}
