:root {
  color-scheme: light;
  --bg: #f5f1eb;
  --panel: rgba(255, 255, 255, 0.84);
  --panel-strong: #ffffff;
  --text: #1b1815;
  --muted: #6b625a;
  --line: rgba(27, 24, 21, 0.12);
  --soft-fill: rgba(117, 96, 68, 0.06);
  --soft-fill-strong: rgba(117, 96, 68, 0.1);
  --shadow: 0 18px 40px rgba(33, 27, 21, 0.08);
  --accent: #201c18;
  --accent-contrast: #f8f5f0;
  --error: #b53d2e;
  --success: #2b7d43;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(117, 96, 68, 0.14), transparent 28%),
    radial-gradient(circle at bottom left, rgba(168, 147, 116, 0.18), transparent 25%),
    var(--bg);
  color: var(--text);
}

body[data-theme="dark"],
#app[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0b;
  --panel: rgba(18, 18, 18, 0.92);
  --panel-strong: #121212;
  --text: #f2ede6;
  --muted: #b3a9a0;
  --line: rgba(242, 237, 230, 0.1);
  --soft-fill: rgba(255, 255, 255, 0.04);
  --soft-fill-strong: rgba(255, 255, 255, 0.08);
  --shadow: 0 24px 52px rgba(0, 0, 0, 0.42);
  --accent: #f2ede6;
  --accent-contrast: #111111;
}

#app {
  min-height: 100vh;
  padding: 34px;
}

.site-header,
.row-between,
.button-row,
.header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.button-row {
  flex-wrap: wrap;
}

.compact-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.title-action-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.title-action-row h2 {
  margin-bottom: 0;
}

.page-shell {
  margin-top: 34px;
}

.workstation {
  display: grid;
  grid-template-columns: minmax(290px, 330px) minmax(680px, 1fr) minmax(290px, 320px);
  gap: 26px;
  align-items: start;
}

.card,
.modal-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.card {
  padding: 24px;
}

.side-card {
  min-height: 520px;
  padding: 28px;
}

.main-card {
  min-height: 620px;
}

.login-card {
  max-width: 420px;
  margin: 10vh auto 0;
}

.card-header h2,
.site-header h1 {
  margin: 2px 0 0;
  font-size: clamp(1.12rem, 1.7vw, 1.65rem);
  line-height: 1.1;
  font-weight: 700;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-size: 0.74rem;
}

.stack-form,
.meta-list {
  display: grid;
  gap: 16px;
}

.stack-form select {
  padding: 10px 50px 10px 15px;
}

.segmented-control {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--soft-fill), var(--panel-strong) 35%);
}

.segment-button {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 9px 15px;
  min-width: 104px;
  box-shadow: none;
}

.segment-button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.side-card .card-header {
  margin-bottom: 18px;
}

.side-card .meta-list {
  gap: 20px;
  margin-bottom: 20px;
}

.side-card .button-row {
  margin-bottom: 18px;
}

.side-card .stack-form {
  margin-top: 10px;
}

.side-card .hint {
  line-height: 1.55;
}

label {
  display: grid;
  gap: 8px;
}

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

input,
textarea,
select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  border-radius: 16px;
  padding: 12px 14px;
}

input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

textarea {
  resize: vertical;
}

button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
}

button.slim-button {
  padding: 9px 15px;
}

button.ghost-button {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

button.danger-button {
  color: var(--error);
}

button.danger-button:not(:disabled):hover {
  border-color: var(--error);
  background: color-mix(in srgb, var(--error) 9%, transparent);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.hint,
.feedback,
.feedback-list,
.meta-list,
td {
  color: var(--muted);
}

.feedback {
  min-height: 1.2rem;
}

.feedback.error,
.chip.error,
.row-status.error {
  color: var(--error);
}

.feedback.success,
.chip.ready,
.row-status.ready {
  color: var(--success);
}

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

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--soft-fill);
}

.selection-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  color: var(--muted);
  background: var(--soft-fill);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(90px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.summary-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: var(--panel-strong);
}

.summary-card strong {
  display: block;
  font-size: 1.2rem;
  margin-top: 4px;
  color: var(--text);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-strong);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.checkbox-col,
.number-col {
  width: 1%;
  white-space: nowrap;
}

.title-col {
  width: 100%;
  min-width: 260px;
}

tbody tr {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

tbody tr:hover {
  background: var(--soft-fill);
}

tbody tr.is-selected {
  background: var(--soft-fill-strong);
}

.row-number {
  display: inline-flex;
  min-width: 34px;
  justify-content: center;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--soft-fill);
  color: var(--text);
  font-weight: 600;
}

.row-status {
  font-weight: 600;
  text-transform: capitalize;
}

.cell-title {
  display: -webkit-box;
  max-width: min(520px, 48vw);
  overflow: hidden;
  line-height: 1.35;
  color: var(--text);
  font-weight: 600;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.cell-description {
  max-width: 340px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.cell-empty {
  color: var(--muted);
}

.batch-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.batch-history-panel {
  margin-top: 16px;
}

.batch-history-panel summary {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
  user-select: none;
}

.batch-history-panel summary span {
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.batch-history-panel summary strong {
  color: var(--text);
  font-size: 0.92rem;
}

.batch-history-panel[open] summary {
  margin-bottom: 12px;
}

.batch-limit-warning {
  border: 1px solid var(--error);
  border-radius: 14px;
  color: var(--error);
  margin: 0 0 12px;
  padding: 10px 12px;
}

.batch-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: var(--panel-strong);
}

.batch-card strong {
  display: block;
  margin: 4px 0 2px;
}

.batch-card button {
  width: 100%;
  margin-top: 10px;
}

.batch-card-empty {
  padding: 12px 14px;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
}

.modal-panel {
  position: relative;
  width: min(980px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 28px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 14px;
  margin: 20px 0 22px;
}

.tool-card,
.tool-panel-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  background: var(--panel-strong);
}

.tool-card strong {
  display: block;
  margin-top: 8px;
  color: var(--text);
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(240px, 300px);
  gap: 18px;
}

.side-panel {
  display: grid;
  gap: 18px;
  align-content: start;
}

.modal-actions {
  gap: 12px;
}

#editor-lock-hint {
  margin: 2px 0 6px;
}

.media-panel {
  display: grid;
  gap: 14px;
}

.market-panel,
.pipeline-panel {
  display: grid;
  gap: 14px;
}

.media-panel-header {
  display: grid;
  gap: 6px;
}

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

.media-panel-header-actions .compact-actions {
  justify-content: flex-end;
  align-items: center;
}

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

.media-card {
  position: relative;
  min-width: 0;
}

.media-thumb {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--soft-fill);
  aspect-ratio: 1 / 1;
  cursor: zoom-in;
  padding: 0;
  color: inherit;
  width: 100%;
  line-height: 0;
}

.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.media-check {
  position: absolute;
  z-index: 4;
  top: 10px;
  left: 10px;
  width: 20px !important;
  height: 20px;
  padding: 0;
  margin: 0;
  cursor: pointer;
  background: var(--panel-strong);
  border: 1px solid rgba(0, 0, 0, 0.24);
  border-radius: 5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}

.media-label {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  overflow: hidden;
  border-radius: 999px;
  padding: 5px 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.74rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.media-empty {
  border: 1px dashed var(--line);
  border-radius: 18px;
  padding: 18px;
  background: var(--soft-fill);
}

.market-summary {
  display: grid;
  gap: 14px;
}

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

.market-reference-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
}

.market-reference-list a {
  color: var(--text);
  text-decoration: none;
}

.market-reference-list a:hover {
  text-decoration: underline;
}

.pipeline-list {
  display: grid;
  gap: 12px;
}

.pipeline-entry {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: var(--soft-fill);
}

.pipeline-entry-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.pipeline-entry-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.pipeline-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  text-transform: capitalize;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.pipeline-status.completed {
  background: rgba(25, 135, 84, 0.1);
  color: #25714b;
}

.pipeline-status.error {
  background: rgba(173, 49, 35, 0.12);
  color: #8f3025;
}

.pipeline-error {
  margin: 0;
  color: #8f3025;
  font-size: 13px;
  line-height: 1.55;
}

.pipeline-json {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.pipeline-json summary {
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
}

.pipeline-json pre {
  margin: 10px 0 0;
  padding: 14px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.04);
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

body[data-theme="dark"] .pipeline-status.completed {
  background: rgba(66, 184, 131, 0.14);
  color: #91d9b6;
}

body[data-theme="dark"] .pipeline-status.error {
  background: rgba(235, 96, 76, 0.16);
  color: #ffb3a8;
}

body[data-theme="dark"] .pipeline-error {
  color: #ffb3a8;
}

body[data-theme="dark"] .pipeline-json pre {
  background: rgba(255, 255, 255, 0.04);
}

.lightbox {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  z-index: 30;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.lightbox-panel {
  position: relative;
  display: grid;
  gap: 14px;
  justify-items: stretch;
  max-width: min(1100px, calc(100vw - 56px));
  max-height: calc(100vh - 56px);
}

.lightbox-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  justify-self: end;
  width: fit-content;
  padding: 0;
}

.lightbox-actions .ghost-button {
  background: #f8f5f0;
  border-color: rgba(255, 255, 255, 0.65);
  color: #111111;
  font-weight: 700;
}

.lightbox-actions .ghost-button:disabled {
  opacity: 0.45;
}

.lightbox-panel img {
  display: block;
  max-width: min(1100px, calc(100vw - 56px));
  max-height: calc(100vh - 120px);
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  background: #000;
}

@media (max-width: 1280px) {
  .workstation {
    grid-template-columns: minmax(280px, 320px) minmax(520px, 1fr);
  }

  .side-card:last-child {
    grid-column: 1 / -1;
    min-height: auto;
  }
}

@media (max-width: 960px) {
  .workstation,
  .tool-grid,
  .editor-layout {
    grid-template-columns: 1fr;
  }

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