* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #3498db;
  --secondary-color: #95a5a6;
  --success-color: #27ae60;
  --danger-color: #e74c3c;
  --accent-color: #9b59b6;
  --background: #f5f7fa;
  --surface: #ffffff;
  --text-primary: #2c3e50;
  --text-secondary: #7f8c8d;
  --border-color: #dcdfe6;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.15);
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--background);
  color: var(--text-primary);
  line-height: 1.6;
  direction: rtl;
  text-align: right;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 30px;
  padding: 30px 20px;
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  border-radius: 12px;
  color: white;
  box-shadow: var(--shadow);
}

.header h1 {
  font-size: 2.5em;
  margin-bottom: 10px;
}

.subtitle {
  font-size: 1.1em;
  opacity: 0.95;
}

/* Main Content */
.main-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 1024px) {
  .main-content {
    grid-template-columns: 1fr;
  }
}

/* Sections */
.input-section,
.preview-section {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border-color);
}

.section-header h2 {
  font-size: 1.3em;
  color: var(--text-primary);
}

.actions {
  display: flex;
  gap: 10px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 10px;
}

.tab-btn {
  padding: 10px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1em;
  font-family: inherit;
  color: var(--text-secondary);
  border-radius: 6px;
  transition: all 0.3s ease;
}

.tab-btn:hover {
  background-color: var(--background);
  color: var(--primary-color);
}

.tab-btn.active {
  background-color: var(--primary-color);
  color: white;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Textarea */
#markdownInput {
  width: 100%;
  min-height: 400px;
  padding: 15px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
  resize: vertical;
  transition: border-color 0.3s ease;
}

#markdownInput:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* Upload Area */
.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  border: 2px dashed var(--border-color);
  border-radius: 8px;
  background-color: var(--background);
  transition: all 0.3s ease;
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--primary-color);
  background-color: rgba(52, 152, 219, 0.05);
}

.upload-hint {
  margin-top: 15px;
  color: var(--text-secondary);
}

/* Filename Input */
.filename-input {
  margin-top: 15px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.filename-input label {
  font-weight: 600;
  color: var(--text-secondary);
}

.filename-input input {
  padding: 10px;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  font-size: 1em;
  transition: border-color 0.3s ease;
}

.filename-input input:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* Preview */
.preview-content {
  flex: 1;
  min-height: 400px;
  padding: 20px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background-color: white;
  overflow-y: auto;
  direction: rtl;
  text-align: right;
}

.preview-content .placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  font-size: 1.1em;
}

/* Preview Markdown Styling */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
  margin: 1.5em 0 0.8em 0;
  font-weight: 600;
  line-height: 1.3;
  color: #2c3e50;
}

.preview-content h1 {
  font-size: 2em;
  border-bottom: 2px solid var(--primary-color);
  padding-bottom: 0.3em;
}

.preview-content h2 {
  font-size: 1.5em;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.2em;
}

.preview-content h3 {
  font-size: 1.25em;
}

.preview-content p {
  margin: 1em 0;
  text-align: justify;
}

.preview-content a {
  color: var(--primary-color);
  text-decoration: none;
  border-bottom: 1px dotted var(--primary-color);
}

.preview-content a:hover {
  color: var(--accent-color);
  border-bottom-style: solid;
}

.preview-content ul,
.preview-content ol {
  margin: 1em 0;
  padding-right: 2em;
}

.preview-content li {
  margin: 0.5em 0;
}

.preview-content blockquote {
  margin: 1.5em 0;
  padding: 0.5em 1.5em;
  border-right: 4px solid var(--primary-color);
  background-color: var(--background);
  color: var(--text-secondary);
}

.preview-content code {
  font-family: 'Courier New', Courier, monospace;
  background-color: #f4f4f4;
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-size: 0.9em;
}

.preview-content pre {
  background-color: #2d2d2d;
  color: #f8f8f2;
  padding: 1em;
  border-radius: 5px;
  overflow-x: auto;
  margin: 1.5em 0;
}

.preview-content pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.preview-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
}

.preview-content table th,
.preview-content table td {
  border: 1px solid var(--border-color);
  padding: 0.8em;
  text-align: right;
}

.preview-content table th {
  background-color: var(--primary-color);
  color: white;
  font-weight: 600;
}

.preview-content table tr:nth-child(even) {
  background-color: var(--background);
}

.preview-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5em auto;
}

.preview-content hr {
  border: none;
  border-top: 2px solid var(--border-color);
  margin: 2em 0;
}

/* Export Section */
.export-section {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.status-message {
  font-size: 0.9em;
  padding: 8px 16px;
  border-radius: 6px;
  display: none;
}

.status-message.success {
  display: block;
  background-color: rgba(39, 174, 96, 0.1);
  color: var(--success-color);
  border: 1px solid var(--success-color);
}

.status-message.error {
  display: block;
  background-color: rgba(231, 76, 60, 0.1);
  color: var(--danger-color);
  border: 1px solid var(--danger-color);
}

.status-message.loading {
  display: block;
  background-color: rgba(52, 152, 219, 0.1);
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 1em;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-secondary {
  background-color: var(--secondary-color);
  color: white;
}

.btn-success {
  background-color: var(--success-color);
  color: white;
}

.btn-accent {
  background-color: var(--accent-color);
  color: white;
}

.btn-large {
  padding: 15px 40px;
  font-size: 1.2em;
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Help Section */
.help-section {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.help-section details {
  cursor: pointer;
}

.help-section summary {
  font-size: 1.1em;
  font-weight: 600;
  color: var(--text-primary);
  padding: 10px;
  border-radius: 6px;
  transition: background-color 0.3s ease;
}

.help-section summary:hover {
  background-color: var(--background);
}

.help-content {
  margin-top: 15px;
  padding: 15px;
  background-color: var(--background);
  border-radius: 8px;
}

.help-content h3 {
  margin-bottom: 10px;
  color: var(--text-primary);
}

.help-content ul {
  list-style: none;
  padding-right: 0;
}

.help-content li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
}

.help-content li:last-child {
  border-bottom: none;
}

.help-content code {
  font-family: 'Courier New', Courier, monospace;
  background-color: #f4f4f4;
  padding: 0.2em 0.6em;
  border-radius: 3px;
  color: var(--accent-color);
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.input-section,
.preview-section,
.export-section,
.help-section {
  animation: fadeIn 0.5s ease;
}

/* Print Styles */
@media print {
  /* Hide everything by default */
  body * {
    visibility: hidden;
  }

  /* Show only the preview content */
  #preview, #preview * {
    visibility: visible;
  }

  /* Position the preview absolute to top-left */
  #preview {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    box-shadow: none;
    background: white;
    overflow: visible;
  }

  /* Reset body styling for print */
  body {
    background: white;
    margin: 0;
    padding: 0;
  }

  .container {
    max-width: 100%;
    margin: 0;
    padding: 0;
  }

  /* Ensure links are readable */
  a {
    text-decoration: underline;
    color: black;
  }

  /* Enhance typography for print */
  .preview-content {
    font-size: 12pt;
    line-height: 1.5;
    color: black;
  }

  .preview-content h1 {
    font-size: 24pt;
    border-bottom: 2px solid black;
  }
  
  .preview-content h2 {
    font-size: 18pt;
    border-bottom: 1px solid #ccc;
  }

  /* Hide placeholder if empty */
  .placeholder {
    display: none !important;
  }
}
