:root {
  --bg: #0d0d0d;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f2f2f2;
  --muted: rgba(242, 242, 242, 0.64);
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.06), transparent 32%),
    linear-gradient(160deg, #060606 0%, #111111 48%, #0b0b0b 100%);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

.background {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 999px;
  filter: blur(24px);
  opacity: 0.22;
}

.orb-a {
  width: 360px;
  height: 360px;
  background: #f5f5f5;
  top: -80px;
  right: -120px;
}

.orb-b {
  width: 280px;
  height: 280px;
  background: #9b9b9b;
  bottom: 40px;
  left: -100px;
}

.shell {
  position: relative;
  max-width: 1480px;
  margin: 0 auto;
  padding: 32px 20px 40px;
}

.auth-shell {
  width: 100%;
  max-width: none;
  min-height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-panel {
  width: min(560px, 100%);
  padding: 32px;
  margin: 0 auto;
  text-align: center;
}

.auth-actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  justify-content: center;
}

.visitor-panel {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.auth-message {
  margin: 10px 0 18px;
  color: var(--muted);
  line-height: 1.6;
  transition: color 0.3s ease, background 0.3s ease;
  padding: 8px 12px;
  border-radius: 12px;
}

.auth-message--success {
  color: #7ee081;
  background: rgba(126, 224, 129, 0.10);
}

.auth-message--error {
  color: #f28b82;
  background: rgba(242, 139, 130, 0.10);
}

.auth-message--warn {
  color: #fdd663;
  background: rgba(253, 214, 99, 0.10);
}

.auth-message--info {
  color: #aecbfa;
  background: rgba(174, 203, 250, 0.10);
}

.auth-panel .label {
  text-align: left;
}

.auth-panel .session-title-input {
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.auth-panel .subtitle,
.auth-panel .eyebrow,
.auth-panel .session-title-hint,
.auth-panel .visitor-panel,
.auth-panel .auth-message {
  text-align: center;
}

.auth-panel .visitor-panel .ghost-btn {
  margin-top: 8px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow);
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 30px;
  margin-bottom: 20px;
}

.hero-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 12px;
}

h1, h2 {
  margin: 0;
}

.subtitle {
  margin: 12px 0 0;
  max-width: 760px;
  color: var(--muted);
  line-height: 1.65;
}

.status-box {
  min-width: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 18px;
  height: fit-content;
}

.auth-box {
  min-width: 320px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.auth-status {
  margin-bottom: 10px;
  color: var(--text);
  font-size: 14px;
}

.auth-inline {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.token-state {
  margin: 8px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.token-state.hidden {
  display: none;
}

.token-state-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.token-state-bar-bg {
  flex: 1;
  min-width: 80px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.10);
  overflow: hidden;
}

.token-state-bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: #aecbfa;
  transition: width 0.5s ease;
}

.token-state-nums {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.auth-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  font: inherit;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.status-dot.idle {
  background: #8f8f8f;
}

.status-dot.busy {
  background: #ffffff;
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.7);
}

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

.history,
.composer,
.result,
.plots {
  padding: 24px;
}

.main-stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.grid {
  display: grid;
  grid-template-columns: 1.02fr 1.18fr;
  gap: 20px;
}

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

.action-inline {
  display: flex;
  gap: 10px;
}

.label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.mode-group {
  margin-bottom: 8px;
}

.mode-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.mode-card {
  appearance: none;
  width: 100%;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.mode-card strong {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
}

.mode-card small {
  color: var(--muted);
  line-height: 1.55;
}

.mode-card:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.07);
}

.mode-card.active {
  border-color: rgba(255, 255, 255, 0.48);
  background: rgba(255, 255, 255, 0.12);
}

.session-title-input {
  width: 100%;
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  font: inherit;
}

.session-title-input:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.session-title-hint {
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.message-input {
  width: 100%;
  min-height: 240px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  resize: vertical;
  font: inherit;
}

.upload-row {
  margin-top: 18px;
}

.upload-box {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  cursor: pointer;
}

.upload-box small {
  color: var(--muted);
}

#fileInput {
  display: none;
}

.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.file-chip,
.badge {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  color: var(--muted);
}

.action-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.primary-btn,
.ghost-btn,
.history-item {
  appearance: none;
  border: 1px solid var(--line);
  font: inherit;
}

.primary-btn,
.ghost-btn {
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease;
}

.primary-btn {
  background: #f4f4f4;
  color: #121212;
}

.ghost-btn {
  background: transparent;
  color: var(--text);
}

.primary-btn:hover,
.ghost-btn:hover,
.history-item:hover {
  transform: translateY(-1px);
}

.primary-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.thinking {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  color: var(--muted);
}

.thinking.hidden {
  display: none;
}

.loader {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: #ffffff;
  animation: spin 0.8s linear infinite;
}

.answer-box {
  min-height: 420px;
  padding: 18px;
  line-height: 1.75;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  overflow: auto;
}

.markdown-body {
  word-break: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 0 0 12px;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote {
  margin: 0 0 14px;
}

.markdown-body pre {
  overflow: auto;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
}

.markdown-body code {
  font-family: "Cascadia Code", "Consolas", monospace;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}

.math-display {
  margin: 14px 0;
  overflow-x: auto;
}

.math-inline {
  display: inline-block;
}

.markdown-body th,
.markdown-body td {
  padding: 8px 10px;
  border: 1px solid var(--line);
}

.plot-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.plot-card {
  display: block;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.plot-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.plot-frame-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.plot-frame-link {
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}

.plot-frame {
  width: 100%;
  min-height: 420px;
  border: 0;
  border-radius: 14px;
  background: #ffffff;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.history-group {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.history-title,
.history-item {
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-title {
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.1);
  position: relative;
  padding-right: 42px;
}

.history-title strong {
  font-size: 15px;
}

.rename-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
}

.history-children {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item strong {
  font-weight: 500;
  font-size: 14px;
  line-height: 1.55;
  overflow: hidden;
  display: -webkit-box;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.history-note {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.76);
  overflow: hidden;
  display: -webkit-box;
  line-clamp: 1;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.history-item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.mini-action-btn {
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.history-time,
.history-item small,
.empty-text {
  color: var(--muted);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

@media (max-width: 960px) {
  .hero,
  .grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .hero {
    padding: 24px;
  }

  .hero-right {
    align-items: stretch;
  }

  .auth-inline {
    flex-direction: column;
  }

  .shell {
    padding: 18px 14px 28px;
  }

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

.auth-toast {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 22px;
  border-radius: 16px;
  border: 1px solid var(--line);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  transform: translateX(calc(100% + 32px));
  opacity: 0;
  transition: transform 0.38s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.28s ease;
  pointer-events: none;
  max-width: 420px;
}

.auth-toast--visible {
  transform: translateX(0);
  opacity: 1;
}

.auth-toast--success {
  background: rgba(30, 70, 32, 0.88);
  border-color: rgba(126, 224, 129, 0.35);
}

.auth-toast--error {
  background: rgba(70, 30, 30, 0.88);
  border-color: rgba(242, 139, 130, 0.35);
}

.auth-toast--info {
  background: rgba(30, 40, 60, 0.88);
  border-color: rgba(174, 203, 250, 0.35);
}

.auth-toast__icon {
  font-size: 20px;
  flex-shrink: 0;
}

.auth-toast--success .auth-toast__icon {
  color: #7ee081;
}

.auth-toast--error .auth-toast__icon {
  color: #f28b82;
}

.auth-toast--info .auth-toast__icon {
  color: #aecbfa;
}

.auth-toast__text {
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-user-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-user-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  flex-wrap: wrap;
}

.admin-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
}

.admin-user-info strong {
  font-size: 15px;
}

.admin-user-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.admin-quota-input {
  width: 120px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  font: inherit;
  text-align: right;
}

.admin-set-btn {
  white-space: nowrap;
}

.token-unit-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

#toastContainer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 9999;
  pointer-events: none;
}
