:root {
  --bg: #ffffff;
  --sidebar: #f4f5f7;
  --border: #e3e5e8;
  --text: #1f2328;
  --muted: #667085;
  --accent: #1d3a8a;
  --accent-hover: #162d6b;
  --user-bubble: #eef2fb;
  --error: #b42318;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 600;
}

.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.link {
  background: none;
  border: 0;
  color: var(--muted);
  padding: 4px 0;
}

.link:hover {
  color: var(--text);
  text-decoration: underline;
}

.icon {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 6px;
}

.icon:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text);
}

.icon.small {
  font-size: 13px;
  padding: 2px 6px;
  visibility: hidden;
}

.error {
  color: var(--error);
}

/* Sign-in ----------------------------------------------------------------------------------- */
.signin {
  min-height: 100%;
  display: grid;
  place-items: center;
  background: var(--sidebar);
  padding: 24px;
}

.signin-card {
  max-width: 420px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px;
  text-align: center;
}

.signin-card h1 {
  margin: 12px 0 8px;
}

.signin-card p {
  color: var(--muted);
  line-height: 1.5;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 22px;
}

.brand-mark.small {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  font-size: 14px;
  margin-right: 8px;
}

/* Layout ------------------------------------------------------------------------------------ */
.app {
  display: flex;
  height: 100%;
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

.sidebar-top {
  padding: 16px;
}

.brand {
  display: flex;
  align-items: center;
  font-weight: 700;
  font-size: 17px;
  margin-bottom: 14px;
}

.badge {
  margin-left: 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--user-bubble);
  border-radius: 6px;
  padding: 2px 6px;
}

.new-chat {
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-weight: 600;
}

.new-chat:hover {
  border-color: var(--accent);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.conversation {
  display: flex;
  align-items: center;
  border-radius: 8px;
  margin-bottom: 2px;
}

.conversation:hover,
.conversation.active {
  background: rgba(0, 0, 0, 0.06);
}

.conversation:hover .icon.small,
.conversation.active .icon.small {
  visibility: visible;
}

.conversation-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: none;
  border: 0;
  padding: 8px 10px;
  text-align: left;
}

.conversation-title {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}

.conversation-date {
  font-size: 12px;
  color: var(--muted);
}

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  font-size: 14px;
}

.user-name {
  font-weight: 600;
  margin-bottom: 2px;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.main-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#toggle-sidebar {
  display: none;
}

/* Messages ---------------------------------------------------------------------------------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
}

.message {
  max-width: 760px;
  margin: 0 auto 18px;
  display: flex;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  background: var(--user-bubble);
  border-radius: var(--radius);
  padding: 10px 14px;
  max-width: 80%;
  white-space: pre-wrap;
}

.message.assistant .bubble {
  width: 100%;
}

.message.error .bubble {
  color: var(--error);
}

.bubble p {
  margin: 0 0 10px;
}

.bubble p:last-child,
.bubble ul:last-child,
.bubble ol:last-child {
  margin-bottom: 0;
}

.bubble ul,
.bubble ol {
  margin: 0 0 10px;
  padding-left: 22px;
}

.bubble a {
  color: var(--accent);
}

.bubble code {
  background: var(--sidebar);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.92em;
}

.bubble pre {
  background: var(--sidebar);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}

.bubble pre code {
  background: none;
  padding: 0;
}

.typing i {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}

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

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

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

.empty {
  max-width: 760px;
  margin: 12vh auto 0;
  text-align: center;
}

.empty h3 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 20px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.suggestions button {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
}

.suggestions button:hover {
  border-color: var(--accent);
}

.note {
  max-width: 760px;
  margin: 0 auto 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #fff7e6;
  color: #7a4b00;
  font-size: 14px;
}

/* Composer ---------------------------------------------------------------------------------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: calc(100% - 40px);
  max-width: 760px;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 10px 10px 16px;
  box-shadow: 0 2px 10px rgba(16, 24, 40, 0.06);
}

.composer:focus-within {
  border-color: var(--accent);
}

.composer textarea {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  font: inherit;
  line-height: 1.5;
  max-height: 200px;
  padding: 6px 0;
  background: transparent;
}

.footnote {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 14px;
}

/* Small screens ----------------------------------------------------------------------------- */
@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.15);
  }

  .sidebar.open {
    transform: none;
  }

  #toggle-sidebar {
    display: inline-block;
  }
}
