:root {
  --ink: #12151c;
  --muted: #5c6575;
  --paper: #eef1f4;
  --paper-2: #f7f8fa;
  --line: #c9d0da;
  --accent: #0d7377;
  --accent-ink: #064e51;
  --danger: #a33b2d;
  --shadow: 0 18px 50px rgba(18, 21, 28, 0.08);
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(18, 21, 28, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18, 21, 28, 0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 35%, #000 20%, transparent 75%);
  pointer-events: none;
  z-index: 0;
}

.bg-wash {
  position: fixed;
  inset: -20% auto auto 50%;
  width: min(720px, 90vw);
  height: 420px;
  transform: translateX(-50%);
  background:
    radial-gradient(closest-side, rgba(13, 115, 119, 0.16), transparent 70%),
    radial-gradient(closest-side, rgba(18, 21, 28, 0.05), transparent 72%);
  filter: blur(8px);
  pointer-events: none;
  z-index: 0;
}

.stage-center {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.gate {
  width: min(420px, 100%);
  background: color-mix(in srgb, var(--paper-2) 88%, white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px 32px;
  animation: rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.brand {
  margin: 0 0 18px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: lowercase;
  color: var(--accent);
}

.brand-inline {
  margin: 0;
}

.title {
  margin: 0 0 8px;
  font-size: clamp(28px, 5vw, 34px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.lede {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}

.gate-form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-input {
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  letter-spacing: 0;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.gate .field-input {
  font-family: var(--mono);
  letter-spacing: 0.08em;
}

.field-select {
  font-family: var(--font);
  letter-spacing: 0;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 12px) 55%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 115, 119, 0.18);
}

.field-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: #f0f2f5;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  padding: 13px 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: var(--accent-ink);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.btn-ghost:hover:not(:disabled) {
  background: #fff;
  color: var(--ink);
}

.btn-sm {
  padding: 8px 12px;
  font-size: 13px;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
  animation: shake 0.35s ease;
}

.mono {
  font-family: var(--mono);
}

/* —— App shell —— */
.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper-2) 85%, white);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 22px;
  min-width: 0;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(18, 21, 28, 0.04);
  border: 1px solid var(--line);
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab:hover {
  color: var(--ink);
}

.tab.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(18, 21, 28, 0.06);
}

.app-main {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 28px 20px 48px;
  flex: 1;
}

.app-main.is-board {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app-shell.is-board {
  height: 100vh;
  overflow: hidden;
}

.app-shell.is-board .app-main {
  flex: 1;
  min-height: 0;
}

/* display:flex у доски иначе перебивает [hidden] и панель торчит в Парсинге */
#panel-plan[hidden],
#panel-parse[hidden] {
  display: none !important;
}

.panel-head {
  margin-bottom: 20px;
}

.panel-title {
  margin: 0 0 4px;
  font-size: 28px;
  letter-spacing: -0.03em;
}

.panel-sub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.panel-board:not([hidden]) {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.board-root {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #e7ebef;
  contain: layout style;
}

.board-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper-2) 90%, white);
}

.board-toolbar-left,
.board-toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.board-hint {
  color: var(--muted);
  font-size: 13px;
}

.board-status {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  min-width: 110px;
}

.board-status[data-kind="ok"] {
  color: var(--accent-ink);
}

.board-status[data-kind="saving"] {
  color: #8a6a1a;
}

.board-status[data-kind="err"] {
  color: var(--danger);
}

.board-colors {
  display: flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.board-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(18, 21, 28, 0.15);
  cursor: pointer;
  padding: 0;
}

.board-swatch.is-active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.board-swatch[data-color="mist"] { background: #f4f6f8; }
.board-swatch[data-color="sage"] { background: #d7e4d8; }
.board-swatch[data-color="sand"] { background: #efe3c8; }
.board-swatch[data-color="sky"] { background: #d3e4ef; }
.board-swatch[data-color="rose"] { background: #ead5d3; }
.board-swatch[data-color="ink"] { background: #2a303a; }

.board-viewport {
  position: relative;
  flex: 1;
  min-height: 420px;
  overflow: hidden;
  cursor: grab;
  background-image:
    radial-gradient(rgba(18, 21, 28, 0.09) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: center;
}

.board-viewport.is-panning {
  cursor: grabbing;
}

.board-world {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  transform-origin: 0 0;
}

.sticky {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(18, 21, 28, 0.12);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(18, 21, 28, 0.08);
  background: #f4f6f8;
  overflow: hidden;
  user-select: none;
  will-change: transform;
  contain: layout style;
}

.sticky.is-selected {
  box-shadow:
    0 0 0 2px rgba(13, 115, 119, 0.45),
    0 14px 34px rgba(18, 21, 28, 0.12);
}

.sticky[data-color="mist"] { background: #f4f6f8; }
.sticky[data-color="sage"] { background: #dce8dd; }
.sticky[data-color="sand"] { background: #f0e5cf; }
.sticky[data-color="sky"] { background: #d8e8f2; }
.sticky[data-color="rose"] { background: #eddcd9; }
.sticky[data-color="ink"] { background: #2a303a; color: #e8ecef; }
.sticky[data-color="ink"] .sticky-text {
  color: #e8ecef;
}
.sticky[data-color="ink"] .sticky-text::placeholder {
  color: rgba(232, 236, 239, 0.45);
}
.sticky[data-color="ink"] .sticky-handle,
.sticky[data-color="ink"] .sticky-del {
  color: rgba(232, 236, 239, 0.7);
}

.sticky-handle {
  height: 28px;
  cursor: grab;
  background: linear-gradient(180deg, rgba(18, 21, 28, 0.06), transparent);
  border-bottom: 1px solid rgba(18, 21, 28, 0.06);
  flex: 0 0 auto;
}

.sticky-handle::after {
  content: "";
  display: block;
  width: 28px;
  height: 3px;
  margin: 12px auto 0;
  border-radius: 99px;
  background: rgba(18, 21, 28, 0.2);
}

.sticky-text {
  flex: 1;
  width: 100%;
  border: 0;
  resize: none;
  background: transparent;
  padding: 10px 14px 28px;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  color: var(--ink);
  outline: none;
  user-select: text;
}

.sticky-resize {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 50%, rgba(18, 21, 28, 0.25) 50%);
  border-radius: 2px;
}

.sticky-del {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 24px;
  height: 22px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.sticky:hover .sticky-del,
.sticky.is-selected .sticky-del {
  opacity: 1;
}

.sticky-del:hover {
  background: rgba(18, 21, 28, 0.08);
  color: var(--danger);
}

.wip {
  max-width: 480px;
  margin-top: 40px;
  padding: 32px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.55);
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper-2) 88%, white);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.field-wide {
  grid-column: 1 / -1;
}

.msel {
  position: relative;
}

.msel-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  appearance: none;
  font: inherit;
  color: var(--ink);
}

.msel-trigger:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.msel-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msel-value.is-placeholder {
  color: var(--muted);
}

.msel-caret {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--muted);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.msel.is-open .msel-caret {
  transform: rotate(180deg);
}

.msel-panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  min-width: 100%;
  max-height: 280px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 14px 36px rgba(18, 21, 28, 0.12);
}

.msel-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.35;
  cursor: pointer;
  color: var(--ink);
}

.msel-option:hover {
  background: color-mix(in srgb, var(--accent) 8%, white);
}

.msel-option.is-all {
  border-bottom: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  margin-bottom: 4px;
  padding-bottom: 10px;
  font-weight: 600;
}

.msel-option.is-group {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: default;
}

.msel-option.is-group:hover {
  background: transparent;
}

.msel-option input {
  margin-top: 2px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.msel-empty {
  margin: 0;
  padding: 10px;
  font-size: 13px;
  color: var(--muted);
}

.cell-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.filters-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

.progress-block {
  margin-bottom: 22px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--muted);
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(18, 21, 28, 0.08);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #14919b);
  transition: width 0.25s ease;
}

.results-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.results-title {
  margin: 0 0 4px;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.results-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: auto;
  max-height: min(58vh, 640px);
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.results-table th,
.results-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.results-table th {
  position: sticky;
  top: 0;
  background: #f4f6f8;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  z-index: 1;
}

.results-table tbody tr:hover {
  background: rgba(13, 115, 119, 0.04);
}

.results-table tbody tr:last-child td {
  border-bottom: 0;
}

.cell-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.cell-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.cell-link:hover {
  text-decoration: underline;
}

.cell-addr {
  max-width: 260px;
  color: var(--muted);
  line-height: 1.35;
}

.rating {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(13, 115, 119, 0.1);
  color: var(--accent-ink);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
}

.empty {
  margin: 0;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

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

@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    padding: 12px 14px;
  }

  .topbar-left {
    width: 100%;
    justify-content: space-between;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .field-wide {
    grid-column: auto;
  }

  .results-head {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gate,
  .error,
  .btn,
  .progress-fill {
    animation: none;
    transition: none;
  }
}
