:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #181b1f;
  --panel-2: #20242a;
  --border: #30363f;
  --text: #eef2f5;
  --muted: #98a2af;
  --accent: #b51f1f;
  --accent-2: #e0a526;
  --user: #22344f;
  --assistant: #1d252d;
  --ok: #5bbf84;
  --warn: #e3b341;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #101214;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
}

.header {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(16, 18, 20, 0.94);
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #4d1212);
  font-weight: 800;
}

.header h1 {
  margin: 0;
  font-size: 1.22rem;
  letter-spacing: 0;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.status {
  flex-shrink: 0;
  font-size: 0.8125rem;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
}

.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }

.sidebar {
  padding: 16px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-section {
  margin: 0;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section:last-child { border-bottom: 0; }

.section-title {
  margin: 0 0 10px;
  font-size: 0.8125rem;
  font-weight: 700;
}

.section-toggle {
  cursor: pointer;
  list-style: none;
}

.section-toggle::-webkit-details-marker { display: none; }

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

select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}

select {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  min-height: 42px;
}

.skill-detail,
.session-box,
.upload-hints {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
}

.skill-detail-name {
  font-weight: 700;
  margin-bottom: 4px;
}

.skill-detail-pack {
  font-size: 0.6875rem;
  color: var(--accent-2);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.skill-detail-desc,
.hint,
.upload-hints,
.empty-hint {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--muted);
}

.settings-body { display: flex; flex-direction: column; gap: 12px; }

.session-box code {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  word-break: break-all;
  margin: 6px 0 10px;
}

button,
.upload-btn {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  min-height: 40px;
}

#newSessionBtn {
  width: 100%;
  padding: 8px 12px;
  color: var(--text);
  background: #15181c;
  border: 1px solid var(--border);
}

.new-chat-btn {
  margin-top: 12px;
}

.history-section {
  min-height: 0;
}

.chat-history {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: stretch;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
}

.history-item.active {
  border-color: rgba(224, 165, 38, 0.45);
  background: rgba(224, 165, 38, 0.08);
}

.history-main {
  min-width: 0;
  min-height: 48px;
  padding: 8px 9px;
  border: 0;
  border-radius: 8px 0 0 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.history-main:hover,
.history-delete:hover {
  background: rgba(152, 162, 175, 0.1);
}

.history-title,
.history-preview {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-title {
  font-size: 0.8125rem;
  font-weight: 650;
}

.history-preview {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.72rem;
}

.history-delete {
  min-height: 48px;
  border: 0;
  border-radius: 0 8px 8px 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
}

.history-empty {
  padding: 10px 2px;
  color: var(--muted);
  font-size: 0.8125rem;
}

.tips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.example {
  flex: 0 0 auto;
  text-align: left;
  padding: 10px 12px;
  color: var(--text);
  background: rgba(181, 31, 31, 0.14);
  border: 1px solid rgba(181, 31, 31, 0.32);
  white-space: nowrap;
}

.example:hover,
#newSessionBtn:hover,
.upload-btn:hover {
  border-color: rgba(224, 165, 38, 0.55);
}

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 880px;
  padding: 14px 16px;
  border-radius: 8px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--user);
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant);
  border: 1px solid var(--border);
}

.message.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
  padding: 8px;
}

.message-attachments,
.model-note {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.skill-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed rgba(152, 162, 175, 0.35);
}

.skill-meta summary {
  cursor: pointer;
}

.skill-meta-content {
  margin-top: 8px;
  white-space: pre-wrap;
}

.skill-body.md-rendered { white-space: normal; }
.md-p { margin: 0 0 0.75em; }
.md-p:last-child { margin-bottom: 0; }
.md-h { margin: 1em 0 0.5em; font-size: 1rem; }
.md-ul { margin: 0.5em 0 0.75em; padding-left: 1.4em; }
.md-code {
  font-family: ui-monospace, Menlo, monospace;
  background: rgba(152, 162, 175, 0.13);
  padding: 0.1em 0.3em;
  border-radius: 4px;
}
.md-pre {
  padding: 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  overflow: auto;
}

.typing-indicator {
  display: flex;
  gap: 6px;
  align-items: center;
  height: 24px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1.1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing {
  0%, 70%, 100% { opacity: 0.35; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-5px); }
}

.composer {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  background: rgba(16, 18, 20, 0.95);
}

.access-panel {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.invite-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.invite-form input {
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}

.invite-form button {
  min-width: 72px;
  padding: 0 14px;
  color: #fff;
  background: var(--accent);
}

.usage-meter,
.invite-status {
  color: var(--muted);
  font-size: 0.8125rem;
}

.usage-meter {
  color: var(--ok);
}

.composer-skill {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(181, 31, 31, 0.1);
  border: 1px solid rgba(181, 31, 31, 0.25);
  font-size: 0.8125rem;
}

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

.composer-examples-title {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 700;
}

.composer-examples .tips {
  min-width: 0;
}

.composer-examples .example {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-skill-label {
  color: var(--muted);
  flex-shrink: 0;
}

textarea {
  resize: vertical;
  min-height: 76px;
  max-height: 32vh;
  padding: 12px 14px;
  border-radius: 8px;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

.composer-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.upload-btn {
  display: inline-flex;
  padding: 8px 12px;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--panel);
}

.stream-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.875rem;
}

#sendBtn {
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--accent), #8b1a1a);
  color: white;
  font-weight: 700;
}

#sendBtn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(224, 165, 38, 0.12);
  border: 1px solid rgba(224, 165, 38, 0.28);
  font-size: 0.8125rem;
}

.attachment-chip button {
  color: var(--muted);
  background: transparent;
}

.attachment-warn {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  color: #111;
  background: var(--warn);
  font-size: 0.6875rem;
  font-weight: 800;
}

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

  .header {
    align-items: flex-start;
    flex-direction: column;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: 34vh;
  }

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