:root {
  --bs-primary: #5A9A4A;
  --bs-primary-rgb: 90, 154, 74;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: #111111;
  color: #e0e0e0;
  font-family: 'Segoe UI', system-ui, sans-serif;
}

/* ── Top bar ── */
.top-bar {
  background: #1a1a1a;
  border-bottom: 1px solid #2a2a2a;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.top-bar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 600;
  color: #e0e0e0;
}
.top-bar .brand .icon {
  font-size: 1.4rem;
}
.top-bar .footer-text {
  font-size: 0.78rem;
  color: #666;
}

/* ── Main layout ── */
.main-area {
  display: flex;
  flex-direction: row;
  flex: 1 1 0;
  overflow: hidden;
  height: calc(100vh - 57px);
}

/* ── Left sidebar ── */
.sidebar {
  width: 610px;
  min-width: 610px;
  background: #1e1e1e;
  border-right: 1px solid #2a2a2a;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}
.section-header {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #888;
  font-weight: 600;
  margin-bottom: 2px;
}
.sidebar .form-label {
  font-size: 0.82rem;
  color: #bbb;
  margin-bottom: 4px;
}
.sidebar .form-control,
.sidebar .form-select {
  background: #252525;
  border-color: #333;
  color: #e0e0e0;
  font-size: 0.88rem;
}
.sidebar .form-control:focus,
.sidebar .form-select:focus {
  background: #2a2a2a;
  border-color: #5A9A4A;
  color: #e0e0e0;
  box-shadow: 0 0 0 0.2rem rgba(90,154,74,0.25);
}
.entities-table-wrap {
  max-height: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid #333;
  border-radius: 4px;
  background: #252525;
}
.entities-table {
  margin-bottom: 0;
  color: #e0e0e0;
  font-size: 0.78rem;
}
.entities-table thead th {
  position: sticky;
  top: 0;
  background: #202020;
  color: #bcbcbc;
  border-color: #444;
  border-right: 1px solid #444;
  padding: 3px 4px;
  white-space: nowrap;
}
.entities-table thead th .btn-delete-col {
  position: absolute;
  top: 1px;
  right: 2px;
  padding: 0 3px;
  font-size: 0.65rem;
  line-height: 1.4;
  background: transparent;
  border: none;
  color: #ff6b6b;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  cursor: pointer;
}
.entities-table thead th:hover .btn-delete-col {
  opacity: 1;
  pointer-events: auto;
}
.entities-table td {
  border-color: #444;
  border-right: 1px solid #444;
  padding: 0;
  background: #252525;
  vertical-align: middle;
}
.entities-table td.text-center {
  padding: 1px 2px;
}
.entities-table .entity-input {
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none !important;
  color: #e0e0e0;
  font-size: 0.75rem;
  padding: 2px 6px !important;
  height: auto;
  min-width: 0;
  width: 100%;
  outline: none;
}
.entities-table .entity-input:focus {
  background: rgba(90,154,74,0.08);
  border: none;
  box-shadow: none !important;
  outline: none;
}
.entities-table .btn-delete-row {
  padding: 0.12rem 0.35rem;
  line-height: 1;
}

/* ── Buttons ── */
.btn-generate {
  background: #5A9A4A;
  border-color: #5A9A4A;
  color: #fff;
  font-weight: 500;
}
.btn-generate:hover {
  background: #4e8840;
  border-color: #4e8840;
  color: #fff;
}
.btn-generate:focus {
  box-shadow: 0 0 0 0.2rem rgba(90,154,74,0.4);
}
.counter-text {
  font-size: 0.78rem;
  color: #666;
}

/* ── Right preview panel ── */
.preview-panel {
  flex: 1 1 0;
  background: #111111;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}

.template-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  flex-shrink: 0;
}
.template-toolbar .form-label {
  font-size: 0.82rem;
  color: #bbb;
  margin: 0;
  white-space: nowrap;
}
.template-toolbar .form-control,
.template-toolbar .form-select {
  background: #252525;
  border-color: #333;
  color: #e0e0e0;
  font-size: 0.82rem;
}

/* ── Konva stage wrapper ── */
#konva-stage-wrap {
  flex: 1 1 0;
  background: #2a2a2a;
  border-radius: 4px;
  overflow: auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#zoom-spacer {
  flex-shrink: 0;
}
#konva-scale-wrap {
  transform-origin: top left;
  flex-shrink: 0;
}
#konva-container {
  /* Sized dynamically to match label pixel dimensions */
}

#preview-strip {
  display: none;
  flex-direction: row;
  gap: 8px;
  overflow-x: auto;
  padding: 8px;
  background: #1a1a1a;
  border-radius: 4px;
  min-height: 120px;
  align-items: flex-start;
  flex-shrink: 0;
}
.preview-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.preview-thumb img {
  border-radius: 2px;
  border: 1px solid #333;
  height: 150px;
  width: auto;
}
.preview-thumb span {
  font-size: 0.65rem;
  color: #888;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Zoom range slider ── */
#input-zoom {
  accent-color: #5A9A4A;
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
}

/* ── PDF viewer modal overlay ── */
#pdf-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 100000;
  display: none;
  align-items: center;
  justify-content: center;
}
#pdf-modal-backdrop {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
}
#pdf-modal-container {
  position: relative;
  width: 95vw;
  height: 92vh;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}
#pdf-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #2a2a2a;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}
#pdf-modal-header span {
  font-size: 0.9rem;
  font-weight: 600;
  color: #e0e0e0;
}
#pdf-modal-close {
  background: #5A9A4A;
  border: none;
  border-radius: 4px;
  color: #fff;
  font-size: 0.82rem;
  padding: 5px 12px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}
#pdf-modal-close:hover {
  background: #4e8840;
}
#pdf-modal-iframe {
  flex: 1 1 0;
  width: 100%;
  border: none;
  background: #fff;
}

/* ── Presets modal ── */
.presets-modal .modal-content {
  background: #1e1e1e;
  border-color: #333;
}
.presets-modal .modal-header {
  background: #252525;
  border-bottom-color: #333;
}
.presets-modal .modal-footer {
  background: #252525;
  border-top-color: #333;
}
.preset-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: #252525;
  border: 1px solid #333;
  border-radius: 4px;
  margin-bottom: 6px;
}
.preset-item:last-child {
  margin-bottom: 0;
}
.preset-item-info {
  flex: 1;
  min-width: 0;
}
.preset-item-name {
  font-size: 0.88rem;
  color: #e0e0e0;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preset-item-date {
  font-size: 0.72rem;
  color: #888;
  white-space: nowrap;
}
.preset-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.presets-empty {
  padding: 20px;
  text-align: center;
  color: #666;
  font-size: 0.88rem;
}
