/* Reset và font */
html, body {
  height: 100%;
  margin: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background-color:#479b69;
}

/* Toolbar */
.toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 40px;
  background: rgba(71, 155, 105, 0);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  z-index: 9999;
  box-shadow: 0 2px 5px rgb(71, 155, 105, 0);
}
.toolbar .logo { 
  font-weight: bold; 
  color: white;
  display: flex;
  align-items: center;
}
.toolbar .logo img {
  height: 24px;
  margin-right: 8px;
}
.toolbar .actions { 
  display: flex; 
  align-items: center; 
  color: white;
}

/* Ô tìm kiếm */
.toolbar .search-box {
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 20px;
  padding: 2px 10px;
  margin-left: 15px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.toolbar .search-box.hidden { display: none; }
.toolbar .search-box input {
  border: none; 
  outline: none;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 14px;
  flex: 1;
  min-width: 150px;
}
.toolbar .search-box button {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 6px 8px;
  color: #666;
  border-radius: 4px;
  transition: all 0.2s;
}
.toolbar .search-box button:hover { 
  color: #4CAF50; 
  background: #f5f5f5;
}
.toolbar .search-box .status-label {
  font-size: 13px;
  margin-left: 10px;
  color: #fff;
  min-width: 100px;
  text-align: right;
  font-weight: 500;
}

/* Container + Flipbook */
.container { 
  margin-top: 40px; 
  height: calc(100% - 40px);
}
#df_manual_book { 
  width: 100%; 
  height: 100%; 
}

/* Panel kết quả tìm kiếm */
#searchResultsPanel {
  position: fixed;
  top: 50px;
  right: -320px;
  width: 300px;
  height: calc(100% - 50px);
  background: #fff;
  border-left: 1px solid #ddd;
  z-index: 9998;
  font-size: 14px;
  transition: right 0.3s ease-in-out;
  display: flex;
  flex-direction: column;
  box-shadow: -2px 0 10px rgba(0,0,0,0.1);
}
#searchResultsPanel.visible { right: 0; }
#searchResultsHeader {
  position: sticky;
  top: 0;
  background: #f8f9fa;
  padding: 0px 10px;
  border-bottom: 1px solid #ddd;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 500;
  color: #0a9919;
}
#searchResultsHeader span {
  cursor: pointer;
  padding: 5px;
  border-radius: 4px;
  transition: background 0.2s;
}
#searchResultsHeader span:hover {
  background: #e9ecef;
}
#searchResultsList { 
  flex: 1; 
  overflow-y: auto; 
  padding: 10px 0;
}
.search-result-item {
  padding: 12px 15px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background 0.2s;
}
.search-result-item:hover { 
  background: #f8f9fa; 
}
.search-result-item.active { 
  background: #e3f2fd; 
  border-left: 3px solid #4CAF50;
}
.snippet-item { 
  padding: 6px 0; 
  cursor: pointer;
  margin: 5px 0;
  padding: 8px;
  border-radius: 4px;
  transition: all 0.2s;
}
.snippet-item:hover { 
  background: #e9ecef; 
}

/* Highlight */
#df_manual_book .df-page { 
  position: relative !important; 
}
.highlight-overlay {
  position: absolute;
  background: #ffeb3b;
  opacity: 0.6;
  pointer-events: none;
  z-index: 5000;
  border-radius: 2px;
}
mark {
  background: #ffeb3b;
  font-weight: bold;
  padding: 0 2px;
  border-radius: 2px;
}

/* AI Chat Box */
#ai-chat-box {
  position: fixed;
  bottom: 80px; 
  right: 20px;
  width: 350px; 
  height: 450px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 12px;
  display: none;
  flex-direction: column;
  box-shadow: 0 5px 25px rgba(0,0,0,0.2);
  z-index: 9999;
  overflow: hidden;
}
#ai-chat-box.show { 
  display: flex; 
  animation: slideUp 0.3s ease-out;
}

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

#ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #4CAF50, #45a049);
  color: white;
  padding: 2px 5px;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  font-weight: 600;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

#ai-chat-header .ai-logo {
  height: 24px;
  margin-right: 8px;
}

#ai-chat-header span {
  cursor: pointer;
  padding: 5px;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
#ai-chat-header span:hover {
  background: rgba(255,255,255,0.2);
}

#ai-chat-messages {
  flex: 1; 
  padding: 5px; 
  overflow-y: auto; 
  font-size: 14px;
  background: #fafafa;
}

/* Message styling */
.user-msg { 
  text-align: right; 
  margin: 2px 0; 
  color: #000; 
  background: #e3f2fd;
  padding: 5px 10px;
  border-radius: 10px;
  max-width: 85%;
  margin-left: auto;
  line-height: 1.4;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  position: relative;
}

.ai-msg { 
  text-align: left; 
  margin: 12px 0; 
  background: #f1f1f1;
  padding: 5px 5px 10px;
  border-radius: 10px;
  margin: 10px 10px 10px 0px;
  position: relative;
  line-height: 1.5;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  border: 1px solid #e0e0e0;
}

/* Markdown styling */
.ai-msg h1, .ai-msg h2, .ai-msg h3 {
  margin: 12px 0 8px;
  font-weight: 600;
  color: #2c3e50;
}

.ai-msg h1 {
  font-size: 1.5em;
  border-bottom: 2px solid #4CAF50;
  padding-bottom: 8px;
}

.ai-msg h2 {
  font-size: 1.3em;
}

.ai-msg h3 {
  font-size: 1.1em;
}

.ai-msg p {
  margin: 8px 0;
  line-height: 1.6;
}

.ai-msg ul, .ai-msg ol {
  margin: 8px 0 8px 25px;
  padding-left: 10px;
}

.ai-msg ul li, .ai-msg ol li {
  margin: 5px 0;
}

.ai-msg code {
  background: #2d2d2d;
  color: #f8f8f2;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 13px;
}

.ai-msg pre {
  margin: 12px 0;
}

.ai-msg pre code {
  display: block;
  background: #2d2d2d;
  color: #f8f8f2;
  padding: 15px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.4;
}

.ai-msg blockquote {
  border-left: 4px solid #4CAF50;
  margin: 12px 0;
  padding: 10px 15px;
  background: #e8f5e9;
  border-radius: 0 4px 4px 0;
}

/* Hiệu ứng typing dots */
.dot {
  animation: blink 1.5s infinite;
  opacity: 0.2;
  color: green;
  display: inline-block;
}

.dot:nth-child(1) { animation-delay: 0s; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
.dot:nth-child(4) { animation-delay: 0.6s; }
.dot:nth-child(5) { animation-delay: 0.8s; }
.dot:nth-child(6) { animation-delay: 1.0s; }
.dot:nth-child(7) { animation-delay: 1.2s; }

@keyframes blink {
  0% { opacity: 0.2; }
  20% { opacity: 1; }
  100% { opacity: 0.2; }
}

/* Nút copy */
.copy-btn {
  position: absolute;
  right: 1px;
  bottom: 1px;
  background: #e0e0e0;
  border: none;
  padding: 1px 1px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: #555;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.copy-btn:hover {
  background: #d5d5d5;
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.copy-btn:active {
  transform: translateY(0);
}

/* Thông báo copy */
.copy-notice {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: #4CAF5011;
  color: white;
  padding: 2px 5px;
  border-radius: 5px;
  font-size: 14px;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  font-weight: 500;
  animation: fadeInOut 1.5s forwards;
}

@keyframes fadeInOut {
  0% { 
    opacity: 0; 
    transform: translateY(15px) scale(0.9);
  }
  20% { 
    opacity: 1; 
    transform: translateY(0) scale(1);
  }
  80% { 
    opacity: 1; 
    transform: translateY(0) scale(1);
  }
  100% { 
    opacity: 0; 
    transform: translateY(-15px) scale(0.9);
  }
}

/* Input area */
#ai-chat-input {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 3px;
  border-top: 1px solid #ddd;
  background: white;
}

#ai-question {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 150px;
  padding: 2px 5px;
  border-radius: 8px;
  border: 1px solid #ddd;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}

#ai-question:focus {
  border-color: #4CAF50;
  box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

#ai-question::placeholder {
  color: #999;
}

#ai-chat-input button {
  border: none;
  background: #4CAF50;
  color: white;
  padding: 5px 10px;
  margin: 0;
  cursor: pointer;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

#ai-chat-input button:hover {
  background: #45a049;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0,0,0,0.25);
}

#ai-chat-input button:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

#ai-chat-input button:disabled {
  background: #cccccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Nút trợ lý AI */
#ai-assistant-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: linear-gradient(135deg, #4CAF501A, #5ed9635e);
  color: white;
  border-radius: 50%;
  width: 45px;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.01);
  overflow: visible;
  z-index: 9998;
  border: none;
  transition: all 3s;
}

#ai-assistant-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

#ai-assistant-button img {
  width: 32px;
  height: 32px;
}

#ai-assistant-button::before,
#ai-assistant-button::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(76, 175, 80, 0.3);
  animation: pulse 2s ease-out infinite;
  z-index: -1;
}

#ai-assistant-button::after {
  animation-delay: 1s;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.8);
    opacity: 0;
  }
}

/* Responsive */
@media (max-width: 768px) {
  #ai-chat-box {
    width: calc(100% - 40px);
    height: 70vh;
    bottom: 90px;
    right: 20px;
  }
  
  .toolbar .search-box input {
    min-width: 150px;
  }
  
  .toolbar .search-box .status-label {
    min-width: 80px;
    font-size: 12px;
  }
}

/* Scrollbar custom */
#ai-chat-messages::-webkit-scrollbar,
#searchResultsList::-webkit-scrollbar {
  width: 6px;
}

#ai-chat-messages::-webkit-scrollbar-track,
#searchResultsList::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

#ai-chat-messages::-webkit-scrollbar-thumb,
#searchResultsList::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

#ai-chat-messages::-webkit-scrollbar-thumb:hover,
#searchResultsList::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}