/* ============================================
   California Rules of Court — CaseMirror
   ============================================
   Extends the base CaseMirror design system
   with rule-specific styling and recursive
   inline expansion components.
   ============================================ */

/* ============================================
   Rules Page Layout
   ============================================ */
.rules-view {
  max-width: var(--max-width);
  margin: 0 auto;
}

.rules-page-header {
  text-align: center;
  margin-bottom: var(--space-2xl);
  padding-bottom: var(--space-xl);
  border-bottom: 1px solid var(--color-border);
}

.rules-page-title {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 600;
  color: var(--color-ink);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

/* State outline in rules header */
.rules-header-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.state-outline-container {
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.rules-page-header:hover .state-outline-container {
  opacity: 1;
}

.rules-page-subtitle {
  font-family: var(--font-ui);
  font-size: 1.125rem;
  color: var(--color-ink-muted);
  max-width: 600px;
  margin: 0 auto;
}

.rules-stats-bar {
  justify-content: center;
  gap: var(--space-2xl);
  margin-bottom: var(--space-xl);
}

/* ============================================
   Search Container
   ============================================ */
.rules-search-container {
  max-width: 600px;
  margin: 0 auto var(--space-2xl);
}

.rules-search-container .search-box {
  position: relative;
}

.rules-search-container .search-input {
  width: 100%;
  padding: var(--space-md) var(--space-lg);
  font-size: 1rem;
  border: 2px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-white);
  transition: all var(--transition-fast);
}

.rules-search-container .search-input:focus {
  outline: none;
  border-color: var(--color-burgundy);
  box-shadow: 0 0 0 3px rgba(139, 38, 53, 0.1);
}

.rules-search-container .search-clear {
  position: absolute;
  right: var(--space-md);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--color-ink-muted);
  cursor: pointer;
  padding: var(--space-xs);
  line-height: 1;
}

.rules-search-container .search-clear:hover {
  color: var(--color-ink);
}

/* ============================================
   Titles Grid
   ============================================ */
.titles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-2xl);
}

.title-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: var(--space-xl);
  transition: all var(--transition-base);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.title-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--color-burgundy);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.title-card:hover {
  border-color: var(--color-burgundy-light);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.title-card:hover::before {
  opacity: 1;
}

.title-card-number {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-burgundy);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-xs);
}

.title-card-name {
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--color-ink);
  line-height: 1.3;
  margin-bottom: var(--space-md);
}

.title-card-count {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-ink-muted);
  background: var(--color-paper);
  padding: var(--space-xs) var(--space-sm);
  border-radius: 4px;
}

/* Skeleton loading */
.title-card-skeleton {
  pointer-events: none;
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-paper-darker) 25%,
    var(--color-paper) 50%,
    var(--color-paper-darker) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: 4px;
}

.skeleton-title {
  height: 14px;
  width: 80px;
  margin-bottom: var(--space-sm);
}

.skeleton-text {
  height: 24px;
  width: 100%;
  margin-bottom: var(--space-md);
}

.skeleton-badge {
  height: 28px;
  width: 100px;
}

.skeleton-paragraph {
  height: 16px;
  width: 100%;
  margin-bottom: var(--space-sm);
}

.skeleton-paragraph.short {
  width: 60%;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ============================================
   Search Results
   ============================================ */
.search-results {
  margin-bottom: var(--space-2xl);
}

.search-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border);
}

.search-results-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-ink);
}

.clear-search-btn {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-burgundy);
  background: none;
  border: 1px solid var(--color-burgundy);
  padding: var(--space-xs) var(--space-md);
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.clear-search-btn:hover {
  background: var(--color-burgundy);
  color: var(--color-white);
}

.search-results-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.search-result-item {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: var(--space-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.search-result-item:hover {
  border-color: var(--color-burgundy-light);
  box-shadow: var(--shadow-sm);
}

.search-result-number {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-burgundy);
  margin-bottom: var(--space-xs);
}

.search-result-name {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--color-ink);
  margin-bottom: var(--space-sm);
}

.search-result-headline {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: var(--color-ink-muted);
  line-height: 1.5;
}

.search-result-headline mark {
  background: rgba(139, 38, 53, 0.15);
  color: var(--color-ink);
  padding: 0 2px;
  border-radius: 2px;
}

/* ============================================
   Title Index View
   ============================================ */
.title-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  margin-bottom: var(--space-lg);
  color: var(--color-ink-muted);
}

.title-index-header {
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 2px solid var(--color-border);
}

.title-index-name {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
  color: var(--color-ink);
  line-height: 1.25;
  margin-bottom: var(--space-xs);
}

.title-index-meta {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-ink-muted);
}

.title-index-count {
  font-style: italic;
}

.title-rules-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.title-rule-item {
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease;
  cursor: pointer;
}

.title-rule-item:hover {
  background-color: var(--color-surface-alt);
}

.title-rule-item-number {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-burgundy);
  min-width: 80px;
  flex-shrink: 0;
}

.title-rule-item-name {
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--color-ink);
  flex: 1;
}

.title-rule-item-skeleton {
  height: 48px;
  padding: var(--space-sm) var(--space-md);
}

/* ============================================
   Rule Detail View
   ============================================ */
.rule-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  margin-bottom: var(--space-lg);
  color: var(--color-ink-muted);
}

.breadcrumb-link {
  color: var(--color-burgundy);
  text-decoration: none;
}

.breadcrumb-link:hover {
  text-decoration: underline;
}

.breadcrumb-separator {
  color: var(--color-ink-muted);
}

.breadcrumb-current {
  color: var(--color-ink);
}

.rule-header {
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 2px solid var(--color-border);
}

.rule-header-main {
  margin-bottom: var(--space-md);
}

.rule-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-burgundy);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-xs);
}

.rule-number {
  font-weight: 600;
}

.rule-name {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
  color: var(--color-ink);
  line-height: 1.25;
}

.rule-meta {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-ink-muted);
}

.rule-citation {
  font-family: var(--font-ui);
  font-style: italic;
}

/* ============================================
   Expansion Controls
   ============================================ */
.expansion-controls {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  background: var(--color-paper-darker);
  border-radius: 8px;
  flex-wrap: wrap;
}

.expansion-label {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-ink);
}

.expansion-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-ink-light);
  background: var(--color-white);
  border: 1px solid var(--color-border);
  padding: var(--space-xs) var(--space-md);
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.expansion-btn:hover {
  color: var(--color-burgundy);
  border-color: var(--color-burgundy);
  background: var(--color-white);
}

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

.expansion-btn svg {
  width: 14px;
  height: 14px;
}

.expansion-count {
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  color: var(--color-ink-muted);
  margin-left: auto;
}

/* ============================================
   Rule Content
   ============================================ */
.rule-content {
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--color-ink);
}

.rule-text {
  margin-bottom: var(--space-lg);
}

.rule-text p {
  margin-bottom: var(--space-md);
}

/* ============================================
   Subdivision Indentation (like official CRC)
   ============================================ */

/* Main subdivisions: (a), (b), (c) - bold, at left margin */
.subdiv {
  margin-bottom: var(--space-sm);
  line-height: 1.7;
}

.subdiv-main {
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
}

.subdiv-main:first-child {
  margin-top: 0;
}

.subdiv-main .subdiv-label,
.subdiv-main .subdiv-heading {
  font-weight: 600;
}

/* Body text under subdivisions - indented */
.subdiv-body {
  margin-left: 2rem;
  margin-bottom: var(--space-sm);
}

/* Numbered sub-subdivisions: (1), (2), (3) - indented */
.subdiv-numbered {
  margin-left: 2rem;
  text-indent: -1.5rem;
  padding-left: 1.5rem;
}

.subdiv-numbered .subdiv-label {
  display: inline-block;
  min-width: 1.5rem;
  text-indent: 0;
}

/* Lettered sub-sub-subdivisions: (A), (B), (C) - further indented */
/* Subtle visual differentiation via typography only (no border/background to avoid confusion with expanded rules) */
.subdiv-lettered {
  margin-left: 4rem;
  text-indent: -1.5rem;
  padding-left: 1.5rem;
  font-weight: normal;
  font-size: 0.95em;
  line-height: 1.65;
  color: var(--color-ink-light);
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
}

.subdiv-lettered .subdiv-label {
  display: inline-block;
  min-width: 1.5rem;
  text-indent: 0;
  font-weight: 500;
  color: var(--color-ink-muted);
  font-size: 0.9em;
  letter-spacing: 0.02em;
}

/* Roman numeral sub-subdivisions: (i), (ii), (iii) - even further indented */
.subdiv-roman {
  margin-left: 6rem;
  text-indent: -1.75rem;
  padding-left: 1.75rem;
}

.subdiv-roman .subdiv-label {
  display: inline-block;
  min-width: 1.75rem;
  text-indent: 0;
}

/* Subdivision history notes (e.g., "(Subd (a) amended effective...") */
.subdiv-history {
  margin-left: 2rem;
  margin-top: var(--space-sm);
  margin-bottom: var(--space-md);
  font-size: 0.875rem;
  font-style: italic;
  color: var(--color-ink-muted);
}

/* Full rule history at end */
.rule-history-text {
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border);
  font-size: 0.875rem;
  color: var(--color-ink-muted);
}

/* Advisory Committee Comment header */
.advisory-comment-header {
  margin-top: var(--space-lg);
  font-weight: 600;
  font-style: italic;
}

/* Subdivision labels */
.subdiv-label {
  color: var(--color-ink);
}

/* Rule reference links in text */
.rule-ref {
  color: var(--color-burgundy);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 1px dashed var(--color-burgundy-light);
  transition: all var(--transition-fast);
}

.rule-ref:hover {
  color: var(--color-burgundy-dark);
  border-bottom-style: solid;
}

/* Form References - External links to CA Courts forms */
.form-ref {
  color: var(--color-sage);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 1px dashed var(--color-sage);
}

.form-ref:hover {
  color: var(--color-sage-dark);
  border-bottom-style: solid;
}

.form-ref::after {
  content: "↗";
  font-size: 0.75em;
  margin-left: 2px;
  opacity: 0.7;
}

/* ============================================
   Nested Rule Expansion (Key Feature)
   ============================================ */
.nested-rule {
  margin: var(--space-lg) 0;
  border-left: 3px solid var(--color-burgundy);
  background: linear-gradient(to right, rgba(139, 38, 53, 0.04), transparent 20%);
  border-radius: 0 8px 8px 0;
  overflow: hidden;
  animation: nested-rule-enter 0.3s ease-out;
}

@keyframes nested-rule-enter {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.nested-rule-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  background: rgba(139, 38, 53, 0.06);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
}

.nested-rule-header:hover {
  background: rgba(139, 38, 53, 0.1);
}

.nested-rule-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nested-rule-number {
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-burgundy);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.nested-rule-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-ink);
}

.nested-rule-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-ink-muted);
  transition: all var(--transition-fast);
}

.nested-rule-toggle:hover {
  border-color: var(--color-burgundy);
  color: var(--color-burgundy);
}

.nested-rule-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform var(--transition-fast);
}

.nested-rule.collapsed .nested-rule-toggle svg {
  transform: rotate(-90deg);
}

.nested-rule-body {
  padding: var(--space-lg);
  overflow: hidden;
  transition: all var(--transition-base);
}

.nested-rule.collapsed .nested-rule-body {
  display: none;
}

/* Depth indicators for deeply nested rules */
.nested-rule[data-depth="1"] {
  border-left-color: var(--color-burgundy);
}

.nested-rule[data-depth="2"] {
  border-left-color: var(--color-burgundy-light);
  margin-left: var(--space-md);
}

.nested-rule[data-depth="3"] {
  border-left-color: #c4707d;
  margin-left: var(--space-lg);
}

.nested-rule[data-depth="4"],
.nested-rule[data-depth="5"] {
  border-left-color: var(--color-border);
  margin-left: var(--space-xl);
}

/* Indentation levels match the context where the rule reference appears */
/* Level 0: Main text / subdivision header - no extra indent */
.nested-rule[data-indent-level="0"] {
  margin-left: 0;
}

/* Level 1: Within numbered (1) or body text - 2rem indent */
.nested-rule[data-indent-level="1"] {
  margin-left: 2rem;
}

/* Level 2: Within lettered (A) - 4rem indent */
.nested-rule[data-indent-level="2"] {
  margin-left: 4rem;
}

/* Level 3: Within roman (i) - 6rem indent */
.nested-rule[data-indent-level="3"] {
  margin-left: 6rem;
}

/* ============================================
   Nested Code Section Expansion (Statutes)
   ============================================
   Similar to nested-rule but with green tint
   to visually distinguish statutes from CRC rules
   ============================================ */
.nested-code-section {
  margin: var(--space-lg) 0;
  border-left: 3px solid #2e7d32; /* Green for statutes */
  background: linear-gradient(to right, rgba(46, 125, 50, 0.04), transparent 20%);
  border-radius: 0 8px 8px 0;
  overflow: hidden;
  animation: nested-rule-enter 0.3s ease-out;
}

.nested-code-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  background: rgba(46, 125, 50, 0.06);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
}

.nested-code-section-header:hover {
  background: rgba(46, 125, 50, 0.1);
}

.nested-code-section-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nested-code-section-name {
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 600;
  color: #1b5e20; /* Dark green */
}

.code-section-source {
  font-size: 0.75rem;
  color: var(--color-ink-muted);
  text-decoration: none;
}

.code-section-source:hover {
  color: #2e7d32;
  text-decoration: underline;
}

.nested-code-section-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-ink-muted);
  transition: all var(--transition-fast);
}

.nested-code-section-toggle:hover {
  border-color: #2e7d32;
  color: #2e7d32;
}

.nested-code-section-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform var(--transition-fast);
}

.nested-code-section.collapsed .nested-code-section-toggle svg {
  transform: rotate(-90deg);
}

.nested-code-section-body {
  padding: var(--space-lg);
  overflow: hidden;
  transition: all var(--transition-base);
}

.nested-code-section.collapsed .nested-code-section-body {
  display: none;
}

.code-section-text {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--color-ink);
  white-space: pre-wrap;
}

.code-section-pending {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-ink-muted);
  font-style: italic;
}

.code-section-pending a {
  color: #2e7d32;
  text-decoration: none;
}

.code-section-pending a:hover {
  text-decoration: underline;
}

/* Indentation levels for code sections (same as rules) */
.nested-code-section[data-indent-level="0"] {
  margin-left: 0;
}

.nested-code-section[data-indent-level="1"] {
  margin-left: 2rem;
}

.nested-code-section[data-indent-level="2"] {
  margin-left: 4rem;
}

.nested-code-section[data-indent-level="3"] {
  margin-left: 6rem;
}

/* Code reference styling in rule text */
.code-ref {
  color: #1b5e20;
  font-weight: 500;
  text-decoration: none;
}

a.code-ref:hover {
  text-decoration: underline;
  color: #0d3d0f;
}

a.code-ref:visited {
  color: #2e7d32;
}

/* ============================================
   Cited By Section
   ============================================ */
.cited-by-section {
  margin-top: var(--space-2xl);
  padding-top: var(--space-xl);
  border-top: 1px solid var(--color-border);
}

.cited-by-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-ink);
  margin-bottom: var(--space-lg);
}

.cited-by-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.cited-by-item {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-burgundy);
  background: var(--color-white);
  border: 1px solid var(--color-border);
  padding: var(--space-xs) var(--space-md);
  border-radius: 20px;
  text-decoration: none;
  transition: all var(--transition-fast);
}

.cited-by-item:hover {
  background: var(--color-burgundy);
  color: var(--color-white);
  border-color: var(--color-burgundy);
}

.cited-by-empty {
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  color: var(--color-ink-muted);
  font-style: italic;
}

/* ============================================
   Footer
   ============================================ */
.main-footer {
  margin-top: auto;
  padding: var(--space-xl) var(--space-lg);
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
}

.footer-content {
  max-width: var(--max-width);
  margin: 0 auto;
  text-align: center;
}

.footer-text {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-ink-muted);
  margin-bottom: var(--space-xs);
}

.footer-text a {
  color: var(--color-burgundy);
}

.footer-disclaimer {
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  color: var(--color-ink-muted);
  opacity: 0.8;
}

/* ============================================
   Rule History Section
   ============================================ */
.rule-history-section {
  margin-top: var(--space-2xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}

.rule-history-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-ink-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.rule-history-toggle:hover {
  background: var(--color-cream);
  border-color: var(--color-burgundy-light);
  color: var(--color-burgundy);
}

.rule-history-toggle svg {
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
}

.rule-history-toggle.expanded svg {
  transform: rotate(180deg);
}

.rule-history-content {
  margin-top: var(--space-md);
  padding: var(--space-md);
  background: var(--color-cream);
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-ink-muted);
  line-height: 1.6;
}

/* ============================================
   Utilities
   ============================================ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
  .rules-page-title {
    font-size: 1.75rem;
  }

  .rules-page-subtitle {
    font-size: 1rem;
  }

  .titles-grid {
    grid-template-columns: 1fr;
  }

  .title-card {
    padding: var(--space-lg);
  }

  .rule-name {
    font-size: 1.5rem;
  }

  .expansion-controls {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .expansion-count {
    margin-left: 0;
    margin-top: var(--space-xs);
  }

  .nested-rule {
    margin-left: 0 !important;
  }
}

/* ============================================
   Settings Panel
   ============================================ */
.settings-wrapper {
  position: relative;
  margin-left: auto;
}

.expansion-controls .settings-wrapper {
  margin-left: var(--space-lg);
}

.settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-ink-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.settings-btn:hover {
  background: var(--color-cream);
  border-color: var(--color-burgundy-light);
  color: var(--color-burgundy);
}

.settings-panel {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: var(--space-xs);
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 280px;
  padding: var(--space-md);
  z-index: 100;
}

.settings-option {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-ink);
  padding: var(--space-sm) 0;
}

.settings-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-burgundy);
  cursor: pointer;
}

.settings-option-text {
  line-height: 1.4;
}

/* ============================================
   Footer Official Link
   ============================================ */
.footer-official-link {
  margin: var(--space-sm) 0;
}

.footer-official-link a {
  color: var(--color-burgundy);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.footer-official-link a:hover {
  color: var(--color-burgundy-dark);
  text-decoration: underline;
}

/* ============================================
   Logo Tagline Alignment
   ============================================ */
.logo-tagline {
  position: relative;
  top: -2px;
}

/* ============================================
   Column View Mode
   ============================================ */
#rule-detail-view.column-view-enabled {
  /* Container for scroll snapping */
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  height: calc(100vh - var(--header-height, 64px) - 40px);
  scroll-behavior: smooth;
}

#rule-detail-view.column-view-enabled .rule-content {
  /* CSS columns for multi-column layout */
  column-width: 350px;
  column-gap: var(--space-xl);
  column-fill: auto;
  /* Height fills available viewport */
  height: calc(100vh - var(--header-height, 64px) - 250px);
}

#rule-detail-view.column-view-enabled .rule-content > * {
  /* Prevent elements from breaking across columns */
  break-inside: avoid;
}

/* Page container for snap scrolling */
#rule-detail-view.column-view-enabled .column-page {
  scroll-snap-align: start;
  min-height: calc(100vh - var(--header-height, 64px) - 250px);
}

/* Subtle column separator */
#rule-detail-view.column-view-enabled .rule-content {
  column-rule: 1px solid var(--color-border-light, #e5e5e5);
}

/* Ensure expansions work within columns */
#rule-detail-view.column-view-enabled .code-expansion,
#rule-detail-view.column-view-enabled .rule-expansion {
  break-inside: avoid;
}

/* Mobile: single column fallback */
@media (max-width: 768px) {
  #rule-detail-view.column-view-enabled .rule-content {
    column-width: auto;
    column-count: 1;
    height: auto;
  }

  #rule-detail-view.column-view-enabled {
    height: auto;
    overflow-y: visible;
    scroll-snap-type: none;
  }
}

/* ============================================
   Jurisdiction Not Available Message
   ============================================ */
.jurisdiction-not-available {
  text-align: center;
  padding: var(--space-2xl) var(--space-xl);
  max-width: 600px;
  margin: var(--space-2xl) auto;
}

.not-available-message {
  font-size: 1.25rem;
  color: var(--color-ink);
  margin-bottom: var(--space-lg);
}

.not-available-hint {
  color: var(--color-ink-muted);
  margin-bottom: var(--space-xl);
}

.not-available-hint a {
  color: var(--color-link);
  text-decoration: none;
}

.not-available-hint a:hover {
  text-decoration: underline;
}

.not-available-cta {
  margin-top: var(--space-lg);
}

.back-to-ca-rules {
  display: inline-block;
  padding: var(--space-sm) var(--space-lg);
  background: var(--color-primary);
  color: white;
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 500;
  transition: background-color 0.2s;
}

.back-to-ca-rules:hover {
  background: var(--color-primary-dark);
  text-decoration: none;
}

/* ============================================
   Rule Navigation (prev/next)
   ============================================ */

.rule-nav {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  padding: var(--space-md);
  background: var(--color-background-alt);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.rule-nav.hidden {
  display: none;
}

.rule-nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  text-decoration: none;
  color: var(--color-text);
  border-radius: var(--radius-sm);
  transition:
    background-color 0.15s,
    color 0.15s;
  min-width: 0;
  flex: 1;
}

.rule-nav-link.nav-prev {
  justify-content: flex-start;
}

.rule-nav-link.nav-next {
  justify-content: flex-end;
  text-align: right;
}

.rule-nav-link:hover:not(.disabled) {
  background: var(--color-background);
  color: var(--color-primary);
}

.rule-nav-link.disabled {
  opacity: 0.4;
  pointer-events: none;
  cursor: default;
}

.rule-nav-arrow {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--color-primary);
  flex-shrink: 0;
}

.rule-nav-link.disabled .rule-nav-arrow {
  color: var(--color-text-muted);
}

.rule-nav-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
}

.rule-nav-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.rule-nav-heading {
  font-size: 0.875rem;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rule-nav-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 var(--space-xs);
  font-size: 0.75rem;
  font-family: inherit;
  color: var(--color-text-muted);
  background: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xs);
  flex-shrink: 0;
}

/* Responsive: hide heading and kbd on small screens */
@media (max-width: 640px) {
  .rule-nav {
    gap: var(--space-sm);
    padding: var(--space-sm);
  }

  .rule-nav-link {
    padding: var(--space-xs) var(--space-sm);
  }

  .rule-nav-heading {
    display: none;
  }

  .rule-nav-kbd {
    display: none;
  }
}
