/*
 * ChatStudio Lite - Terminal Aesthetic Styles
 * Uses CSS variables from /spaces/assets/css/theme.css with terminal overrides
 */

:root {
  --bg: #000000;
  --bg2: #0d0d0d;
  --bg3: #141414;
  --border: #1e1e1e;
  --text: #e5e5e5;
  --text2: #6b6b6b;
  --accent: #6366f1;
  --accent-dim: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --danger: #ef4444;
  --user-msg: #0a0a14;
  --ai-msg: #0d0d0d;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  font-family: var(--font-mono), -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  overflow: hidden;
}

/* App body: sidebar + main in a row, fills remaining height after sticky header */

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* Header */

.header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.header-brand {
  color: var(--accent);
  font-weight: bold;
  font-size: 1.1em;
  text-decoration: none;
  text-shadow: 0 0 12px rgba(99, 102, 241, 0.3);
}

.header-brand:hover {
  color: var(--accent-dim);
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* Buttons */

.btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9em;
  font-family: inherit;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--accent);
  color: #000;
  font-weight: bold;
}

.btn-primary:hover {
  background: var(--accent-dim);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.25);
}

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.15);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8em;
}

/* Hamburger */

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4em;
  cursor: pointer;
  padding: 4px 8px;
}

@media (max-width: 700px) {
  .hamburger {
    display: block;
  }
}

/* Sidebar */

.sidebar {
  width: 280px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  height: 100%;
}

@media (max-width: 700px) {
  .sidebar {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    z-index: 100;
    width: 100%;
  }
  .sidebar.open {
    display: flex;
  }
}

.sidebar h3 {
  color: var(--accent);
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.module-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.module-item {
  padding: 10px 12px;
  background: var(--bg3);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  position: relative;
}

.module-item:hover {
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.1);
}

.module-item.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.1);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.15);
}

.module-name {
  font-weight: 600;
  font-size: 0.95em;
  font-family: var(--font-mono);
}

.module-desc {
  font-size: 0.75em;
  color: var(--text2);
  margin-top: 4px;
}

.module-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: none;
  gap: 4px;
}

.module-item:hover .module-actions {
  display: flex;
}

.module-action-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75em;
  font-family: var(--font-mono);
}

.module-action-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.module-action-btn.delete:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.add-module-btn {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text2);
  justify-content: center;
  width: 100%;
}

.add-module-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Main area */

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

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 100%;
  scroll-behavior: smooth;
}

/* Messages */

.message {
  max-width: 100%;
  width: 100%;
  padding: 14px 18px;
  border-radius: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 0.95em;
  animation: msgFadeIn 0.3s ease-out;
}

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

.message.user {
  align-self: flex-end;
  background: var(--user-msg);
  border-bottom-right-radius: 4px;
  border: 1px solid rgba(99, 102, 241, 0.12);
}

.message.ai {
  align-self: flex-start;
  background: var(--ai-msg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message .role {
  font-size: 0.7em;
  color: var(--accent);
  margin-bottom: 6px;
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.message.user .role {
  color: var(--accent);
}

.message.ai .role {
  color: var(--accent-dim);
}

.msg-copy {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.9em;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

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

.msg-copy:hover {
  color: var(--accent);
  background: rgba(99, 102, 241, 0.1);
}

.message a {
  color: var(--accent);
  text-decoration: underline;
}

.message a:hover {
  text-shadow: 0 0 8px rgba(99, 102, 241, 0.35);
}

.message code {
  background: #222;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.message pre {
  background: #1a1a22;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid var(--border);
}

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

/* Input area */

.input-area {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.input-area textarea {
  flex: 1;
  min-width: 200px;
  padding: 12px 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text);
  font-size: 1em;
  font-family: var(--font-mono);
  outline: none;
  resize: none;
}

.input-area textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.15);
}

.input-area textarea::placeholder {
  color: var(--text2);
}

.input-area button {
  padding: 12px 24px;
}

/* Typing indicator */

.typing {
  color: var(--text2);
  font-style: italic;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  animation: typingDot 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
  animation-delay: 0s;
}

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

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

@keyframes typingDot {
  0%, 80%, 100% {
    opacity: 0.2;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Streaming cursor */

.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

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

/* Model select */

.model-select {
  padding: 6px 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.75em;
  font-family: var(--font-mono);
  cursor: pointer;
  max-width: 140px;
}

.model-select:focus {
  border-color: var(--accent);
  outline: none;
}

/* Modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.open {
  display: flex;
}

.modal-content {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  color: var(--accent);
  font-size: 1.1em;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 1.5em;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--danger);
}

.modal-body {
  padding: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9em;
  color: var(--text2);
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95em;
  font-family: var(--font-mono);
}

.form-group textarea {
  min-height: 120px;
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.1);
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Help panel */

.help-panel {
  background: var(--bg3);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.help-panel h4 {
  color: var(--accent);
  margin-bottom: 10px;
  font-size: 0.95em;
}

.help-panel p {
  font-size: 0.85em;
  color: var(--text2);
  line-height: 1.5;
  font-family: var(--font-mono);
}

.help-commands {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.help-cmd {
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8em;
  color: var(--accent);
  font-family: var(--font-mono);
}

/* Toast */

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg2);
  border: 1px solid var(--accent);
  padding: 12px 20px;
  border-radius: 8px;
  z-index: 300;
  animation: slideIn 0.3s;
  font-family: var(--font-mono);
}

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

/* Settings */

.settings-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.settings-row label {
  min-width: 80px;
  color: var(--text2);
  font-size: 0.9em;
}

.settings-row input {
  flex: 1;
}

/* Logs panel */

.logs-panel {
  background: var(--bg3);
  border-radius: 12px;
  padding: 16px;
  max-height: 300px;
  overflow-y: auto;
}

.log-entry {
  font-size: 0.8em;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  font-family: var(--font-mono);
}

.log-entry:last-child {
  border-bottom: none;
}

.log-time {
  color: var(--text2);
  min-width: 70px;
}

.log-action {
  min-width: 60px;
}

.log-detail {
  flex: 1;
  color: var(--text);
  word-break: break-all;
}
