:root {
  --bg: #0b0f14;
  --panel: hsl(var(--h), 40%, 13%);
  --panel-2: hsl(var(--h), 38%, 11%);
  --border: rgba(255, 255, 255, 0.08);
  --text: rgba(255, 255, 255, 0.9);
  --muted: rgba(255, 255, 255, 0.62);
  --h: 252;
  --h2: calc(var(--h) + 280);
  --sat: 100%;
  --sat-accent: 100%;
  --sat-accent-2: 66%;
  --sat-surface: 32%;
  --sat-surface-2: 34%;
  --sat-chrome: 30%;
  --sat-sidebar-top: 40%;
  --sat-panel-bg: 40%;
  --accent: hsl(var(--h), var(--sat-accent), 68%);
  --accent-2: hsl(var(--h2), var(--sat-accent-2), 50%);
  --surface: hsla(var(--h), var(--sat-surface), 12%, 0.75);
  --surface-2: hsla(var(--h), var(--sat-surface-2), 12%, 0.8);
  --chrome: hsla(var(--h), var(--sat-chrome), 6%, 0.75);
  --chrome-strong: hsla(var(--h), var(--sat-chrome), 6%, 0.98);
  --sidebar-top: hsla(var(--h), var(--sat-sidebar-top), 13%, 0.96);
  --sidebar-bottom: hsla(var(--h), var(--sat-chrome), 6%, 0.96);
  --panel-bg: hsla(var(--h), var(--sat-panel-bg), 13%, 0.65);
  --danger: #ff4d6d;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: radial-gradient(
      1200px 700px at 20% 0%,
      hsla(var(--h), var(--sat-accent), 68%, 0.25),
      transparent 60%
    ),
    radial-gradient(
      900px 500px at 90% 10%,
      hsla(var(--h2), var(--sat-accent-2), 50%, 0.12),
      transparent 55%
    ),
    var(--bg);
}

.app-shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, var(--sidebar-top), var(--sidebar-bottom));
  padding: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 12px;
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  height: 36px;
  width: auto;
  flex: 0 0 auto;
}

.brand-text {
  min-width: 0;
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.panel-title {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.input,
.textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  outline: none;
}

.input::placeholder,
.textarea::placeholder {
  color: rgba(255, 255, 255, 0.42);
}

.textarea {
  resize: vertical;
  min-height: 48px;
  line-height: 1.35;
}

.textarea.code {
  font-family: var(--mono);
  font-size: 12px;
}

.input-file {
  width: 100%;
  color: var(--muted);
}

.btn {
  border: 1px solid hsla(var(--h), var(--sat-accent), 68%, 0.38);
  background: hsla(var(--h), var(--sat-accent), 68%, 0.15);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: transform 0.06s ease, background 0.15s ease;
}

.btn:hover {
  background: hsla(var(--h), var(--sat-accent), 68%, 0.24);
}

.btn:active {
  transform: translateY(1px);
}

.btn.btn-primary {
  background: linear-gradient(
    90deg,
    hsla(var(--h), var(--sat-accent), 68%, 0.55),
    hsla(var(--h2), var(--sat-accent-2), 50%, 0.35)
  );
  border-color: hsla(var(--h), var(--sat-accent), 68%, 0.6);
}

.btn.btn-secondary {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.06);
}

.btn.btn-xs {
  padding: 6px 10px;
  font-size: 12px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-title-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.panel-title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 20px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.list {
  display: grid;
  gap: 6px;
  min-height: 0;
  align-content: start;
  grid-auto-rows: max-content;
}

.list.small {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
  max-height: none;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
  min-height: 36px;
  max-height: 44px;
}

.list-item > span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item.active {
  border-color: hsla(var(--h), var(--sat-accent), 68%, 0.65);
  background: hsla(var(--h), var(--sat-accent), 68%, 0.16);
}

.file-row {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 8px 10px;
}

.file-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 10px;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn.icon-only {
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.list-item > .icon-btn,
.file-row > .icon-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.danger {
  border: 1px solid rgba(255, 77, 109, 0.4);
  background: rgba(255, 77, 109, 0.12);
}

.icon-btn svg {
  display: block;
}

.muted {
  color: var(--muted);
  font-size: 12px;
  margin-top: 0;
}

.status-bad {
  color: var(--danger);
}

.sidebar > .panel:last-of-type {
  flex: 1 1 auto;
}

#collections {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.panel-collapsed {
  padding-bottom: 10px;
}

.panel-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

#collectionsPanel {
  height: 800px;
  flex: 0 0 800px;
  min-height: 800px;
  flex-shrink: 0;
}

#collectionsPanel.panel-collapsed {
  height: auto;
  flex: 0 0 auto;
  min-height: 0;
}

.main {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100vh;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--chrome);
  backdrop-filter: blur(8px);
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
}

.sidebar-toggle {
  display: none;
}

.sidebar-overlay {
  display: none;
}

.messages {
  padding: 12px;
  overflow: auto;
}

.empty-chat {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
}

.empty-chat-logo {
  width: min(420px, 70%);
  height: auto;
  opacity: 0.46;
  filter: drop-shadow(0 18px 38px rgba(0, 0, 0, 0.45));
}

.empty-chat-strapline {
  color: rgba(226, 232, 240, 0.72);
  font-size: 13px;
  letter-spacing: 0.2px;
  text-align: center;
  max-width: 520px;
}

.message {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  max-width: 900px;
  box-shadow: var(--shadow);
}

.message.user {
  margin-left: auto;
  max-width: 95%;
  background: hsla(var(--h), var(--sat-accent), 68%, 0.16);
  border-color: hsla(var(--h), var(--sat-accent), 68%, 0.5);
}

.message.from-user {
  margin-left: auto;
  max-width: 95%;
}

.message.assistant {
  background: hsla(var(--h), var(--sat-panel-bg), 13%, 0.7);
}

.message.user .message-content {
  text-align: right;
}

.message.from-user .message-content {
  text-align: right;
}

.message-role {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 8px;
}

.message-content {
  white-space: normal;
  line-height: 1.45;
}

.message-content p {
  margin: 0 0 10px 0;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 0 0 10px 0;
  line-height: 1.2;
}

.message-content h1 {
  font-size: 16px;
}

.message-content h2 {
  font-size: 14px;
}

.message-content h3 {
  font-size: 13px;
}

.message-content ul,
.message-content ol {
  margin: 0 0 10px 18px;
  padding: 0;
}

.message-content li {
  margin: 4px 0;
}

.message-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
}

.message-content pre.md-pre {
  margin: 0 0 10px 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.28);
  overflow: auto;
}

.message-content pre.md-pre code {
  display: block;
  padding: 0;
  border: none;
  background: transparent;
  white-space: pre;
}

.message-content a {
  color: rgba(181, 170, 255, 1);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--chrome);
  backdrop-filter: blur(8px);
}

.status {
  min-height: 26px;
  padding: 0 12px 12px 12px;
  color: rgba(255, 255, 255, 0.64);
  font-size: 12px;
}

.dialog {
  width: min(980px, 96vw);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--chrome-strong);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog-body {
  padding: 16px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.dialog-title {
  font-weight: 750;
}

.viewer-frame {
  width: 100%;
  height: min(80vh, 820px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: hsla(var(--h), var(--sat-surface), 12%, 0.6);
}

.viewer-content {
  width: 100%;
  height: min(80vh, 820px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: hsla(var(--h), var(--sat-surface), 12%, 0.6);
  overflow: auto;
  padding: 14px;
  display: none;
}

.text-preview {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.4;
  margin: 0;
}

.docx-preview img {
  max-width: 100%;
  height: auto;
}

.docx-preview table {
  border-collapse: collapse;
  max-width: 100%;
}

.docx-preview td,
.docx-preview th {
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 6px 8px;
  vertical-align: top;
}

.list.small {
  scrollbar-color: rgba(255, 255, 255, 0.28) rgba(255, 255, 255, 0.06);
  scrollbar-width: thin;
}

#collections {
  scrollbar-color: rgba(255, 255, 255, 0.28) rgba(255, 255, 255, 0.06);
  scrollbar-width: thin;
}

.list.small::-webkit-scrollbar,
#collections::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.viewer-content::-webkit-scrollbar {
  width: 10px;
}

.list.small::-webkit-scrollbar-track,
#collections::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track,
.viewer-content::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
}

.list.small::-webkit-scrollbar-thumb,
#collections::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.viewer-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.28);
  border-radius: 999px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.label-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

@media (max-width: 980px) {
  .sidebar-open {
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 360px;
    max-width: 92vw;
    border-right: 1px solid var(--border);
    border-bottom: none;
    transform: translateX(-105%);
    transition: transform 160ms ease;
    z-index: 50;
  }

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

  .sidebar-toggle {
    display: inline-flex;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    z-index: 40;
  }

  .sidebar-open .sidebar-overlay {
    display: block;
  }

  #collectionsPanel {
    height: 60vh;
    flex: 0 0 auto;
    min-height: 0;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}
