:root {
  color-scheme: light;
  --ink: #171412;
  --muted: #756f68;
  --line: #ded8cf;
  --paper: #fbfaf7;
  --soft: #f0ece5;
  --night: #12100e;
  --accent: #e94d3c;
  --mint: #7fb7a3;
  --blue: #426f98;
  --gold: #c99b3c;
  --shadow: 0 18px 45px rgba(23, 20, 18, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  padding-bottom: 80px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  background: rgba(251, 250, 247, 0.92);
  border-bottom: 1px solid rgba(222, 216, 207, 0.85);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: var(--night);
  color: #fff3d6;
  font-weight: 800;
}

.brand-title {
  margin: 0;
  font-size: 17px;
  line-height: 1.05;
}

.brand-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.mode-switch button,
.pill-button,
.icon-button,
.primary-button,
.ghost-button,
.danger-button {
  min-height: 40px;
  border-radius: 7px;
  color: var(--ink);
}

.mode-switch button {
  min-width: 96px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
}

.mode-switch button.active {
  background: var(--night);
  color: #fff;
}

.layout {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 20px 16px 0;
}

.hero {
  display: grid;
  gap: 22px;
  padding: 24px 0 12px;
}

.hero-copy {
  max-width: 760px;
}

.city-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.select-control,
.search-control,
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: 0;
}

.select-control {
  width: auto;
  min-height: 40px;
  padding: 0 38px 0 12px;
}

.pill-button,
.ghost-button {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #fff;
}

.primary-button {
  padding: 0 16px;
  background: var(--night);
  color: #fff;
}

.danger-button {
  padding: 0 14px;
  background: #f7d8d3;
  color: #8a2116;
}

.hero h1 {
  margin: 0;
  max-width: 700px;
  font-size: clamp(34px, 7vw, 72px);
  line-height: 0.95;
  letter-spacing: 0;
}

.hero p {
  max-width: 620px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.45;
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

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

.stat strong {
  display: block;
  font-size: 24px;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
}

.category-rail {
  display: flex;
  gap: 8px;
  margin: 10px -16px 22px;
  padding: 0 16px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.category-rail::-webkit-scrollbar {
  display: none;
}

.category-chip {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  white-space: nowrap;
}

.category-chip.active {
  border-color: var(--night);
  background: var(--night);
  color: #fff;
}

.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 26px 0 14px;
}

.section-title h2 {
  margin: 0;
  font-size: 23px;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
}

.featured-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.event-card,
.compact-card,
.admin-panel,
.detail-sheet,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 0 rgba(23, 20, 18, 0.03);
}

.event-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

.event-image {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--soft);
}

.event-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.badge-row {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(18, 16, 14, 0.82);
  color: #fff;
  font-size: 12px;
}

.badge.free {
  background: var(--mint);
  color: #10251d;
}

.event-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 14px;
}

.event-meta,
.compact-meta,
.admin-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  color: var(--muted);
  font-size: 13px;
}

.event-card h3,
.compact-card h3 {
  margin: 10px 0 8px;
  font-size: 20px;
  line-height: 1.15;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.event-card p,
.compact-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.card-actions,
.admin-actions,
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: auto;
  padding-top: 14px;
}

.icon-button {
  display: inline-grid;
  min-width: 40px;
  place-items: center;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 18px;
}

.icon-button.active {
  border-color: var(--accent);
  background: #fff0ee;
  color: var(--accent);
}

.compact-list {
  display: grid;
  gap: 10px;
}

.compact-card {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  min-height: 134px;
  padding: 10px;
}

.compact-card img {
  width: 92px;
  height: 112px;
  border-radius: 7px;
  object-fit: cover;
  background: var(--soft);
}

.compact-card > div {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.compact-card h3 {
  font-size: 17px;
}

.desktop-columns {
  display: grid;
  gap: 22px;
}

.search-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.search-control {
  min-height: 44px;
  padding: 0 13px;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 10px;
  z-index: 30;
  display: grid;
  width: min(440px, calc(100% - 20px));
  grid-template-columns: repeat(4, 1fr);
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.bottom-nav button {
  min-height: 56px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.bottom-nav button.active {
  color: var(--ink);
  background: var(--soft);
}

.admin-grid {
  display: grid;
  gap: 14px;
}

.admin-panel {
  padding: 14px;
}

.admin-panel h2,
.admin-panel h3 {
  margin: 0 0 12px;
}

.metrics-grid,
.sources-grid {
  display: grid;
  gap: 10px;
}

.source-row,
.candidate-row,
.published-row {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.status {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
}

.status.approved,
.status.published,
.status.extracted,
.status.success {
  background: #dcefe7;
  color: #1b5e46;
}

.status.rejected,
.status.duplicate,
.status.error,
.status.failed,
.status.avito_suspicious {
  background: #f6d8d2;
  color: #8a2116;
}

.status.insufficient_data,
.status.partial_success,
.status.avito_needs_review {
  background: #f6e8c7;
  color: #755213;
}

.field-grid {
  display: grid;
  gap: 10px;
}

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

.field label {
  color: var(--muted);
  font-size: 12px;
}

.field input,
.field select,
.field textarea {
  min-height: 42px;
  padding: 9px 11px;
}

.field textarea {
  min-height: 86px;
  resize: vertical;
}

.detail-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: end;
  justify-content: center;
  padding: 16px;
  background: rgba(18, 16, 14, 0.45);
}

.detail-sheet {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(760px, 100%);
  max-height: min(860px, calc(100vh - 32px));
  overflow: hidden;
  box-shadow: var(--shadow);
}

.detail-media {
  aspect-ratio: 16 / 9;
  max-height: 340px;
  overflow: hidden;
  background: var(--soft);
}

.detail-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.detail-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.94);
}

.detail-body {
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.detail-body h2 {
  margin: 10px 0;
  font-size: 28px;
  line-height: 1.05;
}

.detail-body p {
  color: var(--muted);
  line-height: 1.55;
}

.detail-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.detail-info-grid > div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf7f2;
}

.detail-info-grid strong,
.detail-info-grid small {
  display: block;
  overflow-wrap: anywhere;
}

.detail-info-grid small,
.detail-label {
  color: var(--muted);
  font-size: 12px;
}

.detail-label {
  display: block;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  z-index: 60;
  width: min(420px, calc(100% - 30px));
  padding: 12px 14px;
  transform: translateX(-50%);
  border-radius: 8px;
  background: var(--night);
  color: #fff;
  box-shadow: var(--shadow);
}

@media (min-width: 760px) {
  .app-shell {
    padding-bottom: 30px;
  }

  .layout {
    padding: 28px 24px 0;
  }

  .hero {
    grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.65fr);
    align-items: end;
    padding-top: 34px;
  }

  .quick-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

  .desktop-columns {
    grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.85fr);
    align-items: start;
  }

  .search-panel {
    grid-template-columns: minmax(220px, 1fr) 150px 140px 140px;
  }

  .bottom-nav {
    display: none;
  }

  .admin-grid {
    grid-template-columns: 320px 1fr;
    align-items: start;
  }

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

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

  .detail-backdrop {
    align-items: center;
  }
}

@media (min-width: 1060px) {
  .featured-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .event-card.primary {
    grid-column: span 2;
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
  }

  .event-card.primary .event-image {
    min-height: 360px;
    height: 100%;
    aspect-ratio: auto;
  }

  .event-card.primary .event-image img {
    height: 100%;
  }

  .event-card.primary .event-content {
    padding: 24px;
  }

  .event-card.primary h3 {
    font-size: 32px;
  }
}

@media (max-width: 520px) {
  .topbar {
    align-items: start;
  }

  .mode-switch button {
    min-width: 72px;
    padding: 0 8px;
    font-size: 12px;
  }

  .quick-stats {
    grid-template-columns: 1fr;
  }

  .compact-card {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .detail-info-grid {
    grid-template-columns: 1fr;
  }

  .compact-card img {
    width: 82px;
    height: 104px;
  }
}

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

.admin-login-layout {
  max-width: 620px;
}

.admin-login-card {
  margin-top: 28px;
}

.source-table-wrap {
  margin-top: 18px;
  overflow-x: auto;
}

.source-table-head,
.source-table-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.2fr) 132px minmax(210px, 1.5fr) 150px 140px 60px 70px 70px minmax(160px, 1fr) 70px 88px minmax(220px, 1.2fr);
  gap: 8px;
  align-items: center;
  min-width: 1480px;
}

.source-table-head {
  color: var(--muted);
  font-size: 12px;
  padding: 0 8px 8px;
}

.source-table-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.72);
}

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

.source-table-row > span {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
}

.source-error {
  color: #a83b2d !important;
}

.source-filters,
.diagnostics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin: 10px 0 12px;
}

.source-table-row small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.toggle-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.source-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

@media (max-width: 760px) {
  .admin-topline {
    align-items: flex-start;
    flex-direction: column;
  }
}

.header-profile {
  justify-self: end;
  max-width: min(260px, 45vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
