:root {
  color-scheme: light;
  --ink-950: #101014;
  --ink-900: #181820;
  --ink-800: #22232c;
  --plum: #3d2448;
  --iris: #7367f0;
  --aqua: #20d6c7;
  --gold: #f0c36a;
  --paper: #f6f3ee;
  --paper-2: #ebe7df;
  --text: #f9f6ef;
  --muted: #817d88;
  --dark-text: #17171d;
  --line: rgba(23, 23, 29, 0.1);
  --panel: #ffffff;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #027a48;
  --grad: linear-gradient(135deg, var(--aqua), var(--gold));
  --shadow: 0 22px 60px rgba(16, 16, 20, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--ink-950);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 12%, rgba(115, 103, 240, 0.24), transparent 28%),
    radial-gradient(circle at 92% 8%, rgba(32, 214, 199, 0.2), transparent 24%),
    linear-gradient(135deg, #101014 0%, #181820 52%, #271d2c 100%);
  color: var(--dark-text);
  font-family: Inter, system-ui, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  background: var(--grad);
  color: #111116;
  cursor: pointer;
  padding: 0 16px;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 14px 32px rgba(32, 214, 199, 0.18);
  transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
}

button:hover {
  box-shadow: 0 18px 42px rgba(240, 195, 106, 0.23);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  border: 1px solid rgba(23, 23, 29, 0.1);
  background: #f9f7f1;
  color: var(--dark-text);
  box-shadow: none;
}

button.danger {
  border: 1px solid #fecdca;
  background: #fff1f0;
  color: var(--danger);
  box-shadow: none;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

input,
select,
textarea {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--dark-text);
  padding: 0 13px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(115, 103, 240, 0.6);
  box-shadow: 0 0 0 4px rgba(115, 103, 240, 0.12);
}

textarea {
  width: 100%;
  min-height: 260px;
  padding: 14px;
  line-height: 1.55;
  resize: vertical;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  color: var(--text);
  font-size: clamp(30px, 4vw, 50px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 6px;
  color: var(--dark-text);
  font-size: 22px;
  line-height: 1.15;
  font-weight: 900;
}

p {
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(16, 16, 20, 0.74);
  padding: 26px 20px;
  color: var(--text);
  backdrop-filter: blur(18px);
}

.brand {
  display: grid;
  gap: 6px;
  color: inherit;
  text-decoration: none;
}

.brand__mark {
  font-size: 27px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.brand__mark span {
  color: var(--aqua);
}

.brand__tag {
  color: rgba(249, 246, 239, 0.58);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.side-nav__item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: rgba(249, 246, 239, 0.68);
  padding: 0 12px;
  text-decoration: none;
  font-weight: 800;
}

.side-nav__item:hover,
.side-nav__item.active {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.side-nav__icon {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(32, 214, 199, 0.14);
  color: var(--aqua);
  font-size: 12px;
  font-weight: 900;
}

.sidebar__note {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  padding: 16px;
}

.sidebar__note p {
  margin: 8px 0 0;
  color: rgba(249, 246, 239, 0.62);
  font-size: 13px;
}

.note-dot {
  display: block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 6px rgba(240, 195, 106, 0.12);
}

.workspace {
  min-width: 0;
  padding: 34px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin: 0 auto 22px;
  max-width: 1180px;
}

.topbar__lead {
  margin-bottom: 0;
  color: rgba(249, 246, 239, 0.66);
  font-size: 16px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 12px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.eyebrow span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--aqua);
  box-shadow: 0 0 0 6px rgba(32, 214, 199, 0.12);
}

.status {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(249, 246, 239, 0.72);
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.login,
.panel {
  max-width: 1180px;
  margin: 0 auto 18px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background: rgba(246, 243, 238, 0.96);
  padding: 20px;
  box-shadow: var(--shadow);
}

.panel--primary {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(246, 243, 238, 0.98));
}

.panel__head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.panel__head p {
  margin-bottom: 0;
}

.panel__kicker {
  margin: 0 0 8px;
  color: var(--iris);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.login form,
.add-source,
.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto auto auto;
  gap: 10px;
  align-items: center;
}

.source-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
  gap: 14px;
  margin-top: 14px;
}

.source-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 92px;
  border: 1px solid rgba(115, 103, 240, 0.18);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.stat-card__icon {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(115, 103, 240, 0.1);
  color: var(--iris);
  font-size: 12px;
  font-weight: 900;
}

.stat-card strong {
  display: block;
  color: var(--dark-text);
  font-size: 20px;
  line-height: 1.1;
}

.stat-card span {
  display: block;
  margin-top: 5px;
  color: #5f6068;
  font-size: 13px;
  font-weight: 700;
}

.source-card {
  display: grid;
  gap: 14px;
  align-items: stretch;
  border: 1px solid rgba(115, 103, 240, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 16px;
}

.source-card--url {
  background:
    linear-gradient(135deg, rgba(32, 214, 199, 0.12), rgba(240, 195, 106, 0.1)),
    rgba(255, 255, 255, 0.82);
}

.source-card--file {
  background:
    linear-gradient(135deg, rgba(115, 103, 240, 0.1), rgba(32, 214, 199, 0.08)),
    rgba(255, 255, 255, 0.82);
}

.document-upload-card {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(260px, 0.8fr);
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
  border: 1px solid rgba(32, 214, 199, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(32, 214, 199, 0.11), rgba(240, 195, 106, 0.09)),
    rgba(255, 255, 255, 0.88);
  padding: 16px;
}

.document-upload-card h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.document-upload-card p {
  margin-bottom: 0;
}

.document-upload-card .upload-actions,
.document-upload-card .upload-status {
  grid-column: 1 / -1;
}

.jump-link {
  display: inline-flex;
  width: fit-content;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--grad);
  color: #111116;
  padding: 0 16px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 900;
}

.source-card h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.source-card p {
  margin-bottom: 0;
}

.source-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.field-label {
  display: grid;
  gap: 6px;
  color: var(--dark-text);
  font-size: 13px;
  font-weight: 900;
}

.field-label + input {
  margin-top: -6px;
}

.source-card--url input#sourceUrl {
  min-height: 48px;
  border-color: rgba(32, 214, 199, 0.34);
  background: rgba(255, 255, 255, 0.9);
  font-weight: 700;
}

.file-drop {
  min-height: 112px;
  border: 1px dashed rgba(115, 103, 240, 0.42);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  display: grid;
  place-items: center;
  align-content: center;
  padding: 16px;
  text-align: center;
  cursor: pointer;
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.file-drop span {
  color: var(--dark-text);
  font-size: 15px;
  font-weight: 900;
}

.file-drop small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.upload-status {
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 800;
}

.upload-status.ok {
  background: #dcfae6;
  color: var(--ok);
}

.upload-status.pending {
  background: #f2f4f7;
  color: #475467;
}

.upload-status.failed {
  background: #fff1f0;
  color: var(--danger);
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.health-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.health-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.health-card__top strong {
  font-size: 15px;
}

.health-card__top span {
  color: var(--dark-text);
  font-weight: 900;
}

.health-card p {
  margin: 10px 0 0;
  font-size: 13px;
}

.meter {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #ece8df;
}

.meter i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--ok);
  transition: width 0.25s ease, background 0.25s ease;
}

.meter i[data-level="warn"] {
  background: var(--warn);
}

.meter i[data-level="bad"] {
  background: var(--danger);
}

.login form {
  grid-template-columns: minmax(220px, 360px) auto;
}

.persona-form {
  display: grid;
  gap: 10px;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.form-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

label input {
  min-height: auto;
  accent-color: var(--iris);
}

.list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.source-item {
  grid-template-columns: 44px minmax(0, 1fr) auto;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(250, 248, 243, 0.96));
}

.source-item--upload {
  border-color: rgba(115, 103, 240, 0.2);
}

.source-item--web {
  border-color: rgba(32, 214, 199, 0.24);
}

.source-item__icon {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(115, 103, 240, 0.12);
  color: var(--iris);
  font-size: 12px;
  font-weight: 900;
}

.source-item--web .source-item__icon {
  background: rgba(32, 214, 199, 0.14);
  color: #138f86;
}

.document-card {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.document-card--ok {
  background: #f0fdf4;
  border-color: #abefc6;
}

.document-card--pending {
  background: #f8fafc;
  border-color: #d0d5dd;
}

.document-card--failed {
  background: #fff6f5;
  border-color: #fecdca;
}

.document-card__state {
  background: var(--muted);
}

.document-card--ok .document-card__state {
  background: var(--ok);
}

.document-card--pending .document-card__state {
  background: #98a2b3;
}

.document-card--failed .document-card__state {
  background: var(--danger);
}

.document-card__body {
  padding: 14px;
}

.document-card__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.document-card__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.document-statuses {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 900;
}

.status-pill.ok {
  background: #dcfae6;
  color: var(--ok);
}

.status-pill.pending {
  background: #eaecf0;
  color: #475467;
}

.status-pill.failed {
  background: #fee4e2;
  color: var(--danger);
}

.warning-note {
  margin-top: 10px;
  border: 1px solid #fedf89;
  border-radius: 8px;
  background: #fffaeb;
  color: var(--warn);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 800;
}

.conversation-layout {
  display: grid;
  grid-template-columns: minmax(240px, 0.38fr) minmax(0, 1fr);
  gap: 14px;
}

.conversation-list,
.conversation-detail {
  min-width: 0;
}

.conversation-list {
  display: grid;
  align-content: start;
  gap: 8px;
}

.conversation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--dark-text);
  padding: 12px;
}

.conversation-row.active,
.conversation-row:hover {
  border-color: rgba(32, 214, 199, 0.42);
  background: #f3fffc;
}

.conversation-row__open {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  box-shadow: none;
}

.conversation-row__open:hover {
  box-shadow: none;
}

.conversation-row__delete {
  align-self: center;
  min-height: 34px;
  padding: 0 12px;
}

.conversation-row__open span {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.conversation-row__open strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-row__open small,
.conversation-row__open i {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.conversation-detail {
  display: grid;
  gap: 12px;
}

.conversation-detail__head {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.conversation-detail__head h3 {
  margin: 0 0 4px;
  font-size: 19px;
}

.conversation-detail__head p {
  margin-bottom: 0;
}

.conversation-message {
  display: grid;
  gap: 12px;
  border: 1px solid rgba(115, 103, 240, 0.16);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.conversation-message__top,
.conversation-meta,
.citation-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.conversation-message__top {
  align-items: center;
  justify-content: space-between;
}

.conversation-message__top span,
.conversation-meta span {
  border-radius: 999px;
  background: #faf8f3;
  color: var(--muted);
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 900;
}

.qa-block {
  display: grid;
  gap: 6px;
}

.qa-label {
  margin: 0;
  color: var(--iris);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.qa-text {
  border: 1px solid rgba(23, 23, 29, 0.08);
  border-radius: 8px;
  background: #fafafa;
  padding: 12px;
  color: var(--dark-text);
  font-size: 14px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.citation-card {
  display: grid;
  gap: 4px;
  min-width: min(260px, 100%);
  border: 1px solid #d0d5dd;
  border-left: 6px solid #98a2b3;
  border-radius: 8px;
  background: #f8fafc;
  padding: 10px 12px;
}

.citation-card--ok {
  border-color: #abefc6;
  border-left-color: var(--ok);
  background: #f0fdf4;
}

.citation-card--failed {
  border-color: #fecdca;
  border-left-color: var(--danger);
  background: #fff6f5;
}

.citation-card strong {
  color: var(--dark-text);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.citation-card span,
.citation-empty {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.item__main {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.item__title {
  color: var(--dark-text);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.item__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #faf8f3;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  border-color: #a6f4c5;
  color: var(--ok);
}

.badge.failed {
  border-color: #fecdca;
  color: var(--danger);
}

.badge.queued,
.badge.limited {
  border-color: #fedf89;
  color: var(--warn);
}

.item__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.empty,
.error {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  padding: 16px;
  color: var(--muted);
}

.error {
  border-color: #fecdca;
  background: #fff6f5;
  color: var(--danger);
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .side-nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .sidebar__note {
    display: none;
  }

  .workspace {
    padding: 24px 18px 34px;
  }
}

@media (max-width: 760px) {
  .topbar,
  .panel__head,
  .item,
  .source-item {
    display: grid;
  }

  .login form,
  .add-source,
  .filters,
  .form-row,
  .source-tools,
  .source-stats,
  .document-upload-card,
  .conversation-layout,
  .source-item,
  .health-grid,
  .document-card__head {
    grid-template-columns: 1fr;
  }

  .form-row {
    display: grid;
  }

  .status {
    width: fit-content;
  }

  .item__actions {
    justify-content: flex-start;
  }

  .document-card__actions,
  .upload-actions {
    justify-content: flex-start;
  }
}
