:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  --bg-dark: #0a0a0a;
  --bg-card: #141414;
  --bg-input: #1a1a1a;
  --bg-hover: #1e1e1e;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #4a9eff;
  --pink: #ff69b4;
  --green: #4ade80;
  --red: #ef4444;
  --sidebar-w: 260px;
}

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

body {
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  width: 100%;
  max-width: 100%;
}

/* ─── SIDEBAR ─── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #0e0e0e;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.rainbow-title {
  font-size: 18px;
  font-weight: 800;
  background: linear-gradient(90deg, #ff0000, #ff7700, #ffff00, #00ff00, #0099ff, #6600ff, #ff00ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.3px;
}

.rainbow-bar {
  height: 3px;
  margin-top: 8px;
  border-radius: 2px;
  background: linear-gradient(90deg, #ff0000, #ff7700, #ffff00, #00ff00, #0099ff, #6600ff, #ff00ff);
}

.sidebar-nav {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  font-family: inherit;
}

.nav-btn:hover { background: var(--bg-hover); color: var(--text); }
.nav-btn.active { background: rgba(74, 158, 255, 0.12); color: var(--accent); }

.nav-icon { font-size: 16px; }

/* ─── MAIN CONTENT ─── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.main-header {
  margin-bottom: 24px;
}

.main-header h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.main-header p {
  color: var(--text-dim);
  font-size: 14px;
}

/* ─── EMPTY STATE ─── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state h2 { font-size: 20px; margin-bottom: 8px; }
.empty-state p { color: var(--text-dim); margin-bottom: 20px; }

/* ─── BUTTONS ─── */
.btn-primary {
  padding: 10px 20px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }

.btn-create {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 8px;
  font-family: inherit;
}
.btn-create:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* ─── CHARACTER CARDS ─── */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.char-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.char-card:hover { border-color: var(--accent); background: var(--bg-hover); }

.char-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.char-avatar-placeholder {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4a9eff, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  flex-shrink: 0;
}

.char-info { flex: 1; min-width: 0; }
.char-name { font-weight: 600; font-size: 15px; }
.char-greeting {
  color: var(--text-dim);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.char-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.char-card:hover .char-delete { opacity: 1; }

/* ─── GROUP CARDS ─── */
.group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}

.group-card {
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.group-card:hover { border-color: var(--accent); }

.group-card-header { display: flex; align-items: center; gap: 12px; }

.group-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a855f7, #ec4899);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.group-info { flex: 1; }
.group-name { font-weight: 600; font-size: 15px; }
.group-members { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.group-topics {
  margin-top: 10px;
  padding: 8px 10px;
  background: rgba(74, 158, 255, 0.08);
  border-radius: 8px;
  font-size: 12px;
  color: var(--accent);
}

/* ─── CREATE FORM ─── */
.create-form {
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input, .form-textarea, .form-select {
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
  outline: none;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--accent);
}

.form-textarea { resize: vertical; min-height: 70px; }
.form-select { cursor: pointer; }
.form-select option { background: var(--bg-dark); }

.form-hint { font-size: 11px; color: var(--text-dim); }

/* ─── UPLOAD ─── */
.upload-area {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}
.upload-area:hover { border-color: var(--accent); background: rgba(74, 158, 255, 0.05); }

.file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 14px;
}

.upload-icon { font-size: 32px; }

/* ─── CHARACTER CHECK GRID ─── */
.char-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}

.char-check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.char-check-label:hover { border-color: var(--accent); }
.char-check-label:has(.char-check:checked) {
  border-color: var(--accent);
  background: rgba(74, 158, 255, 0.1);
}

.char-check { accent-color: var(--accent); }

.check-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.check-avatar-placeholder {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4a9eff, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ─── CHAT ─── */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #0e0e0e;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-btn {
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.back-btn:hover { background: var(--bg-hover); }

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-header-avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4a9eff, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.group-avatar-icon { font-size: 16px; }

.chat-header-name { font-weight: 600; font-size: 15px; }
.chat-header-members {
  display: block;
  color: var(--text-dim);
  font-size: 11px;
}

.chat-header-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  position: relative;
}
.icon-btn:hover { background: var(--bg-hover); }

.voice-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
  transition: background 0.2s;
}
.voice-on .voice-dot { background: var(--red); box-shadow: 0 0 6px var(--red); }

.auto-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
  transition: background 0.2s;
}
.auto-on .auto-dot { background: var(--pink); box-shadow: 0 0 6px var(--pink); }
.auto-on { border-color: var(--pink); }

/* ─── MESSAGES ─── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 80%;
}

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

.msg-char {
  align-self: flex-start;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.msg-avatar-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4a9eff, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  max-width: 100%;
  word-wrap: break-word;
}

.msg-bubble-user {
  background: var(--accent);
  color: #000;
  border-bottom-right-radius: 4px;
}

.msg-bubble-char {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-name {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 3px;
  opacity: 0.7;
}

.msg-bubble-user .msg-name { color: rgba(0,0,0,0.5); }
.msg-bubble-char .msg-name { color: var(--accent); }

.msg-text {
  font-size: 14px;
  line-height: 1.5;
}

/* ─── TYPING ─── */
.dot-anim span {
  animation: blink 1.4s infinite both;
}
.dot-anim span:nth-child(2) { animation-delay: 0.2s; }
.dot-anim span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0; }
  40% { opacity: 1; }
}

/* ─── CHAT INPUT ─── */
.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: #0e0e0e;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.chat-input:focus { border-color: var(--accent); }

.send-btn {
  padding: 12px 20px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 24px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.send-btn:hover { filter: brightness(1.1); }

/* ─── HISTORY ─── */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 600px;
}

.history-item {
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.history-item:hover { border-color: var(--accent); }

.history-date { font-size: 12px; color: var(--accent); font-weight: 600; }
.history-preview { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.history-count { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* ─── VOICE GRID ─── */
.voice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}

.voice-item {
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.voice-name { font-weight: 600; font-size: 13px; }
.voice-id { font-size: 10px; color: var(--text-dim); margin-top: 2px; word-break: break-all; }

/* ─── MOBILE ─── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 100;
    transition: left 0.3s;
  }

  .sidebar.open { left: 0; }

  .main-content { padding: 16px; }

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

  .msg { max-width: 90%; }

  .chat-header-actions { gap: 4px; }
  .icon-btn { width: 32px; height: 32px; font-size: 12px; }
}
