* {
  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 {
  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 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 1024px) {
  .main-content {
    grid-template-columns: 1fr;
  }
}

.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 {
  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;
}

#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 {
  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 {
  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-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-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 {
  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);
}

.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 {
  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);
}

@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;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.header-links {
  display: flex;
  gap: 8px;
}

.btn-header {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-header:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.btn-header.logged-in {
  background: rgba(39, 174, 96, 0.4);
}

.btn-header.guest {
  background: rgba(243, 156, 18, 0.3);
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: white;
  padding: 30px;
  border-radius: 12px;
  width: 90%;
  max-width: 420px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-close {
  position: absolute;
  top: 12px;
  left: 12px;
  background: none;
  border: none;
  font-size: 1.5em;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}

.modal-close:hover {
  color: var(--danger-color);
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border-color);
}

.auth-tab {
  flex: 1;
  padding: 12px;
  border: none;
  background: var(--border-color);
  cursor: pointer;
  font-size: 1em;
  font-weight: normal;
  font-family: inherit;
  color: var(--text-secondary);
  border-radius: 8px 8px 0 0;
  transition: all 0.3s;
}

.auth-tab:not(.active):hover {
  background: #e8e8e8;
}

.auth-tab.active {
  background: var(--primary-color);
  color: #fff;
  font-weight: bold;
  border-bottom: none;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form[hidden] {
  display: none;
}

.auth-form input {
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 1em;
  font-family: inherit;
  direction: rtl;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.auth-divider {
  text-align: center;
  color: var(--text-secondary);
  margin: 20px 0;
  position: relative;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border-color);
}

.auth-divider::before { right: 0; }
.auth-divider::after { left: 0; }

.guest-note {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85em;
  margin-top: 12px;
}

.bottom-nav {
  text-align: center;
  margin-bottom: 20px;
}

.bottom-nav .btn {
  text-decoration: none;
  display: inline-block;
}
