/**
 * OpenClaw WebUI - Styles
 * Dark theme inspired by OpenWebUI
 */

:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #242424;
  --bg-hover: #2a2a2a;
  --bg-active: #333;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0a0;
  --text-muted: #666;
  --border-color: #333;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --accent: #22c55e;
  --danger: #ef4444;
  --user-msg-bg: #2f2f2f;
  --assistant-msg-bg: #1a1a1a;
  --code-bg: #0d0d0d;
  --font-mono: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --transition: 0.2s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
}

/* ==================== Login Page ==================== */

.login-container {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-header .logo {
  margin-bottom: 16px;
}

.login-header h1 {
  font-size: 1.75rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.login-header p {
  color: var(--text-secondary);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-form input {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 1rem;
  color: var(--text-primary);
  transition: border-color var(--transition);
}

.login-form input:focus {
  outline: none;
  border-color: var(--primary);
}

.login-form input::placeholder {
  color: var(--text-muted);
}

.login-error {
  color: var(--danger);
  text-align: center;
  padding: 12px;
  background: rgba(239, 68, 68, 0.1);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.login-error.hidden {
  display: none;
}

/* ==================== Buttons ==================== */

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--primary);
  color: white;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 500;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
}

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

.btn-send {
  background: var(--primary);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-send:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-send.loading {
  animation: pulse 1s infinite;
}

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

.btn-attach {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.btn-attach:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-canvas {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.btn-canvas:hover,
.btn-canvas.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-logout {
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.btn-logout:hover {
  background: var(--danger);
  color: white;
}

.btn-canvas-action {
  padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.btn-canvas-action:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

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

.app-container {
  display: flex;
  height: 100%;
}

/* ==================== Sidebar ==================== */

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

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
}

.user-name {
  font-size: 0.9rem;
  color: var(--text-primary);
}

/* ==================== Conversations List ==================== */

.conversations-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conversation-item {
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
}

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

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

.conv-title {
  font-size: 0.9rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 24px;
}

.conv-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.conv-delete {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  padding: 4px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  opacity: 0;
}

.conversation-item:hover .conv-delete {
  opacity: 1;
}

.conv-delete:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.no-conversations {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
  font-size: 0.85rem;
}

/* ==================== Main Content ==================== */

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

.chat-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.model-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-selector label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.model-selector select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: 0.85rem;
}

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

/* ==================== Chat Container ==================== */

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
}

.empty-state svg {
  opacity: 0.5;
  margin-bottom: 16px;
}

.empty-state h2 {
  font-size: 1.25rem;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 0.9rem;
}

/* ==================== Messages ==================== */

.message {
  display: flex;
  gap: 12px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: var(--primary);
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-text {
  background: var(--bg-secondary);
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  border-top-left-radius: var(--radius-sm);
  line-height: 1.6;
}

.message.user .message-text {
  background: var(--user-msg-bg);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-sm);
}

.message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.attached-file {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ==================== Code Blocks ==================== */

.code-block {
  background: var(--code-bg);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 12px 0;
  overflow-x: auto;
  position: relative;
}

.code-block code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre;
}

.inline-code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}

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

.input-container {
  padding: 16px 20px 24px;
  background: var(--bg-primary);
}

.files-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.file-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.file-remove {
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 2px;
}

.file-remove:hover {
  color: var(--danger);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 900px;
  margin: 0 auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px;
}

.input-wrapper:focus-within {
  border-color: var(--primary);
}

#message-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.5;
  resize: none;
  min-height: 24px;
  max-height: 200px;
  padding: 8px 4px;
  font-family: inherit;
}

#message-input:focus {
  outline: none;
}

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

/* ==================== Code Canvas ==================== */

.canvas-panel {
  position: absolute;
  right: -400px;
  top: 0;
  bottom: 0;
  width: 400px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: right var(--transition);
  z-index: 10;
}

.canvas-panel.open {
  right: 0;
}

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

#canvas-language {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: 0.85rem;
  flex: 1;
}

.canvas-editor {
  flex: 1;
  background: var(--code-bg);
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 16px;
  resize: none;
}

.canvas-editor:focus {
  outline: none;
}

/* ==================== Scrollbar ==================== */

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

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

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

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

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

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: left var(--transition);
  }
  
  .sidebar.open {
    left: 0;
  }
  
  .canvas-panel {
    width: 100%;
    right: -100%;
  }
  
  .message {
    max-width: 100%;
  }
  
  .input-wrapper {
    max-width: 100%;
  }
}

/* ==================== Syntax Highlighting (Basic) ==================== */

.language-javascript .keyword { color: #c678dd; }
.language-javascript .string { color: #98c379; }
.language-javascript .number { color: #d19a66; }
.language-javascript .comment { color: #5c6370; }
.language-javascript .function { color: #61afef; }

.language-python .keyword { color: #c678dd; }
.language-python .string { color: #98c379; }
.language-python .number { color: #d19a66; }
.language-python .comment { color: #5c6370; }
.language-python .function { color: #61afef; }