:root {
  --ink: #0b2a32;
  --ink-soft: #3d5c66;
  --teal: #0d8a8a;
  --teal-deep: #066666;
  --mint: #9ee7d8;
  --line: rgba(11, 42, 50, 0.12);
  --panel: rgba(255, 255, 255, 0.62);
  --shadow: 0 18px 50px rgba(6, 80, 90, 0.12);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "DM Sans", system-ui, sans-serif;
  --header-h: 4.25rem;
  --tabs-h: 3.4rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1100px 640px at 90% -8%, rgba(158, 231, 216, 0.5), transparent 55%),
    radial-gradient(860px 560px at -8% 95%, rgba(13, 138, 138, 0.16), transparent 50%),
    linear-gradient(165deg, #f7fcfb 0%, #eef7f5 48%, #e4f3f0 100%);
  min-height: 100vh;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(11, 42, 50, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(11, 42, 50, 0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 25%, transparent 78%);
  pointer-events: none;
  z-index: 0;
  animation: grid-drift 28s linear infinite;
}

.bg-glow {
  position: fixed;
  width: min(42vw, 480px);
  height: min(42vw, 480px);
  right: 6%;
  top: 20%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(158, 231, 216, 0.45), transparent 70%);
  filter: blur(22px);
  pointer-events: none;
  z-index: 0;
  animation: pulse-glow 6s ease-in-out infinite;
}

.shell-header,
.module-tabs,
.workspace {
  position: relative;
  z-index: 1;
}

.shell-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--header-h);
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(243, 250, 251, 0.72);
  backdrop-filter: blur(10px);
}

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

.brand-mark {
  width: 1.7rem;
  height: 1.7rem;
  flex-shrink: 0;
  border-radius: 0.45rem;
  background: linear-gradient(135deg, var(--mint), var(--teal));
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
  animation: mark-breathe 3.5s ease-in-out infinite;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.module-tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.55rem 1.25rem;
  overflow-x: auto;
  scrollbar-width: thin;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.35);
  -webkit-overflow-scrolling: touch;
}

.module-tabs::-webkit-scrollbar {
  height: 4px;
}

.tab-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.55rem 0.9rem;
  border-radius: 0.5rem;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.tab-btn:hover {
  color: var(--ink);
  background: rgba(13, 138, 138, 0.08);
}

.tab-btn.active {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal-deep);
  box-shadow: 0 8px 20px rgba(6, 102, 102, 0.22);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(320px, 1.25fr);
  gap: 1.25rem;
  padding: 1.25rem 1.5rem 1.75rem;
  min-height: calc(100vh - var(--header-h) - var(--tabs-h));
  animation: rise-in 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.intro-panel,
.chat-panel {
  min-width: 0;
}

.intro-panel {
  padding: 0.35rem 0.25rem 1rem;
}

.eyebrow {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--teal-deep);
  font-weight: 700;
}

.module-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 3.2vw, 2.35rem);
  line-height: 1.18;
  letter-spacing: -0.025em;
  font-weight: 600;
}

.module-desc {
  margin: 1rem 0 0;
  font-size: 1.02rem;
  line-height: 1.7;
  color: var(--ink-soft);
}

.module-points {
  margin: 1.15rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.55rem;
}

.module-points li {
  position: relative;
  padding-left: 1.1rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink);
}

.module-points li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--teal);
}

.prompt-note {
  margin: 1.4rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--ink-soft);
}

.prompt-settings {
  margin-top: 1.35rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.prompt-settings-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.btn-settings {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.55rem 0.9rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.btn-settings:hover,
.btn-settings[aria-expanded="true"] {
  background: rgba(13, 138, 138, 0.1);
  border-color: rgba(13, 138, 138, 0.35);
  color: var(--teal-deep);
}

.prompt-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--teal-deep);
  background: rgba(13, 138, 138, 0.12);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

.prompt-editor {
  margin-top: 0.9rem;
  display: grid;
  gap: 0.85rem;
  animation: rise-in 0.35s ease both;
}

.field {
  display: grid;
  gap: 0.4rem;
}

.field > span {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.field textarea,
.prompt-preview {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.88rem;
  line-height: 1.55;
  padding: 0.75rem 0.85rem;
  resize: vertical;
}

.field textarea:focus {
  outline: 2px solid rgba(13, 138, 138, 0.35);
  border-color: var(--teal);
}

.prompt-preview-label {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.prompt-preview {
  margin: 0;
  max-height: 160px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(11, 42, 50, 0.04);
  color: var(--ink-soft);
}

.prompt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.prompt-actions .btn {
  appearance: none;
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.65rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
}

.prompt-actions .btn.primary {
  background: var(--teal);
  color: #fff;
}

.prompt-actions .btn.primary:hover {
  background: var(--teal-deep);
}

.prompt-actions .btn.ghost {
  background: rgba(255, 255, 255, 0.7);
  border-color: var(--line);
  color: var(--ink);
}

.prompt-save-hint {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.82rem;
  color: var(--teal-deep);
}

.prompt-save-hint.error {
  color: #8a2f2f;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 62vh;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--panel);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  overflow: hidden;
  /* 给 Chat SDK 明确的可用高度 */
  height: calc(100vh - var(--header-h) - var(--tabs-h) - 2.5rem);
}

.chat-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.45);
}

.chat-panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

#chatModuleTag {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--teal-deep);
  background: rgba(13, 138, 138, 0.1);
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
}

.chat-mount {
  position: relative;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.chat-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 480px;
  overflow: hidden;
}

/* 尽量让 SDK 注入的根节点铺满右侧面板（避免仍按右下角浮层定位） */
.chat-container > * {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
}

.chat-placeholder {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  font-size: 0.95rem;
  padding: 1.5rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.72);
}

.chat-placeholder[hidden] {
  display: none !important;
}

.chat-placeholder.error {
  color: #8a2f2f;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-glow {
  0%,
  100% {
    opacity: 0.65;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
}

@keyframes mark-breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

@keyframes grid-drift {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(48px);
  }
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    padding: 1rem 1.1rem 1.4rem;
  }

  .chat-panel {
    height: auto;
    min-height: 68vh;
  }

  .chat-mount {
    height: 68vh;
    min-height: 460px;
  }
}

@media (max-width: 640px) {
  .shell-header {
    padding: 0.75rem 1rem;
  }

  .module-tabs {
    padding: 0.45rem 0.75rem;
  }

  .brand-sub {
    display: none;
  }

  .tab-btn {
    font-size: 0.82rem;
    padding: 0.5rem 0.75rem;
  }
}

/* ---- auth / admin ---- */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn.small {
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  padding: 1.75rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.auth-brand {
  margin-bottom: 1.1rem;
}

.auth-card h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.7rem;
}

.auth-lede {
  margin: 0.55rem 0 1.2rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.55;
}

.auth-form {
  display: grid;
  gap: 0.85rem;
}

.auth-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.auth-form input {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.7rem 0.8rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

.auth-error {
  margin: 0;
  color: #8a2f2f;
  font-size: 0.88rem;
}

.admin-wrap {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 1.25rem;
  padding: 1.25rem 1.5rem 2rem;
}

.admin-panel {
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.72);
  padding: 1.2rem 1.25rem 1.4rem;
  box-shadow: var(--shadow);
}

.admin-panel h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
}

.admin-desc {
  margin: 0.45rem 0 1rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.create-user-form,
.history-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 0.75rem;
}

.create-user-form input,
.history-filters select {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.55rem 0.7rem;
  font: inherit;
  background: #fff;
}

.form-hint {
  min-height: 1.2em;
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--teal-deep);
}

.table-wrap {
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.45rem;
  text-align: left;
  vertical-align: middle;
}

.data-table .ops {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(280px, 1.4fr);
  gap: 0.85rem;
  min-height: 420px;
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  overflow: auto;
  max-height: 560px;
  background: rgba(255, 255, 255, 0.65);
}

.conv-list li {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 0.86rem;
}

.conv-list li:hover,
.conv-list li.active {
  background: rgba(13, 138, 138, 0.1);
}

.msg-list {
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.85rem;
  overflow: auto;
  max-height: 560px;
  background: rgba(255, 255, 255, 0.65);
}

.msg-item {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px dashed var(--line);
}

.msg-role {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--teal-deep);
  margin-bottom: 0.25rem;
}

.msg-item pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-body);
  font-size: 0.88rem;
  line-height: 1.55;
}

.empty-tip {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.empty-tip.error {
  color: #8a2f2f;
}

@media (max-width: 900px) {
  .history-layout {
    grid-template-columns: 1fr;
  }
}
