:root {
  --chat-bg: #080c1a;
  --chat-panel: #0d1326;
  --chat-muted: #a0aec0;
  --chat-accent: #14b8a6;
  --bubble-other: #1e293b;
  --bubble-me: #0dcaf0;

  --radius: 12px;
  --pad: 20px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial,
    sans-serif;
  background-color: var(--chat-bg);
}

body.chat-mode {
  background: linear-gradient(180deg, #050913 0%, #080c1a 100%);
  color: #e6eef8;
  transition: background 0.3s ease, color 0.3s ease;
}

body.light-mode {
  --chat-bg: #f0f4f8;
  --chat-panel: #ffffff;
  --chat-muted: #475569;
  --chat-accent: #10b981;
  --bubble-other: #e2e8f0;
  --bubble-me: #14b8a6;
  color: #111827;
  background-color: var(--chat-bg);
}

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: 260px;
  background: var(--chat-panel);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: 100%;
}

body.light-mode .sidebar {
  background: var(--chat-panel);
  border-right: 1px solid #cbd5e1;
}

.sb-brand {
  font-weight: 800;
  font-size: 22px;
  color: var(--chat-accent);
  text-shadow: 0 0 6px rgba(20, 184, 166, 0.7);
}
body.light-mode .sb-brand {
  text-shadow: none;
}

.sb-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.sidebar-btn,
.logout-btn {
  padding: 12px;
  border-radius: var(--radius);
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, box-shadow 0.2s ease, background 0.2s ease,
    color 0.2s ease;
}
.sidebar-btn:active,
.logout-btn:active {
  transform: translateY(1px);
}

.sidebar-btn {
  background: #0b152d;
  color: #dbeafe;
}
.sidebar-btn:hover {
  background: #141b3f;
  box-shadow: 0 0 8px rgba(20, 184, 166, 0.45);
}
body.light-mode .sidebar-btn {
  background: var(--chat-accent);
  color: #fff;
}
body.light-mode .sidebar-btn:hover {
  background: #0f766e;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.35);
}

.logout-btn {
  background: #1f2937;
  color: #e5e7eb;
}
.logout-btn:hover {
  background: #374151;
}
body.light-mode .logout-btn {
  background: #ef4444;
  color: #fff;
}
body.light-mode .logout-btn:hover {
  background: #dc2626;
}

.sb-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sb-item {
  padding: 12px;
  border-radius: var(--radius);
  color: var(--chat-muted);
  cursor: pointer;
  user-select: none;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-item:hover {
  background: #16203f;
  color: #fff;
  box-shadow: 0 0 8px rgba(20, 184, 166, 0.4);
}
.sb-item.active {
  background: rgba(20, 184, 166, 0.15);
  color: #fff;
  outline: 1px solid rgba(20, 184, 166, 0.35);
}
body.light-mode .sb-item {
  color: var(--chat-muted);
}
body.light-mode .sb-item:hover {
  background: #d1e7dd;
  color: #111827;
  box-shadow: none;
}
body.light-mode .sb-item.active {
  background: #bbf7d0;
  color: #065f46;
  outline: 1px solid #86efac;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  transition: background 0.3s ease;
  min-width: 0;
}

.main-header {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 var(--pad);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  color: var(--chat-muted);
  background: linear-gradient(90deg, #0d1326 0%, #0b1020 100%);
  flex-shrink: 0;
}
body.light-mode .main-header {
  background: #f8fafc;
  border-bottom: 1px solid #cbd5e1;
}

#convTitle {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px clamp(12px, 2.5vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.msg {
  max-width: min(78%, 720px);
  padding: 12px 16px;
  border-radius: 16px;
  color: #fff;
  font-size: clamp(14px, 1.8vw, 15.5px);
  line-height: 1.55;
  word-wrap: break-word;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.msg:hover {
  transform: translateY(-1px);
}

.msg.other {
  background: linear-gradient(135deg, var(--bubble-other) 0%, #16203f 100%);
  align-self: flex-start;
  border-top-left-radius: 0;
}
body.light-mode .msg.other {
  background: linear-gradient(135deg, var(--bubble-other) 0%, #d1e7dd 100%);
  color: #111827;
}

.msg.me {
  background: linear-gradient(135deg, var(--bubble-me) 0%, #14b8a6 100%);
  color: #041014;
  align-self: flex-end;
  border-top-right-radius: 0;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(13, 202, 240, 0.35);
}
body.light-mode .msg.me {
  background: linear-gradient(135deg, var(--bubble-me) 0%, #0d9488 100%);
  color: #f0fdf4;
}

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px var(--pad);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: #0b1320;
  flex-shrink: 0;
}
body.light-mode .composer {
  background: #ffffff;
  border-top: 1px solid #cbd5e1;
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 180px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(20, 184, 166, 0.35);
  background: #0f1a2c;
  color: white;
  font-size: 15px;
  resize: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.composer textarea:focus {
  border-color: var(--chat-accent);
  box-shadow: 0 0 8px rgba(20, 184, 166, 0.45);
}
body.light-mode .composer textarea {
  background: #f0f4f8;
  color: #111827;
  border: 1px solid #cbd5e1;
}
body.light-mode .composer textarea:focus {
  border-color: var(--chat-accent);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.28);
}

.composer button {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: none;
  background: var(--chat-accent);
  color: #041014;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.05s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.composer button:hover {
  background: #0f766e;
  box-shadow: 0 0 12px rgba(20, 184, 166, 0.5);
}
.composer button:active {
  transform: translateY(1px);
}
body.light-mode .composer button {
  color: #ffffff;
}

.msg code,
pre {
  background: rgba(20, 184, 166, 0.1);
  padding: 6px 10px;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono",
    "Courier New", monospace;
  font-size: 0.92em;
  overflow-x: auto;
}

.typing {
  display: inline-block;
  width: 44px;
}
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  background: var(--chat-accent);
  border-radius: 50%;
  opacity: 0.9;
  animation: blink 1s infinite;
}
@keyframes blink {
  0%,
  50%,
  100% {
    opacity: 0.9;
  }
  25%,
  75% {
    opacity: 0.2;
  }
}

@media (max-width: 1024px) {
  .app {
    flex-direction: column;
    height: 100dvh;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    overflow-y: visible;
    max-height: none;
    flex-shrink: 0;
  }
  body.light-mode .sidebar {
    border-bottom: 1px solid #cbd5e1;
  }

  .sb-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
    padding-bottom: 4px;

    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  .sb-list::-webkit-scrollbar {
    display: none;
  }

  .sb-item {
    flex: 0 0 auto;
    max-width: 60vw;
  }

  .main-header {
    height: 60px;
  }
  .msg {
    max-width: 85%;
  }
}

@media (max-width: 720px) {
  :root {
    --pad: 12px;
  }

  .sb-actions {
    width: 100%;
  }
  .sidebar-btn,
  .logout-btn {
    flex: 1 1 0;
  }

  .sb-list {
    gap: 6px;
  }
  .sb-item {
    padding: 10px;
    border-radius: 10px;
  }

  .chat-area {
    padding: 12px;
    gap: 10px;
  }
  .msg {
    max-width: 92%;
    padding: 10px 12px;
    border-radius: 14px;
  }

  .composer {
    padding: 10px var(--pad);
    gap: 8px;
  }
  .composer textarea {
    min-height: 40px;
    font-size: 14px;
    padding: 10px;
  }
  .composer button {
    padding: 10px 12px;
  }

  .main-header {
    padding: 0 var(--pad);
    gap: 8px;
  }
  #convTitle {
    max-width: 60vw;
  }
}

@media (max-width: 380px) {
  .sb-brand {
    font-size: 18px;
  }
  .sidebar-btn,
  .logout-btn {
    padding: 10px;
    font-size: 14px;
  }
  .msg {
    font-size: 14px;
  }
}
