:root {
  --panel: rgba(10, 13, 19, 0.92);
  --ink: #f3f7fb;
  --muted: #97a2b3;
  --line: rgba(255, 255, 255, 0.1);
  --accent-soft: rgba(60, 166, 255, 0.14);
  --accent-dark: #8fd1ff;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius-lg: 28px;
  --header-group-height: 54px;
  --header-column-height: 60px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(60, 166, 255, 0.18), transparent 30%),
    radial-gradient(circle at bottom right, rgba(75, 209, 141, 0.1), transparent 26%),
    linear-gradient(180deg, #07090d 0%, #030406 100%);
}

button,
input,
textarea {
  font: inherit;
}

.page-shell {
  width: min(1380px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.image-table-shell,
.editor-drawer,
.preview-dialog {
  backdrop-filter: blur(14px);
}

.image-table-shell {
  position: relative;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 30px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 16px;
  padding: 8px 4px 18px;
}

.toolbar-metrics {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-right: auto;
}

.metric {
  min-width: 110px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 1.15rem;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
}

.button,
.ghost-button,
.mini-button,
.icon-button {
  appearance: none;
  border: 0;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    background-color 0.18s ease,
    border-color 0.18s ease,
    opacity 0.18s ease;
}

.button:hover,
.ghost-button:hover,
.mini-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.button {
  background: linear-gradient(135deg, #2e7dd6 0%, #19529f 100%);
  color: #f6fbff;
  padding: 13px 18px;
  border-radius: 999px;
  box-shadow: 0 12px 22px rgba(25, 82, 159, 0.3);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 12px 16px;
  border-radius: 999px;
}

.ghost-button:disabled,
.button:disabled,
.mini-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.table-frame {
  position: relative;
  overflow: hidden;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.table-scroll {
  overflow: auto;
  max-width: 100%;
}

.image-table {
  width: max(100%, 1024px);
  border-collapse: separate;
  border-spacing: 0;
}

.image-table thead th {
  position: sticky;
  z-index: 4;
}

.group-row th {
  top: 0;
  height: var(--header-group-height);
  padding: 10px 18px;
  background: rgba(9, 13, 20, 0.98);
  color: #f2f7fc;
  text-align: left;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.95rem;
  letter-spacing: 0.03em;
}

.column-row th {
  top: var(--header-group-height);
  height: var(--header-column-height);
  padding: 14px 18px;
  background: rgba(16, 21, 30, 0.98);
  color: var(--ink);
  text-align: left;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  font-size: 0.95rem;
}

.group-row th:first-child {
  border-top-left-radius: 22px;
}

.group-row th:last-child {
  border-top-right-radius: 22px;
}

.image-table tbody td {
  position: relative;
  padding: 14px;
  background: rgba(255, 255, 255, 0.02);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.image-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.04);
}

.cell-button {
  width: 100%;
  min-height: 156px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  border: 1px dashed transparent;
  border-radius: 18px;
  padding: 12px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.cell-button:hover,
.cell-button.is-active {
  border-color: rgba(60, 166, 255, 0.4);
  background: rgba(60, 166, 255, 0.08);
}

.cell-empty {
  margin: auto 0;
  color: var(--muted);
  line-height: 1.6;
}

.cell-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(60, 166, 255, 0.18), rgba(75, 209, 141, 0.14)),
    #111722;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

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

.cell-text {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cell-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.cell-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #cfeaff;
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 6px 10px;
}

.row-toolbar-anchor {
  overflow: visible;
}

.row-toolbar {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 999px;
  background: rgba(6, 9, 14, 0.92);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
  z-index: 3;
}

.image-table tbody tr:hover .row-toolbar,
.row-toolbar:focus-within {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.mini-button,
.icon-button {
  border-radius: 999px;
  color: #eff6ff;
  background: rgba(255, 255, 255, 0.08);
}

.mini-button {
  padding: 8px 12px;
  font-size: 0.84rem;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
}

.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
}

.panel-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.editor-drawer {
  position: fixed;
  top: 18px;
  right: 18px;
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  border-radius: 28px;
  background: rgba(11, 15, 22, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow);
  transform: translateX(calc(100% + 24px));
  transition: transform 0.22s ease;
  z-index: 24;
}

.editor-drawer.is-open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.drawer-head h3 {
  margin: 0;
  font-size: 1.5rem;
}

.drawer-head p {
  margin: 8px 0 0;
  color: var(--muted);
}

.drawer-section {
  display: grid;
  gap: 10px;
}

.drawer-label {
  font-size: 0.88rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--accent-dark);
}

.drawer-image {
  display: grid;
  place-items: center;
  min-height: 220px;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at top, rgba(60, 166, 255, 0.16), transparent 52%),
    linear-gradient(180deg, rgba(18, 24, 35, 0.98), rgba(10, 13, 19, 0.98));
}

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

.drawer-empty {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
  line-height: 1.7;
}

.drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.drawer-help {
  color: var(--muted);
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.6;
}

.drawer-textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  padding: 14px 16px;
  color: var(--ink);
  line-height: 1.6;
}

.drawer-textarea:focus {
  outline: 2px solid rgba(60, 166, 255, 0.25);
  border-color: rgba(60, 166, 255, 0.3);
}

.drawer-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.preview-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 28;
}

.preview-backdrop.is-open {
  display: flex;
}

.preview-dialog {
  width: min(920px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  background: rgba(10, 13, 19, 0.98);
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 18px;
  box-shadow: var(--shadow);
}

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

.preview-toolbar strong {
  font-size: 1.05rem;
}

.preview-frame {
  overflow: hidden;
  border-radius: 22px;
  background: #111722;
}

.preview-frame img {
  width: 100%;
  max-height: calc(100vh - 180px);
  object-fit: contain;
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 980px) {
  .toolbar {
    justify-content: flex-start;
  }

  .toolbar-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100vw - 18px, 100%);
    padding-top: 18px;
  }

  .image-table-shell {
    padding: 12px;
    border-radius: 22px;
  }

  .metric {
    min-width: 0;
    flex: 1;
  }

  .group-row th {
    padding: 10px 12px;
  }

  .column-row th,
  .image-table tbody td {
    padding-left: 10px;
    padding-right: 10px;
  }

  .cell-button {
    min-height: 130px;
    padding: 10px;
  }

  .row-toolbar {
    top: 8px;
    right: 8px;
    gap: 6px;
  }

  .mini-button {
    padding: 8px 10px;
  }

  .editor-drawer {
    top: auto;
    right: 9px;
    left: 9px;
    bottom: 10px;
    width: auto;
    max-height: min(82vh, 720px);
    border-radius: 24px;
    transform: translateY(calc(100% + 14px));
  }

  .editor-drawer.is-open {
    transform: translateY(0);
  }

  .drawer-image {
    min-height: 180px;
  }
}

@media (hover: none) {
  .row-toolbar {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }
}
