:root {
  --bg: #0f1724;
  --panel: linear-gradient(180deg, #191a2a 0%, #161827 100%);
  --muted: #9aa4c4;
  --text: #e6eef8;
  --accent-start: #7c4dff;
  --accent-end: #3ad0ff;
  --glass: rgba(255, 255, 255, 0.03);
  --shadow: 0 6px 20px rgba(4, 8, 20, 0.6);
  --radius: 14px;
  --glass-2: rgba(255, 255, 255, 0.02);
  --msg-user: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.06),
    rgba(255, 255, 255, 0.02)
  );
  --msg-user-meta: rgba(255, 255, 255, 0.8);
}

body[data-theme="light"] {
  --bg: #f6f8fb;
  --panel: linear-gradient(180deg, #ffffff 0%, #fbfbff 100%);
  --muted: #6b7280;
  --text: #0f1724;
  --glass: rgba(16, 24, 40, 0.02);
  --glass-2: rgba(16, 24, 40, 0.03);
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.06);
  --msg-user: linear-gradient(180deg, rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.02));
  --msg-user-meta: rgba(51, 51, 51, 0.8);
}

* {
  box-sizing: border-box;
}
html,
body,
#root {
  height: 100%;
}
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial;
  background: radial-gradient(
      1200px 600px at 10% 10%,
      rgba(124, 77, 255, 0.08),
      transparent 8%
    ),
    radial-gradient(
      1000px 500px at 90% 90%,
      rgba(58, 208, 255, 0.04),
      transparent 10%
    ),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 20px;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  gap: 20px;
  height: calc(100vh - 40px);
  position: relative;
}

.sidebar {
  width: 260px;
  min-width: 80px;
  background: var(--panel);
  border-radius: 20px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow);
  transition: width 0.28s ease, transform 0.18s;
  overflow: hidden;
  position: relative;
}
.sidebar-top {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar.collapsed {
  width: 80px;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
}

.brand .material-icons {
  font-size: 28px;
}

.collapse-btn {
  margin-left: auto;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 6px;
  border-radius: 8px;
}
.sidebar.collapsed .collapse-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  margin-left: 0;
  opacity: 0;
  pointer-events: none;
  background: var(--glass);
}
.sidebar.collapsed:hover .collapse-btn {
  opacity: 1;
  pointer-events: auto;
}
.collapse-btn:hover {
  background: var(--glass-2);
}

.nav {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.nav.nav-secondary {
  margin-top: 0;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 12px;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.18s;
}
.nav #navChats { color: var(--text); background: var(--glass-2); }
.nav #navChats .material-icons { font-size: 18px; }
.nav #navChats:hover { background: var(--glass); }
.nav-item .material-icons {
  font-size: 20px;
}
.nav-item .label {
  font-size: 14px;
}
.nav-item:hover {
  background: var(--glass);
  color: var(--text);
}
.nav-item.active {
  background: linear-gradient(90deg, var(--accent-start), var(--accent-end));
  color: white;
  box-shadow: 0 6px 18px rgba(99, 66, 255, 0.14);
}
  
.conv-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.conv-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: var(--glass-2);
  cursor: pointer;
  transition: background 0.18s;
}
.conv-item:hover { background: var(--glass); }
.conv-item.active {
  background: linear-gradient(90deg, var(--accent-start), var(--accent-end));
  color: white;
}
.conv-item .conv-icon { display: none; }
.conv-item .conv-meta { display: flex; flex-direction: column; min-width: 0; }
.conv-item .title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .preview { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .time { font-size: 11px; color: var(--muted); margin-left: auto; }
.conv-item .conv-actions {
  margin-left: auto;
  display: none;
  gap: 6px;
}
.conv-item:hover .conv-actions { display: inline-flex; }
.conv-action-btn { border: none; background: transparent; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 8px; }
.conv-action-btn .material-icons { font-size: 16px; }
.conv-item.active .conv-action-btn { color: rgba(255,255,255,0.9); }
.conv-action-btn:hover { background: var(--glass); }

.sidebar .sidebar-bottom {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}
.profile {
  display: flex;
  gap: 10px;
  align-items: center;
}
.profile .avatar {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--accent-start), var(--accent-end));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.profile .meta .name {
  font-weight: 600;
}
.profile .meta .role {
  font-size: 12px;
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.02),
    rgba(255, 255, 255, 0.01)
  );
  box-shadow: var(--shadow);
}

.chat-header {
  padding: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.chat-title .title {
  font-weight: 700;
  font-size: 16px;
}
.chat-title .subtitle {
  font-size: 13px;
  color: var(--muted);
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
  gap: 12px;
  min-height: 0;
}

.messages {
  overflow: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.msg {
  max-width: 78%;
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.4;
  animation: fadeIn 0.18s ease;
}
.msg.user {
  margin-left: auto;
  background: var(--msg-user);
  color: var(--text);
  border-bottom-right-radius: 6px;
}
.msg.bot {
  margin-right: auto;
  background: linear-gradient(90deg, var(--accent-start), var(--accent-end));
  color: white;
  border-bottom-left-radius: 6px;
}

.msg .meta {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  margin-top: 8px;
}

.msg.user .meta {
  color: var(--msg-user-meta);
}

.typing {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.typing .dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.9);
  opacity: 0.85;
  animation: typing 1.1s infinite;
}
.typing .dot:nth-child(2) {
  animation-delay: 0.12s;
}
.typing .dot:nth-child(3) {
  animation-delay: 0.24s;
}
@keyframes typing {
  0% {
    transform: translateY(0);
    opacity: 0.3;
  }
  50% {
    transform: translateY(-6px);
    opacity: 1;
  }
  100% {
    transform: translateY(0);
    opacity: 0.3;
  }
}

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

.composer {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  background: var(--glass);
  position: sticky;
  bottom: 0;
  backdrop-filter: saturate(120%) blur(8px);
  -webkit-backdrop-filter: saturate(120%) blur(8px);
}
.input-group {
  flex: 1;
}
textarea {
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  padding: 8px;
  max-height: 140px;
}
.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 10px;
}
.icon-btn:hover {
  background: var(--glass-2);
  color: var(--text);
}

.send-btn {
  border: none;
  padding: 10px 14px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: linear-gradient(90deg, var(--accent-start), var(--accent-end));
  color: white;
  box-shadow: 0 10px 30px rgba(68, 36, 255, 0.16);
}
.send-btn:active {
  transform: translateY(1px);
}

.btn {
  border-radius: 10px;
  padding: 8px 12px;
  border: none;
  cursor: pointer;
}
.btn.small {
  padding: 6px 10px;
  font-size: 14px;
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.02);
}

@media (max-width: 900px) {
  body { padding: 0; }
  .app {
    padding: 0;
    gap: 0;
    height: 100dvh;
  }
  .sidebar {
    position: fixed;
    z-index: 60;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(86vw, 320px);
    border-radius: 0 20px 20px 0;
    transform: translateX(-120%);
    transition: transform 0.2s ease;
  }
  .sidebar.hidden { transform: translateX(-120%); }
  .sidebar:not(.hidden) { transform: translateX(0); }
  .main { margin-left: 0; border-radius: 0; }
  .mobile-only {
    display: inline-flex;
  }
  .collapse-btn {
    display: none;
  }
  .sidebar.collapsed { width: min(86vw, 320px); }
  .messages { padding-bottom: calc(env(safe-area-inset-bottom) + 84px); }
  .chat-header { padding: 12px; }
  .chat-area { padding: 10px; gap: 10px; }
  .composer { border-radius: 12px; padding: 10px; bottom: env(safe-area-inset-bottom); }
  body.no-scroll {
    overflow: hidden;
  }
  .overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 36, 0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
    z-index: 50;
  }
  .overlay.visible {
    opacity: 1;
    pointer-events: auto;
  }
}
@media (min-width: 901px) {
  .mobile-only {
    display: none;
  }
}

.sidebar.collapsed .brand-text,
.sidebar.collapsed .label,
.sidebar.collapsed .subtitle,
.sidebar.collapsed .meta,
.sidebar.collapsed .profile .meta {
  display: none;
}
.sidebar.collapsed .nav-item {
  justify-content: center;
}
.sidebar.collapsed .conv-list { padding-right: 0; }
.sidebar.collapsed .conv-item { justify-content: center; }
.sidebar.collapsed .conv-item .conv-meta { display: none; }
.sidebar.collapsed .conv-item .conv-actions { display: none !important; }
.sidebar.collapsed .sidebar-bottom {
  justify-content: center;
  padding-top: 8px;
}

.sidebar.collapsed .nav-item .material-icons {
  font-size: 24px;
}
.sidebar.collapsed .collapse-btn .material-icons {
  transform: rotate(180deg);
  transition: transform 0.18s ease;
}
.sidebar.collapsed .controls {
  flex-direction: column;
}
.sidebar.collapsed .collapse-btn {
  align-self: center;
}

.messages::-webkit-scrollbar {
  width: 10px;
}
.messages::-webkit-scrollbar-thumb {
  background: var(--glass-2);
  border-radius: 10px;
}
.messages:hover::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
}
