/* Reusable article styles for guides and posts */

/* Headings with improved hierarchy and spacing */
.article-content h1 {
  text-align: center;
  font-size: 1.75rem; /* text-3xl, increased from 1.5rem */
  font-weight: 800; /* increased weight for better hierarchy */
  letter-spacing: -0.025em; /* tracking-tight */
  margin-bottom: 2rem; /* increased bottom margin */
  color: #1f2937; /* darker color for better contrast */
}

@media (min-width: 768px) {
  .article-content h1 {
    font-size: 2.25rem; /* md:text-4xl, increased from 1.875rem */
    margin-bottom: 2.5rem;
  }
}

.article-content h2 {
  text-align: center;
  color: #3a5221; /* theme deep green primary-700/800 */
  font-size: 1.5rem; /* text-2xl */
  font-weight: 700;
  margin-top: 3rem; /* increased top margin for better section separation */
  margin-bottom: 1.5rem;
  letter-spacing: -0.025em;
}

.article-content h3 {
  text-align: center;
  color: #3a5221;
  font-size: 1.25rem; /* text-xl */
  font-weight: 600;
  margin-top: 2.5rem;
  margin-bottom: 1.25rem;
  letter-spacing: -0.015em;
}

.article-content h4 {
  text-align: left; /* changed to left align for better readability */
  color: #374151;
  font-size: 1.125rem; /* text-lg */
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 1rem;
}

.article-content h2::after,
.article-content h3::after {
  content: "";
  display: block;
  width: 64px;
  height: 3px;
  margin: 12px auto 0; /* slightly increased margin */
  background: linear-gradient(135deg, #5d8736, #809d3c);
  border-radius: 9999px;
}

/* Body text with improved readability */
.article-content p {
  color: #374151; /* gray-700 */
  line-height: 1.75; /* improved line height for better readability */
  font-size: 1.125rem; /* increased from 1.0625rem to 18px for better readability */
  margin-bottom: 1.25rem; /* increased paragraph spacing */
}

.article-content ul,
.article-content ol {
  color: #374151;
  line-height: 1.75; /* consistent with paragraph line height */
  font-size: 1.125rem; /* consistent with paragraph font size */
  margin-bottom: 1.25rem;
}

.article-content li {
  margin-bottom: 0.5rem; /* spacing between list items */
}

.article-content li:last-child {
  margin-bottom: 0;
}

/* Tables */
.article-content table th,
.article-content table td {
  font-size: 0.975rem; /* slightly smaller than body text */
}

.article-content table th {
  font-weight: 600; /* bold but not excessive */
}

/* Code blocks */
.prose pre {
  background: #f8fafc; /* light background */
  border: 1px solid #e5e7eb; /* border */
  border-radius: 0.75rem; /* rounded corners */
  padding: 1rem; /* sufficient padding */
}

/* Utility: improved spacing for sections and content blocks */
.article-content section {
  margin-top: 2.5rem; /* increased from 1.75rem */
  margin-bottom: 2.5rem;
}

/* Enhanced spacing for content blocks */
.article-content .section-card {
  margin-bottom: 2rem; /* increased spacing between cards */
}

.article-content .section-card > *:first-child {
  margin-top: 0; /* remove top margin from first element in cards */
}

.article-content .section-card > *:last-child {
  margin-bottom: 0; /* remove bottom margin from last element in cards */
}

/* Improved spacing for special content blocks */
.article-content blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.5rem;
  border-left: 4px solid #5d8736;
  background-color: #f8fdf4;
  font-style: italic;
}

.article-content .warning-box,
.article-content .info-box {
  margin: 1.5rem 0;
  padding: 1.25rem;
  border-radius: 0.75rem;
}

/* Better spacing for nested content */
.article-content ul ul,
.article-content ol ol,
.article-content ul ol,
.article-content ol ul {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  margin-left: 1.5rem;
}

/* Improved table spacing */
.article-content table {
  margin: 1.5rem 0; /* increased table margins */
}

/* Better spacing for image placeholders */
.article-content [data-image-placeholder="true"] {
  margin: 2rem 0; /* increased spacing around image placeholders */
}

/* Table of Contents (TOC) */
.sticky-toc {
  position: sticky;
  top: 2rem;
}

.toc-nav {
  background: white;
  border-radius: 0.75rem; /* rounded-xl */
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); /* shadow-sm */
  border: 1px solid #e5e7eb; /* border-gray-200 */
  padding: 1.5rem; /* p-6 */
}

.toc-nav h3 {
  font-size: 1.125rem; /* text-lg */
  font-weight: 600; /* font-semibold */
  color: #111827; /* text-gray-900 */
  margin-bottom: 1rem; /* mb-4 */
  text-align: left; /* override center alignment */
}

.toc-nav h3::after {
  display: none; /* remove underline for TOC title */
}

.toc-nav nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem; /* space-y-2 */
  font-size: 0.875rem; /* text-sm */
}

.toc-nav a {
  display: block;
  color: #374151; /* text-gray-700 */
  text-decoration: none;
  transition: all 0.3s ease;
  padding: 0.5rem 0.75rem; /* py-2 px-3 */
  border-radius: 0.375rem; /* rounded-md */
  position: relative;
}

.toc-nav a:hover {
  color: #3a5221; /* hover:text-primary-700 */
  background-color: #f4ffc3; /* hover:bg-primary-50 */
}

/* Active TOC link styles using main brand color */
.toc-nav a.toc-active {
  color: #ffffff; /* text-white */
  background-color: #5d8736; /* bg-primary-500 - main brand color */
  font-weight: 600; /* font-semibold */
  box-shadow: 0 2px 4px rgba(93, 135, 54, 0.2); /* shadow with primary color */
}

.toc-nav a.toc-active::before {
  content: '';
  position: absolute;
  left: -0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0.25rem; /* w-1 */
  height: 1.5rem; /* h-6 */
  background-color: #5d8736; /* bg-primary-500 */
  border-radius: 0.125rem; /* rounded-sm */
}

/* Section Cards with Hover Effects */
.section-card {
  transition: all 0.3s ease;
  background: #fff;
  border-radius: 0.75rem; /* rounded-xl */
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); /* shadow-sm */
  border: 1px solid #e5e7eb; /* border-gray-200 */
  padding: 1.5rem; /* p-6 */
  margin-bottom: 1.5rem; /* mb-6 */
}

.section-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(93, 135, 54, 0.12); /* enhanced shadow with primary color */
}

/* Enhanced Table Styles */
.article-content table {
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.article-content table thead {
  background-color: #f9fafb; /* bg-gray-50 */
}

.article-content table thead th {
  padding: 0.75rem 1.5rem; /* px-6 py-3 */
  text-align: left;
  font-size: 0.75rem; /* text-xs */
  font-weight: 500; /* font-medium */
  color: #6b7280; /* text-gray-500 */
  text-transform: uppercase;
  letter-spacing: 0.05em; /* tracking-wider */
}

.article-content table tbody {
  background-color: white;
  border-top: 1px solid #e5e7eb; /* divide-y divide-gray-200 */
}

.article-content table tbody tr {
  border-top: 1px solid #e5e7eb; /* divide-y divide-gray-200 */
}

.article-content table tbody tr:nth-child(even) {
  background-color: #f9fafb; /* bg-gray-50 for alternating rows */
}

.article-content table tbody td {
  padding: 0.75rem 1.5rem; /* px-6 py-3 */
  color: #374151; /* text-gray-700 */
}

.article-content table tbody td.font-mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  color: #111827; /* text-gray-900 */
}

/* Back to Calculator Button Styles */
.back-to-calculator-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.25rem; /* px-5 py-3 */
  border-radius: 0.75rem; /* rounded-xl */
  border: 2px solid #4a6b2a; /* border-primary-600 */
  color: #3a5221; /* text-primary-700 */
  background-color: #f4ffc3; /* bg-primary-50 */
  font-weight: 600; /* font-semibold */
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); /* shadow-sm */
  text-decoration: none;
  transition: background-color 0.2s ease;
}

.back-to-calculator-btn:hover {
  background-color: #e8f5c8; /* hover:bg-primary-100 */
}

/* Mobile Floating Back Button */
.mobile-floating-back-btn {
  position: fixed;
  bottom: 1rem; /* bottom-4 */
  left: 50%;
  transform: translateX(-50%); /* -translate-x-1/2 */
  z-index: 50; /* z-50 */
  display: inline-flex;
  align-items: center;
  padding: 0.75rem 1rem; /* px-4 py-3 */
  border-radius: 9999px; /* rounded-full */
  background-color: #4a6b2a; /* bg-primary-600 */
  color: white;
  font-weight: 500; /* font-medium */
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); /* shadow-lg */
  text-decoration: none;
  transition: background-color 0.2s ease;
}

.mobile-floating-back-btn:hover {
  background-color: #3a5221; /* hover:bg-primary-700 */
}

/* Hide mobile floating button on desktop */
@media (min-width: 768px) {
  .mobile-floating-back-btn {
    display: none;
  }
}

/* Mobile TOC Button (方案A) */
.mobile-toc-button {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  background-color: #5d8736;
  border: none;
  border-radius: 8px;
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(93, 135, 54, 0.3);
  cursor: pointer;
  z-index: 1001;
  transition: all 0.3s ease;
  font-size: 12px;
  color: white;
  font-weight: 500;
}

.mobile-toc-button:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(93, 135, 54, 0.4);
}

.mobile-toc-button.visible {
  display: flex;
}

.mobile-toc-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Mobile TOC Overlay */
.mobile-toc-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-toc-overlay.visible {
  display: block;
  opacity: 1;
}

/* Mobile TOC Panel */
.mobile-toc-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: 90%;
  max-width: 400px;
  max-height: 70vh;
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s ease;
}

.mobile-toc-overlay.visible .mobile-toc-panel {
  transform: translate(-50%, -50%) scale(1);
}

.mobile-toc-panel-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mobile-toc-panel-title {
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  margin: 0;
}

.mobile-toc-close-button {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background-color 0.2s ease;
}

.mobile-toc-close-button:hover {
  background-color: #f3f4f6;
}

.mobile-toc-close-button svg {
  width: 20px;
  height: 20px;
  stroke: #6b7280;
}

.mobile-toc-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.mobile-toc-panel-content a {
  display: block;
  padding: 12px 24px;
  color: #374151;
  text-decoration: none;
  font-size: 15px;
  border-bottom: 1px solid #f3f4f6;
  transition: all 0.2s ease;
}

.mobile-toc-panel-content a:last-child {
  border-bottom: none;
}

.mobile-toc-panel-content a:hover {
  background-color: #f4ffc3;
  color: #3a5221;
}

.mobile-toc-panel-content a.toc-active {
  background-color: #5d8736;
  color: white;
  font-weight: 600;
}

/* Hide mobile TOC button on desktop */
@media (min-width: 1024px) {
  .mobile-toc-button,
  .mobile-toc-overlay {
    display: none !important;
  }
}