:root {
  --bg: #141414;
  --panel: #1e1e1e;
  --text: #f2f2f2;
  --muted: #9a9a9a;
  --line: #333;
  --accent: #c4a35a;
  --accent-text: #1a1a1a;
  --danger: #c45a5a;
  --row-active: #2f2a1f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, sans-serif;
}

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: #111;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  font-size: 15px;
}

.tabs {
  display: flex;
  gap: 6px;
}

.tab {
  border: 1px solid var(--line);
  background: #222;
  color: var(--muted);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
}

.tab.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.app {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: calc(100vh - 53px);
}

.app[data-mode="batch"] {
  grid-template-columns: minmax(0, 1fr) 420px;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 14px 28px;
  overflow: auto;
}

.panel h1 {
  margin: 0 0 12px;
  font-size: 17px;
}

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

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

.field input,
.field textarea,
.batch-col-tools select {
  width: 100%;
  border: 1px solid var(--line);
  background: #171717;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.batch-col-tools select:focus,
#batch-table select:focus,
#batch-table input:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

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

.check.inline {
  margin: 0;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.actions button,
.batch-toolbar button,
.batch-col-tools button {
  border: 0;
  border-radius: 6px;
  padding: 9px 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}

.actions button.secondary,
.batch-toolbar button.secondary,
.batch-col-tools button.secondary {
  background: #3a3a3a;
  color: var(--text);
}

.actions button:nth-child(3),
.actions button:nth-child(4) {
  grid-column: 1 / -1;
}

.actions button:disabled,
.batch-toolbar button:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* ===== Batch workspace ===== */
.batch-workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #181818;
}

.batch-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #1c1c1c;
}

.batch-toolbar-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.batch-meta-inline {
  font-size: 12px;
  color: var(--muted);
}

.batch-dropzone {
  flex: 1;
  min-height: 0;
  outline: none;
  display: flex;
  flex-direction: column;
}

.batch-dropzone:focus {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.batch-empty {
  margin: auto;
  max-width: 480px;
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  line-height: 1.5;
}

.batch-empty strong {
  display: block;
  color: var(--text);
  font-size: 18px;
  margin-bottom: 10px;
}

.batch-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.batch-table-scroll {
  height: 100%;
  overflow: auto;
}

#batch-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 13px;
}

#batch-table th,
#batch-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid #2a2a2a;
  padding: 0;
  vertical-align: middle;
}

#batch-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #242424;
  min-width: 140px;
}

#batch-table th.idx,
#batch-table td.idx {
  min-width: 44px;
  width: 44px;
  text-align: right;
  color: var(--muted);
  padding: 8px 10px;
  background: #1f1f1f;
  position: sticky;
  left: 0;
  z-index: 3;
}

#batch-table th.idx {
  z-index: 4;
  background: #242424;
}

#batch-table th.th-actions,
#batch-table td.th-actions {
  min-width: 40px;
  width: 40px;
  text-align: center;
  position: sticky;
  right: 0;
  background: #1f1f1f;
  z-index: 3;
}

#batch-table th.th-actions {
  background: #242424;
  z-index: 4;
}

.th-map {
  display: grid;
  gap: 4px;
  padding: 6px 8px;
}

.th-map select {
  width: 100%;
  border: 1px solid var(--line);
  background: #171717;
  color: var(--text);
  border-radius: 4px;
  padding: 6px 8px;
  font: inherit;
}

.th-src {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#batch-table tr.active {
  background: var(--row-active);
}

#batch-table tr.active td.idx,
#batch-table tr.active td.th-actions {
  background: #3a3428;
}

#batch-table input,
#batch-table textarea {
  width: 180px;
  min-width: 150px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  resize: vertical;
  line-height: 1.35;
  display: block;
}

#batch-table textarea {
  min-height: 38px;
  field-sizing: content;
}

#batch-table tr.active input,
#batch-table tr.active textarea {
  background: transparent;
}

#batch-table input:focus,
#batch-table textarea:focus {
  background: #111;
  border-color: var(--accent);
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}

.icon-btn:hover {
  color: var(--danger);
}

.batch-col-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: #1c1c1c;
  font-size: 13px;
  color: var(--muted);
}

.batch-col-tools select {
  width: 180px;
}

/* ===== Preview ===== */
.preview-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #101010;
}

.preview-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.preview-hint {
  font-size: 12px;
  opacity: 0.75;
}

.preview-canvas-wrap {
  flex: 1;
  overflow: auto;
  padding: 12px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

#preview,
.preview-canvas {
  max-width: 100%;
  height: auto;
  background: #222;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  cursor: zoom-in;
}

.preview-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
  overflow: auto;
}

.preview-lightbox.hidden {
  display: none !important;
}

.preview-lightbox canvas {
  max-width: min(96vw, 1100px);
  max-height: 96vh;
  width: auto;
  height: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  background: #222;
  cursor: zoom-out;
}

body.lightbox-open {
  overflow: hidden;
}

@media (max-width: 1100px) {
  .app,
  .app[data-mode="batch"] {
    grid-template-columns: 1fr;
    height: auto;
  }

  .batch-workspace {
    min-height: 50vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-wrap {
    min-height: 50vh;
  }
}
