/* Font Declarations */
@font-face {
  font-family: 'InstacartContrastHeadline';
  src: url('fonts/Instacart_Contrast_Headline-SemiBold.otf') format('opentype');
}

@font-face {
  font-family: 'InstacartContrastHeadlineBold';
  src: url('fonts/Instacart_Contrast_Subhead-Bold.ttf') format('truetype');
}

@font-face {
  font-family: 'InstacartContrastHeadlineExtraBold';
  src: url('fonts/Instacart_Contrast_Subhead-ExtraBold.ttf') format('truetype');
}

@font-face {
  font-family: 'InstacartContrastTextBold';
  src: url('fonts/Instacart_Contrast_Text-ExtraBold.otf') format('opentype');
}

@font-face {
  font-family: 'InstacartSansHeadlineRegular';
  src: url('fonts/Instacart_Sans_Headline-Regular.ttf') format('truetype');
}

@font-face {
  font-family: 'InstacartSansHeadlineSemiBold';
  src: url('fonts/Instacart_Sans_Headline-SemiBold.ttf') format('truetype');
}

@font-face {
  font-family: 'InstacartSansTextRegularItalic';
  src: url('fonts/Instacart_Sans_Text-Regular_Italic.ttf') format('truetype');
}

@font-face {
  font-family: 'BaguetScriptRegular';
  src: url('fonts/Melvastype - Baguet Script Regular.otf') format('opentype');
}

@font-face {
  font-family: 'InstacartSansTextRegular';
  src: url('fonts/Instacart_Sans_Text-Regular.ttf') format('truetype');
}

/* Base Styles */
:root {
  --primary-color: #0AAD0A;
  --primary-hover: #088A08;
  --background-light: #003D29; /* Dark green background */
  --background-dark: #222;
  --text-light: #000000; /* Black text for good contrast on cashew container */
  --text-dark: #eee;
  --border-light: #ddd;
  --border-dark: #555;
  --card-bg-light: #FAF1E5; /* Cashew colored container */
  --card-bg-dark: #333;
  --input-bg-light: #fff; /* New variable for input backgrounds */
}

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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

/* Static background image for both light and dark modes */
body {
  background-color: #ffffff; /* Fallback color */
  background-image: url('produce-green.jpg');
  background-size: cover;
  background-position: center center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  transition: color 0.3s ease;
}

/* Dark mode styling with overlay for darker appearance but same background image */
body.dark-mode {
  color: var(--text-dark);
  position: relative;
}

/* Add a semi-transparent overlay in dark mode for a darker feel */
body.dark-mode::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black overlay */
  z-index: -1;
  pointer-events: none;
}

/* Add additional dark mode contrast improvements */
body.dark-mode .container {
  background-color: rgba(0, 0, 0, 0.6); /* Semi-transparent container for better readability */
  border-radius: 10px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

/* Ensure text remains readable in both modes */
body.dark-mode .rich-text-editor {
  background-color: rgba(10, 10, 10, 0.2);
  border-color: #555;
  /* No color override to preserve text colors */
}

/* Make the preview transparent in dark mode */
body.dark-mode .preview {
  background-color: transparent;
  border-color: rgba(255, 255, 255, 0.2);
  /* No color override to preserve text colors */
}

/* Ensure preview text is fully transparent without changing text color */
body.dark-mode #textPreview {
  background-color: transparent;
  /* No color override to preserve text colors */
}

/* CRITICAL - STRONGER rules to force text colors in dark mode */
body.dark-mode span[style*="color"],
body.dark-mode font[color],
body.dark-mode .rich-text-editor span[style*="color"],
body.dark-mode .rich-text-editor font[color],
body.dark-mode .preview span[style*="color"],
body.dark-mode .preview font[color],
body.dark-mode #textPreview span[style*="color"],
body.dark-mode #textPreview font[color] {
  color: inherit !important;
}

/* Override any text styling that might be coming from parent elements */
body.dark-mode .rich-text-editor,
body.dark-mode #textPreview {
  color: initial !important;
}

/* Force black for text with no explicit color in dark mode */
body.dark-mode .rich-text-editor:not([style*="color"]),
body.dark-mode #textPreview:not([style*="color"]) {
  color: #000000 !important;
}

/* Reset any default text color */
.rich-text-editor {
  color: initial;
}

#textPreview {
  color: initial;
}

/* Editor Label styling (for "Write text below") */
.editor-label {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-light);
}

/* Make dark mode color changes to UI elements only */
body.dark-mode .editor-label {
  color: var(--text-dark);
}

/* Make direct color changes to text elements */
h1, label, .preview-label, .toggle-label, #letterSpacingValue {
  color: var(--text-light);
}

/* Make sure all inputs and interactive elements have white backgrounds */
select, input[type="number"], .rich-text-editor, .preview, .custom-fonts-list, .format-btn {
  background-color: var(--input-bg-light);
}

.container {
  max-width: 800px;
  background-color: var(--card-bg-light);
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: background-color 0.3s, box-shadow 0.3s;
  
  /* Center the container vertically and horizontally */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  
  /* Handle overflow better */
  max-height: 95vh;
  overflow-y: auto;
}

/* Scrollbar styling for better appearance */
.container::-webkit-scrollbar {
  width: 8px;
}

.container::-webkit-scrollbar-track {
  background: transparent;
}

.container::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

body.dark-mode .container::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.2);
}

/* Header and Utility Controls */
.header-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.utility-buttons {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-left: auto; /* This pushes the utility buttons to the right */
}

.logout-btn {
  padding: 8px 16px;
  background-color: #666;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.2s;
}

.logout-btn:hover {
  background-color: #555;
}

h1 {
  text-align: center;
  margin-bottom: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-light);
}

.controls {
  display: flex;
  gap: 15px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 150px;
}

label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-light);
}

select, input[type="number"] {
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  font-family: inherit;
  font-size: 14px;
  background-color: var(--input-bg-light); /* Changed to use new variable */
  color: var(--text-light);
  width: 100%;
  transition: border-color 0.2s;
}

select:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-color);
}

.range-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  background: #ddd;
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
}

#letterSpacingValue {
  font-size: 14px;
  color: var(--text-light);
  min-width: 40px;
}

input[type="color"] {
  -webkit-appearance: none;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 4px;
  background: none;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--border-light);
  border-radius: 4px;
}

.color-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 5px;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s;
  margin-bottom: 4px;
  position: relative; /* Added for tooltip positioning */
}

/* Special outline for the Cashew color swatch */
.color-swatch[data-color="#FAF1E5"] {
  border: 1px solid #ccc;
}

.color-swatch:hover {
  transform: scale(1.15);
}

/* Color swatch tooltip */
.color-swatch::after {
  content: attr(title);
  position: absolute;
  top: -30px; /* Changed from bottom to top */
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 100; /* Increased z-index significantly */
  pointer-events: none; /* Ensures hover doesn't get interrupted */
}

.color-swatch:hover::after {
  opacity: 1;
  visibility: visible;
}

.color-swatch.active {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.format-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  padding: 15px;
  background-color: #f9f9f9;
  border-radius: 8px;
  align-items: center;
  transition: background-color 0.3s;
}

.format-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  background-color: var(--input-bg-light); /* Changed to use new variable */
  border: 1px solid var(--border-light);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.format-btn.active {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.align-controls {
  display: flex;
  gap: 5px;
  margin-left: auto;
}

.input-area {
  margin-bottom: 20px;
}

.rich-text-editor {
  width: 100%;
  min-height: 100px;
  padding: 16px;
  font-size: 16px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  outline: none;
  overflow-y: auto;
  transition: border-color 0.2s;
  background-color: var(--input-bg-light); /* Changed to use new variable */
}

.rich-text-editor:focus {
  border-color: var(--primary-color);
}

.rich-text-editor[placeholder]:empty:before {
  content: attr(placeholder);
  color: #999;
}

.editor-instructions {
  margin-top: 8px;
  font-size: 12px;
  color: #666;
  text-align: center;
  font-style: italic;
}

.preview-section {
  margin-bottom: 20px;
}

.preview-label {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-light);
}

.preview {
  border: 1px solid var(--border-light);
  padding: 30px;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--input-bg-light); /* Changed to use new variable */
  margin-bottom: 20px;
  border-radius: 6px;
  transition: background-color 0.3s, border-color 0.3s;
}

#textPreview {
  width: 100%;
  text-align: center;
  overflow-wrap: break-word;
  /* Default styling - will be overridden by JS */
  font-size: 36px;
  font-family: 'InstacartContrastHeadline';
}

.action-buttons {
  display: flex;
  justify-content: center;
}

#downloadBtn {
  padding: 10px 24px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: background-color 0.2s;
}

#downloadBtn:hover {
  background-color: var(--primary-hover);
}

#resetBtn {
  padding: 8px 16px;
  background-color: #666;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  margin-right: 5px;
  transition: background-color 0.2s;
}

#resetBtn:hover {
  background-color: #555;
}

/* Custom Font Upload Styles */
.custom-font-section {
  margin-top: 10px;
}

.secondary-btn {
  padding: 8px 16px;
  background-color: #666;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.2s;
}

.secondary-btn:hover {
  background-color: #555;
}

.custom-fonts-list {
  max-height: 100px;
  overflow-y: auto;
  margin-top: 8px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background-color: var(--input-bg-light); /* Changed to use new variable */
}

.custom-font-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background-color: #f9f9f9;
  border-bottom: 1px solid var(--border-light);
}

.custom-font-item:last-child {
  border-bottom: none;
}

.custom-font-name {
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 8px;
  font-size: 13px;
}

.use-font-btn {
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
}

.use-font-btn:hover {
  background-color: var(--primary-hover);
}

/* Toast notification for reset confirmation */
.toast-notification {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.toast-notification.show {
  opacity: 1;
  visibility: visible;
}

/* Dark Mode Toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 15px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .3s;
  border-radius: 22px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

.toggle-label {
  margin-left: 8px;
  font-size: 14px;
  color: var(--text-light);
}

/* Export History Styles */
.history-section {
  margin-bottom: 20px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.history-label {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-light);
  margin: 0;
}

.export-history-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 15px;
  max-height: 300px;
  overflow-y: auto;
  padding: 15px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background-color: var(--input-bg-light);
}

.history-item {
  position: relative;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  aspect-ratio: 1.6 / 1;
  background-color: white;
}

.history-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.history-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.history-item-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: space-between;
  padding: 5px;
  opacity: 0;
  transition: opacity 0.2s;
}

.history-item:hover .history-item-overlay {
  opacity: 1;
}

.history-btn {
  background: none;
  border: none;
  color: white;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  transition: background-color 0.2s;
}

.history-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.history-edit-btn {
  color: #ECAA01; /* Turmeric color for edit button */
}

.history-download-btn {
  color: var(--primary-color);
}

.history-delete-btn {
  color: #ff4d4d;
}

.history-timestamp {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.5);
  color: white;
  padding: 3px 6px;
  font-size: 10px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.history-item:hover .history-timestamp {
  opacity: 1;
}

.empty-history-message {
  grid-column: 1 / -1;
  text-align: center;
  padding: 30px 0;
  color: #999;
  font-style: italic;
}

/* Signature */
.signature {
  position: fixed;
  bottom: 10px;
  left: 10px;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 11px;
  color: #FFFFFF;
  opacity: 0.7;
  z-index: 100;
  pointer-events: none; /* Makes it non-interactive */
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.5); /* Adds a subtle shadow for better visibility */
}

/* Dark Mode Styles - Additional styles that don't conflict with background image */
body.dark-mode .container {
  background-color: var(--card-bg-dark);
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

body.dark-mode .format-controls {
  background-color: #444;
}

body.dark-mode .format-btn {
  background-color: #555;
  color: var(--text-dark);
  border-color: #666;
}

body.dark-mode .format-btn.active {
  background-color: var(--primary-color);
  color: white;
}

body.dark-mode textarea {
  background-color: #444;
  color: var(--text-dark);
  border-color: #555;
}

body.dark-mode #letterSpacingValue,
body.dark-mode label,
body.dark-mode .toggle-label,
body.dark-mode .preview-label,
body.dark-mode .editor-label,
body.dark-mode h1,
body.dark-mode .history-label {
  color: var(--text-dark);
}

body.dark-mode select,
body.dark-mode input[type="number"] {
  background-color: #444;
  color: var(--text-dark);
  border-color: #555;
}

body.dark-mode .color-swatch.active {
  outline-color: #fff;
}

body.dark-mode .editor-instructions {
  color: #aaa;
}

body.dark-mode .custom-font-item {
  background-color: #444;
  border-color: #555;
  color: var(--text-dark);
}

body.dark-mode .custom-fonts-list {
  border-color: #555;
  background-color: #444;
}

body.dark-mode .toast-notification {
  background-color: rgba(255, 255, 255, 0.8);
  color: #222;
}

body.dark-mode .logout-btn {
  background-color: #555;
  color: var(--text-dark);
  border-color: #666;
}

body.dark-mode .logout-btn:hover {
  background-color: #444;
}

body.dark-mode .export-history-container {
  background-color: var(--card-bg-dark);
  border-color: #555;
}

body.dark-mode .history-item {
  border-color: #555;
  background-color: #444;
}

body.dark-mode .empty-history-message {
  color: #777;
}

/* Add CSS for background transition effect */
.bg-transitioning::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.2);
  z-index: -1;
  animation: fadeInOut 0.5s ease;
}

@keyframes fadeInOut {
  0% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}

/* Make the app responsive on smaller screens */
@media (max-width: 600px) {
  .controls, .format-controls {
    flex-direction: column;
  }
  
  .align-controls {
    margin-left: 0;
    margin-top: 10px;
  }
  
  .header-controls {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  
  .utility-buttons {
    margin-top: 10px;
  }
  
  .export-history-container {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
  
  .history-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  /* Adjust container positioning for mobile */
  .container {
    position: relative;
    top: 5%;
    left: 0;
    transform: none;
    margin: 20px auto;
    width: 90%;
    max-height: none;
  }
}
.subtle-link {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: opacity 0.2s;
}

.subtle-link:hover {
  opacity: 0.7;
}

.signature {
  margin-top: 20px;
  margin-bottom: 20px;
  text-align: center;
  font-size: 14px;
  color: #666; /* Ensure this has some color */
  display: block; /* Ensure it's displayed as a block element */
  width: 100%; /* Make it take up full width */
  position: relative; /* Ensure it's in the normal document flow */
  opacity: 1; /* Make sure it's fully visible */
  z-index: 1; /* Ensure it's above any background elements */
}