/* EchoLex and EchoPatterns Styles */

/* EchoLex Token Styles */
.echolex-token {
  cursor: pointer;
  transition: background-color 0.2s ease, text-decoration 0.2s ease;
  border-radius: 2px;
  padding: 1px 2px;
  margin: 0 1px;
}

.echolex-token:hover {
  background-color: rgba(59, 130, 246, 0.15);
  text-decoration: underline;
}

body.theme-dark .echolex-token:hover {
  background-color: rgba(96, 165, 250, 0.2);
}

/* Grammar Highlight Styles */
.grammar-highlight {
  cursor: pointer;
  background-color: hsla(var(--pattern-hue, 200), 70%, 85%, 0.4);
  border-bottom: 2px solid hsl(var(--pattern-hue, 200), 70%, 50%);
  padding: 1px 2px;
  border-radius: 2px;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.grammar-highlight:hover {
  background-color: hsla(var(--pattern-hue, 200), 70%, 75%, 0.6);
  border-bottom-color: hsl(var(--pattern-hue, 200), 70%, 40%);
}

body.theme-dark .grammar-highlight {
  background-color: hsla(var(--pattern-hue, 200), 50%, 30%, 0.5);
  border-bottom-color: hsl(var(--pattern-hue, 200), 50%, 60%);
}

body.theme-dark .grammar-highlight:hover {
  background-color: hsla(var(--pattern-hue, 200), 50%, 40%, 0.7);
  border-bottom-color: hsl(var(--pattern-hue, 200), 50%, 70%);
}

/* EchoLex Panel */
.echolex-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 320px;
  max-width: 90vw;
  background: var(--bg-secondary, #ffffff);
  border-left: 1px solid var(--border-color, #e5e7eb);
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.echolex-panel.active {
  transform: translateX(0);
}

.echolex-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #f9fafb);
}

.echolex-panel-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.echolex-panel-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text-secondary, #6b7280);
  transition: color 0.2s ease;
}

.echolex-panel-close:hover {
  color: var(--text-primary, #111827);
}

.echolex-panel-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}

.echolex-panel-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary, #6b7280);
}

.echolex-word-header {
  margin-bottom: 16px;
}

.echolex-word-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.echolex-word-surface {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary, #111827);
}

.echolex-word-reading {
  font-size: 1rem;
  color: var(--text-secondary, #6b7280);
}

.echolex-word-romaji {
  font-size: 0.9rem;
  color: var(--text-tertiary, #9ca3af);
  font-style: italic;
}

.echolex-word-level {
  display: inline-block;
  padding: 2px 8px;
  background: var(--accent-color, #3b82f6);
  color: white;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.echolex-word-meaning {
  margin: 12px 0;
  padding: 12px;
  background: var(--bg-secondary, #f3f4f6);
  border-radius: 6px;
  line-height: 1.6;
}

.echolex-word-pos,
.echolex-word-base {
  margin: 8px 0;
  font-size: 0.9rem;
  color: var(--text-secondary, #6b7280);
}

.echolex-word-examples {
  margin: 16px 0;
}

.echolex-word-examples strong {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary, #6b7280);
}

.echolex-word-examples ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.echolex-word-examples li {
  margin: 12px 0;
  padding: 12px;
  background: var(--bg-secondary, #f3f4f6);
  border-radius: 6px;
  border-left: 3px solid var(--accent-color, #3b82f6);
}

.example-jp {
  font-size: 1rem;
  margin-bottom: 4px;
  color: var(--text-primary, #111827);
}

.example-vi {
  font-size: 0.9rem;
  color: var(--text-secondary, #6b7280);
}

.echolex-word-actions {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color, #e5e7eb);
}

.echolex-save-btn {
  width: 100%;
  padding: 10px 16px;
  background: var(--accent-color, #3b82f6);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.echolex-save-btn:hover {
  background: var(--accent-hover, #2563eb);
}

.echolex-save-btn.saved {
  background: var(--success-color, #10b981);
}

.echolex-save-btn.saved:hover {
  background: var(--success-hover, #059669);
}

/* EchoPatterns Panel */
.echopatterns-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 320px;
  max-width: 90vw;
  background: var(--bg-secondary, #ffffff);
  border-left: 1px solid var(--border-color, #e5e7eb);
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
  z-index: 98;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* When both panels are active, adjust positioning */
/* On desktop: stack horizontally if space allows */
@media (min-width: 1024px) {
  .echolex-panel.active ~ .echopatterns-panel.active {
    right: 320px;
    max-width: calc(90vw - 320px);
  }
}

/* On smaller screens, only show one panel at a time */
@media (max-width: 1023px) {
  .echolex-panel.active ~ .echopatterns-panel.active {
    right: 0;
    max-width: 90vw;
  }
  
  /* Hide EchoLex when EchoPatterns is active on mobile */
  .echopatterns-panel.active ~ .echolex-panel.active {
    display: none;
  }
}

.echopatterns-panel.active {
  transform: translateX(0);
}

.echopatterns-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #f9fafb);
}

.echopatterns-panel-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.echopatterns-panel-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text-secondary, #6b7280);
  transition: color 0.2s ease;
}

.echopatterns-panel-close:hover {
  color: var(--text-primary, #111827);
}

.echopatterns-panel-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}

.echopatterns-panel-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary, #6b7280);
}

.echopatterns-pattern-header {
  margin-bottom: 16px;
}

.echopatterns-pattern-name {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-primary, #111827);
  margin-bottom: 8px;
}

.echopatterns-pattern-level {
  display: inline-block;
  padding: 2px 8px;
  background: var(--accent-color, #3b82f6);
  color: white;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.echopatterns-pattern-label {
  margin: 12px 0;
  padding: 12px;
  background: var(--bg-secondary, #f3f4f6);
  border-radius: 6px;
  font-weight: 500;
  color: var(--text-primary, #111827);
}

.echopatterns-pattern-description,
.echopatterns-pattern-description-jp {
  margin: 16px 0;
  line-height: 1.6;
}

.echopatterns-pattern-description strong,
.echopatterns-pattern-description-jp strong {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary, #6b7280);
}

.echopatterns-pattern-examples {
  margin: 16px 0;
}

.echopatterns-pattern-examples strong {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary, #6b7280);
}

.echopatterns-pattern-examples ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.echopatterns-pattern-examples li {
  margin: 12px 0;
  padding: 12px;
  background: var(--bg-secondary, #f3f4f6);
  border-radius: 6px;
  border-left: 3px solid var(--accent-color, #3b82f6);
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .echolex-panel,
  .echopatterns-panel {
    width: 100%;
    max-width: 100%;
    top: auto;
    bottom: 60px; /* chừa chỗ cho mobile-bottom-nav */
    height: 52vh;
    max-height: 52vh;
    transform: translateY(110%);
    border-left: none;
    border-top: 1px solid var(--border-color, #e5e7eb);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.45);
  }

  .echolex-panel.active,
  .echopatterns-panel.active {
    transform: translateY(0);
  }

  /* Smaller header on mobile */
  .echolex-panel-header,
  .echopatterns-panel-header {
    padding: 8px 10px;
  }

  .echolex-panel-header h3,
  .echopatterns-panel-header h3 {
    font-size: 0.9rem;
  }

  .echolex-panel-close,
  .echopatterns-panel-close {
    font-size: 0.95rem;
    padding: 2px 6px;
  }

  /* Smaller content padding and font sizes */
  .echolex-panel-content,
  .echopatterns-panel-content {
    padding: 10px;
    padding-bottom: 12px;
  }

  /* Smaller word header */
  .echolex-word-header {
    margin-bottom: 10px;
  }

  .echolex-word-main {
    gap: 6px;
    margin-bottom: 6px;
  }

  .echolex-word-surface {
    font-size: 1.1rem;
  }

  .echolex-word-reading {
    font-size: 0.8rem;
  }

  .echolex-word-romaji {
    font-size: 0.75rem;
  }

  .echolex-word-level {
    font-size: 0.7rem;
    padding: 2px 6px;
  }

  .echolex-word-meaning {
    margin: 6px 0;
    padding: 8px;
    font-size: 0.85rem;
    line-height: 1.4;
  }

  .echolex-word-pos,
  .echolex-word-base {
    margin: 4px 0;
    font-size: 0.8rem;
  }

  .echolex-word-examples {
    margin: 10px 0;
  }

  .echolex-word-examples strong {
    margin-bottom: 4px;
    font-size: 0.8rem;
  }

  .echolex-word-examples li {
    margin: 6px 0;
    padding: 8px;
    font-size: 0.85rem;
  }

  .example-jp {
    font-size: 0.85rem;
    margin-bottom: 2px;
  }

  .example-vi {
    font-size: 0.8rem;
  }

  .echolex-word-actions {
    margin-top: 10px;
    padding-top: 10px;
  }

  .echolex-save-btn {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  /* EchoPatterns mobile adjustments */
  .echopatterns-pattern-header {
    margin-bottom: 10px;
  }

  .echopatterns-pattern-name {
    font-size: 1rem;
    margin-bottom: 4px;
  }

  .echopatterns-pattern-level {
    font-size: 0.7rem;
    padding: 2px 6px;
  }

  .echopatterns-pattern-label {
    margin: 6px 0;
    padding: 8px;
    font-size: 0.85rem;
  }

  .echopatterns-pattern-description,
  .echopatterns-pattern-description-jp {
    margin: 10px 0;
    font-size: 0.85rem;
    line-height: 1.4;
  }

  .echopatterns-pattern-description strong,
  .echopatterns-pattern-description-jp strong {
    margin-bottom: 4px;
    font-size: 0.8rem;
  }

  .echopatterns-pattern-examples {
    margin: 10px 0;
  }

  .echopatterns-pattern-examples strong {
    margin-bottom: 4px;
    font-size: 0.8rem;
  }

  .echopatterns-pattern-examples li {
    margin: 6px 0;
    padding: 8px;
    font-size: 0.85rem;
  }

  .echolex-panel-empty,
  .echopatterns-panel-empty {
    padding: 30px 16px;
    font-size: 0.9rem;
  }
}

/* Dark theme adjustments */
body.theme-dark .echolex-panel,
body.theme-dark .echopatterns-panel {
  background: var(--bg-secondary, #1f2937);
  border-left-color: var(--border-color, #374151);
}

body.theme-dark .echolex-panel-header,
body.theme-dark .echopatterns-panel-header {
  background: var(--bg-primary, #111827);
  border-bottom-color: var(--border-color, #374151);
}

body.theme-dark .echolex-word-meaning,
body.theme-dark .echopatterns-pattern-label,
body.theme-dark .echolex-word-examples li,
body.theme-dark .echopatterns-pattern-examples li {
  background: var(--bg-primary, #111827);
}

