*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #e5e5e5;
  color: #222;
}

.app-window {
  max-width: 1300px;
  margin: 20px auto;
  background: #f6f6f6;
  border-radius: 6px;
  box-shadow: 0 0 0 1px #d0d0d0, 0 16px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  padding: 10px 16px;
  background: #f0f0f0;
  border-bottom: 1px solid #d0d0d0;
}

.app-header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.app-main {
  display: grid;
  grid-template-columns: 1.1fr 1.1fr 1.2fr;
  gap: 0;
  min-height: 560px;
}

/* Panels */

.panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid #d0d0d0;
}

.panel:last-child {
  border-right: none;
}

.panel-header {
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  background: #f7f7f7;
  border-bottom: 1px solid #d0d0d0;
}

.panel-body {
  padding: 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-scroll {
  overflow-y: auto;
}

.panel-footer {
  padding: 10px 12px;
  border-top: 1px solid #d0d0d0;
  background: #fafafa;
  font-size: 12px;
}

/* Upload / Bildflächen */

.upload-area {
  border: 1px dashed #b0b0b0;
  border-radius: 4px;
  padding: 10px;
  text-align: center;
  background: #ffffff;
}

.file-label {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 4px;
  background: #0078d4;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.file-label input {
  display: none;
}

.hint {
  margin: 6px 0 0;
  font-size: 11px;
  color: #666;
}

.image-frame {
  flex: 1;
  border-radius: 4px;
  background: #fdfdfb;
  border: 1px solid #d0d0d0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.preview-frame {
  background: #f8f8f8;
}

.image-frame img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: none;
}

.image-placeholder {
  font-size: 12px;
  color: #888;
}

/* Footerinfos */

.size-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  align-items: center;
}

.size-row label {
  font-size: 12px;
  margin-right: 4px;
}

.size-row input[type="number"] {
  width: 70px;
  padding: 2px 4px;
  font-size: 12px;
}

.unit {
  font-size: 11px;
  color: #666;
}

.meta-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  color: #555;
}

.meta-row span {
  font-weight: 500;
}

/* Form rechter Bereich */

.form-row {
  margin-bottom: 10px;
  font-size: 12px;
}

.form-row label {
  display: block;
  margin-bottom: 2px;
}

.form-row label input[type="checkbox"] {
  margin-right: 6px;
  cursor: pointer;
}

/* Horizontale Form-Row */
.form-row-horizontal {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.form-row-horizontal .form-item {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.form-row-horizontal .form-item:first-child {
  flex: 0 0 auto;
}

.form-row-horizontal .form-item label {
  margin-bottom: 2px;
}

.form-row-horizontal .form-item input[type="color"] {
  width: 60px;
  height: 32px;
  padding: 2px;
  cursor: pointer;
}

.form-row select,
.form-row input[type="number"],
.form-row input[type="text"] {
  width: 100%;
  padding: 4px 6px;
  font-size: 12px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.slider-row input[type="range"] {
  flex: 1;
}

.slider-value {
  width: 32px;
  text-align: right;
  font-size: 11px;
}

/* Buttons */

.primary-btn,
.secondary-btn {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
}

.primary-btn {
  background: #0078d4;
  color: #fff;
  border-color: #0078d4;
  margin-bottom: 6px;
}

.primary-btn:hover {
  background: #005ea6;
}

/* Update Button - Volle Breite im Panel-Footer */
.panel-footer .primary-btn,
#updateImageBtn {
  width: 100%;
  display: block;
}

.secondary-btn {
  background: #f3f3f3;
  border-color: #c0c0c0;
  color: #333;
}

.secondary-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Update Size Button nach rechts ausrichten */
.panel-footer {
  position: relative;
}

#updateSizeBtn {
  float: right;
  clear: both;
  margin-bottom: 6px;
}

/* Loading Animation */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(2px);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e0e0e0;
  border-top: 4px solid #0078d4;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  margin-top: 12px;
  font-size: 13px;
  color: #555;
  font-weight: 500;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.3s ease-out;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8f8f8;
  border-radius: 8px 8px 0 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #d32f2f;
}

.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: #666;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.modal-close:hover {
  background-color: #e0e0e0;
  color: #333;
}

.modal-body {
  padding: 24px 20px;
  flex: 1;
  overflow-y: auto;
  text-align: center;
}

.error-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.modal-body p {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: #333;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  justify-content: flex-end;
  background: #fafafa;
  border-radius: 0 0 8px 8px;
}

.modal-footer .primary-btn {
  margin: 0;
  min-width: 80px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Responsive */

@media (max-width: 1024px) {
  .app-main {
    grid-template-columns: 1fr;
  }

  .panel {
    border-right: none;
    border-bottom: 1px solid #d0d0d0;
  }

  .panel:last-child {
    border-bottom: none;
  }
  
  .modal-content {
    width: 95%;
    max-width: none;
  }
}
