
:root {
  --primary-color: #3498db;
  --secondary-color: #2980b9;
  --accent-color: #e74c3c;
  --light-gray: #f4f7f9;
  --dark-gray: #333;
  --medium-gray: #777;
  --border-color: #dfe6e9;
  --border-radius: 8px;
  --box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--light-gray);
  color: var(--dark-gray);
  line-height: 1.6;
}

header {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  padding: 1rem;
  text-align: center;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

header h1 {
    font-size: 1.5rem;
}

main {
  padding: 1.5rem;
}

.app-container {
  display: grid;
  grid-template-columns: minmax(350px, 450px) 1fr;
  gap: 1.5rem;
  max-width: 1800px;
  margin: 0 auto;
  align-items: start;
}

.controls-panel {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  height: calc(100vh - 150px);
  display: flex;
  flex-direction: column;
}

.controls-nav {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
    border-top-left-radius: var(--border-radius);
    border-top-right-radius: var(--border-radius);
}

.nav-link {
    flex: 1;
    padding: 0.85rem 1rem;
    text-decoration: none;
    text-align: center;
    color: var(--medium-gray);
    font-weight: 600;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s, background-color 0.2s;
}

.nav-link:hover {
    background-color: #f8f9fa;
    color: var(--primary-color);
}

.nav-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.controls-content {
  padding: 0 1.5rem 1.5rem 1.5rem;
  overflow-y: auto;
  flex-grow: 1;
}


.preview-container {
  position: sticky;
  top: 1.5rem;
  background: white;
  padding: 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  height: calc(100vh - 150px);
  display: flex;
  flex-direction: column;
}

h2, h3 {
  color: var(--primary-color);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}
h3 {
  margin-top: 1.5rem;
}
.controls-content section:first-child h3 {
  margin-top: 0;
}
h4 {
  color: var(--dark-gray);
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 1rem;
}
.control-section h4:first-of-type {
  margin-top: 0;
}


.control-section {
  margin-bottom: 1.5rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: #555;
  font-size: 0.9rem;
}

input[type="range"],
textarea,
input[type="color"] {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="color"] {
    padding: 0.25rem;
    min-height: 40px;
}


input[type="range"]:focus,
textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
    outline: none;
}

textarea {
  resize: vertical;
  font-family: inherit;
}

.file-upload-label {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    background-color: #f0f0f0;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    margin-bottom: 1rem;
    text-align: center;
    width: 100%;
}
.file-upload-label:hover {
    background-color: #e9e9e9;
}

.font-controls, .size-controls, .logo-controls, .text-controls, .download-controls, .style-controls {
    margin-bottom: 1rem;
}

.checkbox-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    background-color: #fdfdfd;
    padding: 0.75rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}
.checkbox-control label {
    margin-bottom: 0;
    font-weight: normal;
    cursor: pointer;
}
.checkbox-control input[type="checkbox"] {
    width: 1.15em;
    height: 1.15em;
    margin-bottom: 0;
    cursor: pointer;
}


.text-editor-toolbar {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
    background-color: #f9f9f9;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}
.editor-btn {
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    background-color: white;
    color: var(--dark-gray);
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s, border-color 0.2s;
    display:flex;
    align-items:center;
    justify-content:center;
}
.editor-btn:hover {
    background-color: #e9e9e9;
    border-color: #ccc;
}
.separator {
    border-left: 1px solid var(--border-color);
    margin: 0 0.5rem;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 1.5rem;
}
.action-button, .download-button {
    padding: 0.75rem 1rem;
    border: none;
    background-color: var(--secondary-color);
    color: white;
    cursor: pointer;
    border-radius: var(--border-radius);
    transition: background-color 0.3s, transform 0.2s;
    font-weight: 600;
}
.action-button:hover, .download-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.download-button {
    background: linear-gradient(135deg, var(--accent-color), #c0392b);
    grid-column: 1 / -1; /* Span full width */
}


.radio-group {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}
.radio-group label {
    font-weight: normal;
}


.paper-preview-wrapper {
  flex-grow: 1;
  background-color: #e9e9e9;
  padding: 2rem;
  border-radius: var(--border-radius);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
}

.paper-preview {
  /* The border-left is now controlled by JavaScript */
  padding: 0.4in 1in;
  background: white;
  box-shadow: 0 0 20px rgba(0,0,0,0.15);
  overflow: hidden; 
  position: relative;
  display: flex;
  flex-direction: column;
}

.preview-header {
    display: flex;
    align-items: center;
    gap: 20px;
    border-bottom: 2px solid var(--dark-gray);
    padding-bottom: 0.5rem;
    flex-shrink: 0;
}

#preview-logo {
    height: auto;
    object-fit: contain;
}

.preview-header-text {
    font-weight: bold;
    line-height: 1.4;
    white-space: pre-wrap;
}

.preview-body-text {
    flex-grow: 1; /* Key for optional body */
    padding: 1rem 0;
    min-height: 100px;
    white-space: pre-wrap;
}

.preview-footer-text {
    border-top: 1px solid #ccc;
    padding-top: 1rem;
    color: var(--medium-gray);
    flex-shrink: 0;
    white-space: pre-wrap;
    text-align: center;
}

#preview-seals-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Allows clicks to go through to content below */
}

.preview-seal {
    position: absolute;
    cursor: move;
    min-width: 50px;
    min-height: 50px;
    pointer-events: auto; /* Seals are interactive */
}

.preview-seal img {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Important for dragging */
}

.resize-handle, .delete-handle {
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    position: absolute;
    width: 22px;
    height: 22px;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-seal:hover .resize-handle,
.preview-seal:hover .delete-handle {
    opacity: 1;
    pointer-events: auto;
}

.preview-seal.is-rendering .resize-handle,
.preview-seal.is-rendering .delete-handle {
    display: none;
}

.resize-handle {
    background: var(--primary-color);
    right: -11px;
    bottom: -11px;
    cursor: se-resize;
}

.delete-handle {
    background: var(--accent-color);
    color: white;
    font-family: monospace;
    font-weight: bold;
    font-size: 16px;
    line-height: 1;
    right: -11px;
    top: -11px;
    cursor: pointer;
}

footer {
  text-align: center;
  margin-top: 1.5rem;
  padding: 1rem;
  background-color: #e1e5e8;
  color: var(--medium-gray);
}

/* Responsive adjustments */
@media (max-width: 1200px) {
  .app-container {
    grid-template-columns: minmax(320px, 400px) 1fr;
  }
}

@media (max-width: 992px) {
  .app-container {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  .controls-panel, .preview-container {
    height: auto;
    position: static;
  }
  .preview-container {
    min-height: 80vh; 
  }
  .controls-content {
      height: auto;
      max-height: 70vh;
  }
}

@media (max-width: 768px) {
  main {
    padding: 1rem;
  }
  header h1 {
    font-size: 1.3rem;
  }
  .controls-nav {
    flex-wrap: wrap;
  }
  .nav-link {
    flex-basis: 50%;
  }
  .preview-header {
      flex-direction: column;
      text-align: center;
  }
  .paper-preview-wrapper {
      padding: 1rem;
  }
}

@media (max-width: 480px) {
  main {
    padding: 0.5rem;
  }
  h2, h3 {
    font-size: 1.1rem;
  }
  .action-buttons {
    grid-template-columns: 1fr;
  }
  .text-editor-toolbar {
    justify-content: center;
    flex-wrap: wrap;
  }
}
