html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: #f7f4f1;
  font-family: 'Segoe UI', Arial, sans-serif;
  color: #222;
  height: 100vh;
  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: 8px;
  position: sticky;
  top: 0;
  z-index: 10;
  transition: background 0.3s, border-color 0.3s;
}
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;
  margin-right: 5px;
  pointer-events: auto;
  opacity: 0.85;
  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;
}
#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;
  transition: background 0.3s;
}
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.05rem;
  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; }
/* Sidebar styles */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: 82vw;
  max-width: 340px;
  min-width: 220px;
  height: 100vh;
  background: #f2ede8;
  box-shadow: 2px 0 18px #0002;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.34s cubic-bezier(.72,.14,.41,1.01), background 0.3s;
  will-change: transform;
  border-top-right-radius: 18px;
  border-bottom-right-radius: 18px;
  overflow-x: hidden;
  overflow-y: auto;
}
.sidebar.show {
  transform: translateX(0);
}
body.dark .sidebar {
  background: #1a1d28;
  box-shadow: 2px 0 18px #0008;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 18px 10px 18px;
  border-bottom: 1px solid #e4dcd2;
  transition: border-color 0.3s;
}
body.dark .sidebar-header { border-bottom: 1px solid #242b38; }
.sidebar-title {
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: .01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-title span {
  font-weight: 400;
  font-size: 1.08rem;
  color: #bba;
}
body.dark .sidebar-title span { color: #6670a3; }
.sidebar-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  color: #aaa;
  cursor: pointer;
  margin-left: 4px;
  transition: color 0.18s;
}
.sidebar-close:hover { color: #4f1aff; }
.chat-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 0 30px 0;
}
.chat-item {
  display: flex;
  align-items: center;
  padding: 8px 18px;
  cursor: pointer;
  font-size: 1.08rem;
  border: none;
  background: none;
  outline: none;
  width: 100%;
  border-radius: 7px;
  margin-bottom: 2px;
  color: #2a2a2a;
  text-align: left;
  transition: background 0.18s, color 0.3s;
  min-height: 34px;
  position: relative;
  gap: 8px;
}
.chat-item.selected {
  background: #e2e6f9;
  color: #2a2a4a;
}
body.dark .chat-item {
  color: #e6e6ee;
}
body.dark .chat-item.selected {
  background: #222b4b;
  color: #b1d4fc;
}
.chat-title {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  min-width: 0;
}
.chat-edit-btn {
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  font-size: 1.12em;
  padding: 0 2px;
  transition: color 0.3s;
}
.chat-edit-btn:hover { color: #4f1aff; }

.chat-delete-btn {
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  font-size: 1.12em;
  padding: 0 2px;
  transition: color 0.3s;
  margin-left: 2px;
  display: flex;
  align-items: center;
}
.chat-delete-btn svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2px;
}
.chat-delete-btn:hover { color: #b1001a; }

.chat-new-btn {
  background: #fff;
  border: 1.5px solid #e2e2e2;
  border-radius: 8px;
  color: #4f1aff;
  font-size: 1.7rem;
  width: 36px; height: 36px;
  margin: 16px 0 8px 18px;
  cursor: pointer;
  box-shadow: 0 1px 6px #0001;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s, color 0.3s, border-color 0.3s;
}
.chat-new-btn:hover { background: #f1f0ff; }
body.dark .chat-new-btn {
  background: #232940;
  border-color: #38405b;
  color: #b1d4fc;
}
.chat-name-input {
  font-size: 1.08rem;
  border: 1px solid #dadada;
  border-radius: 5px;
  padding: 2px 6px;
  width: 80%;
  margin-right: 7px;
}
body.dark .chat-name-input {
  background: #181a2b;
  color: #e3e6ed;
  border: 1px solid #232940;
}
@media (max-width: 600px) {
  .sidebar {
    width: 97vw;
    max-width: 97vw;
  }
}
/* 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;
}
