:root {
  --primary: #1E6FFF;
  --primary-hover: #4A8BFF;
  --primary-soft: #E8F1FF;
  --text: #1A2233;
  --muted: #6B7280;
  --line: #E5E7EB;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --bg: #F7F9FC;
  --white: #FFFFFF;
  --shadow: 0 12px 30px rgba(26, 34, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #FFFFFF 0%, #F4F8FF 100%);
}

.auth-panel {
  width: min(440px, 100%);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.auth-panel h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.auth-panel p {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.6;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--white);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px;
}

.avatar-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
}

.avatar-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  overflow-x: auto;
  padding: 3px 2px 6px;
}

.avatar-option {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border: 1px solid transparent;
  background: var(--white);
  color: var(--text);
  border-radius: 999px;
  padding: 0;
  display: grid;
  place-items: center;
}

.avatar-option:hover {
  border-color: var(--primary-hover);
  background: var(--primary-soft);
}

.avatar-option.active {
  border-color: var(--primary);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(30, 111, 255, 0.14);
}

.avatar-art {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: var(--avatar-fg);
  background: var(--avatar-bg);
}

.avatar-art.compact {
  width: 38px;
  height: 38px;
  border-radius: 8px;
}

.avatar-svg {
  width: 26px;
  height: 26px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.avatar-art.compact .avatar-svg {
  width: 22px;
  height: 22px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
}

.brand-logo img {
  width: 40px;
  height: 40px;
  display: block;
}

.brand-title {
  font-weight: 800;
  line-height: 1.2;
}

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

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

.nav button,
.mobile-nav button {
  border: 0;
  color: var(--muted);
  background: transparent;
}

.nav button {
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.icon {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-icon {
  width: 20px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 20px;
}

.nav button.active,
.nav button:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 26px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel,
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 18px;
}

.card {
  padding: 16px;
}

.card-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.metric {
  font-size: 28px;
  font-weight: 800;
  margin: 8px 0 2px;
}

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

.small {
  font-size: 13px;
}

.btn {
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--text);
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--primary-hover);
  color: var(--primary);
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
}

.btn.primary:hover {
  background: var(--primary-hover);
  color: var(--white);
}

.btn.danger {
  color: var(--danger);
  border-color: #FECACA;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--muted);
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

.icon-btn:hover {
  border-color: var(--primary-hover);
  color: var(--primary);
  background: var(--primary-soft);
}

.icon-btn.danger {
  color: var(--danger);
  border-color: #FECACA;
}

.icon-btn.danger:hover {
  background: #FEF2F2;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-head h3 {
  margin: 0 0 4px;
}

.section-head p {
  margin: 0;
}

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

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

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

.readonly-list {
  display: grid;
  gap: 8px;
}

.readonly-item {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #FAFBFD;
  padding: 8px 10px;
  color: var(--text);
}

.readonly-item span {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 22px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 700;
}

.field label {
  font-weight: 700;
  font-size: 14px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--text);
  min-height: 40px;
  padding: 9px 11px;
  outline: none;
}

.field textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.6;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 111, 255, 0.12);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--white);
  padding: 5px 11px;
  color: var(--muted);
}

.tag.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.tabs button {
  border: 1px solid var(--line);
  background: var(--white);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--muted);
  white-space: nowrap;
}

.tabs button.active {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  background: #F3F4F6;
  color: var(--muted);
}

.status.ready,
.status.active,
.status.ok {
  background: #ECFDF5;
  color: #047857;
}

.status.failed,
.status.danger {
  background: #FEF2F2;
  color: #B91C1C;
}

.status.parsing,
.status.warn {
  background: #FFFBEB;
  color: #B45309;
}

.progress {
  height: 9px;
  border-radius: 999px;
  background: #EEF2F7;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  background: #FAFBFD;
}

tr:last-child td {
  border-bottom: 0;
}

.split {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 16px;
}

.kb-shell {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.folder-list {
  display: grid;
  gap: 8px;
}

.folder-button {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--text);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
}

.folder-button:hover,
.folder-button.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.folder-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-button b {
  min-width: 28px;
  height: 24px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  padding: 0 8px;
  color: var(--muted);
  background: #F3F4F6;
  font-size: 12px;
}

.folder-button.active b {
  color: var(--primary);
  background: var(--white);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.breadcrumb button {
  border: 0;
  background: transparent;
  color: var(--primary);
  padding: 0;
}

.chat-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr) minmax(240px, 320px);
  gap: 16px;
  min-height: calc(100vh - 130px);
}

.chat-window {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 560px;
}

.chat-recommendations {
  display: grid;
  gap: 8px;
}

.question-btn {
  width: 100%;
  min-height: 40px;
  height: auto;
  justify-content: flex-start;
  padding: 9px 11px;
  text-align: left;
  line-height: 1.45;
  white-space: normal;
  overflow-wrap: anywhere;
}

.messages {
  overflow: auto;
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.bubble {
  max-width: min(720px, 92%);
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.bubble p {
  margin: 0 0 10px;
}

.bubble p:last-child,
.bubble .clean-list:last-child {
  margin-bottom: 0;
}

.clean-heading {
  font-weight: 800;
  margin: 4px 0 8px;
}

.clean-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  display: grid;
  gap: 7px;
}

.clean-list li {
  position: relative;
  padding-left: 16px;
}

.clean-list li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.82em;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.45;
}

.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: rgba(15, 23, 42, 0.08);
  border-radius: 5px;
  padding: 2px 5px;
}

.bubble.user {
  margin-left: auto;
  background: var(--primary);
  color: var(--white);
}

.bubble.assistant {
  background: #F3F6FA;
}

.chat-input {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: flex;
  gap: 10px;
}

.chat-input textarea {
  flex: 1;
  min-height: 46px;
  max-height: 130px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  resize: vertical;
}

.trace-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  line-height: 1.55;
}

.skill-category {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.skill-category-title {
  font-weight: 800;
  color: var(--text);
}

.empty {
  border: 1px dashed #C9D4E5;
  border-radius: 8px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: #FCFDFF;
}

.empty.compact {
  padding: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(26, 34, 51, 0.34);
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal {
  width: min(720px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: var(--white);
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 22px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.modal-head h3,
.modal-head p {
  margin: 0;
}

.modal-head h3 {
  margin-bottom: 4px;
}

.url-upload-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.step {
  height: 6px;
  border-radius: 999px;
  background: #E5E7EB;
}

.step.active {
  background: var(--primary);
}

.mobile-nav {
  display: none;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(380px, calc(100vw - 40px));
  background: var(--text);
  color: var(--white);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.admin-shell {
  min-height: 100vh;
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
}

.admin-main {
  padding: 22px;
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: #F3F4F6;
  border-radius: 6px;
  padding: 2px 5px;
  overflow-wrap: anywhere;
}

.code-block {
  margin: 10px 0 0;
  max-height: 340px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0F172A;
  color: #E5E7EB;
  padding: 12px;
  line-height: 1.55;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

  .sidebar {
    display: none;
  }

  .main {
    padding: 18px 14px 82px;
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    border-top: 1px solid var(--line);
    background: var(--white);
  }

  .mobile-nav button {
    min-width: 0;
    height: 60px;
    display: grid;
    place-items: center;
    gap: 2px;
    font-size: 11px;
  }

  .mobile-nav .icon {
    width: 17px;
    height: 17px;
  }

  .mobile-nav button.active {
    color: var(--primary);
    background: var(--primary-soft);
  }

  .grid.cols-3,
  .grid.cols-2,
  .split,
  .kb-shell,
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .chat-layout {
    min-height: auto;
  }

  .chat-window {
    min-height: 520px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .auth-panel,
  .modal,
  .panel,
  .card {
    padding: 14px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .metric {
    font-size: 24px;
  }

  .toolbar,
  .chat-input {
    align-items: stretch;
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }

  .stepper {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

}
