:root {
  --bg-top: #f3f8ff;
  --bg-bottom: #fff8f2;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --surface-strong: #f1f6ff;
  --text: #102138;
  --text-muted: #5d6d84;
  --line: #d9e4f3;
  --line-strong: #bfd1e8;
  --brand: #ff5f3e;
  --brand-strong: #de4326;
  --brand-cool: #1f7ae0;
  --brand-cool-strong: #165fbb;
  --accent: #10a47f;
  --danger: #dc3f56;
  --warning: #f18a25;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-soft: 0 10px 34px rgba(16, 53, 97, 0.08);
  --shadow-card: 0 20px 44px rgba(16, 53, 97, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 14% 18%, rgba(31, 122, 224, 0.2), transparent 34%),
    radial-gradient(circle at 86% 82%, rgba(255, 95, 62, 0.15), transparent 32%),
    linear-gradient(166deg, var(--bg-top), var(--bg-bottom));
  font-family: "Avenir Next", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
}

body::before,
body::after {
  content: "";
  position: fixed;
  pointer-events: none;
  z-index: 0;
  border-radius: 999px;
  filter: blur(2px);
}

body::before {
  width: 360px;
  height: 360px;
  left: -132px;
  top: -142px;
  background: rgba(31, 122, 224, 0.12);
  animation: ambientFloat 16s ease-in-out infinite;
}

body::after {
  width: 300px;
  height: 300px;
  right: -120px;
  bottom: -120px;
  background: rgba(255, 95, 62, 0.12);
  animation: ambientFloat 18s ease-in-out infinite reverse;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-frame {
  position: relative;
  z-index: 1;
  width: min(1240px, calc(100vw - 34px));
  margin: 24px auto 28px;
}

.topbar,
.chat-topbar,
.workspace-card,
.chat-sidebar,
.chat-main,
.simple-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.96), rgba(247, 251, 255, 0.94));
  box-shadow: var(--shadow-soft);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 22px;
  margin-bottom: 16px;
}

.brand {
  margin: 0;
  font-size: 1.22rem;
  font-weight: 720;
  letter-spacing: 0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 38px;
  font: inherit;
  font-size: 0.93rem;
  font-weight: 640;
  letter-spacing: 0.01em;
  color: #fff;
  background: linear-gradient(136deg, var(--brand), var(--brand-strong));
  box-shadow: 0 8px 18px rgba(222, 67, 38, 0.28);
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.16s ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: saturate(1.04);
}

.btn:focus-visible {
  outline: 3px solid rgba(255, 95, 62, 0.2);
  outline-offset: 1px;
}

.btn:disabled {
  opacity: 0.55;
  transform: none;
  box-shadow: none;
  cursor: not-allowed;
}

.btn.alt {
  background: linear-gradient(136deg, var(--brand-cool), var(--brand-cool-strong));
  box-shadow: 0 8px 18px rgba(22, 95, 187, 0.24);
}

.btn.ghost {
  color: #1f5eaf;
  background: linear-gradient(150deg, #eef4ff, #e4efff);
  box-shadow: none;
}

.btn.warning {
  background: linear-gradient(136deg, #f29b3d, #e07114);
  box-shadow: 0 8px 18px rgba(224, 113, 20, 0.24);
}

.btn.danger {
  background: linear-gradient(136deg, var(--danger), #bc2d45);
  box-shadow: 0 8px 18px rgba(188, 45, 69, 0.24);
}

.btn.micro {
  min-height: 32px;
  padding: 7px 12px;
  font-size: 0.82rem;
}

.btn.submit {
  min-width: 108px;
}

input,
select,
textarea {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid #c9d9ee;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: #ffffff;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #8eb6e6;
  box-shadow: 0 0 0 3px rgba(31, 122, 224, 0.14);
  outline: none;
}

.field-label {
  display: block;
  margin: 5px 0 6px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.status-line {
  min-height: 24px;
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 0.91rem;
  line-height: 1.35;
}

.status-line:not(:empty) {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #dce7f5;
  background: #f6faff;
}

.status-line.error {
  color: #bf3148;
}

.status-line.error:not(:empty) {
  border-color: #f0ccd3;
  background: #fff2f4;
}

.status-line.success {
  color: #0f8b6b;
}

.status-line.success:not(:empty) {
  border-color: #ccece2;
  background: #edfbf5;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.workspace-card {
  padding: 16px;
  min-height: 360px;
}

.workspace-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.workspace-head h2,
.workspace-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 680;
}

.session-list,
.manage-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.session-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 4px 2px;
}

.session-link {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(160deg, #ffffff, #f7fbff);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.session-link:hover {
  transform: translateY(-1px);
  border-color: #b9d0ed;
  box-shadow: 0 8px 18px rgba(20, 76, 137, 0.08);
}

.session-link.active {
  border-color: #9cbde5;
  background: linear-gradient(160deg, #edf5ff, #f7fbff);
}

.session-title {
  font-size: 0.95rem;
  line-height: 1.3;
  word-break: break-word;
}

.session-meta {
  color: var(--text-muted);
  font-size: 0.79rem;
}

.session-item-admin {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.session-link-fill {
  min-width: 0;
}

.login-page {
  overflow: hidden;
}

.login-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  width: min(1080px, calc(100vw - 34px));
  margin: 0 auto;
  display: grid;
  place-items: center;
  padding: 26px 0;
}

.login-stage {
  width: 100%;
  display: grid;
  grid-template-columns: 1.06fr 0.94fr;
  border: 1px solid var(--line-strong);
  border-radius: 30px;
  overflow: hidden;
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.9), rgba(246, 251, 255, 0.9));
  box-shadow: var(--shadow-card);
  animation: panelRise 0.35s ease;
}

.login-cover {
  position: relative;
  min-height: 520px;
  background:
    radial-gradient(circle at 24% 20%, rgba(255, 255, 255, 0.26), transparent 42%),
    radial-gradient(circle at 78% 74%, rgba(255, 255, 255, 0.2), transparent 38%),
    linear-gradient(150deg, #1d64c6 0%, #2390ce 50%, #0fa77b 100%);
}

.login-cover::before,
.login-cover::after {
  content: "";
  position: absolute;
  border-radius: 999px;
}

.login-cover::before {
  width: 220px;
  height: 220px;
  left: -56px;
  top: 34px;
  border: 1px solid rgba(255, 255, 255, 0.24);
}

.login-cover::after {
  width: 170px;
  height: 170px;
  right: 36px;
  bottom: 64px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.cover-glow {
  position: absolute;
  width: 320px;
  height: 320px;
  right: -72px;
  bottom: -92px;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 35%, rgba(255, 255, 255, 0.44), rgba(255, 255, 255, 0.06) 68%, rgba(255, 255, 255, 0) 100%);
}

.simple-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.login-card,
.simple-card {
  width: min(500px, 100%);
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  padding: 24px;
}

.login-page .login-card {
  width: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 52px 44px 40px;
  background: transparent;
}

.login-title {
  margin: 0;
  font-size: 1.48rem;
  font-weight: 730;
}

.login-subtitle {
  margin: 8px 0 0;
  color: var(--text-muted);
}

.login-form {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.input-wrap {
  position: relative;
}

.input-wrap::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  transform: translateY(-50%);
  background: linear-gradient(136deg, var(--brand), var(--brand-strong));
  box-shadow: 0 0 0 4px rgba(255, 95, 62, 0.16);
}

.login-page .input-wrap input {
  padding-left: 34px;
  height: 42px;
}

.login-submit {
  width: 100%;
  margin-top: 8px;
  min-height: 42px;
  font-size: 0.95rem;
}

.login-page .status-line {
  margin-top: 14px;
}

.home-frame,
.admin-frame,
.manage-frame {
  min-height: calc(100vh - 52px);
}

.manage-topbar {
  margin-bottom: 16px;
}

.manage-headline {
  display: grid;
  gap: 4px;
}

.nav-back {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.nav-back:hover {
  color: #1f5eaf;
}

.manage-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(160deg, #ffffff, #f7fbff);
}

.manage-main {
  min-width: 0;
}

.manage-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-grid .workspace-card {
  min-height: 470px;
}

.code-context-status {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 11px;
  background: linear-gradient(160deg, #ffffff, #f7fbff);
  color: var(--text);
  font-size: 0.84rem;
}

.code-context-status.error {
  border-color: #ffc4c4;
  background: #fff5f5;
}

.code-context-status.success {
  border-color: #bfe8c9;
  background: #f3fff6;
}

.context-status-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
}

.context-status-grid div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.context-status-grid dt {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.context-status-grid dd {
  margin: 0;
  font-size: 0.84rem;
  word-break: break-word;
}

.admin-form {
  display: grid;
  gap: 6px;
}

.user-item {
  gap: 10px;
}

.user-actions {
  display: grid;
  grid-template-columns: 132px auto 1fr auto;
  gap: 8px;
  align-items: center;
}

.user-active-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.user-active-wrap input {
  width: auto;
  margin: 0;
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #c8dbf2;
  color: #1a5eae;
  background: #e8f2ff;
  font-size: 0.73rem;
}

.chat-frame {
  height: calc(100vh - 48px);
  min-height: 700px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.chat-topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
}

.session-headline {
  min-width: 0;
}

.session-subtitle {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.chat-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  gap: 12px;
}

.chat-sidebar {
  padding: 12px;
  overflow: auto;
}

.side-head {
  margin: 4px 0 8px;
}

.session-list.compact {
  margin-bottom: 14px;
}

.chat-main {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 10px;
  padding: 12px;
  overflow: hidden;
  background: #ffffff;
}

.thread {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 10px;
  padding: 6px 4px 8px;
  border-radius: 14px;
  border: 0;
  background: transparent;
}

.thread-empty {
  color: var(--text-muted);
  padding: 8px;
}

.msg {
  max-width: min(80%, 780px);
  border-radius: 14px;
  border: 1px solid #d5e3f5;
  padding: 10px 12px;
  line-height: 1.5;
  animation: panelRise 0.2s ease;
  align-self: flex-start;
}

.msg.user {
  align-self: flex-end;
  border-color: #ffd2c7;
  background: linear-gradient(140deg, #fff0ec, #fff6f4);
}

.msg.assistant {
  align-self: flex-start;
  border-color: #cfe0f6;
  background: linear-gradient(140deg, #f4f9ff, #fbfdff);
}

.msg.pending {
  opacity: 0.82;
  animation: pulse 1.2s ease-in-out infinite;
}

.msg-role {
  margin-bottom: 5px;
  font-size: 0.74rem;
  color: var(--text-muted);
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.msg-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.composer textarea {
  min-height: 96px;
  max-height: 240px;
  resize: vertical;
  border-radius: 12px;
  padding: 12px;
  background: #ffffff;
}

#switch-session-type {
  justify-self: start;
}

.hidden {
  display: none !important;
}

.hidden-mobile {
  display: inline-flex;
}

@keyframes ambientFloat {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(0, 16px, 0);
  }
}

@keyframes panelRise {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

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

@media (max-width: 1120px) {
  .login-shell {
    width: min(820px, calc(100vw - 26px));
  }

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

  .login-cover {
    min-height: 170px;
  }

  .login-page .login-card {
    padding: 28px 24px 24px;
  }

  .workspace-grid,
  .chat-grid {
    grid-template-columns: 1fr;
  }

  .chat-frame {
    min-height: 0;
    height: auto;
  }

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

  .chat-main {
    min-height: 560px;
  }

  .msg {
    max-width: 90%;
  }

  .manage-item,
  .session-item-admin {
    grid-template-columns: 1fr;
  }

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

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

  .hidden-mobile {
    display: none !important;
  }
}

@media (max-width: 760px) {
  .app-frame {
    width: calc(100vw - 18px);
    margin: 10px auto 16px;
  }

  .topbar,
  .chat-topbar,
  .workspace-card,
  .chat-sidebar,
  .chat-main,
  .simple-card {
    border-radius: 16px;
  }

  .topbar,
  .chat-topbar {
    padding: 12px;
  }

  .workspace-card,
  .chat-sidebar,
  .chat-main {
    padding: 12px;
  }

  .brand {
    font-size: 1.08rem;
  }

  .btn {
    min-height: 36px;
    padding: 9px 14px;
  }

  .login-shell {
    width: calc(100vw - 16px);
    padding: 8px 0;
  }

  .login-stage {
    border-radius: 20px;
  }

  .login-page .login-card {
    padding: 18px 16px 16px;
  }

  .login-title {
    font-size: 1.24rem;
  }

  .msg {
    max-width: 95%;
  }

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

  .composer .btn.submit {
    width: 100%;
  }
}
