:root {
  color-scheme: light;
  --bg: #f5f7f2;
  --surface: #ffffff;
  --ink: #17211d;
  --muted: #637067;
  --primary: #0d6584;
  --primary-dark: #084a61;
  --line: #dbe3dc;
  --soft: #eaf1ea;
}

* { box-sizing: border-box; }

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

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px;
}

.narrowShell {
  max-width: 760px;
}

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

h1, h2, p { margin: 0; }
h1 { font-size: 34px; letter-spacing: 0; }
h2 { font-size: 19px; }
h3 { margin: 0; font-size: 16px; }
p { color: var(--muted); margin-top: 5px; }

.publicHero {
  align-items: flex-start;
  margin: 10px 0 14px;
}

.publicHero h1 {
  font-size: 28px;
}

.publicHero p {
  font-size: 15px;
}

.publicPanel {
  padding: 20px;
}

.actions, .sectionTitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compactTitle {
  align-items: flex-start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(23, 33, 29, 0.05);
}

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

.adminPanel {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.4fr);
  gap: 16px;
  align-items: end;
}

.adminGrid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(220px, 1fr);
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  font: inherit;
}

textarea {
  resize: vertical;
  min-height: 220px;
  font-family: Consolas, ui-monospace, monospace;
}

.jsonLabel {
  margin-top: 14px;
}

.manualHistoryBlock {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.manualHistoryRows {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

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

.manualHistoryRow strong,
.manualHistoryRow span,
.manualHistoryRow small {
  display: block;
}

.manualHistoryRow span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.manualHistoryRow small {
  margin-top: 4px;
  color: #536057;
}

.historyActions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.emptyState {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 13px;
  color: var(--muted);
  background: #fbfdfb;
}

button, .ghost {
  border: 0;
  border-radius: 8px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: var(--primary);
  color: white;
}

.linkButton {
  display: inline-block;
  text-decoration: none;
}

.secondary, .ghost {
  background: var(--soft);
  color: var(--ink);
}

.danger {
  background: #f4dddd;
  color: #8b1e1e;
}

.ghost input { display: none; }

.tablePicker {
  align-items: end;
}

.tablePicker label {
  flex: 1;
}

.calcGrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(240px, 0.8fr);
  gap: 14px;
  align-items: end;
  margin-top: 14px;
}

output {
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--soft);
  font-weight: 700;
}

output strong,
output span {
  display: block;
}

output span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
}

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

.publicAdForm .grid {
  grid-template-columns: 1fr;
  gap: 12px;
}

.publicAdForm label {
  font-size: 12px;
}

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

.advancedBox summary {
  cursor: pointer;
  font-weight: 700;
}

.advancedBox .grid {
  margin-top: 12px;
}

.localityTarget {
  border: 1px solid #e4ebe5;
  border-radius: 8px;
  padding: 12px;
  background: #f7faf7;
}

.localityTargetHeader {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.localityTargetHeader strong,
.localityTargetHeader span {
  display: block;
}

.localityTargetHeader span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  margin-top: 4px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  background: var(--soft);
  gap: 3px;
  flex-shrink: 0;
}

.segmented button {
  background: transparent;
  color: var(--ink);
  padding: 8px 11px;
}

.segmented button.active {
  background: var(--primary);
  color: white;
}

.localityChooser {
  margin-top: 14px;
}

.localitySearchRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.localitySuggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.localitySuggestions button,
.selectedLocalities button {
  background: var(--soft);
  color: var(--ink);
  padding: 8px 10px;
}

.selectedLocalities {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 38px;
  margin-top: 10px;
  align-items: center;
}

.selectedLocalities button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.selectedLocalities span {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  font-size: 12px;
}

.selectedLocalities strong {
  font-size: 14px;
  color: var(--muted);
}

.selectedLocalities em {
  color: var(--muted);
  font-style: normal;
  font-weight: 600;
  font-size: 13px;
}

.imageDrop {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.imageDrop span {
  color: var(--muted);
  font-weight: 600;
}

.tableWrap {
  overflow: auto;
  margin-top: 14px;
}

.adRows {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.adEditor {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdfb;
}

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

.compactAdvanced {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface);
}

.compactAdvanced summary {
  color: var(--muted);
  font-size: 13px;
}

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

.checkLabel {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkLabel input {
  width: auto;
}

.adPreview {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-height: 190px;
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  background: var(--soft);
}

.publicAdForm > button[type="submit"] {
  width: 100%;
  min-height: 50px;
  font-size: 16px;
  background: #1f7f4c;
}

.publicAdForm output {
  border: 0;
  min-height: auto;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--muted);
  background: #f0f6f0;
}

.emptyPreview {
  border: 1px dashed var(--line);
}

.adPreview img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 6px;
}

.adPreview strong,
.adPreview span {
  display: block;
}

.adPreview span {
  color: var(--muted);
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}

td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
}

td:last-child {
  width: 1%;
  white-space: nowrap;
}

pre {
  min-height: 240px;
  max-height: 420px;
  overflow: auto;
  background: #101815;
  color: #e9f5ed;
  border-radius: 8px;
  padding: 16px;
  margin: 14px 0 0;
}

@media (max-width: 820px) {
  .shell { padding: 18px 14px; }
  .topbar, .sectionTitle { align-items: stretch; flex-direction: column; }
  .grid, .calcGrid, .adminPanel, .adminGrid { grid-template-columns: 1fr; }
  .simpleAdGrid { grid-template-columns: 1fr; }
  .manualHistoryRow { grid-template-columns: 1fr; }
  .historyActions { justify-content: stretch; }
  .historyActions > * { flex: 1; text-align: center; }
  .localityTargetHeader, .localitySearchRow { grid-template-columns: 1fr; flex-direction: column; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .publicHero h1 { font-size: 25px; }
  .publicPanel { padding: 16px; }
  .adPreview {
    min-height: 180px;
  }
  .adPreview img {
    height: 140px;
  }
}
