:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --soft: #eef2f6;
  --line: #d8dee8;
  --text: #17202a;
  --muted: #667085;
  --primary: #1e3a5f;
  --primary-2: #2f5f98;
  --teal: #0f766e;
  --red: #b42318;
  --amber: #a15c07;
  --green: #067647;
  --shadow: 0 12px 30px rgba(23, 32, 42, 0.07);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body, #app {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  letter-spacing: 0;
}

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: min(100%, 420px);
  padding: 32px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  /* background: var(--primary); */
  background: transparent;
  color: #fff;
  font-weight: 900;
}

.mark img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.brand h1, .brand p {
  margin: 0;
}

.brand h1 {
  color: var(--primary);
  font-size: 22px;
}

.brand p {
  color: var(--muted);
  font-size: 13px;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px 16px;
  background: #fff;
  border-right: 1px solid var(--line);
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 8px;
  color: #233146;
  font-weight: 700;
}

.nav a.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 10px 24px rgba(11, 77, 184, .18);
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  z-index: 5;
  top: 0;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px);
  -o-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.search {
  width: min(460px, 42vw);
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.content {
  padding: 28px;
}

.page {
  display: grid;
  gap: 20px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h2 {
  margin: 4px 0 0;
  color: var(--primary);
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.12;
}

.subtle {
  color: var(--muted);
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, .7fr);
  gap: 16px;
}

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card {
  padding: 20px;
}

.card small {
  color: var(--muted);
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.card strong {
  display: block;
  margin-top: 12px;
  color: var(--primary);
  font-size: 30px;
}

.panel {
  overflow: hidden;
}

.panel-head {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}

.panel-head h3 {
  margin: 0;
  color: var(--primary);
}

.panel-body {
  padding: 18px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: var(--soft);
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

tr:hover td {
  background: #fbfdff;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 10px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.chip.ok {
  background: #dcf8ee;
  color: var(--green);
}

.chip.warn {
  background: #fff1d6;
  color: var(--amber);
}

.chip.bad {
  background: #ffe2e2;
  color: var(--red);
}

.actions, .row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--primary);
  font-weight: 900;
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.btn.danger {
  color: var(--red);
}

.icon-btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
}

.notification-trigger strong {
  min-width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
}

.form {
  display: grid;
  gap: 14px;
}

.form.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.field input, .field select, .field textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: 0;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(11, 77, 184, .10);
}

.error {
  padding: 12px 14px;
  border: 1px solid #ffb4b4;
  border-radius: 8px;
  background: #fff0f0;
  color: var(--red);
}

.empty {
  padding: 34px;
  color: var(--muted);
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 32, 51, .38);
}

.modal {
  width: min(760px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 30px 80px rgba(16, 32, 51, .24);
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: #f9fbff;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  margin: 0;
  color: var(--primary);
}

.modal-body {
  padding: 18px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.stepper {
  display: grid;
  gap: 12px;
}

.step {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.step h4 {
  margin: 0 0 10px;
  color: var(--primary);
}

.quick-add {
  display: grid;
  gap: 12px;
}

.quick-target-form {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.history-box {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.history-box p {
  margin: 6px 0 12px;
}

.line-rows {
  display: grid;
  gap: 10px;
}

.line-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(90px, .45fr) minmax(120px, .55fr) minmax(150px, .7fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.sample-row {
  grid-template-columns: minmax(150px, 1fr) minmax(90px, .45fr) auto;
}

.line-row select,
.line-row input {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}

.camera-box {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.camera-box video,
.camera-box img {
  width: 100%;
  max-height: 420px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #111827;
  object-fit: contain;
}

.report-preview {
  display: grid;
  gap: 16px;
}

.report-json {
  max-height: 280px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  color: #e5edf7;
  white-space: pre-wrap;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.crm-progress {
  display: flex;
  justify-content: flex-end;
  color: var(--muted);
  font-weight: 900;
}

.crm-step {
  display: none;
  opacity: 0;
  transform: translateX(10px);
  transition: opacity .18s ease, transform .18s ease;
}

.crm-step.active {
  display: grid;
  gap: 14px;
  opacity: 1;
  transform: translateX(0);
}

.crm-step h4 {
  margin: 0;
  color: var(--primary);
}

.crm-items {
  display: grid;
  gap: 12px;
}

.crm-item {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.crm-item label {
  color: var(--text);
  font-weight: 800;
}

.crm-item textarea {
  width: 100%;
  min-height: 84px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  resize: vertical;
}

.product-picker {
  display: grid;
  gap: 10px;
}

.product-choice {
  min-height: 62px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.product-choice input {
  width: 18px;
  height: 18px;
}

.product-choice span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.product-choice strong,
.mini-card strong {
  overflow-wrap: anywhere;
}

.product-choice small {
  color: var(--muted);
  line-height: 1.35;
}

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

.mini-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.mini-card p {
  margin: 0;
  color: var(--muted);
}

.product-detail-backdrop {
  z-index: 42;
}

.product-detail-modal {
  width: min(920px, 100%);
}

.product-sheet {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 340px);
  gap: 18px;
  align-items: start;
}

.product-sheet h4,
.visit-detail-view h4 {
  margin: 0 0 8px;
  color: var(--primary);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(120px, .35fr) minmax(0, 1fr);
  gap: 8px 14px;
  margin: 0;
}

.detail-grid dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.detail-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.prospectus,
.stamp-preview-large {
  width: 100%;
  max-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
  object-fit: contain;
}

.visit-detail-view {
  display: grid;
  gap: 18px;
}

.visit-row {
  cursor: pointer;
}

.visit-row button,
.visit-row a {
  cursor: pointer;
}

.notification-list {
  display: grid;
  gap: 10px;
}

.notification-item {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.notification-item.unread {
  border-color: rgba(11, 77, 184, .35);
  background: #f4f8ff;
}

.notification-item p {
  margin: 0;
  color: var(--muted);
}

.notification-item small {
  color: var(--muted);
}

.visit-map {
  min-height: 360px;
}

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

.leaflet-container {
  font-family: var(--font);
}

.map-stage {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(11, 77, 184, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(11, 77, 184, .08) 1px, transparent 1px),
    #f8fbff;
  background-size: 44px 44px;
}

.map-empty {
  min-height: 280px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.map-pin {
  position: absolute;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--teal);
  box-shadow: 0 10px 22px rgba(8, 120, 111, .28);
}

.map-pin:hover,
.map-pin:focus {
  z-index: 2;
  outline: 0;
  transform: translate(-50%, -50%) scale(1.15);
}

.map-tooltip {
  position: absolute;
  left: 50%;
  bottom: 28px;
  width: max-content;
  max-width: 220px;
  transform: translateX(-50%);
  display: none;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
  line-height: 1.35;
  box-shadow: var(--shadow);
}

.map-pin:hover .map-tooltip,
.map-pin:focus .map-tooltip {
  display: block;
}

.map-axis {
  position: absolute;
  z-index: 1;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .86);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.map-axis.lat {
  left: 12px;
  top: 12px;
}

.map-axis.lng {
  right: 12px;
  bottom: 12px;
}

.diagnostic-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.diagnostic-grid div {
  display: grid;
  gap: 8px;
  padding: 18px;
  background: #fff;
}

.diagnostic-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.diagnostic-grid strong {
  color: var(--primary);
  font-size: 34px;
}

.mobile-top {
  display: none;
}

@media (max-width: 1040px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    height: auto;
    padding: 14px;
    align-items: stretch;
    flex-direction: column;
  }

  .search {
    width: 100%;
  }

  .content {
    padding: 18px;
    padding-bottom: 86px;
  }

  .grid-4, .form.two {
    grid-template-columns: 1fr;
  }

  .product-choice {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .product-choice .btn {
    grid-column: 1 / -1;
    width: 100%;
  }

  .product-sheet,
  .detail-grid {
    grid-template-columns: 1fr;
  }

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

  .line-row,
  .sample-row {
    grid-template-columns: 1fr;
  }

  .topbar .row {
    flex-wrap: wrap;
  }

  .notification-trigger {
    width: 100%;
    justify-content: space-between;
  }

  .diagnostic-grid {
    grid-template-columns: 1fr;
  }

  .map-tooltip {
    max-width: 180px;
  }

  .page-head {
    align-items: start;
    flex-direction: column;
  }

  .mobile-top {
    position: fixed;
    z-index: 8;
    bottom: 0;
    left: 0;
    right: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-top: 1px solid var(--line);
    background: #fff;
  }

  .mobile-top a {
    display: grid;
    place-items: center;
    min-height: 62px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }

  .mobile-top a.active {
    color: var(--primary);
  }
}
