* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: repeating-conic-gradient(#f0f0f0 0% 25%, #fff 0% 50%) 50% / 20px 20px;
  color: #333;
  min-height: 100vh;
}

.app-container {
  display: flex;
  flex-direction: row-reverse;
  min-height: 100vh;
  align-items: flex-start;
}

/* Controls Panel */
.controls-panel {
  width: 320px;
  padding: 20px;
  background: #EFEFEF;
  border: 2px solid #4A7C2F;
  border-radius: 16px;
  overflow-y: auto;
  flex-shrink: 0;
  margin: 20px;
  position: sticky;
  top: 20px;
  height: fit-content;
  max-height: calc(100vh - 40px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.controls-panel h1 {
  font-size: 22px;
  color: #00205B;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid #c8c8c8;
}

/* Form Controls */
.control-group {
  margin-bottom: 14px;
}

.control-group label {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: #00205B;
  letter-spacing: 0.1px;
  margin-bottom: 6px;
}

.control-group input[type="text"],
.control-group select,
.control-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #b9b9b9;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s;
  background: #fff;
  font-family: inherit;
}

.control-group textarea {
  resize: none;
  height: 3.5em;
  overflow-y: auto;
  line-height: 1.2;
  padding: 6px 10px;
}

.control-group input[type="text"]:focus,
.control-group select:focus,
.control-group textarea:focus {
  outline: none;
  border-color: #4A7C2F;
  box-shadow: 0 0 0 2px rgba(74, 124, 47, 0.3);
}

.control-group input[type="text"]:disabled,
.control-group textarea:disabled {
  background: #e9ecef;
  color: #6c757d;
}

.control-group input[type="color"] {
  width: 100%;
  height: 40px;
  border: 1px solid #b9b9b9;
  border-radius: 8px;
  cursor: pointer;
  padding: 4px;
  background: #fff;
}

.control-group input[type="range"] {
  width: 100%;
  margin-top: 4px;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  background: #FFB81C;
  border-radius: 4px;
  outline: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: #FFB81C;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.control-group input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: #FFB81C;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.scale-ppi {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
  text-align: right;
}

/* Colour preset swatches (guidelines-approved combos) */
.swatch-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.swatch {
  -webkit-appearance: none;
  appearance: none;
  width: 32px;
  height: 32px;
  border: 2px solid #4A7C2F;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  background-clip: border-box;
  background-repeat: no-repeat !important;
  background-size: 100% 100% !important;
  box-shadow: none;
}

.swatch:hover {
  border-color: #00205B;
}

.contrast-warning {
  font-size: 12px;
  color: #9B1C1C;
  margin-top: 8px;
  line-height: 1.4;
}

.control-row {
  display: flex;
  gap: 12px;
}

.control-row .control-group {
  flex: 1;
}

/* Checkboxes */
.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #FFB81C;
}

.checkbox-group label {
  font-size: 14px;
  color: #00205B;
  text-transform: none;
  margin: 0;
}

/* File Upload */
.file-input-wrapper {
  position: relative;
  flex: 1;
}

.file-input-wrapper input[type="file"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  z-index: 1;
}

.file-input-wrapper:hover .btn-primary {
  background: #fff;
  border: 2px solid #4A7C2F;
}

/* Fill the wrapper so paired buttons (e.g. Export/Import JSON) stay equal */
.file-input-wrapper .btn {
  width: 100%;
}

/* Buttons */
.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  white-space: nowrap;
}

.btn:hover { opacity: 0.9; }

.btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.btn-primary:hover,
.btn-secondary:hover {
  background: #fff;
  border: 2px solid #4A7C2F;
  opacity: 1;
}

.btn-primary {
  background: #4A7C2F;
  color: #FFB81C;
  border: 2px solid #4A7C2F;
}

.btn-secondary {
  background: #4A7C2F;
  color: #FFB81C;
  border: 2px solid #4A7C2F;
}

.btn-outline {
  background: #fff;
  border: 2px solid #4A7C2F;
  color: #00205B;
}

.btn-outline:hover {
  color: #FFB81C;
  opacity: 1;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-group .btn {
  flex: 1;
  min-width: 80px;
}

/* Drawer (Library & Typography) */
.drawer {
  margin-bottom: 14px;
  border: 1px solid #c8c8c8;
  border-radius: 8px;
  background: #fff;
}

.drawer summary {
  cursor: pointer;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  color: #00205B;
  letter-spacing: 0.1px;
}

.drawer-section {
  padding: 12px;
  border-top: 1px solid #ddd;
}

.drawer-section > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #00205B;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.drawer .control-group {
  margin-bottom: 12px;
}

.drawer .control-group:last-child {
  margin-bottom: 0;
}

.drawer .sub-label {
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  margin-top: 12px;
}

.typography-section {
  padding-top: 14px;
  border-top: 1px solid #ddd;
}

.export-block {
  position: sticky;
  bottom: -20px;
  z-index: 2;
  margin: 0 -20px 14px;
  padding: 14px 20px;
  background: #efefef;
  border-top: 1px solid #c8c8c8;
  border-bottom: 1px solid #c8c8c8;
}

.export-primary-actions { flex-wrap: nowrap; }

.export-primary-actions .btn { min-width: 0; }

.export-more { margin-top: 8px; }

.export-more summary {
  cursor: pointer;
  color: #53606f;
  font-size: 12px;
  text-align: center;
}

.export-more .btn-group { margin-top: 10px; }

.preset-name {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 2px solid #4A7C2F;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}

.preset-list {
  list-style: none;
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}

.preset-list li {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.preset-list .preset-load {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 6px 10px;
  border: 2px solid #4A7C2F;
  border-radius: 8px;
  background: #fff;
  color: #00205B;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-list .preset-load:hover {
  background: #4A7C2F;
  color: #FFB81C;
}

.preset-list .preset-delete {
  border: 2px solid #4A7C2F;
  border-radius: 8px;
  background: #fff;
  color: #00205B;
  font-size: 12px;
  padding: 0 8px;
  cursor: pointer;
}

.preset-list .preset-delete:hover {
  background: #00205B;
  color: #fff;
  border-color: #00205B;
}

.preset-empty {
  font-size: 12px;
  color: #888;
}

.btn-group-spaced {
  margin-top: 8px;
}

/* Preview Area */
.preview-area {
  flex: 1;
  align-self: stretch;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  overflow: auto;
}


.preview-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#previewImage {
  max-width: 100%;
  max-height: calc(100vh - 160px);
  height: auto;
  object-fit: contain;
  cursor: pointer;
}

.preview-hint {
  font-size: 12px;
  color: #888;
  margin: 0;
}

.footer-note {
  position: absolute;
  bottom: 14px;
  left: 24px;
  right: 24px;
  font-size: 11px;
  color: #888;
  margin-top: 16px;
  text-align: center;
  line-height: 1.4;
}

.footer-note a {
  color: #4A7C2F;
}

/* Utilities */
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 800px) {
  .app-container {
    flex-direction: column-reverse;
    align-items: stretch;
    min-height: auto;
  }

  .controls-panel {
    width: auto;
    max-height: none;
    margin: 10px;
    padding: 16px;
    position: static;
  }

  .preview-area {
    min-height: 250px;
    padding: 10px;
  }
}
