:root {
  --bg: #0f1117;
  --bg-elevated: #171a23;
  --bg-input: #1f2330;
  --border: #2a2e3a;
  --text: #f2f3f7;
  --text-dim: #9aa0b0;
  --accent: #6366f1;
  --bubble-user: #6366f1;
  --bubble-bot: #1f2330;
  --radius: 18px;
  font-family: "Segoe UI", "Tahoma", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* ---------- شاشة الاختيار ---------- */

.picker-header {
  padding: 48px 24px 24px;
  text-align: center;
}

.picker-header h1 {
  font-size: 26px;
  margin: 0 0 8px;
  font-weight: 700;
}

.subtitle {
  color: var(--text-dim);
  margin: 0;
  font-size: 15px;
}

.persona-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.persona-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  text-align: right;
}

.persona-card:hover,
.persona-card:active {
  transform: translateY(-2px);
  border-color: var(--card-color, var(--accent));
}

.persona-card .avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--card-color, var(--accent)) 25%, transparent);
}

.persona-card .info {
  flex: 1;
  min-width: 0;
}

.persona-card .name {
  font-weight: 700;
  font-size: 17px;
  margin-bottom: 2px;
}

.persona-card .role {
  color: var(--text-dim);
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.persona-card .chevron {
  color: var(--text-dim);
  font-size: 20px;
  flex-shrink: 0;
}

/* ---------- شاشة المحادثة ---------- */

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

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 26px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  transform: scaleX(-1);
}

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

.chat-header .avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  background: color-mix(in srgb, var(--persona-color, var(--accent)) 25%, transparent);
}

.chat-name {
  font-weight: 700;
  font-size: 15.5px;
}

.chat-role {
  font-size: 12px;
  color: var(--text-dim);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble-row {
  display: flex;
  width: 100%;
}

.bubble-row.user {
  justify-content: flex-end;
}

.bubble-row.bot {
  justify-content: flex-start;
}

.bubble {
  max-width: 78%;
  padding: 10px 15px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: pop-in 0.18s ease;
}

.bubble-row.user .bubble {
  background: var(--bubble-user);
  color: white;
  border-bottom-left-radius: 6px;
}

.bubble-row.bot .bubble {
  background: var(--bubble-bot);
  color: var(--text);
  border-bottom-right-radius: 6px;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.typing .bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
}

.typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: bounce 1.2s infinite ease-in-out;
}

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

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.composer input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 12px 18px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.composer input:focus {
  border-color: var(--persona-color, var(--accent));
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--persona-color, var(--accent));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.send-btn svg {
  transform: scaleX(-1);
}

/* شريط السكرول */
.messages::-webkit-scrollbar,
.persona-list::-webkit-scrollbar {
  width: 6px;
}
.messages::-webkit-scrollbar-thumb,
.persona-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
