* {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  height: 100vh;
}
body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  background: #fff;
}
.container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}
.auth-section {
  background: #f2f2f2;
  padding: 40px 32px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  text-align: center;
  width: 100%;
  max-width: 420px;
}
.auth-section h1 {
  font-size: 28px;
  margin-bottom: 40px;
  color: #333;
}
.auth-section input[type="password"] {
  width: 100%;
  padding: 16px;
  margin-bottom: 20px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 18px;
  outline: none;
}
.auth-section input[type="password"]:focus {
  border-color: #10a37f;
}
.auth-section button {
  width: 100%;
  padding: 16px;
  background: #10a37f;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
}
.auth-section button:hover {
  background: #0d8a6a;
}
#authError {
  color: #dc3545;
  margin-top: 16px;
  font-size: 16px;
  min-height: 24px;
}
.main-app {
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: row;
}
#sidebar {
  width: 300px;
  background: #f7f7f8;
  border-right: 1px solid #e5e5e5;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left 0.3s ease;
  margin-left: 0;
}
#sidebar.closed {
  margin-left: -300px;
}
.sidebar-header {
  padding: 16px;
  font-weight: 600;
  font-size: 16px;
  color: #333;
  border-bottom: 1px solid #e5e5e5;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sidebar-header button {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #666;
  padding: 4px 8px;
  border-radius: 4px;
}
.sidebar-header button:hover {
  background: #e5e5e5;
}
.logout-btn {
  background: #dc3545 !important;
  color: white !important;
  padding: 6px 12px !important;
  border-radius: 6px !important;
  font-size: 14px !important;
}
.logout-btn:hover {
  background: #c82333 !important;
}
#list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.chat-item {
  padding: 12px 14px;
  cursor: pointer;
  border-radius: 8px;
  margin-bottom: 4px;
  background: #fff;
  transition: all 0.15s ease;
}
.chat-item:hover {
  background: #ececec;
}
.chat-item.active {
  background: #10a37f;
}
.chat-item.active .chat-title,
.chat-item.active .chat-time {
  color: #fff;
}
.chat-title {
  font-weight: 500;
  color: #333;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}
.chat-time {
  font-size: 11px;
  color: #888;
}
#chatPanel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  min-width: 0;
}
#chatHeader {
  padding: 12px 16px;
  border-bottom: 1px solid #e5e5e5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fff;
}
.header-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
#menuBtn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #333;
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}
#menuBtn:hover {
  background: #f0f0f0;
}
#backBtn {
  background: none;
  border: 1px solid #e5e5e5;
  font-size: 13px;
  cursor: pointer;
  color: #333;
  padding: 6px 10px;
  border-radius: 6px;
  flex-shrink: 0;
  display: none;
}
#backBtn:hover {
  background: #f0f0f0;
}
#backBtn.show {
  display: inline-block;
}
#chatTitle {
  font-weight: 600;
  font-size: 16px;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  min-width: 0;
}
#searchBox {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}
#searchInput {
  padding: 8px 12px;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  font-size: 14px;
  width: 350px;
  outline: none;
}
#searchInput:focus {
  border-color: #10a37f;
}
#searchBtn {
  background: #10a37f;
  border: none;
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
}
#searchBtn:hover {
  background: #0d8a6a;
}
#clearBtn {
  background: #dc3545;
  border: none;
  color: #fff;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
  display: none;
}
#clearBtn:hover {
  background: #c82333;
}
#clearBtn.show {
  display: inline-block;
}
#loading {
  padding: 12px 20px;
  color: #888;
  font-size: 13px;
}
#chat {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
}
.message {
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 10px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
}
.message.user {
  background: #f0f0f0;
  color: #333;
  margin-left: 20px;
}
.message.assistant {
  background: #fff;
  color: #333;
  margin-right: 20px;
  border: 1px solid #e5e5e5;
}
.message-role {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  color: #10a37f;
}
.message.user .message-role {
  color: #666;
}
.message h2, .message h3, .message h4 {
  margin: 8px 0;
  font-size: 14px;
}
.message code {
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.message strong {
  font-weight: 600;
}
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #888;
  font-size: 15px;
  text-align: center;
}
.empty-state small {
  margin-top: 8px;
  font-size: 12px;
  color: #aaa;
}
.search-result {
  padding: 14px 16px;
  border-bottom: 1px solid #e5e5e5;
  cursor: pointer;
  transition: background 0.15s;
}
.search-result:hover {
  background: #f5f5f5;
}
.search-result-title {
  font-weight: 600;
  color: #333;
  margin-bottom: 4px;
}
.search-result-type {
  font-size: 11px;
  color: #10a37f;
  margin-bottom: 4px;
}
.search-result-preview {
  font-size: 13px;
  color: #666;
  line-height: 1.4;
}
.search-result mark {
  background: #fff3cd;
  padding: 0 2px;
  border-radius: 2px;
}
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: #f7f7f8;
}
::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

/* Mobile */
@media (max-width: 768px) {
  .auth-section {
    max-width: none;
    padding: 60px 40px;
    border-radius: 16px;
  }
  .auth-section h1 {
    font-size: 32px;
    margin-bottom: 50px;
  }
  .auth-section input[type="password"] {
    padding: 18px;
    font-size: 19px;
  }
  .auth-section button {
    padding: 18px;
    font-size: 19px;
  }

  .main-app {
    flex-direction: column;
  }
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 100;
    margin-left: 0;
    width: 280px;
  }
  #sidebar.closed {
    margin-left: -280px;
  }
  #chatPanel {
    width: 100vw;
    max-width: 100vw;
  }
  #chatHeader {
    padding: 10px 12px;
  }
  #searchBox {
    flex: 1;
  }
  #searchInput {
    flex: 1;
    width: auto;
    min-width: 0;
    font-size: 16px;
    padding: 12px 14px;
  }
  #searchBtn, #clearBtn {
    padding: 12px 16px;
    font-size: 16px;
  }
  #chatTitle {
    font-size: 18px;
  }
  .message {
    margin-left: 0;
    margin-right: 0;
    padding: 16px 18px;
    font-size: 16px;
  }
  .message-role {
    font-size: 11px;
  }
  #chat {
    padding: 16px;
  }
  .chat-item {
    padding: 16px 14px;
  }
  .chat-title {
    font-size: 16px;
  }
  .chat-time {
    font-size: 13px;
  }
  .empty-state {
    font-size: 17px;
  }
}

.hidden {
  display: none !important;
}

.main-app:not(.hidden) {
  display: flex !important;
}
