/* ============================================
   Translation Documentation Layout Styles
   ============================================ */

/* 全局 box-sizing */
.translation-layout *,
.translation-layout *::before,
.translation-layout *::after {
  box-sizing: border-box;
}

/* Main Layout Container */
.translation-layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
  min-height: calc(100vh - 200px);
  width: 100%;
  overflow-x: hidden;
}

/* ============================================
   Left Sidebar - Table of Contents
   ============================================ */

.translation-sidebar {
  width: 280px;
  position: sticky;
  top: 80px;
  height: calc(100vh - 100px);
  overflow-y: auto;
  padding: 2rem 1.5rem;
  border-right: 1px solid #e0e0e0;
  background-color: #fafafa;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid #007acc;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 1.2rem;
  color: #333;
  font-weight: 600;
}

.toc-close {
  display: none; /* Hidden on desktop */
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  color: #666;
  transition: color 0.2s;
}

.toc-close:hover {
  color: #007acc;
}

/* Table of Contents List */
.table-of-contents {
  font-size: 0.9rem;
}

.no-toc {
  color: #999;
  font-style: italic;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-item {
  margin: 0;
  line-height: 1.6;
}

.toc-h2 {
  margin-top: 0.75rem;
}

.toc-h3 {
  padding-left: 1rem;
  margin-top: 0.5rem;
}

.toc-h4 {
  padding-left: 2rem;
  margin-top: 0.5rem;
}

.toc-link {
  display: block;
  color: #555;
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

.toc-link:hover {
  background-color: #e8f4ff;
  color: #007acc;
  border-left-color: #007acc;
  transform: translateX(2px);
}

.toc-link.active {
  background-color: #e8f4ff;
  color: #007acc;
  font-weight: 600;
  border-left-color: #007acc;
}

/* Custom Scrollbar for Sidebar */
.translation-sidebar::-webkit-scrollbar {
  width: 6px;
}

.translation-sidebar::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.translation-sidebar::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.translation-sidebar::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* ============================================
   Main Content Area
   ============================================ */

.translation-content {
  flex: 1;
  max-width: 900px;
  padding: 2rem 3rem;
  background-color: #fff;
  overflow-x: hidden;
}

/* Article Header */
.post-header {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid #e0e0e0;
}

.post-title {
  font-size: 2.5rem;
  line-height: 1.2;
  margin-bottom: 1rem;
  color: #1a1a1a;
  font-weight: 700;
}

.post-meta-wrapper {
  margin-bottom: 1.5rem;
}

.post-meta {
  color: #666;
  font-size: 0.95rem;
  margin: 0;
}

/* Cover Image */
.translation-cover {
  margin: 2rem 0;
  text-align: center;
}

.translation-cover img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* Description Box */
.translation-description {
  margin: 1.5rem 0;
  padding: 1.5rem;
  background: linear-gradient(135deg, #f5f9ff 0%, #e8f4ff 100%);
  border-left: 4px solid #007acc;
  border-radius: 6px;
}

.translation-description p {
  margin: 0;
  font-size: 1.05rem;
  font-style: italic;
  color: #555;
  line-height: 1.6;
}

/* Links Section */
.translation-links {
  margin: 1.5rem 0;
  padding: 1.5rem;
  background-color: #fafafa;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

.translation-links .link-item {
  margin: 0.75rem 0;
  font-size: 0.95rem;
}

.translation-links .link-item:first-child {
  margin-top: 0;
}

.translation-links .link-item:last-child {
  margin-bottom: 0;
}

.translation-links strong {
  color: #333;
}

.translation-links a {
  color: #007acc;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.translation-links a:hover {
  color: #005a9e;
  text-decoration: underline;
}

/* Article Content */
.post-content {
  font-size: 1.05rem;
  line-height: 1.8;
  color: #333;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.post-content * {
  max-width: 100%;
  box-sizing: border-box;
}

.post-content h2 {
  font-size: 1.8rem;
  margin-top: 3rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e0e0e0;
  color: #1a1a1a;
  font-weight: 600;
}

.post-content h3 {
  font-size: 1.4rem;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: #1a1a1a;
  font-weight: 600;
}

.post-content h4 {
  font-size: 1.2rem;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  color: #333;
  font-weight: 600;
}

.post-content p {
  margin-bottom: 1.25rem;
}

.post-content code {
  background-color: #f5f5f5;
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-size: 0.9em;
  font-family: 'Monaco', 'Consolas', monospace;
  color: #e83e8c;
}

.post-content pre {
  background-color: #f5f5f5;
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1.5rem 0;
  border: 1px solid #e0e0e0;
}

.post-content pre code {
  background-color: transparent;
  padding: 0;
  color: #333;
}

.post-content blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.5rem;
  border-left: 4px solid #007acc;
  background-color: #f9f9f9;
  font-style: italic;
  color: #555;
}

.post-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 2rem auto;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.post-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
  font-size: 0.95rem;
  background-color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.post-content table th {
  background-color: #f5f5f5;
  font-weight: 600;
  text-align: left;
  padding: 0.75rem;
  border: 1px solid #e0e0e0;
}

.post-content table td {
  padding: 0.75rem;
  border: 1px solid #e0e0e0;
}

.post-content table tr:nth-child(even) {
  background-color: #fafafa;
}

.post-content ul,
.post-content ol {
  margin: 1.25rem 0;
  padding-left: 2rem;
}

.post-content li {
  margin-bottom: 0.5rem;
  line-height: 1.7;
}

/* ============================================
   Mobile TOC Toggle Button
   ============================================ */

.toc-toggle {
  display: none; /* Hidden on desktop */
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: #007acc;
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 122, 204, 0.4);
  z-index: 999;
  transition: all 0.3s ease;
}

.toc-toggle:hover {
  background-color: #005a9e;
  transform: scale(1.1);
}

.toc-toggle:active {
  transform: scale(0.95);
}

/* ============================================
   Mobile Responsive Styles
   ============================================ */

@media screen and (max-width: 768px) {
  /* 防止整个页面横向滚动 */
  html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }

  .translation-layout {
    flex-direction: column;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Hide sidebar by default on mobile */
  .translation-sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 280px;
    height: 100vh;
    z-index: 1000;
    transition: left 0.3s ease;
    border-right: none;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    padding-top: 1rem;
  }

  /* Show sidebar when mobile-open class is added */
  .translation-sidebar.mobile-open {
    left: 0;
  }

  /* Show close button on mobile */
  .toc-close {
    display: block;
  }

  /* Show toggle button on mobile */
  .toc-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Adjust content padding on mobile */
  .translation-content {
    padding: 1rem 0.75rem;
    max-width: 100vw;
    width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  .post-content,
  .post-content * {
    max-width: 100%;
    box-sizing: border-box;
  }

  .post-header {
    padding-bottom: 1.5rem;
  }

  .post-title {
    font-size: 1.75rem;
    line-height: 1.3;
    word-wrap: break-word;
  }

  .post-content h2 {
    font-size: 1.4rem;
    margin-top: 2rem;
    word-wrap: break-word;
  }

  .post-content h3 {
    font-size: 1.2rem;
    margin-top: 1.5rem;
    word-wrap: break-word;
  }

  .post-content h4 {
    font-size: 1.1rem;
    margin-top: 1.25rem;
    word-wrap: break-word;
  }

  .post-content {
    font-size: 0.95rem;
    line-height: 1.7;
    overflow-x: hidden;
    word-wrap: break-word;
  }

  .post-content p {
    margin-bottom: 1rem;
  }

  /* 表格在移动端横向滚动 */
  .post-content table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1.5rem -0.75rem;
    font-size: 0.85rem;
    max-width: calc(100vw - 1.5rem);
  }

  .post-content table thead {
    display: table-header-group;
  }

  .post-content table tbody {
    display: table-row-group;
  }

  .post-content table tr {
    display: table-row;
  }

  .post-content table th,
  .post-content table td {
    display: table-cell;
    padding: 0.5rem;
    white-space: nowrap;
  }

  /* 代码块优化 */
  .post-content pre {
    padding: 0.75rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.85rem;
    margin: 1rem -0.75rem;
    border-radius: 4px;
    max-width: calc(100vw - 1.5rem);
    width: calc(100% + 1.5rem);
  }

  .post-content code {
    font-size: 0.85rem;
    word-break: break-all;
    overflow-wrap: break-word;
  }

  .post-content pre code {
    font-size: 0.8rem;
    white-space: pre;
    word-break: normal;
    display: block;
  }

  /* 行内代码块 */
  .post-content p code,
  .post-content li code {
    word-break: break-all;
    white-space: normal;
  }

  /* 图片优化 */
  .post-content img {
    max-width: 100%;
    height: auto;
    margin: 1.5rem auto;
  }

  .translation-cover img {
    max-width: 100%;
    height: auto;
  }

  /* 列表优化 */
  .post-content ul,
  .post-content ol {
    padding-left: 1.5rem;
    margin: 1rem 0;
  }

  .post-content li {
    margin-bottom: 0.5rem;
  }

  /* 引用块优化 */
  .post-content blockquote {
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
  }

  /* 描述框和链接框优化 */
  .translation-description {
    margin: 1rem 0;
    padding: 1rem;
    font-size: 0.95rem;
  }

  .translation-links {
    margin: 1rem 0;
    padding: 1rem;
    font-size: 0.9rem;
  }

  /* 确保长单词和 URL 能够断行 */
  .post-content a {
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* 强制所有文本内容都不溢出 */
  .post-content p,
  .post-content li,
  .post-content div,
  .post-content span,
  .post-content h1,
  .post-content h2,
  .post-content h3,
  .post-content h4,
  .post-content h5,
  .post-content h6 {
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
  }

  /* Overlay for mobile menu */
  .translation-sidebar.mobile-open::before {
    content: '';
    position: fixed;
    top: 0;
    left: 280px;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: -1;
  }
}

/* Tablet adjustments */
@media screen and (min-width: 769px) and (max-width: 1024px) {
  .translation-sidebar {
    width: 240px;
    padding: 1.5rem 1rem;
  }

  .translation-content {
    padding: 2rem;
  }
}

/* ============================================
   Dark Mode Support
   ============================================ */

@media (prefers-color-scheme: dark) {
  .translation-sidebar {
    background-color: #1e1e1e;
    border-right-color: #333;
  }

  .sidebar-header h3 {
    color: #e0e0e0;
  }

  .toc-link {
    color: #b0b0b0;
  }

  .toc-link:hover {
    background-color: #2d2d2d;
    color: #4da6ff;
    border-left-color: #4da6ff;
  }

  .toc-link.active {
    background-color: #2d2d2d;
    color: #4da6ff;
    border-left-color: #4da6ff;
  }

  .translation-content {
    background-color: #121212;
  }

  .post-header {
    border-bottom-color: #333;
  }

  .post-title {
    color: #e0e0e0;
  }

  .post-meta {
    color: #999;
  }

  .translation-description {
    background: linear-gradient(135deg, #1a2332 0%, #1e2d3d 100%);
    border-left-color: #4da6ff;
  }

  .translation-description p {
    color: #b0b0b0;
  }

  .translation-links {
    background-color: #1e1e1e;
    border-color: #333;
  }

  .translation-links strong {
    color: #e0e0e0;
  }

  .translation-links a {
    color: #4da6ff;
  }

  .translation-links a:hover {
    color: #7cb8ff;
  }

  .post-content {
    color: #d0d0d0;
  }

  .post-content h2,
  .post-content h3,
  .post-content h4 {
    color: #e0e0e0;
    border-bottom-color: #333;
  }

  .post-content code {
    background-color: #2d2d2d;
    color: #ff79c6;
  }

  .post-content pre {
    background-color: #1e1e1e;
    border-color: #333;
  }

  .post-content pre code {
    color: #d0d0d0;
  }

  .post-content blockquote {
    background-color: #1e1e1e;
    border-left-color: #4da6ff;
    color: #b0b0b0;
  }

  .toc-toggle {
    background-color: #4da6ff;
  }

  .toc-toggle:hover {
    background-color: #7cb8ff;
  }
}

