* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Cairo', sans-serif;
  background: #f7f7f8;
  color: #1a1a1a;
}
.app-shell { height: 100vh; width: 100%; }

/* ---------- Auth gate ---------- */
.auth-gate {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #10a37f 0%, #0d7f66 100%);
}
.auth-card {
  background: #fff;
  border-radius: 20px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  max-width: 380px;
  width: 90%;
}
.brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 10px;
  background: #10a37f; color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px;
}
.brand-logo.big { width: 64px; height: 64px; font-size: 32px; margin: 0 auto 16px; border-radius: 16px; }
.auth-card h1 { margin: 0; font-size: 28px; }
.auth-card p { color: #666; margin: 8px 0 28px; }
.auth-actions { display: flex; gap: 12px; flex-direction: column; }

.btn {
  display: inline-block; padding: 12px 20px; border-radius: 10px; text-decoration: none;
  font-weight: 600; font-size: 15px; cursor: pointer; border: none; transition: .15s;
}
.btn-primary { background: #0d7f66; color: #fff; }
.btn-primary:hover { background: #0a6b56; }
.btn-outline { background: #fff; color: #0a6b56; border: 1.5px solid #0a6b56; }
.btn-outline:hover { background: #f0fbf8; }

/* ---------- Main layout ---------- */
.main-app { display: flex; height: 100vh; }

.sidebar {
  width: 280px;
  background: #1a1d21;
  color: #ececec;
  display: flex;
  flex-direction: column;
  padding: 12px;
  flex-shrink: 0;
  transition: margin .2s;
}
.new-chat-btn {
  background: transparent;
  border: 1px solid #3a3d41;
  color: #ececec;
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  text-align: right;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}
.new-chat-btn:hover { background: #2a2d31; }

.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: #d8d8d8;
  gap: 6px;
}
.conv-item:hover { background: #2a2d31; }
.conv-item.active { background: #343941; color: #fff; }
.conv-title {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;
}
.conv-delete {
  background: none; border: none; color: #999; cursor: pointer; font-size: 14px; padding: 2px 6px; border-radius: 4px;
  flex-shrink: 0;
}
.conv-delete:hover { color: #ff6b6b; background: #3a3d41; }

.sidebar-footer {
  border-top: 1px solid #2f3237;
  padding-top: 10px;
  margin-top: 8px;
  font-size: 13px;
}
.user-chip { color: #ccc; padding: 6px 8px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-link { color: #999; text-decoration: none; padding: 6px 8px; display: block; }
.logout-link:hover { color: #fff; }

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 20;
  background: #1a1d21;
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 38px; height: 38px;
  font-size: 18px;
  cursor: pointer;
}

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid #e5e5e5;
  background: #fff;
}
.chat-header h2 { margin: 0; font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
}
.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #444;
  text-align: center;
  padding: 0 20px;
}
.empty-state h2 { font-weight: 700; margin: 0; }

.msg-row {
  max-width: 820px;
  margin: 0 auto 22px;
  padding: 0 20px;
  display: flex;
  gap: 12px;
}
.msg-row.user { flex-direction: row; }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff;
}
.msg-row.user .msg-avatar { background: #6b7280; }
.msg-row.assistant .msg-avatar { background: #10a37f; }
.msg-body { flex: 1; min-width: 0; line-height: 1.8; }
.msg-body p { margin: 0 0 10px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body pre {
  background: #1e1e1e; color: #e5e5e5; padding: 12px 14px; border-radius: 10px; overflow-x: auto;
  direction: ltr; text-align: left; font-size: 13.5px;
}
.msg-body code { background: #eee; padding: 2px 5px; border-radius: 4px; font-size: 13.5px; }
.msg-body pre code { background: none; padding: 0; }
.msg-body ul, .msg-body ol { padding-inline-start: 22px; margin: 8px 0; }

.typing-dots { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%; background: #999; display: inline-block;
  animation: blink 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.composer {
  display: flex;
  gap: 10px;
  padding: 14px 20px 20px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid #d9d9d9;
  border-radius: 14px;
  padding: 13px 16px;
  font-family: inherit;
  font-size: 15px;
  max-height: 160px;
  outline: none;
}
.composer textarea:focus { border-color: #10a37f; }
.composer button {
  width: 46px; height: 46px;
  border-radius: 12px;
  border: none;
  background: #10a37f;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transform: scaleX(-1);
}
.composer button:disabled { background: #bdbdbd; cursor: not-allowed; }
.composer button:hover:not(:disabled) { background: #0d8c6d; }

.error-banner {
  max-width: 820px; margin: 0 auto 14px; padding: 10px 16px; background: #fdecea; color: #b42318;
  border-radius: 10px; font-size: 14px;
}

@media (max-width: 768px) {
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; z-index: 15; height: 100vh; margin-right: -280px;
  }
  .sidebar.open { margin-right: 0; box-shadow: 4px 0 20px rgba(0,0,0,.3); }
  .chat-header { padding-right: 60px; }
}
