:root {
  color-scheme: dark;
  --bg: #060608;
  --bg-elevated: #0c0c10;
  --surface: #101014;
  --surface-hover: #16161c;
  --surface-active: #1a1a22;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #ececf1;
  --text-secondary: #9898a8;
  --text-muted: #5c5c6e;
  --accent: #2dd4bf;
  --accent-dim: rgba(45, 212, 191, 0.12);
  --accent-glow: rgba(45, 212, 191, 0.35);
  --violet: #818cf8;
  --danger: #f87171;
  --danger-dim: rgba(248, 113, 113, 0.12);
  --sidebar-w: 200px;
  --radius: 10px;
  --radius-lg: 14px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --transition: 160ms ease;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* Ambient background */

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.ambient-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 30%, black 20%, transparent 75%);
}

.ambient-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.35;
}

.ambient-glow-a {
  width: 520px;
  height: 520px;
  top: -180px;
  left: 10%;
  background: var(--accent-glow);
}

.ambient-glow-b {
  width: 420px;
  height: 420px;
  bottom: -120px;
  right: 5%;
  background: rgba(129, 140, 248, 0.25);
}

/* Brand mark */

.brand-mark {
  position: relative;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  flex-shrink: 0;
}

.brand-mark-sm {
  width: 36px;
  height: 36px;
  border-radius: 10px;
}

.brand-core {
  position: absolute;
  inset: 10px;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  box-shadow: 0 0 20px var(--accent-glow);
}

.brand-mark-sm .brand-core {
  inset: 8px;
}

/* Login */

.login-screen {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 48px;
}

.login-panel {
  width: min(440px, 100%);
  padding: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(12, 12, 16, 0.85);
  backdrop-filter: blur(24px);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 24px 80px rgba(0, 0, 0, 0.5);
}

.login-brand {
  display: flex;
  gap: 18px;
  align-items: center;
  margin-bottom: 36px;
}

.brand-eyebrow {
  margin: 0 0 4px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.brand-title {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 6px 0 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.login-form {
  display: grid;
  gap: 18px;
}

.login-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--danger-dim);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: var(--danger);
  font-size: 0.88rem;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot-live {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* App shell */

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  border-right: 1px solid var(--border);
  background: rgba(8, 8, 10, 0.9);
  backdrop-filter: blur(12px);
}

.sidebar-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 0 6px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.sidebar-eyebrow {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.sidebar-title {
  margin: 2px 0 0;
  font-weight: 600;
  font-size: 0.88rem;
}

.sidebar-nav {
  display: grid;
  gap: 2px;
  align-content: start;
}

.nav-label {
  margin: 0 0 6px 8px;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  text-align: left;
}

.nav-item svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.55;
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
}

.nav-item.active {
  background: var(--surface);
  color: var(--text);
}

.nav-item.active svg {
  opacity: 0.9;
  color: var(--accent);
}

.sidebar-footer {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.stat-block {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 8px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* Workspace */

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  padding: 20px 32px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-eyebrow {
  margin: 0 0 4px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.header-meta {
  display: flex;
  gap: 10px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
  background: var(--surface);
}

.workspace-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel {
  display: none;
  height: 100%;
}

.panel.active {
  display: block;
}

/* Documents layout */

.docs-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1px;
  height: 100%;
  background: var(--border);
}

.docs-layout.has-detail {
  grid-template-columns: 340px 1fr 380px;
}

.ingest-column {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  overflow-y: auto;
}

.list-column,
.detail-column {
  background: var(--bg);
  overflow: hidden;
  min-height: 0;
}

.surface-card {
  padding: 22px;
  background: var(--bg-elevated);
}

.surface-card-fill {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.card-head {
  margin-bottom: 18px;
}

.card-head-row {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
}

.card-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.card-desc {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.card-tag {
  display: inline-block;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.format-list {
  display: grid;
  gap: 8px;
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.format-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  align-items: baseline;
  font-size: 0.8rem;
}

.format-row dt {
  margin: 0;
  font-weight: 500;
  color: var(--text-secondary);
}

.format-row dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.stack {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: rgba(45, 212, 191, 0.4);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

textarea {
  resize: vertical;
  min-height: 140px;
  line-height: 1.55;
}

.file-drop {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 88px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--transition), background var(--transition);
}

.file-drop:hover {
  border-color: rgba(45, 212, 191, 0.35);
  background: var(--surface-hover);
}

.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-drop-text {
  font-size: 0.82rem;
  color: var(--text-muted);
  pointer-events: none;
}

.file-drop.has-file .file-drop-text {
  color: var(--accent);
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-primary {
  background: linear-gradient(135deg, rgba(45, 212, 191, 0.2), rgba(129, 140, 248, 0.15));
  border-color: rgba(45, 212, 191, 0.35);
  color: var(--accent);
}

.btn-primary:hover {
  background: linear-gradient(135deg, rgba(45, 212, 191, 0.28), rgba(129, 140, 248, 0.22));
  border-color: rgba(45, 212, 191, 0.5);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-danger {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.2);
  background: transparent;
}

.btn-danger:hover {
  background: var(--danger-dim);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn-full {
  width: 100%;
}

.btn-icon {
  width: 16px;
  height: 16px;
}

.btn-send {
  width: 40px;
  height: 40px;
  padding: 0;
  flex-shrink: 0;
}

.btn-send svg {
  width: 18px;
  height: 18px;
}

/* Documents list */

.documents-list {
  flex: 1;
  overflow-y: auto;
  display: grid;
  gap: 8px;
  align-content: start;
  padding-right: 4px;
}

.document-item {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--transition), background var(--transition);
}

.document-item:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.document-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.document-title {
  margin: 0 0 4px;
  font-size: 0.92rem;
  font-weight: 500;
  word-break: break-word;
}

.document-meta {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--accent);
}

.document-preview {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.document-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.card-head-row .detail-actions {
  align-self: start;
}

.empty-state {
  display: grid;
  gap: 4px;
  padding: 48px 24px;
  text-align: center;
}

.empty-state p {
  margin: 0;
  color: var(--text-secondary);
  font-weight: 500;
}

.empty-state span {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.detail-content {
  flex: 1;
  overflow-y: auto;
  display: grid;
  gap: 10px;
  align-content: start;
  padding-right: 4px;
}

.chunk {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.chunk-label {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chunk p {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text-secondary);
}

/* Chat */

.chat-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 0 36px 24px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: grid;
  gap: 20px;
  align-content: start;
  padding: 24px 0;
  min-height: 0;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 820px;
}

.message.user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 500;
  flex-shrink: 0;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(45, 212, 191, 0.2);
}

.message.user .msg-avatar {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border);
}

.msg-body {
  min-width: 0;
}

.bubble {
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  white-space: pre-wrap;
  font-size: 0.92rem;
}

.message.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.message.user .bubble {
  background: linear-gradient(135deg, rgba(45, 212, 191, 0.15), rgba(129, 140, 248, 0.1));
  border: 1px solid rgba(45, 212, 191, 0.2);
  color: var(--text);
}

.sources {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 10px;
}

.sources-label {
  margin: 0 0 4px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.source {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.source strong {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
  font-weight: 500;
  font-size: 0.78rem;
}

.loading {
  opacity: 0.6;
}

.loading .bubble::after {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}

.chat-composer {
  flex-shrink: 0;
  padding-top: 8px;
}

.composer-inner {
  display: flex;
  gap: 10px;
  align-items: end;
  padding: 10px 10px 10px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.composer-inner textarea {
  flex: 1;
  min-height: 24px;
  max-height: 160px;
  padding: 4px 0;
  border: none;
  background: transparent;
  resize: none;
  line-height: 1.5;
}

.composer-inner textarea:focus {
  box-shadow: none;
}

.composer-hint {
  margin: 8px 4px 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Toast */

.toast {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 100;
  padding: 12px 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-active);
  color: var(--text);
  font-size: 0.88rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.hidden {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

/* Delete modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-active);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.modal-eyebrow {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--danger);
}

.modal-panel h3 {
  margin: 0 0 12px;
  font-size: 1.15rem;
}

.modal-copy {
  margin: 0 0 24px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.modal-copy strong {
  color: var(--text);
  font-weight: 500;
  word-break: break-word;
}

.modal-actions {
  display: flex;
  justify-content: end;
  gap: 10px;
}
