/**
 * Checklist Directive
 * Styled checklist containers for bullet lists and task lists
 */

/* Base Checklist Styles */
.checklist {
  position: relative;
  margin-block: 1.5rem;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  box-shadow: var(--elevation-card);
}

/* Checklist Header (title + progress inline) */
.checklist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

/* Checklist Title - Prominent heading style */
.checklist-title {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.checklist-title::before {
  content: '✓';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  flex-shrink: 0;
}

/* Checklist Content */
.checklist-content {
  position: relative;
}

/* List styling in checklists */
.checklist-content ul,
.checklist-content ol {
  margin: 0;
  padding-inline-start: 0;
  list-style: none;
}

.checklist-content li {
  position: relative;
  padding-inline-start: 1.5rem;
  margin: var(--space-2) 0;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--color-text-secondary);
}

/* Bullet styling for regular lists (non-task lists) */
.checklist-content ul > li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--color-primary);
  font-weight: var(--weight-medium);
  font-size: 1em;
}

/* Hide bullet arrows when checklist has task items (checkboxes) */
.checklist-has-tasks .checklist-content ul > li::before {
  content: none;
}

/* Task list styling (checkboxes) */
.checklist-content input[type="checkbox"] {
  position: absolute;
  left: 0;
  top: 0.125rem;
  margin: 0;
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  accent-color: var(--color-primary);
}

/* Styled checkbox appearance */
.checklist-content input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-bg);
  transition: all var(--transition-base);
}

.checklist-content input[type="checkbox"]:checked {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M2 6l3 3 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 0.75rem;
}

.checklist-content input[type="checkbox"]:hover {
  border-color: var(--color-primary);
}

.checklist-content input[type="checkbox"]:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Completed task styling */
.checklist-content li:has(input[type="checkbox"]:checked) {
  color: var(--color-text-secondary);
  text-decoration: line-through;
  opacity: 0.7;
}

/* Nested lists */
.checklist-content ul ul,
.checklist-content ol ol {
  margin-top: 0.5rem;
  padding-inline-start: 1.5rem;
}

.checklist-content ul ul > li::before {
  content: '◦';
  color: var(--color-text-secondary);
}

/* Dark theme adjustments */
[data-theme="dark"] .checklist {
  background: var(--color-bg-secondary);
}

[data-theme="dark"] .checklist-content input[type="checkbox"] {
  background-color: var(--color-bg-tertiary);
  border-color: var(--color-border);
}

[data-theme="dark"] .checklist-content input[type="checkbox"]:checked {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
}

/* Spacing adjustments */
.checklist-content > *:first-child {
  margin-top: 0;
}

.checklist-content > *:last-child {
  margin-bottom: 0;
}

/* Code blocks in checklists */
.checklist-content pre {
  margin: 0.75rem 0;
}

.checklist-content code {
  background-color: rgba(0, 0, 0, 0.05);
  padding: 0.125rem 0.25rem;
  border-radius: var(--radius-sm);
}

[data-theme="dark"] .checklist-content code {
  background-color: rgba(255, 255, 255, 0.1);
}

/* ==============================================
   CHECKLIST VARIANTS & OPTIONS
   ============================================== */

/* Style: Numbered - Show numbers instead of bullets */
.checklist-numbered .checklist-content ul {
  counter-reset: checklist-item;
}

.checklist-numbered .checklist-content ul > li::before {
  counter-increment: checklist-item;
  content: counter(checklist-item) '.';
  font-weight: var(--weight-semibold);
  font-size: 0.9em;
  min-width: 1.25em;
}

/* Compact spacing */
.checklist-compact {
  padding: var(--space-2) var(--space-3);
}

.checklist-compact .checklist-content li {
  margin: var(--space-1) 0;
  font-size: var(--text-xs);
}

/* Progress indicator (inline with header)
 * Compact design: [1/3] [████░░░░]
 * Text comes first for readability, then visual bar
 */
.checklist-progress {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Progress text: "1/3" */
.checklist-progress-text {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;  /* Fixed-width numbers for stability */
}

/* Track is the progress bar background */
.checklist-progress-track {
  width: 3.5rem;  /* Fixed width for consistency */
  height: 4px;
  background: var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

/* Bar fills the track based on percentage */
.checklist-progress-bar {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width var(--transition-base);
  position: relative;
  overflow: hidden;
}

/* Subtle shimmer animation on progress bar */
.checklist-progress-bar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 100%
  );
  animation: progress-shimmer 2s infinite;
}

@keyframes progress-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Dark mode progress */
[data-theme="dark"] .checklist-progress-track {
  background: var(--color-border-dark);
}

[data-theme="dark"] .checklist-progress-bar::before {
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.1) 50%,
    transparent 100%
  );
}
