* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Montserrat', sans-serif;
  background-color: #F5F7FA;
  color: #4A4A4A;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  padding: 1rem;
  background: #4A90E2;
  color: white;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

footer {
  text-align: center;
  padding: 0.75rem;
  background-color: #E1E8ED;
  font-size: 0.9rem;
  margin-top: auto;
}

.editor-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 130px);
  gap: 1rem;
  padding: 1rem;
  overflow: hidden; /* Prevent container from expanding */
}

textarea {
  width: 50%;
  height: 100%; /* Set fixed height */
  min-height: 0; /* Important for flex children to respect max-height */
  padding: 1rem;
  font-family: 'Montserrat', sans-serif;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  resize: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  background-color: #FFFFFF;
  overflow-y: auto; /* Enable vertical scrolling */
}

.preview-container {
  width: 50%;
  display: flex;
  flex-direction: column;
  height: 100%; /* Set fixed height to match textarea */
  min-height: 0; /* Allow child elements to shrink */
}

.preview-header {
  display: flex;
  justify-content: flex-end;
  padding: 0.5rem;
  gap: 0.5rem;
  flex-shrink: 0; /* Prevent header from shrinking */
}

.preview-area {
  flex: 1;
  min-height: 0; /* Critical for scrolling to work in flex container */
  max-height: calc(100% - 50px); /* Adjusted to account for header */
  padding: 1rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #FFFFFF;
  overflow-y: auto !important; /* Force vertical scrolling */
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Table Styling */
.preview-area table, .styled-table {
  border-collapse: collapse !important;
  width: 100% !important;
  margin: 1rem 0 !important;
  table-layout: fixed !important;
  border: 1px solid #ddd !important;
}

.preview-area table th, .preview-area table td,
.styled-table th, .styled-table td {
  border: 1px solid #ddd !important;
  padding: 8px !important;
  text-align: left !important;
  word-wrap: break-word !important;
}

.preview-area table th,
.styled-table th {
  background-color: #f5f5f5 !important;
  font-weight: bold !important;
}

.preview-area table tr:nth-child(even),
.styled-table tr:nth-child(even) {
  background-color: #f9f9f9 !important;
}

/* Enhanced table styling */
.preview-area table thead,
.styled-table thead {
  border-bottom: 2px solid #ddd !important;
}

/* Export Buttons */
.export-button {
  background-color: #4A90E2;
  color: white;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  transition: background-color 0.3s ease;
}

.export-button:hover {
  background-color: #357ABD;
}

/* Security notice styling */
.security-warning {
  background-color: #ffe0e0;
  border-left: 4px solid #ff5252;
  padding: 10px;
  margin: 10px 0;
  color: #d32f2f;
}

/* Error message styling */
.error-message, .wasm-error {
  background-color: #fff3cd;
  border-left: 4px solid #ffc107;
  padding: 10px;
  margin: 10px 0;
  color: #856404;
}

@media (max-width: 768px) {
  .editor-container {
    flex-direction: column;
    height: calc(100vh - 130px);
    overflow: hidden;
  }
  
  textarea, .preview-container {
    width: 100%;
  }
  
  textarea {
    height: 40%;
    min-height: 0;
  }
  
  .preview-container {
    height: 60%;
    min-height: 0;
  }
  
  .preview-area {
    min-height: 0;
    max-height: calc(100% - 50px);
  }
}

@media (max-width: 480px) {
  .preview-header {
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
  }
  
  .export-button {
    width: 100%;
  }
}

/* Dark Theme Styles */
body.dark-theme {
  background-color: #1e1e1e;
  color: #e0e0e0;
}

body.dark-theme header {
  background: #4A90E2;
  color: #ffffff;
}

body.dark-theme footer {
  background-color: #2d2d2d;
  color: #bbbbbb;
}

body.dark-theme textarea,
body.dark-theme .preview-area {
  background-color: #2a2a2a;
  border-color: #444;
  color: #e0e0e0;
  box-shadow: 0 1px 3px rgba(255, 255, 255, 0.05);
}

body.dark-theme .preview-area table, 
body.dark-theme .styled-table {
  border-color: #444 !important;
}

body.dark-theme .preview-area table th, 
body.dark-theme .preview-area table td,
body.dark-theme .styled-table th, 
body.dark-theme .styled-table td {
  border-color: #444 !important;
}

body.dark-theme .preview-area table th,
body.dark-theme .styled-table th {
  background-color: #3a3a3a !important;
}

body.dark-theme .preview-area table tr:nth-child(even),
body.dark-theme .styled-table tr:nth-child(even) {
  background-color: #333333 !important;
}

/* Smooth transitions for mode change */
body, textarea, .preview-area, .export-button {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}