:root {
  --bg-gradient: radial-gradient(120% 120% at 20% 20%, #ffd6f3 0%, #d6c4ff 40%, #c3d9ff 100%);
  --panel: rgba(255, 255, 255, 0.72);
  --panel-strong: rgba(255, 255, 255, 0.9);
  --primary: #9d7cff;
  --primary-strong: #7a5bff;
  --text: #2a1b4a;
  --muted: #6a5c85;
  --border: rgba(255, 255, 255, 0.45);
  --shadow: 0 20px 50px rgba(93, 63, 211, 0.2);
  --radius-lg: 18px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg-gradient);
  font-family: 'Nunito', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 24px;
}
.app {
  width: 100%;
  max-width: 1300px;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
  position: relative;
  height: calc(100vh - 48px);
}
.app.sidebar-collapsed {
  grid-template-columns: 0px 1fr;
  gap: 0;
}
.sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(14px);
  transition: width 0.25s ease, transform 0.25s ease, opacity 0.25s ease;
}
.sidebar.collapsed {
  width: 0;
  padding: 0;
  border: 0;
  margin: 0;
  overflow: hidden;
  transform: translateX(-8px);
  opacity: 0;
  pointer-events: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.2px;
}
.brand .logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #b89bff, #7d5bff);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 8px 20px rgba(125, 91, 255, 0.3);
}
.primary-btn {
  background: linear-gradient(135deg, #a783ff, #8c6bff);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(125, 91, 255, 0.26);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  width: 100%;
}
.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(125, 91, 255, 0.32);
  filter: brightness(1.03);
}
.sidebar section {
  margin-top: 18px;
}
.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.7px;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
}
.history {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 10px;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border 0.15s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}
.history-item:hover {
  background: rgba(255, 255, 255, 0.6);
  border-color: var(--border);
}
.style-card {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}
.collapse-btn {
  margin-top: auto;
  border: none;
  background: rgba(255, 255, 255, 0.65);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  font-weight: 700;
  color: var(--primary-strong);
  transition: background 0.15s ease;
  display: none;
}
.collapse-btn:hover { background: rgba(255, 255, 255, 0.85); }
.main {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 80vh;
  overflow: hidden;
  backdrop-filter: blur(12px);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.6);
}
.title-group {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.topbar .title {
  font-weight: 700;
  font-size: 18px;
}
.ghost-btn {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
  color: var(--primary-strong);
  display: inline-flex;
  gap: 8px;
  align-items: center;
  transition: background 0.15s ease;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.95); }
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(255,255,255,0.55) 0%, rgba(255,255,255,0.75) 100%);
  min-height: 0; /* allow internal scroll */
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}
.message {
  display: flex;
  gap: 12px;
  max-width: 82%;
}
.message.user { margin-left: auto; flex-direction: row-reverse; }
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(135deg, #c5b0ff, #8c6bff);
  box-shadow: 0 10px 22px rgba(125, 91, 255, 0.25);
  flex-shrink: 0;
}
.avatar.user { background: linear-gradient(135deg, #ffb36b, #ff7a7a); }
.bubble {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 14px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.05);
  line-height: 1.5;
  font-weight: 600;
  white-space: pre-wrap;
}
.message.user .bubble {
  background: #f5ecff;
  border-color: #e3d6ff;
}
.input-panel {
  padding: 12px 18px 18px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
}
.toolbox-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
.toolbox-trigger {
  border: 1px dashed var(--primary);
  color: var(--primary-strong);
  background: rgba(157, 124, 255, 0.09);
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  transition: all 0.15s ease;
}
.toolbox-trigger:hover { filter: brightness(1.05); transform: translateY(-1px); }
.composer {
  display: grid;
  grid-template-columns: 1fr 130px 52px;
  gap: 10px;
  align-items: center;
}
textarea {
  width: 100%;
  resize: vertical;
  min-height: 70px;
  border-radius: 14px;
  border: 1px solid #e0d5ff;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  outline: none;
  transition: border 0.15s ease, box-shadow 0.15s ease;
}
textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(157, 124, 255, 0.18); }
select {
  border-radius: 12px;
  border: 1px solid #e0d5ff;
  padding: 10px 12px;
  font-weight: 700;
  color: var(--primary-strong);
  background: #fff;
}
.send-btn {
  border: none;
  background: linear-gradient(135deg, #a783ff, #8c6bff);
  color: #fff;
  border-radius: 14px;
  height: 100%;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 18px rgba(125, 91, 255, 0.25);
  transition: transform 0.15s ease;
}
.send-btn:hover { transform: translateY(-1px); }
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(33, 24, 68, 0.35);
  backdrop-filter: blur(4px);
  padding: 18px;
  z-index: 20;
}
.hidden { display: none !important; }
.modal-card {
  width: min(820px, 94vw);
  background: rgba(255, 255, 255, 0.92);
  border-radius: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 12px;
  color: var(--text);
}
.close-btn, .back-btn {
  border: none;
  background: rgba(157, 124, 255, 0.1);
  color: var(--primary-strong);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-weight: 700;
}
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.tile {
  border: 1px solid #e3dcff;
  border-radius: 12px;
  padding: 14px;
  background: rgba(157, 124, 255, 0.05);
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: center;
  transition: transform 0.12s ease, border 0.12s ease, background 0.12s ease;
  font-weight: 700;
}
.tile:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  background: rgba(157, 124, 255, 0.1);
}
.tile .icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #f1eaff;
  color: var(--primary-strong);
  font-size: 18px;
}
.example-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}
.example-item {
  border: 1px solid #e3dcff;
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: border 0.12s ease, background 0.12s ease;
}
.example-item:hover {
  border-color: var(--primary);
  background: rgba(157, 124, 255, 0.08);
}
.example-title { font-weight: 800; color: var(--text); }
.example-desc { color: var(--muted); margin-top: 6px; line-height: 1.5; }
@media (max-width: 960px) {
  body { padding: 14px; }
  .app { grid-template-columns: 1fr; }
  .app.sidebar-collapsed { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; height: calc(100vh - 28px); }
  .sidebar.collapsed { transform: translateX(-110%); opacity: 0; }
}
