/* CSS Custom Properties for theming */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #30363d;

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;

  --border-color: #30363d;
  --border-subtle: #21262d;

  --accent-primary: #58a6ff;
  --accent-success: #3fb950;
  --accent-warning: #d29922;
  --accent-error: #f85149;

  --font-mono: 'SF Mono', 'Menlo', 'Monaco', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

  --sidebar-width: 280px;
  --header-height: 48px;
  --input-height: 56px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  height: 100%;
  display: flex;
}

/* Layout */
.app-layout {
  display: flex;
  height: 100%;
  width: 100%;
}

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

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

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

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

/* Session List */
.session-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-card {
  position: relative;
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease;
}

.session-card:hover {
  background: var(--bg-hover);
}

.session-card.active {
  background: var(--bg-hover);
  border: 1px solid var(--accent-primary);
}

.session-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.session-card-name {
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-card-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.session-card-status.idle {
  background: var(--text-muted);
}

.session-card-status.running {
  background: var(--accent-success);
  animation: pulse 2s infinite;
}

.session-card-status.waiting_permission {
  background: var(--accent-warning);
  animation: pulse 1s infinite;
}

.session-card-status.error {
  background: var(--accent-error);
}

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

.session-card-preview {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-menu {
  position: absolute;
  top: 100%;
  right: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 100;
  overflow: hidden;
}

.session-menu button {
  display: block;
  width: 100%;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.session-menu button:hover {
  background: var(--bg-hover);
}

.session-menu button.danger {
  color: var(--accent-error);
}

.session-rename-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

/* Main content area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.main-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.main-header-title {
  font-weight: 500;
  color: var(--text-primary);
}

/* Message stream */
.message-stream {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.message {
  margin-bottom: 16px;
  max-width: 900px;
}

.message-user {
  background: var(--bg-tertiary);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-left: auto;
  max-width: 80%;
}

.message-assistant {
  padding: 12px 0;
}

.message-system {
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px 0;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 0;
}

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

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

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

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

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

.message-assistant pre {
  background: var(--bg-tertiary);
  padding: 12px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
}

.message-assistant code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

/* Tool calls */
.tool-call {
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  margin: 8px 0;
  overflow: hidden;
}

.tool-call-header {
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.tool-call-header:hover {
  background: var(--bg-hover);
}

.tool-call-icon {
  color: var(--accent-primary);
  font-size: 12px;
}

.tool-call-name {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent-primary);
}

.tool-call-summary {
  color: var(--text-secondary);
  font-size: 12px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-call-body {
  padding: 12px;
  border-top: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-secondary);
  max-height: 300px;
  overflow-y: auto;
}

.tool-call-body.hidden {
  display: none;
}

/* Permission card */
.permission-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--accent-warning);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 16px 0;
}

.permission-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--accent-warning);
  font-weight: 500;
}

.permission-card-tool {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-secondary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  overflow-x: auto;
}

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

/* Prompt input */
.prompt-container {
  padding: 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
}

.prompt-input-wrapper {
  display: flex;
  gap: 8px;
  max-width: 900px;
}

.prompt-input {
  flex: 1;
  min-height: var(--input-height);
  max-height: 200px;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  resize: none;
  outline: none;
}

.prompt-input:focus {
  border-color: var(--accent-primary);
}

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

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: none;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: var(--accent-primary);
  color: white;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

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

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

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

.btn-success {
  background: var(--accent-success);
  color: white;
}

.btn-danger {
  background: var(--accent-error);
  color: white;
}

.btn-icon {
  padding: 8px;
  background: transparent;
  color: var(--text-secondary);
}

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

/* Connection indicator */
.connection-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-success);
}

.connection-indicator.disconnected {
  background: var(--accent-error);
}

.connection-indicator.connecting {
  background: var(--accent-warning);
  animation: pulse 1s infinite;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  text-align: center;
  padding: 32px;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 8px;
}

/* Project selector modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: 24px;
  min-width: 400px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  margin-bottom: 16px;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
}

.modal-body {
  margin-bottom: 16px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Project list */
.project-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.project-item {
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease;
}

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

.project-item-name {
  font-weight: 500;
}

.project-item-path {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* Streaming cursor */
.streaming-cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--accent-primary);
  animation: blink 1s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

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

/* Mobile responsive */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
  }

  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    inset: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

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

  .main-content {
    width: 100%;
  }

  .modal {
    min-width: 0;
    width: calc(100vw - 32px);
    margin: 16px;
  }
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

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

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

/* Text input */
input[type="text"] {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
}

input[type="text"]:focus {
  border-color: var(--accent-primary);
}

input[type="text"]::placeholder {
  color: var(--text-muted);
}

/* Labels */
label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Form groups */
.form-group {
  margin-bottom: 16px;
}

/* Auth screen */
.auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px;
}

.auth-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: 32px;
  width: 100%;
  max-width: 400px;
}

.auth-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
  text-align: center;
}

.auth-subtitle {
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 24px;
}

.auth-error {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid var(--accent-error);
  color: var(--accent-error);
  padding: 12px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: 13px;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-start;
}

.status-button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, color 0.15s;
}

.status-button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Status modal */
.status-modal {
  max-width: 360px;
}

.status-section {
  margin-bottom: 20px;
}

.status-section:last-child {
  margin-bottom: 0;
}

.status-section h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.status-label {
  color: var(--text-secondary);
  font-size: 13px;
}

.status-value {
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
}

.status-value.status-ok {
  color: var(--accent-success);
}

.status-value.status-warning {
  color: var(--accent-warning);
}

.status-percent {
  color: var(--text-secondary);
  font-weight: 400;
  margin-left: 4px;
}

.status-bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}

.status-bar-fill {
  height: 100%;
  background: var(--accent-primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.status-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
  line-height: 1.4;
}

.status-hint code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
}

/* Error Toast */
.error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--accent-error);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  cursor: pointer;
  z-index: 1000;
  max-width: 90vw;
  animation: toast-in 0.2s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.error-toast-icon {
  color: var(--accent-error);
  font-size: 16px;
}

.error-toast-message {
  flex: 1;
  font-size: 13px;
  line-height: 1.4;
}

.error-toast-dismiss {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}

.error-toast-dismiss:hover {
  color: var(--text-primary);
}
