* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(59,130,246,0.18), transparent 28%),
    radial-gradient(circle at top right, rgba(168,85,247,0.16), transparent 30%),
    linear-gradient(180deg, #0b1120 0%, #111827 100%);
  color: #f8fafc;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.mobile-backdrop {
  display: none;
}

.app-shell {
  width: 100%;
  max-width: 1400px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  backdrop-filter: blur(10px);
}

.sidebar {
  width: 280px;
  background: rgba(15, 23, 42, 0.82);
  border-right: 1px solid rgba(148, 163, 184, 0.14);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  gap: 16px;
  transition: transform 0.25s ease;
  z-index: 40;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f8fafc;
}

.sidebar-btn,
.nav-btn,
.top-btn,
#sendBtn,
.history-item,
.menu-toggle-btn {
  border: 0;
  cursor: pointer;
  transition: 0.2s ease;
}

.sidebar-btn.primary {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
  padding: 12px 14px;
  border-radius: 14px;
  text-align: left;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.25);
}

.sidebar-btn.primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.history-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-title {
  font-size: 0.82rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.history-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.history-item {
  width: 100%;
  text-align: left;
  background: rgba(30, 41, 59, 0.5);
  color: #e2e8f0;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.9rem;
  line-height: 1.35;
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.history-item:hover {
  background: rgba(51, 65, 85, 0.85);
}

.history-item.active {
  background: rgba(59, 130, 246, 0.16);
  color: #eff6ff;
}

.history-empty {
  color: #64748b;
  font-size: 0.88rem;
  line-height: 1.4;
  padding: 8px 4px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-btn {
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.95rem;
}

.nav-btn:hover {
  background: rgba(148, 163, 184, 0.08);
}

.nav-btn.active {
  background: rgba(59, 130, 246, 0.16);
  color: #eff6ff;
}

.sidebar-bottom {
  padding-top: 6px;
}

.mini-note {
  color: #94a3b8;
  font-size: 0.85rem;
  line-height: 1.45;
}

.main-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  padding-top: max(18px, calc(env(safe-area-inset-top) + 12px));
  background: rgba(15, 23, 42, 0.66);
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  backdrop-filter: blur(18px);
}

.topbar-left-wrap {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.menu-toggle-btn {
  display: none;
  background: rgba(30, 41, 59, 0.82);
  color: #e2e8f0;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.14);
  flex-shrink: 0;
}

.topbar-left h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.topbar-left p {
  color: #94a3b8;
  font-size: 0.92rem;
  line-height: 1.4;
  max-width: 760px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.top-btn {
  background: rgba(30, 41, 59, 0.82);
  color: #e2e8f0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.88rem;
  border: 1px solid rgba(148, 163, 184, 0.14);
}

.top-btn:hover {
  background: rgba(51, 65, 85, 0.95);
}

.top-btn.danger {
  background: rgba(127, 29, 29, 0.24);
  color: #fecaca;
}

.top-btn.danger:hover {
  background: rgba(127, 29, 29, 0.38);
}

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  width: 100%;
}

.message.user {
  justify-content: flex-end;
}

.message.assistant {
  justify-content: flex-start;
}

.content {
  max-width: 78%;
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 0.96rem;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.16);
}

.message.user .content {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.message.assistant .content {
  background: rgba(30, 41, 59, 0.9);
  color: #f8fafc;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-bottom-left-radius: 6px;
}

.composer {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  padding: 16px 20px;
  padding-bottom: max(16px, calc(env(safe-area-inset-bottom) + 10px));
  background: rgba(15, 23, 42, 0.72);
  border-top: 1px solid rgba(148, 163, 184, 0.12);
  backdrop-filter: blur(18px);
}

#messageInput {
  flex: 1;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.16);
  color: #fff;
  border-radius: 18px;
  padding: 14px 16px;
  min-height: 54px;
  max-height: 180px;
  resize: none;
  outline: none;
  font: inherit;
  line-height: 1.45;
}

#messageInput::placeholder {
  color: #94a3b8;
}

#messageInput:focus {
  border-color: rgba(96, 165, 250, 0.8);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

#sendBtn {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  border-radius: 16px;
  padding: 0 18px;
  height: 54px;
  min-width: 92px;
  font-size: 0.95rem;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.24);
}

#sendBtn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

#sendBtn:disabled {
  opacity: 0.62;
  cursor: not-allowed;
  transform: none;
}

@media (max-width: 900px) {
  .menu-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.6);
    z-index: 30;
  }

  .mobile-backdrop.open {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    max-width: 82vw;
    transform: translateX(-100%);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .content {
    max-width: 88%;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar-left h1 {
    font-size: 1.08rem;
  }

  .topbar-left p {
    font-size: 0.84rem;
  }

  .topbar-actions {
    gap: 6px;
  }

  .top-btn {
    padding: 9px 10px;
    font-size: 0.8rem;
  }

  .chat-area {
    padding: 16px 14px;
  }

  .composer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .content {
    max-width: 92%;
    font-size: 0.93rem;
  }

  #sendBtn {
    min-width: 80px;
    height: 50px;
  }

  #messageInput {
    min-height: 50px;
  }
}
