:root {
  --sago-blue: #1d9bd1;
  --sago-blue-bright: #36b8e8;
  --sago-bg: #0d1015;
  --sago-bg-alt: #12161d;
  --sago-panel: #161b24;
  --sago-border: #243042;
  --sago-text: #e6f3fb;
  --sago-text-dim: #8aa6b8;
  --sago-bubble-bot: #1b2230;
  --sago-danger: #ff6b6b;
}

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

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--sago-bg);
  color: var(--sago-text);
  overflow: hidden;
}

.chat-app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* dynamic viewport unit avoids mobile address-bar clipping */
  overflow: hidden;
}

/* ---------------- Sidebar ---------------- */
.chat-sidebar {
  width: 340px;
  flex-shrink: 0;
  background: var(--sago-bg-alt);
  border-right: 1px solid var(--sago-border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 36px 28px 20px;
  overflow-y: auto;
}

.sidebar-logo {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  display: block;
  box-shadow: 0 0 32px rgba(29, 155, 209, 0.45);
}

.sidebar-title {
  margin-top: 18px;
  font-size: 28px;
  font-weight: 700;
  color: #fff;
}

.sidebar-subtitle {
  color: var(--sago-blue-bright);
  font-size: 15px;
  margin-top: 2px;
}

.sidebar-card {
  margin-top: 26px;
  background: var(--sago-panel);
  border: 1px solid var(--sago-border);
  border-radius: 14px;
  padding: 18px;
}

.sidebar-card h2 {
  font-size: 18px;
  color: var(--sago-blue-bright);
  margin-bottom: 8px;
}

.sidebar-card p {
  font-size: 14px;
  line-height: 1.55;
  color: var(--sago-text-dim);
}

.sidebar-tips {
  list-style: none;
  margin-top: 22px;
}

.sidebar-tips li {
  display: flex;
  gap: 10px;
  font-size: 13px;
  color: var(--sago-text-dim);
  line-height: 1.5;
  margin-bottom: 14px;
}

.sidebar-tips i {
  color: var(--sago-blue);
  margin-top: 2px;
}

.sidebar-footer {
  font-size: 12px;
  color: #4d6072;
  text-align: center;
  margin-top: 24px;
}

/* ---------------- Main / conversation ---------------- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
  min-height: 0; /* allow the inner message list to shrink and scroll */
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--sago-border);
  font-weight: 600;
  background: var(--sago-bg-alt);
}

.chat-header-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}

.new-chat-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--sago-border);
  color: var(--sago-text);
  padding: 7px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.new-chat-btn:hover {
  border-color: var(--sago-blue);
  color: var(--sago-blue-bright);
}

.new-chat-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-bubble {
  display: flex;
  gap: 10px;
  max-width: 78%;
}

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

.bubble-avatar {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: var(--sago-bubble-bot);
  color: var(--sago-blue-bright);
}

.bubble-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-bubble.user .bubble-avatar {
  background: var(--sago-blue);
  color: #fff;
}

.bubble-body {
  background: var(--sago-bubble-bot);
  padding: 12px 16px;
  border-radius: 14px;
  border-top-left-radius: 4px;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.chat-bubble.user .bubble-body {
  background: linear-gradient(135deg, var(--sago-blue), var(--sago-blue-bright));
  color: #fff;
  border-radius: 14px;
  border-top-right-radius: 4px;
}

.bubble-body img.bubble-image {
  display: block;
  max-width: 240px;
  max-height: 240px;
  border-radius: 10px;
  margin-bottom: 8px;
}

.bubble-body.notice {
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid rgba(255, 107, 107, 0.35);
  color: #ffc9c9;
}

/* Typing indicator */
.typing .bubble-body {
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sago-text-dim);
  animation: blink 1.3s infinite both;
}

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

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

/* ---------------- Composer ---------------- */
.chat-composer {
  border-top: 1px solid var(--sago-border);
  padding: 16px 24px 20px;
  background: var(--sago-bg-alt);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--sago-panel);
  border: 1px solid var(--sago-border);
  border-radius: 16px;
  padding: 6px 8px 6px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.composer-row:focus-within {
  border-color: var(--sago-blue);
  box-shadow: 0 0 0 3px rgba(29, 155, 209, 0.18);
}

.composer-input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--sago-text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 160px;
  padding: 8px 0;
}

.composer-input::placeholder {
  color: #5d7588;
}

.composer-attach,
.composer-send {
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 15px;
}

.composer-attach {
  background: transparent;
  color: var(--sago-text-dim);
}

.composer-attach:hover {
  color: var(--sago-blue-bright);
}

.composer-send {
  background: linear-gradient(135deg, var(--sago-blue), var(--sago-blue-bright));
  color: #fff;
}

.composer-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.composer-error {
  color: var(--sago-danger);
  font-size: 13px;
  margin-top: 8px;
}

/* Image preview chip */
.image-preview {
  position: relative;
  display: inline-block;
  margin-bottom: 10px;
}

/* The `hidden` attribute must win over `display: inline-block` above */
.image-preview[hidden] {
  display: none;
}

.image-preview img {
  max-height: 80px;
  border-radius: 10px;
  border: 1px solid var(--sago-border);
  display: block;
}

.image-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--sago-danger);
  color: #fff;
  cursor: pointer;
  font-size: 11px;
}

/* Drag & drop overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(13, 16, 21, 0.88);
  border: 2px dashed var(--sago-blue);
  color: var(--sago-blue-bright);
  font-size: 18px;
  text-align: center;
  z-index: 5;
}

.chat-main.dragging .drop-overlay {
  display: flex;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar,
.chat-sidebar::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-sidebar::-webkit-scrollbar-thumb {
  background: var(--sago-border);
  border-radius: 4px;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 768px) {
  .chat-app {
    flex-direction: column;
  }

  .chat-sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    overflow: hidden;
  }

  .sidebar-inner {
    display: flex;
    align-items: center;
    gap: 14px;
  }

  .sidebar-logo {
    width: 48px;
    height: 48px;
    border-radius: 12px;
  }

  .sidebar-title {
    margin-top: 0;
    font-size: 20px;
  }

  .sidebar-card,
  .sidebar-tips,
  .sidebar-subtitle,
  .sidebar-footer {
    display: none;
  }

  .chat-bubble {
    max-width: 90%;
  }
}
