html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: #f7f4f1;
  font-family: 'Segoe UI', Arial, sans-serif;
  color: #222;
  box-sizing: border-box;
  transition: background 0.3s, color 0.3s;
}
body.dark {
  background: #11151c;
  color: #e3e6ed;
}
.topbar {
  display: flex;
  align-items: center;
  height: 48px;
  padding: 0 12px;
  background: #f7f4f1;
  border-bottom: 1px solid #eee;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
}
body.dark .topbar {
  background: #171c26;
  border-bottom: 1px solid #242b38;
}
.topicon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #cfcfcf;
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
  transition: background 0.3s, border-color 0.3s;
}
body.dark .topicon {
  background: #232940;
  border-color: #38405b;
}
.topicon svg {
  width: 20px;
  height: 20px;
  stroke: #8a7e7e;
  fill: none;
  stroke-width: 2.2px;
  transition: stroke 0.3s;
}
body.dark .topicon svg {
  stroke: #b3b9cb;
}
.brand {
  font-size: 1.3rem;
  font-weight: 700;
  color: #4f1aff;
  margin-left: 6px;
  letter-spacing: 0.02em;
}
body.dark .brand { color: #b1a5ff; }
#chat-area {
  flex: 1 1 auto;
  padding: 0 0 80px 0;
  margin: 0;
  overflow-y: auto;
  width: 100vw;
  max-width: 100vw;
  background: #f7f4f1;
  position: relative;
  min-height: 60vh;
}
body.dark #chat-area {
  background: #11151c;
}
.message {
  margin: 22px 18px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 2px 8px #0001;
  max-width: 94vw;
  line-height: 1.7;
  font-size: 1.07rem;
  word-break: break-word;
  transition: background 0.3s, color 0.3s;
  position: relative;
}
.ai {
  background: #f0f7f1;
  color: #184a24;
  margin-left: 44px;
}
.user {
  background: #f4f1f7;
  color: #3a295a;
  margin-right: 44px;
  text-align: right;
}
body.dark .message {
  background: #232940;
  color: #dbdfff;
  box-shadow: 0 2px 8px #0008;
}
body.dark .ai {
  background: #232940;
  color: #6df0b9;
}
body.dark .user {
  background: #202042;
  color: #b1a5ff;
}
.inputbar-container {
  width: 100vw;
  max-width: 100vw;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 11;
  background: none;
  pointer-events: none;
  display: flex;
  justify-content: center;
}
.inputbar {
  width: 98vw;
  max-width: 600px;
  margin: 12px auto;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 4px 24px #0002;
  display: flex;
  align-items: center;
  padding: 8px 12px 8px 18px;
  pointer-events: all;
  border: 1.5px solid #f3ecec;
  gap: 10px;
  transition: background 0.3s, border-color 0.3s;
}
body.dark .inputbar {
  background: #232940;
  border-color: #38405b;
  box-shadow: 0 4px 24px #0008;
}
#user-input {
  border: none;
  outline: none;
  font-size: 1.13rem;
  flex: 1 1 auto;
  background: transparent;
  color: #222;
  padding: 8px 0;
  margin: 0;
  transition: color 0.3s;
}
body.dark #user-input {
  color: #e3e6ed;
}
#user-input:disabled {
  color: #888;
  background: transparent;
}
#send-btn {
  background: #4f1aff;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  cursor: pointer;
  transition: background 0.15s;
  box-shadow: 0 2px 8px #0001;
  margin-left: 2px;
  margin-right: 4px;
}
#send-btn:disabled {
  background: #c1c1c1;
  cursor: not-allowed;
}
body.dark #send-btn {
  background: #5865f2;
}
@media (max-width: 600px) {
  .inputbar { max-width: 99vw; }
  #chat-area { max-width: 100vw; }
  .message { max-width: 97vw;}
}
/* Markdown styles */
#chat-area pre { background: #21232c; color: #e9e9e9; padding: 8px; border-radius: 5px; overflow-x: auto;}
#chat-area code { background: #e7e4e4; color: #b04219; border-radius: 3px; padding: 2px 4px; }
body.dark #chat-area pre { background: #161a29; color: #b7daf4; }
body.dark #chat-area code { background: #232940; color: #9ae7ff; }
/* Message limit info */
#limit-info {
  margin: 8px 0 0 0;
  text-align: center;
  font-size: .96em;
  color: #b77c3c;
}
body.dark #limit-info { color: #d9b55c; }
/* Settings Modal */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.23);
  z-index: 3000;
  align-items: center;
  justify-content: center;
  transition: background 0.3s;
}
.modal.show { display: flex; }
.modal-content {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 2px 18px #0003;
  padding: 36px 26px;
  max-width: 92vw;
  min-width: 200px;
  max-height: 60vh;
  font-size: 1.13rem;
  text-align: center;
  position: relative;
  transition: background 0.3s, color 0.3s;
}
body.dark .modal-content {
  background: #232940;
  color: #e3e6ed;
}
.close-btn {
  background: #e8e8e8;
  border: none;
  border-radius: 8px;
  font-size: 1.2rem;
  position: absolute;
  top: 14px; right: 20px;
  padding: 4px 11px;
  cursor: pointer;
  transition: background 0.15s;
}
.close-btn:hover {
  background: #e0e0ff;
}
body.dark .close-btn {
  background: #161a29;
  color: #b1d4fc;
}
/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  margin-right: 12px;
  vertical-align: middle;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #ccc;
  border-radius: 24px;
  transition: .3s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px; width: 18px;
  left: 3px; bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: .3s;
}
input:checked + .slider {
  background-color: #4f1aff;
}
input:checked + .slider:before {
  transform: translateX(20px);
  background-color: #b1a5ff;
}
/* Floating Bubble */
.floating-bubble {
  pointer-events: none;
  font-family: inherit;
}
.copy-btn {
  background: none;
  border: none;
  color: #8a7e7e;
  position: absolute;
  top: 7px;
  right: 10px;
  font-size: 1.18em;
  cursor: pointer;
  opacity: 0.7;
  padding: 3px 6px;
  border-radius: 5px;
  transition: background 0.13s, color 0.13s, opacity 0.2s;
  z-index: 10;
}
.copy-btn:hover, .copy-btn:focus {
  background: #f1f1f1;
  color: #4f1aff;
  opacity: 1;
}
body.dark .copy-btn:hover, body.dark .copy-btn:focus {
  background: #242b38;
  color: #b1d4fc;
}
.export-btn {
  background: #4f1aff;
  color: #fff;
  border: none;
  border-radius: 9px;
  font-size: 1.07em;
  padding: 7px 18px;
  margin-top: 6px;
  cursor: pointer;
  transition: background 0.16s, color 0.16s;
  box-shadow: 0 1px 3px #0001;
}
.export-btn:hover, .export-btn:focus {
  background: #6849e1;
  color: #fff;
}

/* Sidebar styles */
.sidebar {
  position: fixed;
  top: 0;
  left: -270px;
  width: 260px;
  height: 100vh;
  background: #fff;
  box-shadow: 2px 0 16px #0002;
  z-index: 3001;
  transition: left 0.23s;
  display: flex;
  flex-direction: column;
}
body.dark .sidebar {
  background: #181d25;
  box-shadow: 2px 0 28px #0005;
}
.sidebar.show { left: 0; }
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 10px 16px;
  border-bottom: 1px solid #eee;
}
body.dark .sidebar-header { border-bottom: 1px solid #232940; }
.sidebar-title {
  font-size: 1.13em;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-close {
  background: none;
  border: none;
  font-size: 1.6em;
  color: #888;
  cursor: pointer;
  padding: 2px 10px;
  border-radius: 7px;
  transition: background 0.16s, color 0.16s;
}
.sidebar-close:hover, .sidebar-close:focus {
  background: #e0e0ff;
  color: #4f1aff;
}
body.dark .sidebar-close:hover, body.dark .sidebar-close:focus {
  background: #232940;
  color: #b1a5ff;
}
.chat-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 0 0 0;
}
.chat-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px 7px 26px;
  cursor: pointer;
  border-radius: 8px;
  font-size: 1.05em;
  transition: background 0.13s;
  position: relative;
  margin-right: 8px;
}
.chat-item.selected {
  background: #e2deff;
  font-weight: 600;
}
body.dark .chat-item.selected {
  background: #232940;
  color: #b1a5ff;
}
.chat-title {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-edit-btn,
.chat-delete-btn {
  background: none;
  border: none;
  font-size: 1em;
  color: #bbaaff;
  padding: 2px 6px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.13s, color 0.13s;
  margin-left: 2px;
}
.chat-edit-btn:hover,
.chat-delete-btn:hover { background: #e9e3ff; color: #4f1aff; }
body.dark .chat-edit-btn:hover,
body.dark .chat-delete-btn:hover { background: #232940; color: #b1a5ff; }
.chat-name-input {
  font-size: 1em;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 2px 6px;
  width: 90%;
  margin: 0 4px;
  background: #f3f1ff;
  color: #333;
}
body.dark .chat-name-input {
  background: #242b38;
  color: #e3e6ed;
  border: 1px solid #35314e;
}
.chat-new-btn {
  background: #4f1aff;
  color: #fff;
  border: none;
  border-radius: 9px;
  font-size: 1.18em;
  padding: 4px 14px;
  margin: 6px 0 3px 18px;
  cursor: pointer;
  transition: background 0.13s, color 0.13s;
  box-shadow: 0 1px 3px #0001;
}
.chat-new-btn:hover, .chat-new-btn:focus {
  background: #6849e1;
  color: #fff;
}
