:root {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-elev: #121a2f;
  --bg-soft: #18233d;
  --line: #2a3657;
  --text: #e8eefc;
  --muted: #9aacd0;
  --accent: #6ea8ff;
  --accent-2: #7ef0c3;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  line-height: 1.45;
  font-weight: 400;
  color: var(--text);
  background: radial-gradient(1200px 600px at 10% -10%, #1a2b55 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #163a3a 0%, transparent 50%), var(--bg);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(11, 16, 32, 0.72);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.brand {
  padding: 22px 20px 12px;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.sidebar-actions {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  transition: 0.15s ease;
}

.btn:hover {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(135deg, #3d74ff, #2bb7a0);
  border-color: transparent;
  color: white;
  font-weight: 600;
}

.btn.ghost {
  background: transparent;
}

.search {
  margin: 0 16px 12px;
}

.search input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  padding: 10px 12px;
  outline: none;
}

.search input:focus {
  border-color: var(--accent);
}

.memory-list {
  overflow: auto;
  padding: 0 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.memory-card {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
}

.memory-card.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(110, 168, 255, 0.35);
}

.memory-card h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}

.memory-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.chip {
  font-size: 0.75rem;
  border-radius: 999px;
  padding: 2px 8px;
  background: rgba(110, 168, 255, 0.12);
  color: var(--accent);
  border: 1px solid rgba(110, 168, 255, 0.25);
}

.chip.kind {
  background: rgba(126, 240, 195, 0.1);
  color: var(--accent-2);
  border-color: rgba(126, 240, 195, 0.25);
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
}

.topbar h2 {
  margin: 0;
  font-size: 1.05rem;
}

.topbar span {
  color: var(--muted);
  font-size: 0.9rem;
}

.chat {
  flex: 1;
  overflow: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.bubble {
  max-width: min(760px, 92%);
  padding: 14px 16px;
  border-radius: 16px;
  white-space: pre-wrap;
  box-shadow: var(--shadow);
  line-height: 1.55;
}

.bubble.user {
  align-self: flex-end;
  background: linear-gradient(160deg, #2d4d9a, #243a78);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bg-elev);
  border: 1px solid var(--line);
}

.bubble .refs {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.empty {
  margin: auto;
  max-width: 560px;
  text-align: center;
  color: var(--muted);
}

.empty h3 {
  color: var(--text);
  margin-bottom: 8px;
}

.tips {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.tips button {
  text-align: left;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: rgba(24, 35, 61, 0.6);
  padding: 10px 12px;
  cursor: pointer;
}

.composer {
  padding: 16px 22px 22px;
  border-top: 1px solid var(--line);
  background: rgba(11, 16, 32, 0.65);
}

.composer-box {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: end;
  max-width: 900px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.attach-chip {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.composer textarea {
  width: 100%;
  min-height: 56px;
  max-height: 180px;
  resize: vertical;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  padding: 12px 14px;
  outline: none;
}

.composer textarea:focus {
  border-color: var(--accent);
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.panel {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 18, 0.65);
  display: grid;
  place-items: center;
  z-index: 30;
  padding: 16px;
}

.panel[hidden] {
  display: none !important;
}

.panel-card {
  width: min(520px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel-card h3 {
  margin: 0 0 12px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  color: var(--muted);
  font-size: 0.9rem;
}

.field input,
.field textarea,
.field select {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 10px 12px;
  outline: none;
}

.field textarea {
  min-height: 120px;
  resize: vertical;
}

.panel-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.detail {
  border-top: 1px solid var(--line);
  padding: 14px 16px 18px;
  background: rgba(18, 26, 47, 0.9);
}

.detail h3 {
  margin: 0 0 6px;
}

.detail p {
  margin: 0;
  white-space: pre-wrap;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
  background: #6b778f;
}

.status-dot.on {
  background: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(126, 240, 195, 0.15);
}

.auth-body {
  min-height: 100vh;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 0;
}

.auth-hero {
  padding: clamp(32px, 8vw, 80px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  background:
    radial-gradient(700px 420px at 20% 20%, rgba(61, 116, 255, 0.28), transparent 60%),
    radial-gradient(600px 360px at 80% 80%, rgba(43, 183, 160, 0.18), transparent 55%),
    linear-gradient(160deg, #0b1020, #121a2f 55%, #0d1828);
}

.brand-mark {
  margin: 0 0 18px;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.auth-hero h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1.1;
  max-width: 10ch;
}

.auth-hero p:last-child {
  margin: 0;
  color: var(--muted);
  max-width: 34ch;
  font-size: 1.05rem;
}

.auth-card {
  margin: auto;
  width: min(420px, calc(100% - 48px));
  background: rgba(18, 26, 47, 0.92);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.auth-card h2 {
  margin: 0 0 18px;
  font-size: 1.35rem;
}

.auth-form .btn.wide,
.btn.wide {
  width: 100%;
}

.auth-error {
  color: #ff7b8a;
  margin: 0 0 10px;
}

.auth-switch {
  margin: 16px 0 0;
  color: var(--muted);
  text-align: center;
}

.auth-switch a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.user-line {
  margin: 4px 0 0 !important;
  font-size: 0.85rem !important;
}

.web-actions {
  margin-top: 12px;
}

@media (max-width: 900px) {
  .auth-page {
    grid-template-columns: 1fr;
  }

  .auth-hero {
    min-height: 34vh;
    padding: 28px 22px;
  }

  .auth-hero h1 {
    max-width: none;
  }
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    max-height: 42vh;
  }
}
