/* Pi Agent Web Interface Styles */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #1a1a2e;
  color: #eaeaea;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: #16213e;
  padding: 1rem;
  border-bottom: 1px solid #0f3460;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 {
  font-size: 1.5rem;
  color: #e94560;
}

/* Main Container */
.container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: #16213e;
  border-right: 1px solid #0f3460;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid #0f3460;
  display: flex;
  gap: 0.5rem;
}

.sidebar-header button {
  flex: 1;
  padding: 0.5rem;
  background: #0f3460;
  color: #eaeaea;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.sidebar-header button:hover {
  background: #e94560;
}

/* Session List */
.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.session-item {
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  background: #0f3460;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.session-item:hover {
  background: #1a4a7a;
}

.session-item.active {
  background: #e94560;
}

.session-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.session-item-title {
  font-weight: 500;
  flex: 1;
}

.session-item-delete {
  background: #e94560;
  color: white;
  border: none;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.session-item-delete:hover {
  background: #d63850;
}

.session-item-meta {
  font-size: 0.75rem;
  color: #aaa;
}

.config-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
  font-size: 0.7rem;
  margin-top: 0.25rem;
}

/* Config Selector Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: #16213e;
  border-radius: 8px;
  padding: 1.5rem;
  min-width: 500px;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h2 {
  margin-top: 0;
  color: #e94560;
  margin-bottom: 1rem;
}

.config-option {
  padding: 1rem;
  margin: 0.5rem 0;
  background: #0f3460;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  border: 2px solid transparent;
}

.config-option:hover {
  background: #1a4a7a;
  border-color: #e94560;
}

.config-option-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.config-icon {
  font-size: 1.5rem;
}

.config-name {
  font-weight: bold;
  color: #eaeaea;
}

.config-description {
  color: #a6accd;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.config-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.config-tool-badge {
  background: rgba(233, 69, 96, 0.2);
  color: #e94560;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.7rem;
}

/* Main Chat Area */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.message {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  line-height: 1.5;
}

.message.user {
  align-self: flex-end;
  background: #0f3460;
  border-bottom-right-radius: 2px;
}

.message.assistant {
  align-self: flex-start;
  background: #16213e;
  border-bottom-left-radius: 2px;
}

.message .thinking {
  color: #888;
  font-style: italic;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
}

.message .text {
  white-space: pre-wrap;
}

.tool-execution {
  background: #1a1a2e;
  border-left: 3px solid #e94560;
  padding: 0.5rem 1rem;
  margin: 0.5rem 0;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 0.875rem;
}

.tool-name {
  color: #e94560;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.tool-output {
  color: #888;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ============================================================================
   Tool Call Blocks
   ============================================================================
   Tool calls are rendered between the assistant's thinking text and the
   tool execution output. They show what tool is being called and with what args.
   
   Structure:
   - .tool-call: Container with red top border (distinct from .tool-execution)
   - .tool-call.streaming: Shows "Calling tool..." while args stream in
   - .tool-call-header: Tool icon + name
   - .tool-call-args: Formatted JSON arguments
   ============================================================================ */

.tool-call {
  background: #1a1a2e;
  border-top: 2px solid #e94560;
  padding: 0.5rem 1rem;
  margin: 0.5rem 0;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 0.875rem;
}

.tool-call.streaming {
  opacity: 0.7;
}

.tool-call-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.tool-call-icon {
  font-size: 1rem;
}

.tool-call-name {
  color: #e94560;
  font-weight: 600;
}

.tool-call-args {
  color: #888;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 0.8rem;
  padding-left: 1.5rem;
}

/* ============================================================================
   Retry Status Blocks
   ============================================================================
   Shown when the upstream API fails and the agent retries.
   
   Structure:
   - .retry-status: Container with orange left border
   - .retry-status.success: Green border when retry succeeds
   - .retry-status.failed: Red border when all retries exhausted
   - .retry-icon: Refresh emoji
   - .retry-text: Error message and attempt counter
   - .retry-timer: Countdown timer
   ============================================================================ */

.retry-status {
  background: #1a1a2e;
  border-left: 3px solid #ff9800;
  padding: 0.5rem 1rem;
  margin: 0.5rem 0;
  font-size: 0.875rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.retry-status.success {
  border-left-color: #4caf50;
}

.retry-status.failed {
  border-left-color: #f44336;
}

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

.retry-text {
  color: #ff9800;
}

.retry-status.success .retry-text {
  color: #4caf50;
}

.retry-status.failed .retry-text {
  color: #f44336;
}

.retry-timer {
  color: #888;
  font-style: italic;
}

/* Input Container */
.input-container {
  padding: 1rem;
  background: #16213e;
  border-top: 1px solid #0f3460;
  display: flex;
  gap: 0.5rem;
}

.input-container input {
  flex: 1;
  padding: 0.75rem 1rem;
  background: #0f3460;
  border: 1px solid #0f3460;
  border-radius: 4px;
  color: #eaeaea;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.input-container input:focus {
  border-color: #e94560;
}

.input-container button {
  padding: 0.75rem 1.5rem;
  background: #e94560;
  color: #eaeaea;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
}

.input-container button:hover {
  background: #d63850;
}

.input-container button:disabled {
  background: #333;
  cursor: not-allowed;
}

/* Status Bar */
.status-bar {
  padding: 0.5rem 1rem;
  background: #0f3460;
  border-top: 1px solid #16213e;
  font-size: 0.75rem;
  color: #888;
  display: flex;
  justify-content: space-between;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
}

.status-dot.streaming {
  background: #ff9800;
  animation: pulse 1s infinite;
}

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

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #666;
  text-align: center;
}

.empty-state h2 {
  margin-bottom: 0.5rem;
  color: #888;
}

/* Loading Spinner */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #e94560;
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Enhanced Modal - Advanced Options */
.modal-field {
  margin-bottom: 1rem;
}

.modal-field label {
  display: block;
  margin-bottom: 0.5rem;
  color: #a6accd;
  font-size: 0.875rem;
}

.modal-field input[type="text"],
.modal-field input[type="number"],
.modal-field select {
  width: 100%;
  padding: 0.5rem;
  background: #0f3460;
  border: 1px solid #0f3460;
  border-radius: 4px;
  color: #eaeaea;
  font-size: 0.875rem;
  outline: none;
}

.modal-field input:focus,
.modal-field select:focus {
  border-color: #e94560;
}

.advanced-options {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #0f3460;
}

.advanced-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: #0f3460;
  border: none;
  border-radius: 4px;
  color: #eaeaea;
  cursor: pointer;
  font-size: 0.875rem;
  width: 100%;
  text-align: left;
  margin-bottom: 1rem;
}

.advanced-toggle:hover {
  background: #1a4a7a;
}

.advanced-toggle::before {
  content: '▼';
  font-size: 0.75rem;
  transition: transform 0.2s;
}

.advanced-toggle.expanded::before {
  transform: rotate(180deg);
}

.advanced-content {
  display: none;
}

.advanced-content.show {
  display: block;
}

.advanced-section {
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.advanced-section h4 {
  margin: 0 0 0.75rem 0;
  color: #e94560;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.advanced-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.advanced-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.advanced-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.modal-actions button {
  flex: 1;
  padding: 0.75rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: background 0.2s;
}

.modal-actions .btn-cancel {
  background: #333;
  color: #eaeaea;
}

.modal-actions .btn-cancel:hover {
  background: #444;
}

.modal-actions .btn-create {
  background: #e94560;
  color: #eaeaea;
}

.modal-actions .btn-create:hover {
  background: #d63850;
}

/* Enhanced Config Badges */
.session-config-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.25rem;
}

.config-badge.memory {
  background: rgba(33, 150, 243, 0.2);
  color: #2196f3;
}

.config-badge.thinking {
  background: rgba(156, 39, 176, 0.2);
  color: #9c27b0;
}

.config-badge.model {
  background: rgba(76, 175, 80, 0.2);
  color: #4caf50;
}

.config-badge.steering {
  background: rgba(255, 152, 0, 0.2);
  color: #ff9800;
}

.config-badge.autocompact {
  background: rgba(255, 193, 7, 0.2);
  color: #ffc107;
}

/* Streaming Behavior Dropdown */
.streaming-select {
  padding: 0.75rem;
  background: #0f3460;
  border: 1px solid #0f3460;
  border-radius: 4px;
  color: #eaeaea;
  font-size: 0.875rem;
  cursor: pointer;
  outline: none;
}

.streaming-select:focus {
  border-color: #e94560;
}

/* Session Info Panel */
.info-panel {
  width: 280px;
  background: #16213e;
  border-left: 1px solid #0f3460;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.info-panel-header {
  padding: 1rem;
  border-bottom: 1px solid #0f3460;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.info-panel-header h3 {
  font-size: 1rem;
  color: #e94560;
}

.info-panel-toggle {
  background: none;
  border: none;
  color: #eaeaea;
  font-size: 1.25rem;
  cursor: pointer;
}

.info-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.info-panel-section {
  margin-bottom: 1rem;
}

.info-panel-section h4 {
  font-size: 0.75rem;
  color: #888;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.info-panel-section p,
.info-panel-section div {
  font-size: 0.875rem;
  color: #eaeaea;
  margin-bottom: 0.25rem;
}

.info-panel-hidden {
  display: none;
}

.presets-container {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.preset-btn {
  flex: 1;
  padding: 0.5rem;
  background: #0f3460;
  border: 1px solid #0f3460;
  border-radius: 4px;
  color: #eaeaea;
  cursor: pointer;
  font-size: 0.75rem;
  transition: all 0.2s;
}

.preset-btn:hover {
  border-color: #e94560;
  background: #1a4a7a;
}

.preset-btn.active {
  background: #e94560;
  border-color: #e94560;
}

/* Responsive: hide info panel on narrow viewports */
@media (max-width: 900px) {
  .info-panel {
    width: 0;
    min-width: 0;
    padding: 0;
    border: none;
  }
  .info-panel:not(.info-panel-hidden) {
    /* Allow manual toggle to still work */
  }
}
