/* ========================================
   唐姝 · Chat — Styles
   ======================================== */

/* ---------- Reset ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

html::-webkit-scrollbar {
  display: none;
}

body {
  height: 100%;
  font-family: 'Noto Serif SC', 'Source Han Serif SC', 'STSong', 'SimSun', 'Songti SC', serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: #0a0a0a;
  color: #fff;
  overflow: hidden;
}

/* ---------- Parallax Background ---------- */
#parallax-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.35)),
    url('../images/assets/denki-bg-gy.webp') center / cover no-repeat;
}

/* ---------- Top Nav ---------- */
#top-nav {
  position: fixed;
  top: clamp(1.5rem, 4vh, 2.5rem);
  right: clamp(1rem, 3vw, 2rem);
  z-index: 15;
  display: flex;
  align-items: center;
}

.nav-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  font-family: 'Helvetica Neue', 'Arial', 'Helvetica', sans-serif;
  font-size: clamp(0.65rem, 0.9vw, 0.8rem);
  font-weight: 800;
  letter-spacing: 0.13em;
  text-decoration: none;
  padding: 0.4rem 0.85rem;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.nav-item:hover {
  background: #fff;
  transform: translateY(-1px);
}

/* LOGIN outline style */
.nav-item.nav-login {
  background: transparent;
  color: #C41E3A;
  border: 1px solid #C41E3A;
}

.nav-item.nav-login:hover {
  background: #C41E3A;
  color: #fff;
}

/* ---------- Logo ---------- */
#logo {
  position: fixed;
  top: 0.5rem;
  left: 1rem;
  width: clamp(120px, 14vw, 180px);
  height: auto;
  z-index: 10;
  opacity: 0.6;
  pointer-events: none;
}

/* ========================================
   Main Layout
   ======================================== */

#chat-layout {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100vh;
  padding: clamp(4rem, 10vh, 6rem) 0 0 0;
}

/* ---------- Sidebar ---------- */
#sidebar {
  width: clamp(220px, 22vw, 300px);
  min-width: 200px;
  display: flex;
  flex-direction: column;
  background: rgba(8, 8, 8, 0.92);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  backdrop-filter: blur(8px);
  overflow: hidden;
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              min-width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.sidebar-title {
  flex: 1;
  font-family: 'Helvetica Neue', 'Arial', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: #C41E3A;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Sidebar toggle button */
.btn-toggle-sidebar {
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease,
              transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
}

.btn-toggle-sidebar:hover {
  color: #fff;
}

/* Elements that fade during collapse */
.history-list,
.sidebar-footer,
.btn-new-chat {
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Collapsed sidebar state */
#sidebar.collapsed {
  width: 44px;
  min-width: 44px;
}

#sidebar.collapsed .sidebar-title,
#sidebar.collapsed .btn-new-chat,
#sidebar.collapsed .history-list,
#sidebar.collapsed .sidebar-footer {
  opacity: 0;
  pointer-events: none;
}

#sidebar.collapsed .btn-toggle-sidebar {
  transform: rotate(180deg);
}

#sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 1rem 0;
  gap: 0;
}

.btn-new-chat {
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.btn-new-chat:hover {
  background: #C41E3A;
  border-color: #C41E3A;
}

/* ---------- History List ---------- */
.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.history-list::-webkit-scrollbar {
  width: 3px;
}

.history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1.2rem;
  cursor: pointer;
  transition: background 0.15s ease;
  border-left: 2px solid transparent;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.history-item.active {
  background: rgba(196, 30, 58, 0.12);
  border-left-color: #C41E3A;
}

.history-item-title {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.history-item.active .history-item-title {
  color: #fff;
}

.history-item-del {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 0 0 0.5rem;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.history-item:hover .history-item-del {
  opacity: 1;
}

.history-item-del:hover {
  color: #C41E3A;
}


/* ========================================
   Chat Main Area
   ======================================== */

#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: rgba(6, 6, 6, 0.55);
}

/* ---------- Messages Container ---------- */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.5rem 2rem;
}

.messages-container::-webkit-scrollbar {
  width: 3px;
}

.messages-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

/* Welcome */
.welcome-message {
  text-align: center;
  padding-top: clamp(4rem, 15vh, 10rem);
  transition: opacity 0.3s ease;
}

.welcome-logo {
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: 400;
  letter-spacing: 0.25em;
  color: #C41E3A;
  margin-bottom: 0.3em;
}

.welcome-message p {
  font-size: clamp(0.85rem, 1.2vw, 1rem);
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.06em;
}

.welcome-sub {
  margin-top: 0.5em;
  font-size: 0.8rem !important;
  color: rgba(255, 255, 255, 0.35) !important;
}

/* ---------- Message Bubbles ---------- */
.message {
  display: flex;
  margin-bottom: 1.5rem;
  animation: msgIn 0.3s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

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

.message-bubble {
  max-width: 72%;
  padding: 0.8rem 1.1rem;
  border-radius: 4px;
  font-size: clamp(0.85rem, 1.05vw, 0.95rem);
  line-height: 1.75;
  letter-spacing: 0.03em;
  word-break: break-word;
}

.message.user .message-bubble {
  background: #C41E3A;
  color: #fff;
}

.message.assistant .message-bubble {
  background: rgba(20, 20, 20, 0.92);
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ---------- Markdown Content Styles ---------- */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4 {
  font-family: 'Helvetica Neue', 'Arial', sans-serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 1.2em 0 0.4em;
  line-height: 1.3;
}

.message-bubble h1 { font-size: 1.4em; }
.message-bubble h2 { font-size: 1.2em; }
.message-bubble h3 { font-size: 1.05em; }
.message-bubble h4 { font-size: 0.95em; }

.message-bubble h2:first-child,
.message-bubble h3:first-child,
.message-bubble h1:first-child {
  margin-top: 0;
}

.message-bubble p {
  margin-bottom: 0.65em;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble ul,
.message-bubble ol {
  padding-left: 1.3em;
  margin: 0.5em 0;
}

.message-bubble li {
  margin-bottom: 0.25em;
}

.message-bubble code {
  background: rgba(0, 0, 0, 0.35);
  padding: 0.15em 0.4em;
  font-size: 0.88em;
  border-radius: 2px;
}

.message-bubble pre {
  background: rgba(0, 0, 0, 0.5);
  padding: 0.9rem 1rem;
  overflow-x: auto;
  margin: 0.6em 0;
  font-size: 0.82em;
  line-height: 1.5;
  border-left: 2px solid #C41E3A;
}

.message-bubble pre code {
  background: none;
  padding: 0;
  font-size: 1em;
}

.message-bubble blockquote {
  border-left: 2px solid #C41E3A;
  padding: 0.3em 0.8em;
  margin: 0.6em 0;
  color: rgba(255, 255, 255, 0.65);
  font-style: italic;
}

.message-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.6em 0;
  font-size: 0.88em;
}

.message-bubble th {
  background: rgba(196, 30, 58, 0.2);
  padding: 0.4em 0.7em;
  text-align: left;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.message-bubble td {
  padding: 0.35em 0.7em;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.message-bubble hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  margin: 1em 0;
}

.message-bubble a {
  color: #C9A96E;
  text-decoration: underline;
}

.message-bubble strong {
  color: inherit;
  font-weight: 700;
}

/* ---------- Streaming cursor ---------- */
.stream-cursor {
  display: inline;
  color: #C41E3A;
  animation: blink 0.8s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ---------- Task list ---------- */
ul.task-list {
  list-style: none;
  padding-left: 0.2em;
}

ul.task-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.4em;
}

ul.task-list input[type="checkbox"] {
  margin-top: 0.3em;
  accent-color: #C41E3A;
  pointer-events: none;
}

/* ---------- Definition list ---------- */
.message-bubble dl {
  margin: 0.5em 0;
}

.message-bubble dt {
  font-weight: 700;
  color: #C9A96E;
  margin-top: 0.4em;
}

.message-bubble dd {
  margin-left: 1em;
  color: rgba(255, 255, 255, 0.75);
  margin-bottom: 0.3em;
}

/* ---------- Images ---------- */
.message-bubble img {
  max-width: 100%;
  height: auto;
  margin: 0.4em 0;
  border-radius: 2px;
}

/* ---------- Colored Text Classes ---------- */
.c-red    { color: #E57373; font-weight: 600; }
.c-gold   { color: #C9A96E; font-weight: 600; }
.c-green  { color: #81C784; }
.c-blue   { color: #64B5F6; }
.c-purple { color: #CE93D8; }
.c-cyan   { color: #4DD0E1; }
.c-orange { color: #FFB74D; font-weight: 500; }

/* Loading dots */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 0.3rem 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  animation: dotBounce 1.4s infinite ease-in-out;
}

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

@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.6); }
  40% { transform: scale(1); }
}

/* Error message */
.message.error .message-bubble {
  background: rgba(196, 30, 58, 0.2);
  border: 1px solid rgba(196, 30, 58, 0.3);
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.8rem;
}

/* ========================================
   Input Area
   ======================================== */

.input-area {
  padding: 0.8rem 2rem 1.2rem;
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0.5rem 0.5rem 0.5rem 0.8rem;
  transition: border-color 0.25s ease, background 0.25s ease;
}

.input-row:focus-within {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.06);
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* ---------- Inline Model Selector ---------- */
.model-select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.55);
  font-family: 'Helvetica Neue', 'Arial', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.35rem 1.6rem 0.35rem 0.5rem;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24'%3E%3Cpolyline points='6 9 12 15 18 9' fill='none' stroke='rgba(255,255,255,0.5)' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
  transition: border-color 0.2s ease, color 0.2s ease;
  max-width: 180px;
}

.model-select:hover {
  border-color: rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.8);
}

.model-select:focus {
  border-color: #C41E3A;
}

.model-select option {
  background: #1a1a1a;
  color: #fff;
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: #fff;
  font-family: inherit;
  font-size: clamp(0.85rem, 1vw, 0.95rem);
  line-height: 1.6;
  resize: none;
  max-height: 150px;
  padding: 0.2rem 0;
  letter-spacing: 0.03em;
}

.chat-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.chat-input::-webkit-scrollbar {
  width: 3px;
}

.btn-send {
  width: 38px;
  height: 34px;
  background: #C41E3A;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.15s ease;
}

.btn-send:hover {
  background: #a01830;
}

.btn-send:active {
  transform: scale(0.95);
}

.btn-send:disabled {
  background: #555;
  cursor: not-allowed;
  opacity: 0.7;
}

/* Stop button state */
.btn-send.stopping {
  background: #fff;
}

.btn-send.stopping:hover {
  background: #e0e0e0;
}

.btn-send.stopping .icon-send { display: none; }
.btn-send.stopping .icon-stop { display: block !important; }
.btn-send.stopping .icon-stop rect { fill: #C41E3A; }

/* ---------- Copy Button on Messages ---------- */
.btn-copy {
  position: absolute;
  top: 6px;
  right: 8px;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  width: 26px;
  height: 26px;
  border-radius: 3px;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.message:hover .btn-copy {
  opacity: 1;
}

.btn-copy:hover {
  color: #fff;
  background: rgba(0, 0, 0, 0.7);
}

.btn-copy.copied {
  color: #C9A96E;
}

/* ---------- Export Button ---------- */
.sidebar-footer {
  padding: 0.7rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-export {
  width: 100%;
  padding: 0.45rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.45);
  font-family: 'Helvetica Neue', 'Arial', sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.btn-export:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
}

.input-hint {
  font-family: 'Helvetica Neue', 'Arial', sans-serif;
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.2);
  letter-spacing: 0.05em;
  margin-top: 0.35rem;
  text-align: right;
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 768px) {
  #sidebar {
    width: 180px;
    min-width: 160px;
  }

  .messages-container {
    padding: 1rem;
  }

  .input-area {
    padding: 0.5rem 0.8rem 0.8rem;
  }

  .message-bubble {
    max-width: 88%;
  }
}

@media (max-width: 560px) {
  #sidebar {
    display: none;
  }

  #chat-layout {
    padding-top: clamp(3rem, 8vh, 5rem);
  }
}
