:root {
  --bg: #f3f6f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --text: #1c292f;
  --muted: #64747b;
  --line: #dfe7e9;
  --brand: #176b5d;
  --brand-dark: #105347;
  --brand-soft: #e7f3f0;
  --accent: #d5a640;
  --danger: #a84242;
  --shadow: 0 14px 36px rgba(28, 41, 47, 0.08);
  --radius: 18px;
  --radius-small: 12px;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

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

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(20px, 5vw, 64px) 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--brand);
  font-size: 0.77rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(1.55rem, 3vw, 2.15rem); letter-spacing: -0.03em; }
h2 { margin-bottom: 2px; font-size: 1.1rem; }
.header-subtitle, .section-heading p, .history-header p { color: var(--muted); margin-bottom: 0; }

.status-pill {
  flex: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 0.84rem;
  font-weight: 750;
}

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

.search-card, .map-card, .result-card, .save-card, .history-card {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.search-card {
  position: relative;
  z-index: 1001;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 18px;
}

.search-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
input {
  width: 100%;
  border: 1px solid #cfdadd;
  border-radius: 11px;
  background: #fff;
  color: var(--text);
  padding: 12px 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(23, 107, 93, 0.12); }

.button {
  border: 0;
  border-radius: 10px;
  padding: 11px 14px;
  font-weight: 760;
  transition: transform 0.12s ease, background 0.12s ease;
}
.button:active:not(:disabled) { transform: translateY(1px); }
.button-primary { background: var(--brand); color: white; }
.button-primary:hover:not(:disabled) { background: var(--brand-dark); }
.button-secondary { background: #edf2f3; color: #304148; }
.button-secondary:hover:not(:disabled) { background: #e3eaec; }
.button-wide { width: 100%; padding: 13px 15px; }

.search-results {
  position: absolute;
  top: calc(100% - 3px);
  left: 14px;
  right: 14px;
  max-height: 340px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 34px rgba(28, 41, 47, 0.16);
}
.search-result-button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 12px 13px;
  color: var(--text);
}
.search-result-button:last-child { border-bottom: 0; }
.search-result-button:hover { background: var(--surface-soft); }
.search-result-button strong { display: block; font-size: 0.92rem; }
.search-result-button span { display: block; margin-top: 3px; color: var(--muted); font-size: 0.82rem; }
.search-message { padding: 13px; color: var(--muted); font-size: 0.9rem; }

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(330px, 0.7fr);
  gap: 18px;
  align-items: stretch;
}

.map-card { overflow: hidden; border-radius: var(--radius); }
.map-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.map-toolbar strong, .map-toolbar span { display: block; }
.map-toolbar span { margin-top: 2px; color: var(--muted); font-size: 0.88rem; }
#map { height: 610px; width: 100%; background: #dfe7e9; }
.map-help { padding: 10px 16px 12px; color: var(--muted); font-size: 0.84rem; border-top: 1px solid var(--line); }

.result-card { border-radius: var(--radius); padding: 20px; }
.section-heading { display: flex; gap: 11px; align-items: flex-start; margin-bottom: 18px; }
.compact-heading { margin-bottom: 14px; }
.step-badge {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 29px;
  height: 29px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 260px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed #cfdadd;
  border-radius: var(--radius-small);
  padding: 24px;
}
.empty-pin {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 10px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 1.6rem;
}
.empty-state p { margin-bottom: 0; }

.result-block, .link-block {
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  padding: 14px;
  margin-bottom: 12px;
}
.result-block-primary { background: var(--brand-soft); border-color: #cfe4df; }
.result-label {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.coordinate-row { display: flex; justify-content: space-between; gap: 16px; align-items: baseline; }
.coordinate-row + .coordinate-row { margin-top: 5px; }
.coordinate-row span { color: var(--muted); font-weight: 700; }
.coordinate-row strong { font-size: 1.45rem; letter-spacing: 0.01em; font-variant-numeric: tabular-nums; }
.coordinate-row-small strong { font-size: 1rem; }
.crs-line { margin-top: 10px; padding-top: 10px; border-top: 1px solid #cfe4df; color: var(--brand-dark); font-size: 0.82rem; font-weight: 750; }
.link-block a { color: var(--brand); word-break: break-all; font-size: 0.9rem; }
.button-stack { margin-top: 14px; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.precision-note {
  margin-top: 16px;
  padding: 12px;
  border-radius: 10px;
  background: #fff8e9;
  border: 1px solid #f0dfb4;
  color: #665328;
  font-size: 0.82rem;
}

.save-card, .history-card { border-radius: var(--radius); padding: 18px; margin-top: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 0.8fr 1.4fr auto; gap: 10px; align-items: end; }
.form-grid label span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 0.8rem; font-weight: 720; }
.save-button { height: 46px; }

.history-header { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-bottom: 12px; }
.history-header h2 { margin-bottom: 2px; }
.history-filter { width: min(360px, 100%); }
.history-list { display: grid; gap: 8px; }
.history-empty { padding: 20px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; }
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
}
.history-main strong { display: block; }
.history-meta { margin-top: 3px; color: var(--muted); font-size: 0.8rem; }
.history-coordinates { margin-top: 5px; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.history-actions { display: flex; gap: 7px; }
.icon-button {
  border: 0;
  border-radius: 9px;
  padding: 8px 10px;
  background: #edf2f3;
  color: #304148;
  font-weight: 700;
}
.icon-button.danger { color: var(--danger); }

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto 24px;
  color: #79878c;
  font-size: 0.77rem;
}

.leaflet-control-layers { border: 0 !important; border-radius: 11px !important; box-shadow: 0 5px 18px rgba(28, 41, 47, 0.15) !important; }
.leaflet-control-zoom { border: 0 !important; box-shadow: 0 5px 18px rgba(28, 41, 47, 0.15) !important; }

@media (max-width: 980px) {
  .main-grid { grid-template-columns: 1fr; }
  #map { height: 520px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .description-field { grid-column: 1 / -1; }
  .save-button { width: 100%; }
}

@media (max-width: 640px) {
  .app-header { padding: 20px 16px; }
  .status-pill { display: none; }
  .app-shell { width: min(100% - 18px, 1480px); margin-top: 10px; }
  .search-form { grid-template-columns: 1fr; }
  .map-toolbar { align-items: flex-start; }
  .map-toolbar span { display: none; }
  #map { height: 470px; }
  .form-grid { grid-template-columns: 1fr; }
  .description-field { grid-column: auto; }
  .button-row { grid-template-columns: 1fr; }
  .history-header { align-items: stretch; flex-direction: column; }
  .history-filter { width: 100%; }
  .history-item { grid-template-columns: 1fr; }
  .history-actions { width: 100%; }
  .history-actions button { flex: 1; }
  .app-footer { flex-direction: column; }
}
