/* ---  Design Tokens (CSS Variables) --- */

:root {
  /* Colors */
  --color-primary: #663399; /* Deep Purple */
  --color-secondary: #4b2e05; /* Dark Brown/Coffee */
  --color-text-subtle: rgba(75, 46, 5, 0.7); /* Subtle Text */
  --color-text-verbatim: #2f1b0a; /* Very Dark Brown */
  --color-light-bg: #fff;
  --color-subtle-bg: #fdf5e6; /* Lightest Gold/Cream */
  --color-subtle-bg-hover: #f7ecd1; /* Slightly darker hover */
  --color-sub-list-bg: #fdf9ef; /* Very light subtle background */
  --color-border-subtle: rgba(102, 51, 153, 0.1);
  --color-border-detail: rgba(102, 51, 153, 0.06);
  --color-success: #28a745; /* Green for success */
  --color-danger: #dc3545; /* Red for alerts */
  --color-modal-bg: rgba(
    0,
    0,
    0,
    0.6
  ); /* Darker overlay for better visibility */

  /* Syntax Highlighting Colors for dark background */
  --color-code-bg: #263238; /* Dark Slate Gray (for high contrast) */
  --color-code-key: #bb98d4; /* Light Purple/Pink */
  --color-code-string: #a6e22e; /* Bright Green */
  --color-code-number: #ae81ff; /* Magenta/Purple */

  /* Spacing */
  --space-xs: 0.25rem;
  --space-s: 0.5rem;
  --space-m: 1rem;
  --space-l: 1.5rem;
  --space-xl: 1.75rem;
  --space-xxl: 2.25rem;

  /* Border Radii */
  --radius-s: 8px;
  --radius-m: 10px;
  --radius-l: 14px;

  /* Transitions */
  --transition-fast: 0.2s ease;
  --transition-medium: 0.3s ease;
  --transition-slow: 0.25s ease;

  /* Typography */
  --font-serif: "Georgia", serif; /* For verbatim */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono",
    monospace; /* New mono font variable */
}

/* Global Button Styles - Enhanced for better visibility and hover effects */
.btn,
.buy-btn,
.open-btn,
.chapter-buy,
.template-buy {
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-s);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  display: inline-block;
  transition: all var(--transition-medium);
  min-width: 120px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  margin: var(--space-xs); /* Added spacing between buttons */
}

.btn:hover,
.buy-btn:hover,
.open-btn:hover,
.chapter-buy:hover,
.template-buy:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn.primary,
.buy-btn.primary {
  background: var(--color-primary);
  color: var(--color-light-bg);
}

.btn.primary:hover {
  background: #5a2d8c;
}

.chapter-buy,
.template-buy {
  background: var(--color-success);
  color: var(--color-light-bg);
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  min-width: 100px; /* Fixed width for consistency */
  flex-shrink: 0; /* Prevent shrinking */
}

.chapter-buy:hover,
.template-buy:hover {
  background: #218838;
}

.open-btn {
  background: var(--color-secondary);
  color: var(--color-light-bg);
  font-size: 0.9rem;
  min-width: 100px; /* Fixed width for consistency */
  padding: 0.45rem 0.9rem;
  flex-shrink: 0; /* Prevent shrinking */
}

.open-btn:hover {
  background: var(--color-primary);
}

/* --- Compliance Section Styling (Chapter List) --- */

.chapters-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-l);
}

.chapter-card {
  background: var(--color-light-bg);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-l);
  overflow: hidden;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.04);
  transition: all var(--transition-slow);
}

.chapter-card:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.chapter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem var(--space-l);
  cursor: pointer;
  background: linear-gradient(to right, var(--color-subtle-bg), #faf0dc);
  transition: background var(--transition-medium);
  position: relative;
  gap: var(--space-m); /* Added gap for spacing */
}

.chapter-header:hover {
  background: var(--color-subtle-bg-hover);
}

.chapter-title-container {
  flex: 1;
  min-width: 0; /* Allow text truncation */
}

.chapter-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-secondary);
  letter-spacing: 0.3px;
  margin: 0;
}

.chapter-meta {
  font-size: 0.9rem;
  color: var(--color-text-subtle);
  margin-top: 0.2rem;
  margin-bottom: 0;
}

.chapter-header-controls {
  display: flex;
  align-items: center;
  gap: var(--space-m); /* Consistent spacing */
  flex-shrink: 0; /* Prevent controls from shrinking */
}

.chev {
  font-size: 1.4rem;
  color: var(--color-primary);
  font-weight: bold;
  transition: transform var(--transition-medium);
  flex-shrink: 0;
}

.chapter-header[aria-expanded="true"] .chev {
  transform: rotate(90deg);
}

.sub-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-top: 1px solid var(--color-border-subtle);
  background: var(--color-sub-list-bg);
  animation: fadeSlide var(--transition-medium);
}

@keyframes fadeSlide {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.sub-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-m) var(--space-l);
  border-bottom: 1px solid var(--color-border-subtle);
  transition: background var(--transition-fast);
  gap: var(--space-m); /* Added gap for spacing */
}

.sub-item:last-child {
  border-bottom: none;
}

.sub-item:hover {
  background: rgba(102, 51, 153, 0.05);
}

.sub-item-content {
  flex: 1;
  min-width: 0; /* Allow text truncation */
  margin-right: var(--space-m);
}

.sub-title {
  font-weight: 600;
  color: var(--color-secondary);
  margin: 0;
}

.sub-item-controls {
  display: flex;
  align-items: center;
  gap: var(--space-m); /* Consistent spacing */
  flex-shrink: 0; /* Prevent controls from shrinking */
}

/* --- Detail View Styling --- */
.detail-article {
  background: var(--color-light-bg);
  border-radius: var(--radius-m);
  box-shadow: 0 10px 30px rgba(75, 46, 5, 0.05);
  border: 1px solid var(--color-border-detail);
  margin: var(--space-m) 0 3rem 0;
  color: var(--color-secondary);
  line-height: 1.7;
  padding: var(--space-xl);
}

/* Breadcrumb + header */
.detail-article header .read-more {
  display: inline-block;
  margin-bottom: var(--space-s);
  color: var(--color-secondary);
  text-decoration: none;
  font-weight: 600;
  background: rgba(102, 51, 153, 0.03);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-s);
  transition: background var(--transition-fast);
}

.detail-article header .read-more:hover {
  background: rgba(102, 51, 153, 0.08);
}

.detail-article header h2 {
  font-size: 1.5rem;
  color: var(--color-primary);
  margin: 0.25rem 0 0.15rem 0;
  line-height: 1.2;
}
.detail-article header h3 {
  font-size: 1.15rem;
  color: var(--color-secondary);
  font-weight: 700;
  margin: 0;
}

/* meta row */
.detail-meta {
  display: flex;
  gap: var(--space-m);
  align-items: center;
  margin-top: var(--space-s);
  color: var(--color-text-subtle);
  font-size: 0.95rem;
}

.detail-buy-section {
  background: var(--color-subtle-bg);
  padding: 1.5rem;
  border-radius: var(--radius-m);
  margin-top: 1.5rem;
  text-align: center;
  border: 1px solid var(--color-border-subtle);
}

.detail-buy-section h4 {
  color: var(--color-primary);
  margin-bottom: 0.5rem;
}

.detail-buy-section p {
  color: var(--color-text-subtle);
  margin-bottom: 1rem;
}

/* Content Area - Style JSON Tags Properly */
.content {
  margin-top: var(--space-m);
}

.content h2 {
  font-size: 1.4rem;
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-border-subtle);
  padding-bottom: 0.5rem;
  margin: 1.5rem 0 1rem 0;
}

.content h3 {
  font-size: 1.2rem;
  color: var(--color-secondary);
  font-weight: 700;
  margin: 1.25rem 0 0.75rem 0;
}

.content ul,
.content ol {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

.content ul li,
.content ol li {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  background: var(--color-light-bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  border-radius: var(--radius-s);
  overflow: hidden;
}

.content table th,
.content table td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border-subtle);
}

.content table th {
  background: var(--color-subtle-bg);
  font-weight: 700;
  color: var(--color-secondary);
}

.content table tr:hover {
  background: rgba(102, 51, 153, 0.02);
}

.content p {
  margin-bottom: 1rem;
  line-height: 1.6;
}

/* --- CODE SNIPPET STYLING --- */

.json-snippet-container {
  /* High contrast background to make it 'pop' from the white page */
  background-color: var(--color-code-bg);
  color: #f8f8f2; /* Light text color */
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: var(--space-l);
  border-radius: var(--radius-m);
  overflow-x: auto;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4); /* Stronger shadow */
  line-height: 1.5;
  margin: var(--space-xl) auto; /* Centers and adds vertical spacing */
  max-width: 100%; /* Ensures it fills available space */
}

.json-snippet-container pre {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* JSON Syntax Highlighting */
.json-tag {
  color: #f92672; /* Strong pink/red for the outer element key */
  font-weight: bold;
}
.json-key {
  color: var(--color-code-key); /* Light Purple/Pink for property names */
}

.json-string {
  color: var(--color-code-string); /* Bright Green for string values */
}

.json-number,
.json-boolean {
  color: var(
    --color-code-number
  ); /* Magenta/Purple for numeric/boolean values */
}

.json-punctuation {
  color: #f8f8f2; /* White/Default color for brackets/commas/colons */
}

/* Verbatim - Now for plain text fallback, but use .content for HTML */
.verbatim {
  white-space: pre-wrap;
  font-family: var(--font-serif);
  font-size: 0.96rem;
  color: var(--color-text-verbatim);
  padding: var(--space-m);
  border-radius: var(--radius-s);
  background: #f8f9fa;
  border: 1px solid rgba(75, 46, 5, 0.3);
  text-align: justify;
  hyphens: auto;
  tab-size: 4;
  overflow-x: auto;
  max-width: 100%;
  margin: 1rem 0;
}

.verbatim code {
  font-size: 0.92rem;
  background: rgba(102, 51, 153, 0.05);
  padding: 0.1em 0.3em;
  border-radius: 4px;
}

.detail-article .btn-group {
  display: flex;
  gap: var(--space-m); /* Increased gap for better spacing */
  flex-wrap: wrap;
  margin-top: var(--space-m);
  align-items: center;
}

.kv-row {
  display: flex;
  gap: var(--space-m);
  flex-wrap: wrap;
  align-items: center;
  color: var(--color-text-subtle);
}
.kv-row strong {
  color: var(--color-secondary);
}

/* Modal Styles - Enhanced for better visibility */
.modal {
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: var(--color-modal-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  background-color: var(--color-light-bg);
  padding: 2.5rem;
  border-radius: var(--radius-l);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  max-width: 450px;
  width: 90%;
  position: relative;
  text-align: center;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-content h2 {
  color: var(--color-primary);
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

.modal-content p {
  color: var(--color-secondary);
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

.modal-content strong {
  color: var(--color-primary);
}

.close {
  position: absolute;
  right: 1rem;
  top: 1rem;
  font-size: 2.5rem;
  cursor: pointer;
  color: var(--color-text-subtle);
  line-height: 1;
  transition: color var(--transition-fast);
}

.close:hover {
  color: var(--color-danger);
  transform: scale(1.1);
}

/* Button overrides in modal for better styling */
.modal .btn {
  margin: 0.5rem;
  padding: 0.8rem 1.5rem;
  font-size: 1rem;
  border-radius: var(--radius-m);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.modal .btn.primary {
  background: var(--color-success);
  color: white;
  border: none;
}

.modal .btn.primary:hover {
  background: #218838;
  transform: translateY(-1px);
}

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

.modal .btn:hover {
  background: var(--color-subtle-bg-hover);
}

main {
  padding: 2rem 4rem;
}

/* --- Responsiveness --- */

@media (min-width: 1000px) {
  .detail-article {
    padding: var(--space-xxl);
  }
}

@media (max-width: 999px) {
  .detail-article {
    padding: var(--space-l);
  }
  .chapter-header,
  .sub-item {
    padding-left: var(--space-m);
    padding-right: var(--space-m);
  }
}

/* Mobile: */
@media (max-width: 768px) {
  .chapter-header {
    padding: var(--space-m);
    flex-wrap: wrap; /* Allow wrapping on mobile */
    gap: var(--space-s);
  }

  .chapter-header-controls {
    width: 100%; /* Full width for controls on mobile */
    justify-content: space-between;
    margin-top: var(--space-s);
  }

  .chapter-buy,
  .template-buy {
    font-size: 0.8rem;
    padding: 0.4rem 0.7rem;
    min-width: 90px; /* Slightly smaller on mobile */
  }

  .sub-item {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-s);
  }

  .sub-item-controls {
    width: 100%;
    justify-content: flex-end;
    margin-top: var(--space-s);
  }

  .open-btn,
  .template-buy {
    align-self: flex-end;
  }

  .detail-buy-section {
    padding: 1rem;
  }

  .modal-content {
    padding: 1.5rem;
    margin: 1rem;
  }

  .modal .btn {
    width: 100%;
    margin: 0.25rem 0;
  }

  main {
    padding: 0;
  }

  main.comply {
    padding: 1rem 1.5rem;
  }
}

@media (max-width: 600px) {
  .detail-article {
    padding: 1.25rem;
    border-radius: var(--radius-m);
  }
  .detail-article header h2 {
    font-size: 1.3rem;
  }
  .detail-article header h3 {
    font-size: 1rem;
  }
  main {
    padding: 1rem;
  }

  .btn-group {
    justify-content: center; /* Center buttons on very small screens */
  }
}

/* --- Print Specific Styles --- */

@media print {
  body {
    background: #fff !important;
    color: #000 !important;
  }
  header,
  footer,
  .hamburger,
  .nav-links,
  .chev,
  .open-btn,
  .template-buy,
  .chapter-buy,
  .buy-all-section,
  .read-more,
  .btn,
  .btn-group,
  .modal,
  .json-snippet-container {
    display: none !important;
  }
  .detail-article {
    box-shadow: none;
    border: none;
    padding: 0;
    margin: 0;
  }
  .content h2,
  .content h3 {
    color: #000;
    border-bottom: 1px solid #ccc;
  }
  .content table {
    box-shadow: none;
    border: 1px solid #ccc;
  }
  .content table th,
  .content table td {
    border: 1px solid #ccc;
  }
  .content ul,
  .content ol {
    padding-left: 20px;
  }
  @page {
    margin: 20mm;
  }
}
