:root {
  color-scheme: light;
  --ink: #18202d;
  --muted: #667085;
  --line: rgba(30, 41, 59, 0.12);
  --glass: rgba(255, 255, 255, 0.72);
  --glass-strong: rgba(255, 255, 255, 0.86);
  --blue: #1677ff;
  --blue-deep: #0f56c8;
  --green: #0f9f7a;
  --rose: #d84b6b;
  --shadow: 0 24px 80px rgba(42, 61, 94, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(231, 246, 255, 0.96), rgba(255, 255, 255, 0.98) 34%, rgba(248, 243, 255, 0.94) 66%, rgba(239, 251, 245, 0.96)),
    linear-gradient(180deg, #ffffff, #f6f8fb);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button,
.button-link {
  min-height: 42px;
  border: 1px solid rgba(22, 119, 255, 0.16);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--blue), var(--blue-deep));
  color: #fff;
  cursor: pointer;
  padding: 0 16px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

button:hover,
.button-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(22, 119, 255, 0.22);
}

button.ghost,
.ghost {
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
  border-color: var(--line);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  outline: none;
  padding: 12px 14px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(22, 119, 255, 0.48);
  box-shadow: 0 0 0 4px rgba(22, 119, 255, 0.10);
  background: rgba(255, 255, 255, 0.94);
}

.page-shell {
  width: 100vw;
  min-height: 100vh;
  padding: 22px;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  grid-template-areas:
    "topbar topbar"
    "nav main"
    "login login";
  gap: 14px;
}

.topbar {
  grid-area: topbar;
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

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

.brand img {
  width: 138px;
  height: auto;
  object-fit: contain;
}

.brand h1,
.glass-card h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: clamp(24px, 3vw, 44px);
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.session {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.main-nav {
  grid-area: nav;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  align-self: start;
  position: sticky;
  top: 22px;
  min-height: calc(100vh - 118px);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.54);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  width: 100%;
  overflow: hidden;
}

.main-nav button {
  width: 100%;
  min-height: 44px;
  border-radius: 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  justify-content: flex-start;
  white-space: normal;
}

.main-nav button.active {
  background: var(--ink);
  color: #fff;
}

.app-main {
  grid-area: main;
  display: grid;
  gap: 14px;
  min-width: 0;
}

.glass-card {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border-radius: 22px;
  padding: 18px;
}

.login-panel {
  grid-area: login;
  min-height: 220px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(280px, 520px);
  gap: 20px;
  align-items: center;
}

.login-panel h2,
.glass-card h2 {
  font-size: 22px;
}

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

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

.metric {
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

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

.metric strong {
  font-size: clamp(34px, 5vw, 58px);
  line-height: 0.95;
}

.page-section {
  display: none;
}

.page-section.active-page {
  display: grid;
  gap: 14px;
}

.page-title {
  min-height: 96px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  padding: 4px 2px 0;
}

.page-title h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 52px);
  line-height: 1;
}

.page-title p:not(.eyebrow) {
  margin: 0;
  max-width: 460px;
  color: var(--muted);
  line-height: 1.55;
}

.ask-grid,
.knowledge-grid,
.training-grid,
.accounts-grid,
.ops-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1.2fr) minmax(320px, 1fr);
  grid-auto-rows: minmax(220px, auto);
  gap: 14px;
}

.ask-grid > *,
.knowledge-grid > *,
.training-grid > *,
.accounts-grid > *,
.ops-grid > * {
  min-width: 0;
}

.ask-card {
  grid-column: span 1;
}

.results-card {
  grid-column: span 2;
}

.list-card {
  grid-column: span 2;
}

.training-card {
  grid-column: span 2;
}

.users-card,
.activity-card {
  grid-column: span 2;
}

.import-card {
  grid-column: span 2;
}

.backup-card {
  min-height: 240px;
}

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

.segmented {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.56);
}

.segmented button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  border: 0;
  box-shadow: none;
}

.segmented button.active {
  background: var(--ink);
  color: #fff;
}

.action-row,
.split-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.action-row {
  margin-top: 12px;
}

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

.message {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--muted);
}

.pill {
  min-width: 54px;
  padding: 8px 10px;
  border-radius: 999px;
  color: var(--blue-deep);
  background: rgba(22, 119, 255, 0.10);
  text-align: center;
  font-weight: 700;
}

.results-list,
.knowledge-list,
.signal-list,
.training-list,
.users-list,
.activity-list,
.preview {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.empty-state {
  min-height: 120px;
  color: var(--muted);
  align-content: center;
}

.result-item,
.knowledge-item,
.signal-item,
.training-item,
.user-item,
.activity-item,
.candidate-item {
  border: 1px solid rgba(30, 41, 59, 0.10);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.64);
  padding: 14px;
}

.result-top,
.knowledge-top,
.signal-top,
.user-top,
.activity-top {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.result-top > div,
.knowledge-top > div,
.signal-top > div,
.user-top > div,
.activity-top > div {
  min-width: 0;
}

.user-controls {
  display: grid;
  grid-template-columns: minmax(140px, 1.1fr) minmax(120px, 0.8fr) minmax(120px, 0.8fr) minmax(150px, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}

.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.stat-chip {
  padding: 7px 9px;
  border-radius: 999px;
  border: 1px solid rgba(30, 41, 59, 0.08);
  background: rgba(255, 255, 255, 0.54);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.pagination-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.pagination-bar button {
  min-height: 36px;
}

.backup-actions {
  min-height: 120px;
  display: flex;
  align-items: center;
}

.item-title {
  margin: 0;
  font-weight: 760;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.item-answer {
  white-space: pre-wrap;
  color: #2f3a4b;
  line-height: 1.62;
  margin: 10px 0 0;
  overflow-wrap: anywhere;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.compact-input {
  max-width: 240px;
}

.library-filters {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  min-width: min(100%, 500px);
}

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  white-space: nowrap;
  color: var(--muted);
}

.switch input {
  width: auto;
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .page-shell {
    grid-template-columns: 190px minmax(0, 1fr);
  }

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

  .ask-grid,
  .knowledge-grid,
  .training-grid,
  .accounts-grid,
  .ops-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .results-card,
  .list-card,
  .users-card,
  .activity-card,
  .import-card {
    grid-column: span 2;
  }
}

@media (max-width: 720px) {
  .page-shell {
    padding: 14px;
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "nav"
      "login"
      "main";
  }

  .topbar,
  .login-panel,
  .card-head,
  .page-title,
  .split-row,
  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .main-nav {
    position: static;
    min-height: 0;
    flex-direction: row;
    overflow-x: auto;
    border-radius: 18px;
    padding: 6px;
  }

  .main-nav button {
    width: auto;
    min-width: max-content;
    min-height: 38px;
    justify-content: center;
    white-space: nowrap;
  }

  .login-panel,
  .metrics-grid,
  .ask-grid,
  .knowledge-grid,
  .training-grid,
  .accounts-grid,
  .ops-grid {
    grid-template-columns: 1fr;
  }

  .results-card,
  .list-card,
  .training-card,
  .users-card,
  .activity-card,
  .import-card {
    grid-column: span 1;
  }

  .brand {
    align-items: flex-start;
  }

  .brand img {
    width: 96px;
  }

  .compact-input {
    max-width: none;
  }

  .library-filters {
    width: 100%;
    min-width: 0;
    flex-direction: column;
    align-items: stretch;
  }

  .user-controls,
  .pagination-bar {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }
}
