*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --app-bg: #e8edf2;
  --surface: #ffffff;
  --surface-soft: #f6f8fb;
  --surface-hover: #eef3f8;
  --ink: #101318;
  --muted: #66717f;
  --faint: #9aa5b3;
  --line: #dfe5ec;
  --accent: #2f7df6;
  --accent-strong: #1f62d0;
  --red: #dc3f36;
  --green: #168a4a;
  --yellow: #b87505;
  --shadow: 0 22px 70px rgba(26, 36, 52, 0.16);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --border: 1px solid var(--line);
}

html {
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #c8d2dd transparent;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: #c8d2dd;
  border-radius: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

body {
  min-height: 100dvh;
  background: var(--app-bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  user-select: none;
}

a {
  color: inherit;
}

.desktop-frame {
  width: min(1360px, calc(100vw - 44px));
  min-height: 660px;
  margin: 22px auto;
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(151, 163, 178, 0.34);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.app-sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 18px;
  padding: 18px 12px;
  border-right: var(--border);
  background: #f8fafc;
  min-width: 0;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  padding: 0 4px;
}

.brand-mark,
.app-glyph {
  display: inline-block;
  background:
    linear-gradient(135deg, transparent 0 36%, #ffffff 36% 48%, transparent 48%),
    var(--accent);
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.28);
}

.brand-mark {
  width: 18px;
  height: 18px;
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0;
}

.sidebar-nav {
  display: grid;
  gap: 5px;
}

.side-action,
.side-link {
  width: 100%;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.side-action:hover,
.side-link:hover {
  background: var(--surface-hover);
}

.side-action.is-active {
  background: var(--accent);
  color: #ffffff;
}

.side-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}

.sidebar-projects {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.sidebar-title {
  padding: 0 6px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.project-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 4px;
  padding-right: 2px;
}

.project-list:empty::before {
  content: "проектов пока нет";
  display: block;
  padding: 10px 6px;
  color: var(--faint);
  font-size: 12px;
}

.project-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.project-row:hover {
  background: var(--surface-hover);
}

.project-row strong {
  min-width: 0;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 650;
}

.project-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

.project-row .status-chip {
  grid-row: span 2;
  height: 22px;
}

.sidebar-footer {
  display: grid;
  gap: 8px;
}

.local-chip {
  width: fit-content;
  margin-left: 10px;
  padding: 2px 7px;
  border: var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  background: var(--surface);
}

.app-workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
  background: var(--surface);
}

.workspace-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  border-bottom: var(--border);
  color: var(--faint);
  font-size: 11px;
}

.workspace-main {
  min-height: 0;
  overflow: auto;
  position: relative;
}

.screen {
  min-height: 100%;
  padding: 22px;
}

.screen.is-hidden {
  display: none;
}

.screen-home {
  display: grid;
  grid-template-rows: minmax(260px, 1fr) auto;
  gap: 24px;
}

.home-center {
  align-self: center;
  justify-self: center;
  width: min(680px, 100%);
  text-align: center;
}

.app-glyph {
  width: 44px;
  height: 44px;
  margin-bottom: 22px;
}

.home-center h1 {
  font-size: 34px;
  line-height: 1.1;
  font-weight: 750;
  letter-spacing: 0;
}

.home-center p {
  max-width: 540px;
  margin: 12px auto 0;
  color: var(--faint);
  font-size: 22px;
  line-height: 1.25;
}

.command-bar {
  width: min(720px, 100%);
  justify-self: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.search-box {
  height: 50px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  border: var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 8px 26px rgba(22, 31, 44, 0.06);
}

.search-box:focus-within {
  border-color: rgba(47, 125, 246, 0.45);
  box-shadow: 0 0 0 4px rgba(47, 125, 246, 0.12);
}

.search-input {
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  padding: 0 16px;
  color: var(--ink);
  background: transparent;
  font-size: 14px;
}

.search-input::placeholder {
  color: var(--faint);
}

.search-btn {
  width: 42px;
  height: 42px;
  align-self: center;
  justify-self: center;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.search-btn:hover {
  background: var(--accent-strong);
}

.quick-action,
.ctrl-btn {
  height: 34px;
  padding: 0 12px;
  border: var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
}

.quick-action {
  height: 50px;
}

.quick-action:hover,
.ctrl-btn:hover {
  background: var(--surface-hover);
}

.ctrl-btn:disabled,
.quick-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ctrl-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.ctrl-btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.ctrl-btn-warning {
  background: #fff8e9;
  border-color: #edc978;
  color: #7b5200;
}

.screen-progress {
  max-width: 760px;
  margin: 0 auto;
  padding-top: 64px;
}

.panel-header,
.results-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.panel-header h2,
.results-meta h2 {
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.results-meta p,
.progress-site {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.progress-site {
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
}

.progress-percent {
  min-width: 54px;
  text-align: right;
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
}

.progress-bar-wrap {
  margin-bottom: 14px;
}

.progress-bar {
  height: 6px;
  overflow: hidden;
  border-radius: 6px;
  background: #e5ebf2;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 240ms ease;
}

.progress-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.stat,
.toolbar-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 9px;
  border: var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.stat-val {
  color: var(--ink);
  font-weight: 700;
}

.progress-log {
  list-style: none;
  display: grid;
  gap: 5px;
}

.progress-log li {
  min-height: 24px;
  padding: 5px 8px;
  overflow: hidden;
  border: var(--border);
  border-radius: 7px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 11px;
}

.screen-results,
.screen-project {
  max-width: 1180px;
  margin: 0 auto;
}

.results-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
  max-width: 720px;
}

.toolbar-strip,
.filter-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-bottom: 14px;
}

.filter-btn {
  height: 30px;
  padding: 0 11px;
  border: var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.filter-btn:hover,
.filter-btn.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

.page-filter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  width: min(340px, 100%);
  height: 30px;
  border: var(--border);
  border-radius: 7px;
  overflow: hidden;
  background: var(--surface);
}

.page-url-filter-input {
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 0 9px;
  color: var(--ink);
  background: transparent;
  font-family: var(--mono);
  font-size: 11px;
}

.page-url-filter-clear {
  border: 0;
  border-left: var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
}

.page-url-filter-clear:hover {
  background: var(--surface-hover);
}

.project-settings {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
}

.settings-label,
.modal-field {
  display: grid;
  gap: 6px;
}

.settings-label span,
.modal-field span,
.project-settings-status,
.modal-status {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.page-exclude-masks-input,
.modal-field textarea,
.modal-field input,
.modal-field select {
  width: 100%;
  min-width: 0;
  border: var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  outline: 0;
}

.page-exclude-masks-input,
.modal-field textarea {
  min-height: 66px;
  resize: vertical;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.4;
}

.modal-field input,
.modal-field select {
  height: 36px;
  padding: 0 10px;
}

.page-exclude-masks-input:focus,
.modal-field textarea:focus,
.modal-field input:focus,
.modal-field select:focus {
  border-color: rgba(47, 125, 246, 0.55);
  box-shadow: 0 0 0 4px rgba(47, 125, 246, 0.11);
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 1px;
}

.gallery-grid {
  column-width: 190px;
  column-gap: 9px;
  line-height: 0;
}

.gallery-grid:empty {
  display: none;
}

.empty-state {
  padding: 30px;
  border: 1px dashed #c7d1dc;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-soft);
}

.intro-empty {
  width: min(520px, 100%);
  margin: 140px auto 0;
}

.image-card {
  display: block;
  width: 100%;
  margin-bottom: 9px;
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  position: relative;
  border-radius: 7px;
  background: #e6ebf2;
}

.image-button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
}

.image-shell {
  position: relative;
  aspect-ratio: var(--thumb-ratio, 1);
  overflow: hidden;
  border-radius: 7px;
  background: #e6ebf2;
}

.image-preview {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  opacity: 0;
  transition: opacity 180ms;
  content-visibility: auto;
}

.image-card.is-loaded .image-preview {
  opacity: 1;
}

.image-fallback {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.image-card.has-image-error .image-preview {
  display: none;
}

.image-card.has-image-error .image-fallback {
  display: grid;
}

.image-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 6px;
  opacity: 0;
  transition: opacity 140ms ease;
}

.selection-chip,
.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 23px;
  min-width: 23px;
  padding: 0 7px;
  border-radius: 7px;
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(16, 19, 24, 0.12);
}

.status-chip {
  margin-left: auto;
}

.selection-chip {
  opacity: 0;
  transform: scale(0.76);
  transition: opacity 120ms ease, transform 120ms ease;
}

.image-card:hover .image-overlay,
.image-card.is-selected .image-overlay,
.image-card.status-matched .image-overlay,
.image-card.status-clean .image-overlay,
.image-card.status-unreadable .image-overlay,
.image-card.status-error .image-overlay,
.image-card.status-manual_required .image-overlay {
  opacity: 1;
}

.image-card.is-selected .selection-chip {
  opacity: 1;
  transform: scale(1);
  background: var(--accent);
  color: #ffffff;
}

.image-card.is-selected .image-shell {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.image-card.status-matched .image-shell {
  outline: 3px solid var(--red);
  outline-offset: -3px;
}

.image-card.status-matched .status-chip {
  background: var(--red);
  color: #ffffff;
}

.image-card.status-clean .status-chip {
  background: var(--green);
  color: #ffffff;
}

.image-card.status-unreadable .status-chip {
  background: var(--ink);
  color: #ffffff;
}

.image-card.status-error .status-chip,
.image-card.status-manual_required .status-chip {
  background: var(--yellow);
  color: #ffffff;
}

.image-info {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 10;
}

.image-info-btn {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 7px;
  background: rgba(255,255,255,0.92);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(16, 19, 24, 0.12);
}

.image-card:hover .image-info-btn,
.image-info.is-open .image-info-btn {
  opacity: 1;
}

.image-info-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 5px);
  min-width: 128px;
  display: grid;
  gap: 2px;
  padding: 5px;
  border: var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 34px rgba(18, 25, 36, 0.16);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-3px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.image-info.is-open .image-info-menu,
.image-info:focus-within .image-info-menu {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.image-info-menu a {
  display: block;
  padding: 7px 9px;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-size: 12px;
}

.image-info-menu a:hover {
  background: var(--surface-hover);
}

.result-link.is-hidden {
  display: none;
}

.validation-panel {
  margin-bottom: 16px;
  padding: 14px;
  border: var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.val-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.val-header > span:last-child {
  color: var(--ink);
  font-weight: 700;
}

.progress-log-compact {
  margin-top: 10px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(32, 43, 58, 0.34);
}

.modal-backdrop.is-hidden {
  display: none;
}

.modal-panel {
  width: min(460px, 100%);
  max-height: calc(100dvh - 44px);
  overflow: auto;
  border: var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(14, 21, 31, 0.28);
}

.modal-panel-wide {
  width: min(780px, 100%);
}

.modal-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.modal-header h2 {
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.modal-close {
  width: 30px;
  height: 30px;
  border: var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.modal-close:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.settings-grid-full {
  grid-column: 1 / -1;
}

.modal-status {
  min-height: 16px;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 900px) {
  .desktop-frame {
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    grid-template-columns: 190px minmax(0, 1fr);
  }

  .home-center h1 {
    font-size: 28px;
  }

  .home-center p {
    font-size: 17px;
  }

  .command-bar {
    grid-template-columns: 1fr;
  }

  .quick-action {
    height: 38px;
  }

  .project-settings,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .desktop-frame {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    display: none;
  }

  .workspace-topbar {
    min-width: 0;
  }

  .screen {
    padding: 16px;
  }

  .results-header,
  .panel-header {
    flex-direction: column;
  }

  .results-controls {
    justify-content: flex-start;
  }

  .ctrl-btn {
    flex: 1 1 auto;
  }

  .gallery-grid {
    column-width: 150px;
  }
}
