/**
 * ZWDS Chart Visualization Styles
 * Comprehensive CSS for 12-palace chart rendering and interactions
 */

/* =================
   CHART CONTAINER
   ================= */

.zwds-chart-container {
  width: 100%;
  height: 100%;
  min-height: 400px;
  position: relative;
  background: #fafafa;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.zwds-chart {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Chart loading states */
.zwds-chart.loading,
.zwds-chart.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  font-size: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.loading-spinner::before {
  content: "";
  width: 24px;
  height: 24px;
  border: 2px solid #e6e6e6;
  border-top: 2px solid #531dab;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* =================
   SVG CHART STYLES
   ================= */

.zwds-chart-svg {
  width: 100%;
  height: 100%;
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.chart-renderer {
  shape-rendering: geometricPrecision;
  text-rendering: optimizeLegibility;
}

/* Chart grid and borders */
.chart-grid line {
  opacity: 0.3;
  transition: opacity 0.3s ease;
}

.chart-border {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.chart-content {
  transition: all 0.3s ease;
}

/* Center decoration */
.chart-center text {
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-weight: bold;
  opacity: 0.6;
}

/* =================
   PALACE STYLES
   ================= */

.zwds-palace {
  cursor: pointer;
  transition: all 0.2s ease;
}

.palace-background {
  transition: all 0.2s ease;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.zwds-palace:hover .palace-background {
  filter: brightness(1.05);
  stroke-width: 2px;
}

.zwds-palace.selected .palace-background {
  filter: brightness(1.1);
  stroke-width: 3px;
  stroke: #531dab;
  fill: #f9f0ff;
}

.zwds-palace.hovered .palace-background {
  stroke: #9254de;
  stroke-width: 2px;
}

/* Palace header text */
.palace-header text {
  user-select: none;
  pointer-events: none;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-weight: 600;
}

/* Palace content container */
.palace-content {
  transition: transform 0.2s ease;
}

.zwds-palace:hover .palace-content {
  transform: scale(1.02);
}

/* =================
   STAR STYLES
   ================= */

.palace-stars {
  transition: all 0.2s ease;
}

.star-position {
  transition: all 0.2s ease;
  cursor: pointer;
}

.star-text {
  user-select: none;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  transition: all 0.2s ease;
  dominant-baseline: hanging;
}

.star-position:hover .star-text {
  font-weight: bold;
  transform: scale(1.1);
  filter: brightness(1.2);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Star categories */
.star-position.major .star-text {
  font-weight: bold;
  fill: #531dab;
}

.star-position.auxiliary .star-text {
  font-weight: normal;
  fill: #722ed1;
}

.star-position.minor .star-text {
  font-weight: normal;
  fill: #8c8c8c;
}

/* Brightness indicators */
.brightness-indicator {
  fill: #ffa500;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* Star tooltips */
.star-tooltip {
  opacity: 0;
  animation: fadeIn 0.3s forwards;
  pointer-events: none;
}

.star-tooltip rect {
  fill: rgba(0, 0, 0, 0.9);
  stroke: #666;
  stroke-width: 1;
  rx: 4;
  ry: 4;
}

.star-tooltip text {
  fill: white;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  pointer-events: none;
}

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

/* =================
   INTERACTIVE ELEMENTS
   ================= */

/* Chart controls */
.chart-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.chart-controls button {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  color: #333;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chart-controls button:hover {
  background: #fff;
  border-color: #9254de;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.chart-controls button:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Export/print button icons */
.export-button::before {
  content: "📥";
  margin-right: 4px;
}

.print-button::before {
  content: "🖨️";
  margin-right: 4px;
}

/* =================
   PALACE DETAIL PANEL
   ================= */

.palace-detail-panel {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 360px;
  max-width: 90vw;
  max-height: 80vh;
  background: white;
  border: 1px solid #d9d9d9;
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #e6e6e6;
  background: linear-gradient(135deg, #f9f0ff 0%, #fafafa 100%);
}

.panel-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #531dab;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.earthly-branch {
  font-size: 14px;
  color: #722ed1;
  font-weight: normal;
}

.close-button {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #999;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
  line-height: 1;
}

.close-button:hover {
  color: #333;
  background: rgba(0, 0, 0, 0.1);
}

.panel-description {
  padding: 20px;
  border-bottom: 1px solid #e6e6e6;
  background: #fafafa;
}

.panel-description p {
  margin: 0 0 12px 0;
  color: #333;
  line-height: 1.6;
}

.palace-stats {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.palace-stats span {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  text-transform: capitalize;
  font-weight: 500;
}

.significance.high {
  background: #f6ffed;
  color: #389e0d;
  border: 1px solid #b7eb8f;
}

.significance.medium {
  background: #fff7e6;
  color: #d46b08;
  border: 1px solid #ffd591;
}

.significance.low {
  background: #f6f6f6;
  color: #666;
  border: 1px solid #d9d9d9;
}

.brightness.bright {
  background: #fff2e8;
  color: #d4380d;
  border: 1px solid #ffbb96;
}

.brightness.normal {
  background: #f6f6f6;
  color: #666;
  border: 1px solid #d9d9d9;
}

.brightness.dark {
  background: #e6f7ff;
  color: #0958d9;
  border: 1px solid #91d5ff;
}

/* Panel tabs */
.panel-tabs {
  display: flex;
  background: #f0f0f0;
  border-bottom: 1px solid #e6e6e6;
}

.tab {
  flex: 1;
  padding: 14px 12px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #666;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
  position: relative;
}

.tab:hover {
  background: rgba(255, 255, 255, 0.8);
  color: #333;
}

.tab.active {
  color: #531dab;
  border-bottom-color: #531dab;
  background: white;
  font-weight: 600;
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: white;
}

/* =================
   TAB CONTENT STYLES
   ================= */

/* Stars tab */
.no-stars {
  text-align: center;
  color: #999;
  font-style: italic;
  padding: 40px 20px;
}

.no-stars p {
  margin: 0 0 8px 0;
  line-height: 1.5;
}

.stars-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.star-item {
  padding: 16px;
  border: 1px solid #e6e6e6;
  border-radius: 8px;
  background: #fafafa;
  transition: all 0.2s ease;
}

.star-item:hover {
  border-color: #531dab;
  background: #f9f0ff;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(83, 29, 171, 0.1);
}

.star-name {
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.star-name strong {
  color: #531dab;
  font-size: 16px;
  font-weight: 600;
}

.star-english {
  font-size: 12px;
  color: #666;
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 3px;
}

.star-influence {
  font-size: 14px;
  color: #333;
  line-height: 1.5;
}

.star-influence p {
  margin: 0;
}

/* Interpretation tab */
.interpretation-content h4 {
  margin: 0 0 12px 0;
  color: #531dab;
  font-size: 16px;
  font-weight: 600;
}

.interpretation-content p {
  margin: 0 0 20px 0;
  line-height: 1.6;
  color: #333;
}

.significance-description {
  padding: 16px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.6;
  border-left: 4px solid;
}

.significance-description.high {
  background: #f6ffed;
  border-left-color: #52c41a;
  color: #389e0d;
}

.significance-description.medium {
  background: #fff7e6;
  border-left-color: #fa8c16;
  color: #d46b08;
}

.significance-description.low {
  background: #f6f6f6;
  border-left-color: #999;
  color: #666;
}

/* Advice tab */
.advice-content h4 {
  margin: 0 0 16px 0;
  color: #531dab;
  font-size: 16px;
  font-weight: 600;
}

.advice-content ul {
  margin: 0;
  padding-left: 20px;
  list-style: none;
}

.advice-content li {
  margin-bottom: 12px;
  line-height: 1.6;
  font-size: 14px;
  color: #333;
  position: relative;
  padding-left: 20px;
}

.advice-content li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: #52c41a;
  font-weight: bold;
}

/* =================
   RESPONSIVE DESIGN
   ================= */

@media (max-width: 768px) {
  .zwds-chart-container {
    min-height: 350px;
  }

  .chart-controls {
    top: 8px;
    right: 8px;
    gap: 4px;
  }

  .chart-controls button {
    padding: 6px 8px;
    font-size: 12px;
  }

  /* Mobile palace detail panel */
  .palace-detail-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-width: none;
    max-height: none;
    border-radius: 0;
    animation: slideInFromBottom 0.3s ease-out;
  }

  @keyframes slideInFromBottom {
    from {
      opacity: 0;
      transform: translateY(100%);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .panel-header {
    padding: 16px;
  }

  .panel-header h3 {
    font-size: 16px;
  }

  .panel-description {
    padding: 16px;
  }

  .panel-content {
    padding: 16px;
  }

  .tab {
    padding: 12px 8px;
    font-size: 12px;
  }

  /* Star tooltip for mobile */
  .star-tooltip {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    top: auto;
    transform: none;
    max-width: none;
  }

  .star-tooltip rect {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .palace-stats {
    flex-direction: column;
    gap: 8px;
  }

  .palace-stats span {
    align-self: flex-start;
  }

  .stars-list {
    gap: 12px;
  }

  .star-item {
    padding: 12px;
  }

  .star-name strong {
    font-size: 14px;
  }
}

/* =================
   HIGH DPI DISPLAYS
   ================= */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .chart-renderer {
    shape-rendering: geometricPrecision;
  }

  .star-text {
    shape-rendering: geometricPrecision;
  }
}

/* =================
   PRINT STYLES
   ================= */

@media print {
  .chart-controls {
    display: none;
  }

  .palace-detail-panel {
    display: none;
  }

  .zwds-chart-container {
    box-shadow: none;
    border: 1px solid #000;
  }

  .zwds-chart-svg {
    width: 100% !important;
    height: auto !important;
  }
}

/* =================
   ACCESSIBILITY
   ================= */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus styles for keyboard navigation */
.zwds-palace:focus,
.star-position:focus,
.tab:focus,
button:focus {
  outline: 2px solid #531dab;
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .palace-background {
    stroke-width: 2px;
  }

  .star-text {
    font-weight: bold;
  }

  .palace-detail-panel {
    border-width: 2px;
  }
}
