:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark light;
  --bg: #0b1020;
  --panel: #151a2a;
  --accent: #8b5cf6;
  --accent-soft: rgba(139, 92, 246, 0.1);
  --border: #252b3f;
  --text: #e5e7eb;
  --muted: #9ca3af;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 16px;
  background: radial-gradient(circle at top, #1f2937 0, #020617 55%);
  color: var(--text);
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

.app {
  max-width: 1120px;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 16px;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.92));
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  box-shadow:
    0 20px 40px rgba(15, 23, 42, 0.75),
    0 0 0 1px rgba(15, 23, 42, 0.6);
  padding: 16px 18px 18px;
  backdrop-filter: blur(18px);
}

.panel h1 {
  margin: 0 0 8px;
  font-size: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(139, 92, 246, 0.5);
  background: radial-gradient(circle at top left, rgba(79, 70, 229, 0.45), rgba(15, 23, 42, 0.7));
  color: #e5e7eb;
}

.panel p {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (max-width: 700px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.field label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
}

.field small {
  font-size: 11px;
  color: #6b7280;
}

input[type="text"],
input[type="number"],
select,
textarea {
  background: radial-gradient(circle at top, #020617, #020617);
  border-radius: 10px;
  border: 1px solid rgba(55, 65, 81, 0.8);
  padding: 7px 9px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  width: 100%;
  font-family: inherit;
}

textarea {
  resize: vertical;
  min-height: 60px;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.55);
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.color-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: radial-gradient(circle at top, #020617, #020617);
  border-radius: 10px;
  border: 1px solid rgba(55, 65, 81, 0.8);
  padding-right: 7px;
}
.color-input-wrapper input[type="text"] {
  border: none;
  padding: 7px 9px;
}
.checkbox-row,
.radio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.checkbox-row input,
.radio-row input {
  accent-color: var(--accent);
}

.file-input {
  font-size: 12px;
  color: var(--muted);
}

.buttons-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

button {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: radial-gradient(circle at top left, rgba(79, 70, 229, 0.9), rgba(15, 23, 42, 0.96));
  color: #f9fafb;
  font-size: 13px;
  padding: 7px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}

button.secondary {
  background: radial-gradient(circle at top left, rgba(30, 64, 175, 0.85), rgba(15, 23, 42, 0.96));
}

button.ghost {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
}

button.danger {
  background: transparent;
  border-color: rgba(248, 113, 113, 0.7);
  color: #fecaca;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button span.icon {
  font-size: 14px;
}

.qr-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.qr-frame {
  padding: 16px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background:
    radial-gradient(circle at top, rgba(31, 41, 55, 0.7), rgba(15, 23, 42, 0.9)),
    repeating-conic-gradient(from 45deg, rgba(15, 23, 42, 0.8) 0deg 30deg, rgba(22, 31, 55, 0.9) 30deg 60deg);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.75),
    inset 0 0 0 1px rgba(148, 163, 184, 0.15);
  display: inline-flex;
  max-width: 100%;
}

canvas {
  background: transparent;
  border-radius: 8px;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  max-width: 100%;
  height: auto;
  display: block;
}

.hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.export-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  max-width: 380px;
}

.export-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.export-row label {
  font-size: 12px;
  color: var(--muted);
}

.pill {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: var(--muted);
}

.status {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  min-height: 14px;
}

.status.ok {
  color: #4ade80;
}

.status.err {
  color: #f97373;
}

.bulk-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 4px;
}

.bulk-table th,
.bulk-table td {
  border-bottom: 1px solid rgba(75, 85, 99, 0.7);
  padding: 4px 6px;
  text-align: left;
  vertical-align: middle;
}

.bulk-table th {
  font-weight: 500;
  color: var(--muted);
}

.bulk-table td.actions {
  width: 1%;
  white-space: nowrap;
}

.bulk-subgrid {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(320px, 1.6fr);
  gap: 10px;
  margin-bottom: 10px;
}

@media (max-width: 900px) {
  .bulk-subgrid-legacy { /* Renamed old class to avoid conflict */
    grid-template-columns: 1fr;
  }
}

.bulk-main-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  margin-top: 12px;
}

@media (max-width: 900px) {
  .bulk-main-layout {
    grid-template-columns: 1fr;
  }
  .bulk-settings {
    order: 1;
  }
  .bulk-actions-preview {
    order: 2; /* Move actions and preview to the bottom on mobile */
  }
}

.bulk-actions-preview .buttons-row {
  flex-direction: column;
  align-items: stretch;
}

.bulk-preview-wrapper {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.bulk-preview-wrapper span {
  font-size: 11px;
  color: var(--muted);
}

/* --- PANEL FOR TEXT / IMAGE OPTIONS --- */
.text-options-panel {
   border-left: 2px solid var(--border);
   padding-left: 10px;
   margin: 8px 0 8px 4px;
}

/* --- Segmented Control --- */
.segmented-control {
  display: flex;
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(55, 65, 81, 0.8);
  overflow: hidden;
  background: radial-gradient(circle at top, #020617, #020617);
  padding: 2px;
}

.segmented-control input[type="radio"] {
  display: none;
}

.segmented-control label {
  flex: 1;
  text-align: center;
  padding: 5px 8px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  border-radius: 8px;
  white-space: nowrap;
}

.segmented-control label:hover {
  background-color: rgba(55, 65, 81, 0.5);
}

.segmented-control input[type="radio"]:checked + label {
  background: var(--accent-soft);
  border: 1px solid rgba(139, 92, 246, 0.3);
  color: var(--text);
  font-weight: 500;
}

.backdrop-settings-container {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 12px;
  align-items: start;
  background: rgba(15, 23, 42, 0.3);
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.1);
  height: 100%; /* Make it fill the grid cell height */
  align-content: start;
}

@media (max-width: 600px) {
  .backdrop-settings-container {
    grid-template-columns: 1fr;
  }
}

.backdrop-preview-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
}

.backdrop-preview-canvas {
  width: 100%;
  height: auto;
  border: 1px dashed rgba(148, 163, 184, 0.3);
  border-radius: 8px;
  background-color: #fff; /* White bg to see transparency */
  background-image: linear-gradient(45deg, #ccc 25%, transparent 25%), 
                    linear-gradient(-45deg, #ccc 25%, transparent 25%), 
                    linear-gradient(45deg, transparent 75%, #ccc 75%), 
                    linear-gradient(-45deg, transparent 75%, #ccc 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
}
.backdrop-preview-canvas.clickable:hover {
  cursor: pointer;
  border-color: var(--accent);
}

.backdrop-controls-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.backdrop-controls-area .grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

select option {
  background-color: #020617; 
  color: #ffffff;            
}

select option:disabled {
  color: #6b7280;           
}

/* --- From index.html --- */
.margin-grid {
  display: grid;
  grid-template-areas: ". top ." "left center right" ". bottom .";
  gap: 4px;
  justify-items: center;
  align-items: center;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.margin-grid > input {
  width: 50px !important;
  text-align: center;
}
.margin-grid > .margin-grid-label {
  grid-area: center;
  font-size: 12px;
  color: var(--muted);
}
#pageMarginTopInput { grid-area: top; }
#pageMarginLeftInput { grid-area: left; }
#pageMarginRightInput { grid-area: right; }
#pageMarginBottomInput { grid-area: bottom; }
.page-settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: end; }

/* --- Slider with Number Input --- */
.slider-input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.slider-input-group input[type="range"] {
  flex-grow: 1;
}
.slider-input-group .slider-input-number {
  width: 60px;
}