:root {
  --brand: #151515;
  --brand-rich: #1a1416;
  --brand-soft: #f0eeee;
  --cream: #f4e9e2;
  --ink: #252323;
  --ink-strong: #111010;
  --muted: #71696b;
  --muted-strong: #494244;
  --line: #ded6d8;
  --line-strong: #b9adb0;
  --paper: #fffdfd;
  --panel: #f7f4f5;
  --soft: #f1ecee;
  --logo-paper: transparent;
  --accent: #d33645;
  --accent-ink: #7f1d28;
  --accent-soft: #fae4e7;
  --secondary: #d33645;
  --secondary-soft: #f5d9de;
  --gold: #d33645;
  --warn: #b96b22;
  --danger: #a43d3d;
  --shadow: 0 18px 42px rgba(32, 27, 28, 0.12);
  --shadow-soft: 0 10px 24px rgba(32, 27, 28, 0.1);
  --poster-w: 1440px;
  --poster-h: 2560px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(180deg, #f0edef 0%, #fffdfd 44%, #eee9eb 100%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  font-weight: 800;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease, background 0.16s ease;
}

button:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-soft);
  background: #fbfdfc;
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(211, 54, 69, 0.22);
  outline-offset: 2px;
}

button svg,
.dropIcon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.sidebar,
.tablePanel,
.previewPanel {
  border: 1px solid rgba(184, 197, 203, 0.85);
  border-radius: 8px;
  background: rgba(255, 254, 253, 0.96);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidebar {
  height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
}

.brand {
  padding: 22px 22px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  background: linear-gradient(180deg, var(--paper), #faf1f3);
  border-bottom: 1px solid rgba(216, 224, 228, 0.7);
}

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

.brandLogo {
  width: 104px;
  height: auto;
  flex: 0 0 auto;
  display: block;
  background: var(--logo-paper);
}

.brandText {
  min-width: 0;
}

.brand p,
.toolbar p {
  margin: 0 0 7px;
  color: var(--secondary);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  max-width: 12ch;
  color: var(--ink-strong);
  font-size: 26px;
  line-height: 1.05;
}

.sizeBadge {
  flex: 0 0 auto;
  border: 1px solid rgba(31, 30, 27, 0.22);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--brand);
  background: var(--brand-soft);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.dropGrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 18px 22px 16px;
}

.dropZone {
  min-height: 108px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 8px;
  background: linear-gradient(180deg, #fbfdfc, var(--panel));
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 14px;
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.compactDrop {
  min-height: 82px;
}

.dropZone:hover,
.dropZone:focus-within {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(211, 54, 69, 0.12);
}

.dropZone.isDragging,
body.isDragging .dropZone:first-child {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropZone input {
  display: none;
}

.dropIcon {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  color: var(--accent-ink);
  background: var(--soft);
  display: grid;
  place-items: center;
  grid-row: 1 / 3;
}

.dropTitle {
  display: block;
  grid-column: 2;
  color: var(--ink-strong);
  font-size: 18px;
  font-weight: 900;
}

.dropMeta {
  display: block;
  grid-column: 2;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  margin: 0 22px 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primaryBtn {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.primaryBtn:hover {
  background: #b72c3a;
  border-color: #b72c3a;
}

.block {
  margin: 0 22px 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

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

.block h2,
.rawBlock summary {
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.blockTop span,
.metrics span {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.fileList {
  min-height: 0;
  max-height: 290px;
  overflow: auto;
  display: grid;
  gap: 8px;
  scrollbar-color: var(--line-strong) transparent;
}

.fileItem,
.emptyFileList {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
  color: var(--muted);
  font-size: 13px;
}

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

.fileItemTop {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.fileItemTop span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-weight: 800;
}

.fileItemTop strong {
  flex: 0 0 auto;
  color: var(--accent-ink);
}

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

.candidatePill {
  min-width: 0;
  border-radius: 999px;
  padding: 5px 7px;
  background: #eef3f4;
  color: #4f5b63;
  font-size: 11px;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.candidatePill.isWinner {
  color: #fff;
  background: var(--brand);
}

.rawBlock {
  margin: auto 22px 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.rawBlock summary {
  cursor: pointer;
}

.rawBlock textarea {
  width: 100%;
  height: 190px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  resize: vertical;
  color: #263039;
  background: #fbfcfd;
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 520px);
  gap: 18px;
}

.tablePanel,
.previewPanel {
  height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
}

.toolbar {
  min-height: 96px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px;
  background: linear-gradient(180deg, var(--paper), #faf1f3);
}

.toolbar h2 {
  max-width: 36ch;
  color: var(--ink-strong);
  font-size: 22px;
  line-height: 1.15;
}

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

.metrics strong {
  color: var(--ink);
}

.tableShell {
  position: relative;
  min-height: 0;
  flex: 1;
  overflow: auto;
  background: #fff;
}

.editorTable {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.editorTable th,
.editorTable td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: middle;
}

.editorTable th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #171213;
  color: #fff;
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  border-bottom: 3px solid var(--accent);
}

.editorTable tbody tr:nth-child(even) {
  background: #fff6f7;
}

.editorTable tbody tr:hover {
  background: #fcecef;
}

.editorTable th:nth-child(1) { width: 116px; }
.editorTable th:nth-child(2) { width: 220px; }
.editorTable th:nth-child(3) { width: 240px; }
.editorTable th:nth-child(4) { width: 240px; }
.editorTable th:nth-child(5) { width: 44px; }

.editorTable input {
  width: 100%;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  outline: none;
  padding: 7px 8px;
  font-size: 13px;
  font-weight: 800;
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.editorTable input:hover {
  border-color: #ead7dc;
  background: #fff;
}

.editorTable input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(211, 54, 69, 0.16);
}

.sourceText,
.toolText {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: #3a444c;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 800;
}

.toolText {
  color: var(--accent-ink);
}

.rowDelete {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  color: var(--danger);
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.rowDelete:hover {
  border-color: transparent;
  box-shadow: none;
  background: #fff0f0;
}

.emptyState {
  position: absolute;
  inset: 110px 0 auto;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
}

.tableShell.hasRows .emptyState {
  display: none;
}

.previewToolbar {
  height: 50px;
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted-strong);
  background: #fbfdfc;
  font-weight: 800;
}

.previewToolbar span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stageShell {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(23, 33, 38, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(23, 33, 38, 0.04) 1px, transparent 1px),
    #eee9eb;
  background-size: 28px 28px;
}

.stageScaler {
  width: calc(var(--poster-w) * var(--preview-scale, 0.25));
  height: calc(var(--poster-h) * var(--preview-scale, 0.25));
}

.poster {
  position: relative;
  width: var(--poster-w);
  height: var(--poster-h);
  transform: scale(var(--preview-scale, 0.25));
  transform-origin: top left;
  background: #fff;
  color: #171213;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0 60px 58px;
  box-shadow: 0 24px 60px rgba(10, 15, 20, 0.22);
}

.posterTop {
  position: relative;
  z-index: 0;
  margin: 0 -60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 42px;
  min-height: 188px;
  padding: 34px 60px 30px;
  color: #171213;
  background: linear-gradient(135deg, #fffdfd 0%, #f9ecef 52%, #f3d4db 100%);
  border-bottom: 8px solid var(--accent);
  overflow: hidden;
}

.posterTop > div {
  min-width: 0;
}

.posterLogo {
  width: 168px;
  height: auto;
  flex: 0 0 auto;
  display: block;
  object-fit: contain;
  padding: 0;
  background: transparent;
  border: 0;
}

.posterTop h2 {
  color: #171213;
  font-size: var(--poster-title, 78px);
  line-height: 0.98;
  letter-spacing: 0;
}

.posterTableWrap {
  flex: 1;
  min-height: 0;
  margin-top: 32px;
  border: 3px solid #171213;
  border-radius: 6px;
  overflow: hidden;
  background: #fffaf8;
}

.posterTable {
  width: 100%;
  height: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.posterTable thead {
  height: var(--poster-head-h, 78px);
}

.posterTable th {
  padding: 0 var(--cell-pad-x, 18px);
  color: #fff;
  background: #171213;
  text-align: left;
  font-size: calc(var(--row-font, 34px) * 0.72);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.posterTable th,
.posterTable td {
  border-right: 2px solid #3d3739;
}

.posterTable th:last-child,
.posterTable td:last-child {
  border-right: 0;
}

.posterTable td {
  border-top: 2px solid #766c70;
  padding: var(--cell-pad-y, 10px) var(--cell-pad-x, 18px);
  font-size: var(--row-font, 36px);
  line-height: 1.08;
  font-weight: 900;
  vertical-align: middle;
  background: #fffaf8;
}

.posterTable tr:nth-child(even) td {
  background: #f8e8eb;
}

.posterSpeciesCol { width: 34%; }
.posterZoneCol { width: 30%; }
.posterTypeCol { width: 36%; }

.posterCellText {
  display: -webkit-box;
  -webkit-line-clamp: var(--line-clamp, 2);
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

.posterSpeciesText,
.posterTypeText {
  text-transform: uppercase;
}

.posterZoneText {
  color: #312b2d;
  font-weight: 850;
}

.poster.isManyRows .posterTop {
  min-height: 176px;
  padding-bottom: 26px;
}

.poster.isManyRows .posterLogo {
  width: 152px;
  padding: 0;
}

body.isExporting .poster {
  transform: none;
  box-shadow: none;
}

@media (max-width: 1420px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .tablePanel,
  .previewPanel {
    height: auto;
    min-height: 640px;
  }

  .previewPanel {
    min-height: 780px;
  }
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }

  .sidebar {
    height: auto;
  }

  .toolbar,
  .brand {
    align-items: flex-start;
    flex-direction: column;
  }

  .metrics {
    justify-content: flex-start;
  }
}

@media (max-width: 620px) {
  .brand,
  .dropGrid,
  .actions,
  .block,
  .rawBlock {
    margin-left: 14px;
    margin-right: 14px;
  }

  .brand {
    padding-left: 14px;
    padding-right: 14px;
  }

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

  .toolbar {
    padding: 18px 14px;
  }
}
