/*! HTML5 Boilerplate v9.0.1 | MIT License | https://html5boilerplate.com/ */

/* main.css 3.0.0 | MIT License | https://github.com/h5bp/main.css#readme */
/*
 * What follows is the result of much research on cross-browser styling.
 * Credit left inline and big thanks to Nicolas Gallagher, Jonathan Neal,
 * Kroc Camen, and the H5BP dev community and team.
 */

/* ==========================================================================
   Base styles: opinionated defaults
   ========================================================================== */

html {
  color: #222;
  font-size: 1em;
  line-height: 1.4;
}

::-moz-selection {
  background: #b3d4fc;
  text-shadow: none;
}

::selection {
  background: #b3d4fc;
  text-shadow: none;
}

hr {
  display: block;
  height: 1px;
  border: 0;
  border-top: 1px solid #ccc;
  margin: 1em 0;
  padding: 0;
}

audio,
canvas,
iframe,
img,
svg,
video {
  vertical-align: middle;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

textarea {
  resize: none;
}

/* ==========================================================================
   Author's custom styles — ChatGPT replica
   ========================================================================== */

:root {
  --sidebar-bg: #171717;
  --main-bg: #212121;
  --input-bg: #2f2f2f;
  --text-primary: #ececec;
  --text-secondary: #b4b4b4;
  --text-muted: #8e8e8e;
  --border-color: #2f2f2f;
  --user-bubble-bg: #2f2f2f;
  --hover-bg: #2a2a2a;
  --accent: #10a37f;
  --sidebar-width: 260px;
  --chat-max-width: 768px;
}

* {
  box-sizing: border-box;
}

html {
  color: var(--text-primary);
  background: var(--main-bg);
  font-family: 'Söhne', -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

body {
  margin: 0;
  padding: 0;
  background: var(--main-bg);
  min-height: 100vh;
  display: flex;
}

/* --- Sidebar --- */

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  gap: 8px;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  flex-grow: 1;
  font-family: inherit;
}

.new-chat-btn:hover {
  background: var(--hover-bg);
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle:hover {
  background: var(--hover-bg);
}

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

.conversation-item {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item:hover {
  background: var(--hover-bg);
}

.conversation-item.active {
  background: var(--hover-bg);
  color: var(--text-primary);
}

/* --- Main area --- */

.main {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  margin-left: var(--sidebar-width);
}

.main-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  flex-shrink: 0;
}

.main-header .sidebar-toggle {
  display: none;
}

.model-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}

.model-selector:hover {
  background: var(--hover-bg);
}

/* --- Chat area --- */

.chat-area {
  flex-grow: 1;
  overflow-y: auto;
  padding: 0 16px;
}

.chat-area::-webkit-scrollbar {
  width: 6px;
}

.chat-area::-webkit-scrollbar-track {
  background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.chat-area::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

#messages {
  max-width: var(--chat-max-width);
  margin: 0 auto;
  padding-bottom: 16px;
}

/* --- Welcome screen --- */

.welcome-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}

.welcome-screen h1 {
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

/* --- Messages --- */

.message {
  margin-bottom: 24px;
  word-wrap: break-word;
}

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

.user-bubble {
  background: var(--user-bubble-bg);
  color: var(--text-primary);
  padding: 12px 16px;
  border-radius: 20px;
  max-width: 75%;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.message-assistant {
  display: flex;
  justify-content: flex-start;
}

.assistant-content {
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.7;
  max-width: 85%;
  white-space: pre-wrap;
}

/* --- Response image --- */

.response-image {
  display: block;
  max-width: 100%;
  margin-top: 12px;
  border-radius: 8px;
}

/* --- Thinking dots --- */

.thinking-dots {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.thinking-dots span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: dot-pulse 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* --- Typing cursor --- */

.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 18px;
  background: var(--text-primary);
  vertical-align: text-bottom;
  margin-left: 1px;
  animation: blink 600ms step-end infinite;
}

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

/* --- Input area --- */

.input-wrapper {
  flex-shrink: 0;
  padding: 0 16px 16px;
}

.input-container {
  max-width: var(--chat-max-width);
  margin: 0 auto;
  position: relative;
  background: var(--input-bg);
  border-radius: 24px;
  border: 1px solid rgba(255,255,255,0.08);
}

#user-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  padding: 14px 48px 14px 20px;
  min-height: 52px;
  max-height: 200px;
  overflow-y: auto;
}

#user-input::placeholder {
  color: var(--text-muted);
}

#user-input:disabled {
  opacity: 0.5;
}

.send-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--text-primary);
  color: var(--main-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}

.send-btn:hover {
  opacity: 0.85;
}

.input-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* --- Responsive --- */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
  }

  .main-header .sidebar-toggle {
    display: flex;
  }

  .welcome-screen h1 {
    font-size: 22px;
  }
}

/* ==========================================================================
   Helper classes
   ========================================================================== */

.hidden,
[hidden] {
  display: none !important;
}

.visually-hidden {
  border: 0;
  clip: rect(0, 0, 0, 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.visually-hidden.focusable:active,
.visually-hidden.focusable:focus {
  clip: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  position: static;
  white-space: inherit;
  width: auto;
}

.invisible {
  visibility: hidden;
}

.clearfix::before,
.clearfix::after {
  content: "";
  display: table;
}

.clearfix::after {
  clear: both;
}

/* ==========================================================================
   Print styles.
   ========================================================================== */

@media print {
  *,
  *::before,
  *::after {
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

  a[href]::after {
    content: " (" attr(href) ")";
  }

  abbr[title]::after {
    content: " (" attr(title) ")";
  }

  a[href^="#"]::after,
  a[href^="javascript:"]::after {
    content: "";
  }

  pre {
    white-space: pre-wrap !important;
  }

  pre,
  blockquote {
    border: 1px solid #999;
    page-break-inside: avoid;
  }

  tr,
  img {
    page-break-inside: avoid;
  }

  p,
  h2,
  h3 {
    orphans: 3;
    widows: 3;
  }

  h2,
  h3 {
    page-break-after: avoid;
  }
}
