:root {
  color-scheme: light;
  --bg: #eef2f6;
  --bg-soft: #f7f9fb;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-muted: #f4f7fa;
  --text: #172026;
  --text-strong: #0f1720;
  --muted: #637181;
  --faint: #8b98a8;
  --line: #d9e1ea;
  --line-strong: #c7d1dc;
  --primary: #0f766e;
  --primary-dark: #0b5d57;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --danger: #b42318;
  --ok: #087443;
  --nav: #121a24;
  --nav-2: #1b2633;
  --nav-line: #2c3948;
  --shadow-sm: 0 1px 2px rgba(15, 23, 32, 0.06);
  --shadow-panel: 0 12px 30px rgba(31, 41, 55, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f7f9fb 0, #eef2f6 360px, #e9eef4 100%);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body:has(.auth-screen.show) {
  overflow: hidden;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--text-strong);
  font-size: 24px;
  line-height: 1.18;
  font-weight: 760;
}

h2 {
  color: var(--text-strong);
  font-size: 15px;
  line-height: 1.3;
  font-weight: 750;
}

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

button {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 720;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  background: #101722;
  padding: 18px;
}

.auth-screen.show {
  display: grid;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  display: grid;
  gap: 15px;
}

.auth-card h1 {
  font-size: 25px;
}

.auth-card p {
  color: var(--muted);
}

.auth-error {
  min-height: 20px;
  color: var(--danger);
  font-weight: 650;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--nav);
  color: #f8fafc;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  min-width: 0;
  border-right: 1px solid #0b1119;
  box-shadow: 8px 0 30px rgba(15, 23, 32, 0.18);
}

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

.brand .mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #0f766e;
  color: #ffffff;
  font-weight: 850;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), 0 8px 18px rgba(15, 118, 110, 0.28);
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 15px;
  letter-spacing: 0;
}

.brand span {
  color: #aab6c4;
  font-size: 12px;
}

.search-wrap input,
label input,
label select,
label textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 10px 11px;
  min-width: 0;
  outline: 0;
  box-shadow: var(--shadow-sm);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.search-wrap input:focus,
label input:focus,
label select:focus,
label textarea:focus {
  border-color: rgba(15, 118, 110, 0.72);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.search-wrap input {
  border-color: var(--nav-line);
  background: var(--nav-2);
  color: #f8fafc;
  box-shadow: none;
}

.search-wrap input::placeholder,
label input::placeholder,
label textarea::placeholder {
  color: var(--faint);
}

.page-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.page-item {
  text-align: left;
  min-height: 76px;
  padding: 11px;
  background: var(--nav-2);
  color: #f8fafc;
  border: 1px solid var(--nav-line);
  border-radius: var(--radius);
  box-shadow: none;
}

.page-item:hover {
  background: #223044;
  border-color: #415065;
}

.page-item.active {
  border-color: #2dd4bf;
  background: #14343a;
  box-shadow: inset 3px 0 0 #2dd4bf;
}

.page-item strong,
.page-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-item strong {
  font-size: 13px;
}

.page-item span {
  color: #b8c4d1;
  font-size: 12px;
  margin-top: 4px;
}

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

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 520px);
  align-items: start;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar > div:first-child {
  padding: 4px 0;
}

.topbar p {
  color: var(--muted);
  margin-top: 6px;
  max-width: 780px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  background: var(--surface);
  border: 1px solid rgba(215, 224, 233, 0.9);
  border-radius: var(--radius);
  padding: 11px 10px;
  box-shadow: var(--shadow-sm);
}

.stat strong,
.stat span {
  display: block;
}

.stat strong {
  color: var(--text-strong);
  font-size: 23px;
  line-height: 1;
  font-weight: 780;
}

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

.grid {
  display: grid;
  grid-template-columns: minmax(440px, 1.15fr) minmax(360px, 0.85fr);
  gap: 16px;
  align-items: start;
}

.panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(213, 222, 232, 0.94);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 1px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #374151;
  font-size: 13px;
  font-weight: 720;
}

label input,
label select,
label textarea {
  font-size: 14px;
  font-weight: 430;
}

textarea {
  resize: vertical;
}

.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.check {
  flex-direction: row;
  align-items: center;
  font-weight: 650;
  color: #334155;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  border-radius: var(--radius);
  padding: 10px;
}

.check input {
  width: 17px;
  height: 17px;
  box-shadow: none;
}

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

.primary {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 7px 16px rgba(15, 118, 110, 0.22);
}

.primary:hover {
  background: var(--primary-dark);
}

.connect {
  color: #fff;
  background: var(--blue);
  box-shadow: 0 7px 16px rgba(37, 99, 235, 0.22);
}

.connect:hover {
  background: var(--blue-dark);
}

.ghost {
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.ghost:hover {
  border-color: #aebccc;
  background: #f8fafc;
}

.sidebar .ghost {
  border-color: var(--nav-line);
  background: var(--nav-2);
  color: #e5edf5;
  box-shadow: none;
}

.sidebar .ghost:hover {
  background: #243246;
}

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

.full {
  width: 100%;
}

.meta-status {
  color: #cbd5e1;
  background: rgba(27, 38, 51, 0.92);
  border: 1px solid var(--nav-line);
  border-radius: var(--radius);
  padding: 10px;
  font-size: 12px;
  line-height: 1.4;
}

.secret-hint {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e40af;
  border-radius: var(--radius);
  padding: 10px 11px;
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: #ecfdf3;
  color: var(--ok);
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
  border: 1px solid #c7ead8;
}

.pill.muted {
  background: #f1f5f9;
  color: #475569;
  border-color: #dbe3ec;
}

.reply-box {
  min-height: 180px;
  white-space: pre-wrap;
  overflow: auto;
  margin: 0;
  border: 1px solid #1f2a3a;
  border-radius: var(--radius);
  padding: 13px;
  background: #111827;
  color: #e2e8f0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.status-box {
  min-height: 130px;
  white-space: pre-wrap;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
  background: #f8fafc;
  color: #172026;
}

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

.knowledge-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 11px;
  background: #f8fafc;
}

.knowledge-item strong,
.knowledge-item span {
  display: block;
}

.knowledge-item strong {
  color: var(--text-strong);
}

.knowledge-item span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.connector ul {
  margin: 0;
  padding-left: 20px;
  color: #334155;
}

.connector li + li {
  margin-top: 8px;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .stats {
    max-width: none;
  }
}

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

  .sidebar {
    position: relative;
    height: auto;
    min-height: auto;
  }

  .page-list {
    max-height: 260px;
  }

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

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

@media (max-width: 640px) {
  .main,
  .sidebar {
    padding: 14px;
  }

  h1 {
    font-size: 21px;
  }

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

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

  .actions {
    justify-content: stretch;
  }

  .actions button {
    flex: 1 1 auto;
  }
}
