:root {
  color-scheme: light;
  --bg: #f5efe5;
  --bg-strong: #efe4d2;
  --panel: rgba(255, 251, 245, 0.96);
  --panel-soft: rgba(255, 255, 255, 0.82);
  --panel-accent: rgba(22, 72, 60, 0.08);
  --border: rgba(24, 50, 42, 0.12);
  --border-strong: rgba(24, 50, 42, 0.18);
  --text: #18322a;
  --muted: #64726c;
  --accent: #1e6d5c;
  --accent-strong: #124e41;
  --accent-soft: rgba(30, 109, 92, 0.12);
  --warning: #a6462a;
  --danger: #ba4444;
  --student: #f0e2ca;
  --assistant: #ffffff;
  --sidebar-start: #18362f;
  --sidebar-end: #21443c;
  --shadow: 0 24px 60px rgba(31, 42, 37, 0.12);
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
  min-width: 0;
}

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

body {
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(circle at top left, rgba(198, 167, 101, 0.18), transparent 28%),
    linear-gradient(135deg, #f8f3eb 0%, #f3ecdf 45%, #efe5d5 100%);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

a {
  color: inherit;
}

.app-shell,
.admin-shell {
  display: grid;
  gap: 18px;
  min-height: 100dvh;
  padding: 18px;
  align-items: start;
}

.app-shell {
  grid-template-columns: 300px minmax(0, 1fr);
}

.admin-shell {
  grid-template-columns: minmax(0, 1fr);
}

.sidebar,
.main-panel,
.admin-panel,
.admin-login-shell {
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  background: linear-gradient(180deg, var(--sidebar-start), var(--sidebar-end));
  color: #f8f7f2;
  min-height: calc(100dvh - 36px);
  position: sticky;
  top: 18px;
}

.main-panel,
.admin-panel,
.admin-login-shell {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  background: var(--panel);
  min-height: calc(100dvh - 36px);
}

.brand-card,
.sidebar-card,
.tool-card,
.admin-card,
.stat-card,
.login-card {
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
}

.brand-card {
  padding: 18px;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.08);
}

.brand-card h1,
.head-copy h2,
.admin-heading h1 {
  margin: 8px 0 6px;
}

.brand-card h1 {
  font-size: 1.9rem;
}

.brand-tag,
.eyebrow,
.section-title {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-copy,
.card-copy,
.head-summary,
.conversation-meta,
.helper-text,
.muted-line {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.brand-copy {
  color: rgba(248, 247, 242, 0.8);
}

.admin-entry {
  display: inline-flex;
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff5db;
  text-decoration: none;
}

.sidebar-card,
.tool-card,
.admin-card,
.login-card {
  padding: 16px;
}

.sidebar-head,
.tool-head,
.main-head,
.admin-toolbar,
.admin-section-head,
.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-head,
.tool-head,
.admin-section-head {
  flex-wrap: wrap;
}

.student-login-form,
.composer-form,
.settings-form,
.admin-login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inline-actions,
.status-group,
.composer-actions,
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button,
.ghost-button,
.conversation-delete,
.role-card,
.prompt-chip,
.filter-chip {
  border: 0;
  transition:
    transform 0.16s ease,
    box-shadow 0.16s ease,
    background 0.16s ease;
}

.primary-button,
.secondary-button,
.ghost-button,
.text-input,
textarea,
.admin-table,
.settings-form textarea {
  border-radius: 16px;
}

.primary-button,
.secondary-button,
.ghost-button {
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
}

.secondary-button {
  background: linear-gradient(135deg, #f1ddb1, #fff1ca);
  color: var(--text);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(24, 50, 42, 0.08);
  color: var(--text);
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.role-card:hover,
.prompt-chip:hover,
.conversation-delete:hover,
.admin-entry:hover,
.filter-chip:hover {
  transform: translateY(-1px);
}

.text-input,
textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(24, 50, 42, 0.12);
  background: #fff;
  color: var(--text);
  outline: none;
}

.text-input:focus,
textarea:focus {
  border-color: rgba(30, 109, 92, 0.32);
  box-shadow: 0 0 0 4px rgba(30, 109, 92, 0.08);
}

.sidebar-section {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.conversation-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

.conversation-item {
  display: flex;
  align-items: stretch;
  gap: 8px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.conversation-item.is-active {
  background: rgba(255, 255, 255, 0.16);
}

.conversation-open {
  flex: 1;
  border: 0;
  padding: 14px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.conversation-title {
  display: block;
  margin-bottom: 5px;
  font-weight: 700;
  color: #ffffff;
  overflow-wrap: anywhere;
}

.conversation-meta {
  color: rgba(248, 247, 242, 0.76);
  overflow-wrap: anywhere;
}

.conversation-delete {
  flex: 0 0 auto;
  margin: 8px 8px 8px 0;
  min-width: 56px;
  padding: 0 12px;
  border-radius: 12px;
  background: rgba(186, 68, 68, 0.94);
  color: #fff;
}

.sidebar-note,
.inline-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.88rem;
}

.sidebar-note,
.inline-pill {
  background: rgba(255, 255, 255, 0.12);
  color: #fff5db;
}

.inline-pill-soft {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.main-head,
.admin-toolbar {
  flex-wrap: wrap;
}

.head-copy h2,
.admin-heading h1 {
  font-size: 2rem;
  line-height: 1.08;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-radius: 26px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.66);
  overflow: visible;
  padding: 14px;
}

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

.message-frame {
  height: clamp(420px, 62vh, 760px);
  min-height: 320px;
  border-radius: 24px;
  border: 1px solid rgba(24, 50, 42, 0.08);
  background:
    linear-gradient(180deg, rgba(255, 252, 247, 0.96), rgba(247, 243, 236, 0.94));
  overflow: hidden;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.role-card,
.prompt-chip,
.filter-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 10px 24px rgba(31, 43, 37, 0.05);
  text-decoration: none;
}

.role-card {
  border: 1px solid rgba(24, 50, 42, 0.08);
  cursor: pointer;
}

.role-card.is-active {
  background: rgba(233, 246, 241, 1);
  border-color: rgba(30, 109, 92, 0.26);
}

.role-name {
  font-size: 0.94rem;
  font-weight: 700;
}

.role-summary {
  color: var(--muted);
  font-size: 0.86rem;
}

.prompt-chip {
  border: 1px solid rgba(24, 50, 42, 0.08);
  cursor: pointer;
  align-items: flex-start;
  justify-content: flex-start;
  flex-direction: column;
  text-align: left;
}

.prompt-chip strong {
  font-size: 0.92rem;
}

.prompt-chip span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.message-viewport {
  height: 100%;
  min-height: 0;
  padding: 0 10px 0 14px;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 18px 8px 18px 4px;
}

.message-empty {
  padding: 24px;
  border-radius: 22px;
  border: 1px dashed rgba(24, 50, 42, 0.14);
  background: rgba(255, 255, 255, 0.7);
  line-height: 1.75;
}

.message-empty p {
  margin: 0;
}

.message-empty-title {
  margin-bottom: 6px;
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text);
}

.message-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.message-main {
  max-width: min(880px, 100%);
}

.message-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 14px;
  background: rgba(24, 50, 42, 0.08);
  font-weight: 700;
  color: var(--accent-strong);
}

.message-card.student .message-avatar {
  background: rgba(198, 143, 54, 0.18);
  color: #8b5e16;
}

.message-head {
  justify-content: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}

.message-role {
  font-weight: 700;
}

.message-time {
  color: var(--muted);
  font-size: 0.86rem;
}

.message-bubble {
  padding: 16px 18px;
  border-radius: 20px;
  border: 1px solid rgba(24, 50, 42, 0.08);
  background: var(--assistant);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.8;
}

.message-card.student .message-bubble {
  background: var(--student);
}

.message-card.loading .message-bubble {
  background: linear-gradient(90deg, #ffffff, #edf3f1, #ffffff);
  background-size: 220% 100%;
  animation: shimmer 1.4s linear infinite;
}

.composer-panel {
  background: transparent;
}

.composer-form {
  padding: 14px;
  border-radius: 22px;
  border: 1px solid rgba(24, 50, 42, 0.08);
  background: #ffffff;
}

#promptInput {
  min-height: 76px;
  max-height: 180px;
  padding: 0;
  resize: none;
  border: 0;
  box-shadow: none;
  background: transparent;
  line-height: 1.8;
}

.composer-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.composer-hint {
  margin: 0;
  max-width: 620px;
  color: var(--muted);
  line-height: 1.65;
}

.status-pill {
  background: var(--accent);
  color: #fff;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

.status-pill-soft {
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
}

.empty-card {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(248, 247, 242, 0.78);
  line-height: 1.7;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  padding: 16px;
}

.stat-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.stat-value {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
}

.stat-desc {
  margin: 8px 0 0;
  color: var(--muted);
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  flex: 1;
}

.settings-form textarea {
  min-height: 108px;
  resize: vertical;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

.admin-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-radius: 18px;
  border: 1px solid rgba(24, 50, 42, 0.08);
  background: rgba(255, 255, 255, 0.72);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.admin-table th,
.admin-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(24, 50, 42, 0.08);
  vertical-align: top;
  text-align: left;
  line-height: 1.6;
}

.admin-table th {
  position: sticky;
  top: 0;
  background: rgba(248, 244, 237, 0.98);
  z-index: 1;
}

.admin-table td small {
  display: block;
  color: var(--muted);
}

.login-card {
  width: min(420px, 100%);
  margin: auto;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }

  100% {
    background-position: -100% 0;
  }
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .app-shell,
  .admin-shell {
    min-height: 100dvh;
  }

  .app-shell,
  .admin-layout {
    grid-template-columns: 1fr;
  }

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

  .main-panel,
  .admin-panel,
  .admin-login-shell {
    min-height: auto;
  }

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

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

@media (max-width: 720px) {
  .app-shell,
  .admin-shell {
    padding: 12px;
    gap: 12px;
  }

  .sidebar,
  .main-panel,
  .admin-panel,
  .admin-login-shell {
    padding: 14px;
    border-radius: 22px;
  }

  .brand-card,
  .sidebar-card,
  .tool-card,
  .admin-card,
  .stat-card,
  .login-card {
    border-radius: 18px;
  }

  .head-copy h2,
  .admin-heading h1 {
    font-size: 1.7rem;
  }

  .message-main {
    max-width: 100%;
  }

  .chat-shell {
    padding: 12px;
  }

  .message-frame {
    height: min(58vh, 620px);
    min-height: 360px;
  }
}
