/**
 * BaZi Storybook Styles (v1)
 * 
 * Responsive layout with accessibility features.
 * Breakpoint: 768px (desktop vs mobile)
 * Dark theme matching BaZi table styling
 */

/* ===== Container ===== */
.storybook-container {
  width: 100%;
  padding: 0;
  font-family: inherit;
  color: var(--fg, #fff);
  line-height: 1.6;
}

.storybook-loading,
.storybook-error {
  text-align: center;
  padding: 60px 20px;
  font-size: 18px;
  color: var(--muted, rgba(255, 255, 255, 0.7));
}

.storybook-error {
  color: #f44336;
}

.error-detail {
  font-size: 14px;
  color: var(--muted, rgba(255, 255, 255, 0.5));
  margin-top: 10px;
}

/* ===== Block Layout ===== */
.storybook-block {
  margin-bottom: 24px;
  padding: 24px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

@media (max-width: 768px) {
  .storybook-block {
    padding: 20px;
    margin-bottom: 20px;
  }
}

/* ===== Progress Indicator ===== */
.narrative-progress {
  grid-column: 1 / -1;
  margin-bottom: 20px;
}

.progress-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent, #5b8def);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.progress-decorative-line {
  width: 100%;
  height: 2px;
  background: linear-gradient(to right, var(--accent, #5b8def) 40%, rgba(255, 255, 255, 0.1) 40%);
  margin-bottom: 16px;
}

/* ===== Block Layout (nested flex layout from JS) ===== */
.storybook-block-layout {
  display: flex;
  flex-direction: row;
  gap: 40px;
  width: 100%;
}

.storybook-block-visual {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  min-width: 0;
}

.storybook-block-content {
  flex: 1;
  min-width: 0;
  padding: 0;
}

@media (max-width: 768px) {
  .storybook-block-layout {
    flex-direction: column;
    gap: 20px;
  }
  
  .storybook-block-visual {
    width: 100%;
  }
}

/* ===== Visual Column ===== */
.block-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* ===== Text Column ===== */
.block-text {
  padding: 20px;
}

.storybook-block-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--fg, #fff);
  margin: 0 0 16px 0;
}

.storybook-block-text {
  font-size: 15px;
  line-height: 1.8;
  color: var(--fg, #fff);
  margin-bottom: 20px;
  word-spacing: 0.05em; /* Subtle breathing room between words */
}

.storybook-block-text p {
  margin: 0 0 20px 0; /* Increased spacing between paragraphs */
  line-height: 1.8;
}

/* Apply max-width only on mobile where layout stacks vertically */
@media (max-width: 768px) {
  .storybook-block-text {
    max-width: 65ch;
  }
}

.block-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--fg, #fff);
  margin: 0 0 16px 0;
}

.block-ai-text {
  font-size: 15px;
  line-height: 1.8;
  color: var(--fg, #fff);
  margin-bottom: 20px;
  word-spacing: 0.05em; /* Subtle breathing room between words */
}

.block-ai-text p {
  margin: 0 0 20px 0; /* Increased spacing between paragraphs */
  line-height: 1.8;
}

/* Apply max-width only on mobile where layout stacks vertically */
@media (max-width: 768px) {
  .block-ai-text {
    max-width: 65ch;
  }
}

.block-truncated-note {
  font-style: italic;
  color: var(--muted, rgba(255, 255, 255, 0.6));
  font-size: 14px;
}

.block-bridge {
  font-style: italic;
  color: var(--muted, rgba(255, 255, 255, 0.7));
  border-left: 3px solid var(--accent, #5b8def);
  padding-left: 16px;
  margin: 20px 0;
}

.block-closing {
  font-size: 16px;
  color: var(--fg, #fff);
  padding: 20px;
  background: rgba(91, 141, 239, 0.1);
  border: 1px solid rgba(91, 141, 239, 0.2);
  border-radius: 8px;
  margin-top: 20px;
}

/* ===== Four Pillars Chart ===== */
.four-pillars-chart {
  display: flex;
  gap: 12px;
  flex-wrap: nowrap;
  justify-content: center;
}

.pillar {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 1 0;
  min-width: 70px;
  max-width: 140px;
  padding: 12px 10px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.pillar:hover,
.pillar:focus {
  border-color: var(--accent, #5b8def);
  box-shadow: 0 4px 12px rgba(91, 141, 239, 0.3);
  outline: none;
}

.pillar-highlighted {
  border-color: #ff9800;
  box-shadow: 0 0 12px rgba(255, 152, 0, 0.5);
}

.pillar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted, rgba(255, 255, 255, 0.7));
  text-transform: uppercase;
  margin-bottom: 10px;
}

.pillar-stem {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent, #5b8def);
  margin-bottom: 6px;
}

.pillar-branch {
  font-size: 20px;
  color: var(--muted, rgba(255, 255, 255, 0.7));
}

@media (max-width: 480px) {
  .four-pillars-chart {
    gap: 8px;
  }
  
  .pillar {
    min-width: 60px;
    padding: 10px 8px;
  }
  
  .pillar-stem {
    font-size: 24px;
  }
  
  .pillar-branch {
    font-size: 16px;
  }
  
  .pillar-label {
    font-size: 10px;
  }
}

/* ===== Strength Gauge ===== */
.strength-gauge {
  width: 100%;
  max-width: 400px;
}

.gauge-bar {
  width: 100%;
  height: 24px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
}

.gauge-fill {
  height: 100%;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 12px;
}

.gauge-fill-blue {
  background: linear-gradient(90deg, #5b8def 0%, #7ba3f0 100%);
}

.gauge-fill-green {
  background: linear-gradient(90deg, #4caf50 0%, #66bb6a 100%);
}

.gauge-fill-orange {
  background: linear-gradient(90deg, #ff9800 0%, #ffb74d 100%);
}

.gauge-label {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg, #fff);
}

@media (max-width: 768px) {
  .strength-gauge {
    max-width: none;
    width: 100%;
  }
}

/* ===== Element Distribution ===== */
.element-distribution {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: 300px;
}

.element-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  font-size: 14px;
}

.element-label {
  min-width: 60px;
  font-weight: 600;
  color: var(--fg, #fff);
}

.element-bar {
  flex: 1;
  height: 24px;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.element-bar-fire {
  background: #d32f2f;
}

.element-bar-water {
  background: #1976d2;
}

.element-bar-wood {
  background: #388e3c;
}

.element-bar-metal {
  background: #616161;
}

.element-bar-earth {
  background: #795548;
}

.element-count {
  min-width: 30px;
  text-align: right;
  font-weight: 600;
  color: var(--fg, #fff);
}

/* ===== Interaction Diagram ===== */
.interaction-diagram {
  width: 100%;
}

.interaction-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  margin-bottom: 16px;
  background: rgba(0, 0, 0, 0.2);
  border-left: 4px solid var(--accent, #5b8def);
  border-radius: 6px;
  transition: all 0.2s ease;
}

.interaction-item:hover,
.interaction-item:focus {
  background: rgba(91, 141, 239, 0.15);
  outline: 2px solid var(--accent, #5b8def);
  outline-offset: 2px;
}

.interaction-icon {
  font-size: 24px;
  margin-right: 8px;
}

.interaction-pillar {
  font-weight: 600;
  color: var(--fg, #fff);
}

.interaction-arrow {
  margin: 0 8px;
  color: var(--muted, rgba(255, 255, 255, 0.6));
}

.interaction-type {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-block;
}

.interaction-severity-high {
  background: #ffebee;
  color: #d32f2f;
}

.interaction-severity-medium {
  background: #fff3e0;
  color: #f57c00;
}

.interaction-severity-low {
  background: #e8f5e9;
  color: #388e3c;
}

.interaction-description {
  font-size: 14px;
  color: var(--fg, #fff);
  margin: 8px 0 0 0;
}

.interaction-empty {
  text-align: center;
  color: var(--muted, rgba(255, 255, 255, 0.5));
  font-style: italic;
  padding: 20px;
}

/* ===== Evidence Panel ===== */
.evidence-panel-container {
  margin-top: 24px;
}

.evidence-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: rgba(76, 175, 80, 0.08);
  border: 1px solid rgba(76, 175, 80, 0.2);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: rgba(76, 175, 80, 0.9);
  transition: all 0.2s ease;
  min-height: 44px;
  min-width: 44px;
  width: fit-content;
}

.evidence-toggle:hover {
  background: rgba(76, 175, 80, 0.12);
  border-color: rgba(76, 175, 80, 0.3);
  color: #4caf50;
  transform: translateY(-1px);
}

.evidence-toggle:focus {
  outline: 2px solid var(--accent, #5b8def);
  outline-offset: 2px;
}

.evidence-toggle[aria-expanded="true"] {
  background: rgba(76, 175, 80, 0.15);
  border-color: #4caf50;
  color: #4caf50;
}

.evidence-icon {
  font-size: 18px;
}

.evidence-panel {
  margin-top: 16px;
  padding: 20px;
  background: rgba(76, 175, 80, 0.05);
  border: 1px solid rgba(76, 175, 80, 0.2);
  border-left: 4px solid #4caf50;
  border-radius: 8px;
  animation: slideDown 0.3s ease-out;
}

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

.trust-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: rgba(76, 175, 80, 0.12);
  border: 1px solid rgba(76, 175, 80, 0.25);
  border-radius: 8px;
  margin-bottom: 20px;
}

.trust-icon {
  font-size: 18px;
  color: #4caf50;
  font-weight: 700;
}

.trust-text {
  font-size: 14px;
  color: #66bb6a;
  font-weight: 600;
  line-height: 1.4;
}

.evidence-list {
  list-style: none;
  padding: 0;
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.evidence-list li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  border-left: 3px solid rgba(76, 175, 80, 0.4);
  transition: all 0.2s ease;
}

.evidence-list li:hover {
  background: rgba(255, 255, 255, 0.05);
  border-left-color: #66bb6a;
  transform: translateX(2px);
}

.evidence-icon-bullet {
  font-size: 16px;
  color: #4caf50;
  flex-shrink: 0;
  margin-top: 2px;
}

.evidence-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.evidence-label-text {
  font-size: 14px;
  line-height: 1.4;
  color: var(--fg, #fff);
  font-weight: 600;
}

.evidence-value {
  font-size: 13px;
  line-height: 1.5;
  color: #66bb6a;
  font-weight: 500;
  padding: 6px 10px;
  background: rgba(76, 175, 80, 0.08);
  border-radius: 4px;
  border-left: 2px solid rgba(76, 175, 80, 0.3);
  font-family: system-ui, -apple-system, sans-serif;
}

.evidence-technical-id {
  font-size: 10px;
  color: var(--muted, rgba(255, 255, 255, 0.35));
  background: rgba(0, 0, 0, 0.3);
  padding: 3px 7px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  align-self: flex-start;
  cursor: help;
  margin-top: 2px;
}

.computation-note {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 13px;
  color: var(--muted, rgba(255, 255, 255, 0.7));
  line-height: 1.6;
}

/* ===== CTAs ===== */
.storybook-expand-cta {
  text-align: center;
  margin: 40px 0;
}

.storybook-expand-btn {
  padding: 14px 28px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--accent, #5b8def);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.storybook-expand-btn:hover {
  background: #4a7dd8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(91, 141, 239, 0.4);
}

.storybook-expand-btn:focus {
  outline: 2px solid var(--accent, #5b8def);
  outline-offset: 4px;
}

.storybook-paid-cta {
  margin: 32px 0;
  padding: 24px;
  background: rgba(91, 141, 239, 0.08);
  border: 1px solid rgba(91, 141, 239, 0.2);
  border-radius: 12px;
  text-align: left;
}

.storybook-paid-cta h4 {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent, #5b8def);
  margin: 0 0 12px 0;
}

.storybook-paid-cta p {
  margin: 0 0 16px 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted, rgba(255, 255, 255, 0.7));
}

.storybook-paid-cta ul {
  margin: 0 0 16px 0;
  padding-left: 20px;
  list-style: none;
}

.storybook-paid-cta li {
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.8;
  color: var(--fg, #fff);
}

.cta-buttons {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.cta-btn {
  flex: 1;
  min-width: 200px;
  padding: 14px 24px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--accent, #5b8def);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cta-btn:hover {
  background: #4a7dd8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(91, 141, 239, 0.4);
}

.cta-btn:focus {
  outline: 2px solid var(--accent, #5b8def);
  outline-offset: 4px;
}

.cta-badge {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.9;
}

/* ===== Thesis ===== */
.storybook-thesis {
  margin: 24px 0;
  padding: 24px;
  background: rgba(76, 175, 80, 0.1);
  border-left: 4px solid #4caf50;
  border-radius: 8px;
}

.storybook-thesis h3 {
  margin: 0 0 12px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--fg, #fff);
}

.storybook-thesis p {
  margin: 0;
  font-size: 15px;
  line-height: 1.7;
  color: var(--fg, #fff);
}

/* ===== Partial State ===== */
.storybook-partial-banner {
  padding: 24px;
  background: #FFF3CD; /* Standard warning yellow */
  border: 2px solid #FFA000;
  border-radius: 8px;
  margin-bottom: 32px;
  box-shadow: 0 2px 8px rgba(255, 152, 0, 0.2);
}

.storybook-partial-banner p {
  margin: 0 0 20px 0;
  color: #856404; /* Dark brown for high contrast on yellow */
  font-size: 16px;
  line-height: 1.6;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.storybook-partial-banner p strong {
  color: #6B4C00; /* Even darker for emphasis */
}

/* Warning icon styling */
.storybook-partial-banner p::before {
  content: '⚠️';
  font-size: 24px;
  flex-shrink: 0;
  line-height: 1;
}

.retry-btn,
.fallback-btn {
  padding: 14px 28px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-right: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  min-height: 44px; /* Touch target size */
}

.retry-btn {
  background: #1976D2; /* Prominent blue */
  color: #fff;
  box-shadow: 0 2px 4px rgba(25, 118, 210, 0.3);
}

.retry-btn:hover {
  background: #1565C0;
  box-shadow: 0 4px 8px rgba(25, 118, 210, 0.4);
  transform: translateY(-1px);
}

.retry-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(25, 118, 210, 0.3);
}

.fallback-btn {
  background: #fff;
  color: #424242;
  border: 2px solid #BDBDBD;
}

.fallback-btn:hover {
  background: #F5F5F5;
  border-color: #9E9E9E;
}

/* ===== Focus Indicators (Accessibility) ===== */
.storybook-container *:focus-visible {
  outline: 2px solid var(--accent, #5b8def);
  outline-offset: 2px;
}

/* ===== Skip Links ===== */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #1976d2;
  color: #fff;
  padding: 8px;
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  top: 0;
}

/* ===== Responsive Adjustments ===== */
@media (max-width: 768px) {
  .cta-buttons {
    flex-direction: column;
  }
  
  .cta-btn {
    min-width: 100%;
  }
}

/* ===== Print Styles ===== */
@media print {
  .evidence-panel-container,
  .storybook-expand-cta,
  .storybook-paid-cta {
    display: none;
  }
  
  .storybook-block {
    page-break-inside: avoid;
  }
}

