:root {
  color-scheme: light;
  --primary-50: #e6f9ef;
  --primary-100: #b3eccb;
  --primary-500: #07c160;
  --primary-600: #06a852;
  --accent-500: #6c02fa;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --danger: #ef4444;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: #f5f5f5;
  color: #333;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.hidden {
  display: none !important;
}

.app-layout {
  display: grid;
  grid-template-columns: 60px minmax(280px, 340px) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  background: #fff;
}

.main-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border-right: 1px solid var(--gray-200);
  background: #fff;
  padding: 16px 6px;
}

.user-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  margin-bottom: 18px;
  place-items: center;
  border: 0;
  border-radius: 11px;
  background: var(--primary-500);
  color: #fff;
  font-weight: 800;
}

.nav-button {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--gray-400);
  text-decoration: none;
  transition: color 0.18s ease, background 0.18s ease;
}

.nav-button:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

.nav-button.active {
  color: var(--primary-500);
}

.conversation-list {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-width: 0;
  border-right: 1px solid var(--gray-200);
  background: #fff;
}

.list-header {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--gray-100);
  padding: 0 16px;
}

.list-header h1 {
  color: var(--gray-900);
  font-size: 20px;
  font-weight: 800;
}

.square-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--gray-100);
  color: var(--gray-700);
  font-size: 23px;
  line-height: 1;
}

.search-box {
  position: relative;
  display: block;
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-100);
}

.search-box svg {
  position: absolute;
  top: 24px;
  left: 28px;
  width: 16px;
  height: 16px;
  color: var(--gray-400);
}

.search-box input {
  width: 100%;
  height: 38px;
  border: 0;
  border-radius: 11px;
  background: var(--gray-100);
  color: var(--gray-900);
  outline: none;
  padding: 0 12px 0 36px;
}

.chat-list {
  overflow-y: auto;
}

.chat-item {
  display: flex;
  width: 100%;
  min-height: 74px;
  align-items: center;
  gap: 12px;
  border: 0;
  border-left: 4px solid transparent;
  background: #fff;
  padding: 12px 16px 12px 12px;
  text-align: left;
  transition: background 0.18s ease;
}

.chat-item:hover {
  background: var(--gray-100);
}

.chat-item.active {
  border-left-color: var(--primary-500);
  background: var(--primary-50);
}

.avatar {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary-500), #35d58a);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}

.avatar-self {
  background: linear-gradient(135deg, #4f7cff, #7b61ff);
}

.chat-item strong {
  display: block;
  overflow: hidden;
  color: var(--gray-900);
  font-size: 15px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item span {
  display: block;
  overflow: hidden;
  margin-top: 5px;
  color: var(--gray-500);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  background: var(--gray-50);
}

.chat-header {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--gray-200);
  background: #fff;
  padding: 0 22px;
}

.chat-title-block {
  min-width: 0;
}

.chat-title-input {
  width: min(520px, 45vw);
  border: 0;
  background: transparent;
  color: var(--gray-900);
  font-size: 17px;
  font-weight: 750;
  outline: none;
}

.chat-meta {
  margin-top: 4px;
  color: var(--gray-400);
  font-size: 12px;
}

.outline-button,
.secondary-button,
.ghost-button,
.primary-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--gray-200);
  border-radius: 11px;
  background: #fff;
  color: var(--gray-700);
  padding: 0 14px;
}

.outline-button {
  border-color: var(--primary-100);
  color: var(--primary-500);
}

.secondary-button {
  background: var(--gray-100);
  border-color: transparent;
}

.primary-button {
  border-color: transparent;
  background: var(--primary-500);
  color: #fff;
}

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

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.messages {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding: 22px 28px;
}

.empty-state {
  margin: auto;
  color: var(--gray-400);
  text-align: center;
}

.empty-state h2 {
  margin-bottom: 8px;
  color: var(--gray-700);
  font-size: 20px;
}

.empty-state p {
  max-width: 420px;
  font-size: 14px;
  line-height: 1.7;
}

.message {
  display: flex;
  max-width: min(760px, 74%);
  align-items: flex-start;
  gap: 10px;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.assistant,
.message.system {
  align-self: flex-start;
}

.message-role {
  margin: 0 2px 5px;
  color: var(--gray-400);
  font-size: 12px;
}

.bubble {
  border: 1px solid var(--gray-100);
  border-radius: 14px;
  border-top-left-radius: 4px;
  background: #fff;
  color: var(--gray-900);
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.user .bubble {
  border-color: transparent;
  border-top-left-radius: 14px;
  border-top-right-radius: 4px;
  background: #95ec69;
}

.system .bubble {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #c2410c;
}

.chat-input {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 150px;
  border-top: 1px solid var(--gray-200);
  background: #fff;
  padding: 12px 16px;
}

.chat-input textarea {
  width: 100%;
  min-height: 78px;
  max-height: 142px;
  border: 0;
  background: transparent;
  color: var(--gray-900);
  outline: none;
  resize: none;
  line-height: 1.6;
}

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.input-footer span {
  color: var(--gray-400);
  font-size: 12px;
}

.input-footer button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: 11px;
  background: var(--primary-500);
  color: #fff;
}

.input-footer button:hover {
  background: var(--primary-600);
}

.input-footer button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(17, 24, 39, 0.45);
  padding: 24px;
}

.roleplay-modal {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(960px, 100%);
  max-height: min(860px, 92vh);
  overflow: hidden;
  border: 1px solid var(--gray-200);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.25);
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
}

.modal-header {
  border-bottom: 1px solid var(--gray-200);
}

.modal-header h2 {
  color: var(--gray-900);
  font-size: 22px;
}

.modal-header p,
.panel-title p {
  margin-top: 4px;
  color: var(--gray-500);
  font-size: 13px;
}

.plain-icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--gray-400);
}

.plain-icon-button:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

.modal-content {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(300px, 0.88fr);
  gap: 18px;
  overflow-y: auto;
  background: var(--gray-50);
  padding: 20px 22px;
}

.form-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  border: 1px solid var(--gray-200);
  border-radius: 16px;
  background: #fff;
  padding: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title h3 {
  color: var(--gray-900);
  font-size: 16px;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--gray-500);
  font-size: 13px;
  white-space: nowrap;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--gray-700);
  font-size: 13px;
  font-weight: 700;
}

.field textarea,
.character-fields input,
.character-fields textarea {
  width: 100%;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  background: #fff;
  color: var(--gray-900);
  outline: none;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.55;
}

.field textarea:focus,
.character-fields input:focus,
.character-fields textarea:focus,
.search-box input:focus {
  border-color: var(--primary-100);
  box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.12);
}

.characters {
  display: grid;
  gap: 10px;
}

.character-empty {
  border: 1px dashed var(--gray-300);
  border-radius: 14px;
  color: var(--gray-500);
  font-size: 13px;
  line-height: 1.7;
  padding: 18px;
  text-align: center;
}

.character-card {
  overflow: hidden;
  border: 1px solid var(--gray-200);
  border-radius: 14px;
  background: #fff;
}

.character-title {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  background: #fff;
  padding: 12px 14px;
  text-align: left;
}

.character-title span {
  color: var(--gray-900);
  font-weight: 750;
}

.character-title small {
  color: var(--gray-500);
}

.character-card.open .character-title {
  background: var(--primary-50);
}

.character-fields {
  display: none;
  gap: 12px;
  border-top: 1px solid var(--gray-200);
  padding: 14px;
}

.character-card.open .character-fields {
  display: grid;
}

.character-fields label {
  display: grid;
  gap: 7px;
  color: var(--gray-700);
  font-size: 13px;
  font-weight: 700;
}

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

.modal-actions {
  border-top: 1px solid var(--gray-200);
}

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a1a1a1;
}

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

  .main-nav {
    display: none;
  }

  .conversation-list {
    max-height: 220px;
    border-right: 0;
    border-bottom: 1px solid var(--gray-200);
  }

  .chat-main {
    min-height: calc(100vh - 220px);
  }

  .chat-title-input {
    width: 100%;
  }

  .messages {
    padding: 18px 14px;
  }

  .message,
  .message.user {
    max-width: 92%;
  }

  .input-footer span {
    display: none;
  }

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