/* aiDocly Styles */

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #4a90d9;
  --primary-hover: #3a7bc8;
  --bg: #ffffff;
  --bg-secondary: #f6f8fa;
  --text: #24292e;
  --text-secondary: #586069;
  --border: #e1e4e8;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --radius: 8px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--text);
  background: var(--bg-secondary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.slogan {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Language Switcher */
.lang-switcher {
  position: relative;
}

.lang-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.8125rem;
  cursor: pointer;
  color: var(--text);
  font-weight: 500;
  transition: background 0.2s;
}

.lang-btn:hover {
  background: var(--border);
}

.lang-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  z-index: 200;
}

.lang-dropdown.show {
  display: block;
}

.lang-option {
  display: block;
  width: 100%;
  padding: 8px 20px;
  border: none;
  background: none;
  font-size: 0.875rem;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  color: var(--text);
}

.lang-option:hover {
  background: var(--bg-secondary);
}

/* Main Content */
.main {
  flex: 1;
  padding: 24px 20px 80px;
}

.container {
  max-width: 960px;
  margin: 0 auto;
}

/* Section Card */
.section-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-label svg {
  opacity: 0.6;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Input Section */
.md-input {
  width: 100%;
  min-height: 240px;
  padding: 16px;
  border: none;
  border-radius: 0;
  background: var(--bg);
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  resize: vertical;
  color: var(--text);
}

.md-input:focus {
  outline: none;
  box-shadow: none;
}

.md-input::placeholder {
  color: #b0b7bf;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
  border-radius: 5px;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-secondary);
  border-color: #c8ccd0;
}

.btn-outline-primary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn-outline-primary:hover {
  background: rgba(74, 144, 217, 0.08);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-export {
  flex: 1;
  justify-content: center;
  padding: 10px 16px;
  font-size: 0.9375rem;
  color: #fff;
  border: none;
  border-radius: 8px;
}

/* PDF — Red/warm tone */
.btn-export-pdf {
  background: #e05252;
}
.btn-export-pdf:hover:not(:disabled) {
  background: #c93c3c;
}

/* Image — Green */
.btn-export-image {
  background: #43a047;
}
.btn-export-image:hover:not(:disabled) {
  background: #388e3c;
}

/* Word — Blue */
.btn-export-docx {
  background: #4a90d9;
}
.btn-export-docx:hover:not(:disabled) {
  background: #3a7bc8;
}

.btn-export:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Preview Toggle */
.preview-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
  user-select: none;
}

.preview-toggle input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
}

/* Preview Content */
.preview-content {
  padding: 24px;
  min-height: 100px;
  overflow-x: auto;
}

/* Markdown body styles */
.markdown-body h1 { font-size: 2em; margin: 0.67em 0; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.5em; margin: 0.83em 0; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h3 { font-size: 1.25em; margin: 1em 0; }
.markdown-body h4 { font-size: 1em; margin: 1.33em 0; }
.markdown-body h5 { font-size: 0.875em; margin: 1.67em 0; }
.markdown-body h6 { font-size: 0.85em; margin: 2.33em 0; color: var(--text-secondary); }

.markdown-body p { margin: 0 0 16px; }
.markdown-body a { color: var(--primary); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }

.markdown-body pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  overflow: auto;
  margin: 0 0 16px;
}

.markdown-body code {
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  font-size: 0.875em;
}

.markdown-body :not(pre) > code {
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 3px;
}

.markdown-body blockquote {
  border-left: 4px solid var(--primary);
  margin: 0 0 16px;
  padding: 12px 20px;
  background: #f0f7ff;
  color: #333;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 16px;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid #dfe2e5;
  padding: 8px 12px;
  text-align: left;
}

.markdown-body th {
  background: #4a5568;
  color: #fff;
  font-weight: 600;
}

.markdown-body tr:nth-child(even) {
  background: var(--bg-secondary);
}

.markdown-body ul,
.markdown-body ol {
  margin: 0 0 16px;
  padding-left: 2em;
}

.markdown-body li {
  margin-bottom: 4px;
}

.markdown-body img {
  max-width: 100%;
  border-radius: 4px;
}

.markdown-body hr {
  border: none;
  border-top: 2px solid var(--border);
  margin: 24px 0;
}

.katex-block {
  text-align: center;
  margin: 1em 0;
  overflow-x: auto;
}

.katex-error {
  color: #d73a49;
  font-family: monospace;
}

/* Floating Export Bar */
.export-floating {
  position: sticky;
  bottom: 0;
  z-index: 90;
  background: var(--bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
  padding: 12px 20px;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.export-floating.hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

.export-floating-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  gap: 12px;
}

/* Footer */
.footer {
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 20px;
  text-align: center;
}

.footer p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.footer .footer-privacy {
  font-size: 0.75rem;
  color: #b0b7bf;
}

/* Toast */
#toast-container {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.875rem;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast-show {
  opacity: 1;
  transform: translateY(0);
}

.toast-error {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.toast-success {
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
}

/* Export Progress Overlay */
.export-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.export-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.export-overlay-card {
  background: var(--bg);
  border-radius: 16px;
  padding: 32px 40px;
  min-width: 320px;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  text-align: center;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.25s ease;
}

.export-overlay.active .export-overlay-card {
  transform: translateY(0) scale(1);
}

.export-overlay-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 20px;
}

.export-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 16px;
}

.export-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.export-progress-fill.fill-pdf { background: #e05252; }
.export-progress-fill.fill-image { background: #43a047; }
.export-progress-fill.fill-docx { background: #4a90d9; }

.export-overlay-time {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* Mobile Responsive */
@media (max-width: 640px) {
  .header-inner {
    height: 52px;
  }

  .slogan {
    display: none;
  }

  .main {
    padding: 16px 12px;
  }

  .md-input {
    min-height: 180px;
    padding: 12px;
    font-size: 14px;
  }

  .preview-content {
    padding: 16px;
  }

  .export-floating-inner {
    flex-direction: column;
    gap: 8px;
  }

  .btn-export {
    width: 100%;
  }

  .section-header {
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* Tablet */
@media (min-width: 641px) and (max-width: 960px) {
  .container {
    padding: 0 12px;
  }
}
