/* Liberation Sans Bold - matches server-side rendering font */
@font-face {
  font-family: 'Liberation Sans';
  src: url('/fonts/LiberationSans-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: block; /* Block rendering until font loads for WYSIWYG */
}

/* Arial Black - display font option */
@font-face {
  font-family: 'Arial Black';
  src: url('/fonts/ArialBlack.ttf') format('truetype');
  font-weight: 900;
  font-style: normal;
  font-display: block;
}

/* Pacifico - cursive font option */
@font-face {
  font-family: 'Pacifico';
  src: url('/fonts/Pacifico-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

/* Dancing Script Bold - cursive font option */
@font-face {
  font-family: 'Dancing Script';
  src: url('/fonts/DancingScript-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: block;
}

:root {
  color-scheme: light;
  --bg: #f7f3ea;
  --bg-accent: #f1e2c8;
  --panel: #ffffff;
  --ink: #1c1a16;
  --muted: #5c5348;
  --line: #e2d6c2;
  --primary: #1f7a6a;
  --primary-dark: #155748;
  --shadow: 0 18px 40px rgba(31, 24, 18, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 50%),
    radial-gradient(circle at 20% 20%, var(--bg-accent), transparent 40%),
    var(--bg);
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 28px 48px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 420px;
}

.status {
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(31, 122, 106, 0.1);
  color: var(--primary-dark);
  font-weight: 600;
  font-size: 14px;
}

.main {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
  align-items: start;
}

.preview {
  min-width: 0;
  overflow-x: auto;
}

.canvas-wrapper {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  /* Explicitly set height to contain the scaled canvas */
  height: calc(898px * 0.65);  /* 584px */
  position: relative;
  overflow: visible;  /* Allow transformer handles to extend outside if needed */
}

#canvas-container {
  width: 899px;
  height: 898px;
  transform: scale(0.65);
  transform-origin: top left;
  /* Remove negative margin that was causing overlap */
  position: absolute;
  top: 0;
  left: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header h2 {
  margin: 0;
  font-size: 20px;
}

.panel-header p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.canvas {
  width: 100%;
  aspect-ratio: 899 / 898;
  border-radius: 18px;
  border: 1px solid var(--line);
  overflow: visible;  /* Changed from hidden - allow transformer handles to show */
  background: #f4f2ee;
}

.hint {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.field input,
.field select {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
}

.field input:focus,
.field select:focus {
  outline: 2px solid rgba(31, 122, 106, 0.2);
  border-color: var(--primary);
}

fieldset.field {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px 14px;
}

fieldset.field legend {
  padding: 0 8px;
  font-size: 12px;
  color: var(--muted);
}

.radio-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 14px;
  color: var(--ink);
}

/* Modifier for radio groups that read better as a fixed 2-up grid than as a
   wrapping row. Scoped on purpose: .radio-group alone is shared with
   Alignment and others, which must stay a single wrapping row. */
.radio-group.radio-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  color: var(--ink);
}

.version-picker {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
}

.version-picker h4 {
  margin: 0 0 8px;
  font-size: 14px;
}

.version-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 150px;
  overflow-y: auto;
}

.version-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.version-item:hover {
  border-color: var(--primary);
}

.version-item.active {
  border-color: var(--primary);
  background: rgba(31, 122, 106, 0.1);
}

.version-item .date {
  color: var(--muted);
  font-size: 12px;
}

.primary {
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  background: var(--primary);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  transition: transform 0.2s ease, background 0.2s ease;
}

.primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.secondary {
  margin-top: 8px;
  align-self: flex-start;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f7f5f2;
  cursor: pointer;
  font-size: 13px;
}

.results {
  margin-top: 16px;
  padding: 14px;
  border-radius: 16px;
  background: #f6f4ef;
  border: 1px dashed var(--line);
  font-size: 13px;
  color: var(--muted);
  min-height: 64px;
}

.results a {
  color: var(--primary-dark);
  font-weight: 600;
  text-decoration: none;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: spin 1s linear infinite;
  display: none;
}

.loading .spinner {
  display: inline-block;
}

.loading span:first-child {
  opacity: 0.8;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

  .header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Text nudge controls */
.nudge-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nudge-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nudge-btn:hover {
  background: var(--bg-accent);
}

.nudge-btn-small {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  cursor: pointer;
  font-size: 12px;
  margin-left: 8px;
}

.nudge-btn-small:hover {
  background: var(--bg-accent);
}

#nudgeValue {
  min-width: 30px;
  text-align: center;
  font-weight: 500;
}

/* Text size controls */
.text-size-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-btn {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.action-btn:hover {
  background: var(--bg-accent);
}

/* Layer controls */
.layer-controls {
  display: flex;
  gap: 8px;
}

/* Color overlay controls */
.color-overlay-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#overlayColorPicker {
  width: 40px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

#overlayColorHex {
  width: 80px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: monospace;
  text-transform: uppercase;
}

/* Layer Selector */
.layers-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s ease;
}

.layer-item:hover {
  background: var(--subtle);
}

.layer-item.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.layer-item.empty {
  color: var(--muted);
  cursor: default;
  font-style: italic;
}

.layer-item .layer-icon {
  font-size: 16px;
}

.layer-item .layer-name {
  flex: 1;
}

.layer-item .layer-controls {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.layer-item:hover .layer-controls {
  opacity: 1;
}

.layer-item .layer-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  font-size: 14px;
  border-radius: 4px;
  transition: background 0.2s;
}

.layer-item .layer-btn:hover {
  background: rgba(0,0,0,0.1);
}

.layer-item .delete-btn:hover {
  background: rgba(220, 38, 38, 0.2);
}

.layer-item.hidden-layer {
  opacity: 0.5;
}

.layer-item.hidden-layer .layer-name {
  text-decoration: line-through;
}

.layer-buttons {
  display: flex;
  gap: 8px;
}

/* ============================================
   SEND TO CUSTOMER SECTION
   ============================================ */

.send-to-customer-section {
  margin-top: 24px;
  padding: 20px;
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
  border: 2px solid #86efac;
  border-radius: 16px;
}

.send-to-customer-section h3 {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--ink);
}

.send-to-customer-section .hint {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--muted);
}

.send-to-customer-section .field {
  margin-bottom: 12px;
}

.send-to-customer-section select,
.send-to-customer-section textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
}

.send-to-customer-section textarea {
  resize: vertical;
  min-height: 80px;
}

.send-to-customer-section select:focus,
.send-to-customer-section textarea:focus {
  outline: 2px solid rgba(31, 122, 106, 0.2);
  border-color: var(--primary);
}

.customer-info {
  margin-bottom: 16px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  font-size: 14px;
}

.customer-info .customer-name {
  color: var(--muted);
}

.customer-info .customer-name strong {
  color: var(--ink);
}

.send-btn {
  width: 100%;
  background: #059669;
}

.send-btn:hover {
  background: #047857;
}

.send-btn:disabled {
  background: #9ca3af;
}

.send-result {
  margin-top: 12px;
  font-size: 14px;
}

.send-result .success {
  color: #059669;
  font-weight: 600;
}

.send-result .error {
  color: #dc2626;
  font-weight: 600;
}

.send-result .hint {
  margin-top: 4px;
  font-size: 12px;
}

/* Helpdesk widget */
.helpdesk-toggle {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  background: #1f7a6a;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0,0,0,0.18);
}

.helpdesk-panel {
  position: fixed;
  right: 20px;
  bottom: 70px;
  width: 320px;
  max-width: calc(100vw - 24px);
  z-index: 1000;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 16px 36px rgba(0,0,0,0.18);
  padding: 12px;
}

.helpdesk-panel h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.helpdesk-panel textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  font-family: inherit;
  font-size: 13px;
}

.helpdesk-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.helpdesk-actions .primary,
.helpdesk-actions .secondary {
  flex: 1;
}

/* ============================================
   FOLDER BROWSER DRAWER
   ============================================ */

#supabase-browser {
  position: fixed;
  top: 80px;
  right: -350px;
  width: 320px;
  height: calc(100vh - 80px);
  background: var(--panel);
  border-left: 2px solid var(--line);
  box-shadow: -4px 0 16px rgba(31, 24, 18, 0.12);
  transition: right 0.3s ease;
  z-index: 100;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#supabase-browser.open {
  right: 0;
}

.drawer-header {
  padding: 16px;
  border-bottom: 2px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.drawer-header div {
  display: flex;
  gap: 8px;
}

.drawer-header button {
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
}

.drawer-header button:hover {
  background: var(--bg-accent);
  border-color: var(--primary);
}

.drawer-status {
  padding: 12px 16px;
  background: var(--bg-accent);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}

.file-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.file-item {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  background: var(--panel);
  border: 2px solid var(--line);
  transition: all 0.2s;
}

.file-item:hover {
  background: var(--bg-accent);
  border-color: var(--primary);
}

.file-item.loaded {
  background: rgba(31, 122, 106, 0.1);
  border-color: var(--primary);
}

.file-item.corrupted {
  background: rgba(255, 150, 0, 0.1);
  border-color: #ff9600;
  opacity: 0.6;
}

.file-thumbnail {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--bg);
}

.file-thumbnail.error {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 11px;
}

.file-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 0;  /* Prevent long filenames from overflowing grid cell */
  overflow: hidden;
}

.file-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-date,
.file-size {
  font-size: 11px;
  color: var(--muted);
}

.file-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}

.add-btn,
.remove-btn {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
}

.add-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.remove-btn:hover {
  background: #c23e3e;
  border-color: #c23e3e;
  color: white;
}

.add-btn:disabled,
.remove-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.empty-state {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

#folder-browser-toggle {
  margin-bottom: 12px;
}
