/* client/src/styles/global.css */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-code: #1a1f2b;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --accent-subtle: #1f3a5f;
  --border: #30363d;
  --border-light: #3d444d;
  --error: #f85149;
  --success: #3fb950;
  --warning: #d29922;
}

.chat-interface {
  display: flex;
  flex-direction: column;
  max-width: 900px;
  height: 100vh;
  margin: 0 auto;
}

.chat-header {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  backdrop-filter: blur(12px);
  justify-content: space-between;
  align-items:  center;
  padding: .875rem 1.5rem;
}

.chat-header h1 {
  background: linear-gradient(135deg, var(--accent), #a371f7);
  -webkit-text-fill-color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
  font-size: 1.25rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: .5rem;
}

button {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  cursor: pointer;
  border-radius: 8px;
  padding: .5rem 1rem;
  transition: all .2s;
  font-size: .85rem;
  font-weight: 500;
}

button:hover:not(:disabled) {
  background-color: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent);
}

button:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.new-chat-button, .history-button {
  font-weight: 500;
}

.history-panel {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  overflow-y: auto;
  max-height: 300px;
  padding: 1rem 1.5rem;
}

.history-panel h2 {
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: .75rem;
  font-size: .9rem;
  font-weight: 600;
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: .375rem;
}

.conversation-item {
  display: flex;
  align-items:  center;
  gap: .5rem;
}

.conversation-button {
  text-align: left;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex: 1;
  padding: .625rem .875rem;
}

.conversation-date {
  color: var(--text-secondary);
  font-size: .85rem;
}

.delete-button {
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background-color: #0000;
  border-radius: 8px;
  padding: .5rem .75rem;
  font-size: 1.1rem;
  font-weight: bold;
  line-height: 1;
}

.delete-button:hover {
  border-color: var(--error);
  color: var(--error);
  background-color: #f8514926;
}

.no-conversations {
  color: var(--text-secondary);
  text-align: center;
  padding: 1rem;
  font-style: italic;
}

.chat-main {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 1.5rem;
}

.welcome-message {
  text-align: center;
  color: var(--text-secondary);
  max-width: 500px;
  margin: auto;
}

.welcome-message h2 {
  color: var(--text-primary);
  margin-bottom: .75rem;
  font-size: 1.5rem;
  font-weight: 600;
}

.welcome-message p {
  margin: .375rem 0;
  font-size: .95rem;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.message {
  display: flex;
  animation: fadeIn .3s ease-out;
  border-radius: 12px;
  flex-direction: column;
  gap: .5rem;
  max-width: 85%;
  padding: 1rem 1.25rem;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-user {
  background-color: var(--pico-primary-background);
  border-radius: 12px 12px 4px;
  align-self:  flex-end;
}

.message-assistant {
  background-color: var(--pico-secondary-background);
  align-self:  flex-start;
}

.message-header {
  display: flex;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
  align-items:  center;
  gap: .375rem;
  font-size: .8rem;
  font-weight: 600;
}

.message-role-icon {
  font-size: .9rem;
}

.message-content {
  word-wrap: break-word;
  overflow-wrap: break-word;
  font-size: .95rem;
  line-height: 1.7;
}

.message-user .message-content {
  white-space: pre-wrap;
}

.cursor {
  animation: blink 1s infinite;
  color: var(--accent);
  margin-left: 2px;
}

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

  51%, 100% {
    opacity: 0;
  }
}

.chat-footer {
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
}

.message-content p {
  margin: .5em 0;
}

.message-content p:first-child {
  margin-top: 0;
}

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

.message-content h1, .message-content h2, .message-content h3, .message-content h4, .message-content h5, .message-content h6 {
  color: var(--text-primary);
  margin: 1em 0 .5em;
  font-weight: 600;
  line-height: 1.3;
}

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

.message-content h1 {
  border-bottom: 1px solid var(--border);
  padding-bottom: .3em;
  font-size: 1.4em;
}

.message-content h2 {
  border-bottom: 1px solid var(--border);
  padding-bottom: .25em;
  font-size: 1.25em;
}

.message-content h3 {
  font-size: 1.1em;
}

.message-content h4 {
  font-size: 1em;
}

.inline-code {
  color: #e6edf3;
  background-color: #6e768133;
  border: 1px solid #6e768126;
  border-radius: 6px;
  padding: .15em .4em;
  font-family: SF Mono, Fira Code, Fira Mono, Roboto Mono, Menlo, Courier, monospace;
  font-size: .88em;
}

.code-block-wrapper {
  overflow: hidden;
  border: 1px solid var(--border);
  background-color: var(--bg-code);
  border-radius: 10px;
  margin: .75em 0;
}

.code-block-header {
  display: flex;
  border-bottom: 1px solid var(--border);
  background-color: #6e76811a;
  justify-content: space-between;
  align-items:  center;
  padding: .5rem 1rem;
}

.code-language {
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-family: SF Mono, Fira Code, Menlo, monospace;
  font-size: .75rem;
  font-weight: 600;
}

.copy-button {
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  background: none;
  border-radius: 6px;
  padding: .25rem .625rem;
  transition: all .2s;
  font-size: .75rem;
  font-weight: 500;
}

.copy-button:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.copy-feedback {
  color: var(--success);
}

.code-block-wrapper pre {
  overflow-x: auto;
  border-radius: 0;
  margin: 0;
  padding: 1rem;
  background-color: #0000 !important;
  border: none !important;
}

.code-block-wrapper pre code {
  font-family: SF Mono, Fira Code, Fira Mono, Roboto Mono, Menlo, Courier, monospace;
  font-size: .85rem;
  line-height: 1.6;
  background: none !important;
  border: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
}

.hljs {
  color: #e6edf3;
  background: none;
}

.hljs-comment, .hljs-quote {
  color: #8b949e;
  font-style: italic;
}

.hljs-keyword, .hljs-selector-tag, .hljs-type {
  color: #ff7b72;
}

.hljs-literal, .hljs-number, .hljs-tag .hljs-attr, .hljs-template-variable, .hljs-variable {
  color: #79c0ff;
}

.hljs-string, .hljs-doctag {
  color: #a5d6ff;
}

.hljs-title, .hljs-section, .hljs-selector-id {
  color: #d2a8ff;
  font-weight: 600;
}

.hljs-subst {
  color: #e6edf3;
}

.hljs-tag .hljs-name, .hljs-name {
  color: #7ee787;
}

.hljs-attribute, .hljs-property {
  color: #79c0ff;
}

.hljs-regexp, .hljs-link {
  color: #a5d6ff;
}

.hljs-symbol, .hljs-bullet, .hljs-built_in, .hljs-builtin-name {
  color: #ffa657;
}

.hljs-meta {
  color: #8b949e;
}

.hljs-deletion {
  color: #ffa198;
  background-color: #f851491a;
}

.hljs-addition {
  color: #7ee787;
  background-color: #3fb9501a;
}

.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: 700;
}

.message-content blockquote {
  border-left: 3px solid var(--accent);
  color: var(--text-secondary);
  background-color: #58a6ff0d;
  border-radius: 0 8px 8px 0;
  margin: .75em 0;
  padding: .5em 1em;
}

.message-content blockquote p {
  margin: .25em 0;
}

.message-content ul, .message-content ol {
  margin: .5em 0;
  padding-left: 1.75em;
}

.message-content li {
  margin: .25em 0;
  line-height: 1.6;
}

.message-content li > p {
  margin: .25em 0;
}

.message-content ul ul, .message-content ol ol, .message-content ul ol, .message-content ol ul {
  margin: .125em 0;
}

.message-content li input[type="checkbox"] {
  accent-color: var(--accent);
  margin-right: .5em;
}

.message-content table {
  border-collapse: collapse;
  overflow-x: auto;
  display: block;
  width: 100%;
  margin: .75em 0;
  font-size: .9em;
}

.message-content thead {
  background-color: #6e76811a;
}

.message-content th, .message-content td {
  border: 1px solid var(--border);
  text-align: left;
  padding: .5em .875em;
}

.message-content th {
  color: var(--text-primary);
  font-weight: 600;
}

.message-content tr:nth-child(2n) {
  background-color: #6e76810d;
}

.message-content hr {
  background: var(--border);
  border: none;
  height: 1px;
  margin: 1em 0;
}

.message-content a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid #0000;
  transition: border-color .2s;
}

.message-content a:hover {
  border-bottom-color: var(--accent);
}

.message-content img {
  border-radius: 8px;
  max-width: 100%;
  margin: .5em 0;
}

.message-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

.message-content em {
  font-style: italic;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: none;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border);
}

::selection {
  background-color: #58a6ff4d;
}

.thinking-block {
  border: 1px solid var(--border);
  overflow: hidden;
  background-color: #d2a8ff0d;
  border-radius: 10px;
  margin-bottom: .75em;
}

.thinking-summary {
  display: flex;
  cursor: pointer;
  color: var(--text-secondary);
  user-select: none;
  list-style: none;
  background-color: #d2a8ff14;
  border-bottom: 1px solid #0000;
  align-items:  center;
  gap: .5rem;
  padding: .625rem 1rem;
  transition: all .2s;
  font-size: .85rem;
  font-weight: 600;
}

.thinking-summary::-webkit-details-marker {
  display: none;
}

.thinking-summary:before {
  content: "▸";
  color: var(--text-muted);
  transition: transform .2s;
  font-size: .75rem;
}

details[open] > .thinking-summary:before {
  transform: rotate(90deg);
}

.thinking-summary:hover {
  color: var(--text-primary);
  background-color: #d2a8ff1f;
}

details[open] > .thinking-summary {
  border-bottom-color: var(--border);
}

.thinking-icon {
  font-size: 1rem;
}

.thinking-spinner {
  animation: thinkingPulse 1.5s ease-in-out infinite;
  color: #d2a8ff;
}

@keyframes thinkingPulse {
  0%, 100% {
    opacity: .4;
  }

  50% {
    opacity: 1;
  }
}

.thinking-content {
  color: var(--text-secondary);
  border-left: 3px solid #d2a8ff4d;
  margin: 0;
  padding: .75rem 1rem;
  font-size: .88rem;
  font-style: italic;
  line-height: 1.6;
}

.thinking-content p {
  margin: .375em 0;
}

.thinking-content p:first-child {
  margin-top: 0;
}

.thinking-content p:last-child {
  margin-bottom: 0;
}

@media (max-width: 768px) {
  .chat-interface {
    max-width: 100%;
  }

  .message, .message-assistant {
    max-width: 95%;
  }

  .chat-header {
    padding: .75rem 1rem;
  }

  .chat-main {
    padding: 1rem;
  }

  .chat-footer {
    padding: .75rem 1rem;
  }

  .code-block-wrapper pre {
    padding: .75rem;
  }
}
