/* Alfred Control Center - Minimal Light Theme */

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

:root {
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-hover: #f0f1f2;
  --border: #e1e4e8;
  --text: #24292e;
  --text-secondary: #586069;
  --text-muted: #959da5;
  --primary: #0366d6;
  --primary-hover: #0256b9;
  --success: #28a745;
  --warning: #f0ad4e;
  --danger: #dc3545;
  --message-user: #f1f8ff;
  --message-assistant: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 6px;
  --radius-lg: 10px;
  --header-height: 56px;
  --sidebar-width: 280px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Consolas', monospace;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

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

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.menu-toggle span {
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: transform 0.2s;
}

.header-center {
  flex: 1;
  text-align: center;
}

.current-session {
  font-weight: 500;
  color: var(--text-secondary);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.connected {
  background: var(--success);
  animation: pulse 2s infinite;
}

.status-dot.disconnected {
  background: var(--danger);
}

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

/* Main Layout */
.main-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

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

.sidebar-section {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section:first-child {
  flex: 1;
}

.agents-section {
  border-top: 1px solid var(--border);
  max-height: 200px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.section-header.collapsible {
  cursor: pointer;
}

.section-header.collapsible:hover {
  background: var(--bg-hover);
}

.collapse-icon {
  font-size: 10px;
  transition: transform 0.2s;
}

.agents-section.collapsed .collapse-icon {
  transform: rotate(-90deg);
}

.agents-section.collapsed .agents-list {
  display: none;
}

.btn-icon {
  width: 24px;
  height: 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Sessions List */
.sessions-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0 8px 8px;
}

.session-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}

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

.session-item.active {
  background: var(--primary);
  color: white;
}

.session-item.active .session-status {
  background: rgba(255,255,255,0.3);
}

.session-item.active .session-preview {
  color: rgba(255,255,255,0.8);
}

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

.session-status.active { background: var(--success); }
.session-status.idle { background: var(--warning); }
.session-status.archived { background: var(--text-muted); }

.session-info {
  flex: 1;
  min-width: 0;
}

.session-name {
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* Agents List */
.agents-list {
  list-style: none;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.agent-item {
  padding: 8px 12px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

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

.agent-status.running {
  background: var(--success);
  animation: pulse 1.5s infinite;
}

.agent-status.idle {
  background: var(--warning);
}

.agent-status.offline {
  background: var(--text-muted);
}

.agent-info {
  flex: 1;
  min-width: 0;
}

.agent-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-task {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chat Panel */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

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

/* Messages */
.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

.message.user {
  align-self: flex-end;
}

.message.assistant,
.message.system {
  align-self: flex-start;
}

.message-content {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  word-break: break-word;
}

.message.user .message-content {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.system .message-content {
  background: transparent;
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
  padding: 6px 10px;
}

.message-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.message.user .message-meta {
  text-align: right;
}

/* Markdown in messages */
.message-content p {
  margin: 0 0 8px 0;
}

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

.message-content pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  margin: 8px 0;
}

.message-content code {
  font-family: var(--font-mono);
  font-size: 12px;
}

.message-content :not(pre) > code {
  background: rgba(0,0,0,0.06);
  padding: 2px 6px;
  border-radius: 3px;
}

.message.user .message-content :not(pre) > code {
  background: rgba(255,255,255,0.2);
}

.message-content ul, .message-content ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-content a {
  color: var(--primary);
}

.message.user .message-content a {
  color: #fff;
  text-decoration: underline;
}

/* Chat Input */
.chat-input-container {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  background: var(--bg);
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  color: var(--text-muted);
  font-size: 12px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

.chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-family: var(--font);
  font-size: 14px;
  resize: none;
  max-height: 150px;
  line-height: 1.4;
}

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

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

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

.btn-send:disabled {
  background: var(--border);
  cursor: not-allowed;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal.open {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.modal-content {
  position: relative;
  background: var(--bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.modal-content h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

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

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
}

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

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

.btn {
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
}

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

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

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

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

/* Mobile Responsive */
@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }
  
  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .header-center {
    display: none;
  }
  
  .message {
    max-width: 95%;
  }
  
  .modal-content {
    width: 95%;
    margin: 0 10px;
  }
}

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

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

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

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

/* Loading state */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--text-muted);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
}

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

/* Cost Tracker */
.cost-tracker {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
  border: 1px solid #86efac;
  border-radius: var(--radius);
  cursor: pointer;
  position: relative;
  margin-right: 12px;
  transition: all 0.2s ease;
}

.cost-tracker:hover {
  background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
  box-shadow: var(--shadow);
}

.cost-tracker:hover .cost-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.cost-icon {
  font-size: 16px;
}

.cost-value {
  font-weight: 600;
  font-size: 14px;
  color: #166534;
  font-variant-numeric: tabular-nums;
}

.cost-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  min-width: 240px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s ease;
}

.cost-tooltip::before {
  content: '';
  position: absolute;
  top: -6px;
  right: 16px;
  width: 12px;
  height: 12px;
  background: var(--bg);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  transform: rotate(45deg);
}

.tooltip-header {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.tooltip-row span:last-child {
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.tooltip-row.total {
  color: #166534;
  font-weight: 600;
}

.tooltip-row.total span:last-child {
  color: #166534;
}

.tooltip-row.session {
  color: var(--primary);
}

.tooltip-row.session span:last-child {
  color: var(--primary);
}

.tooltip-row.alltime {
  color: var(--text-muted);
  font-size: 12px;
}

.tooltip-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

/* High cost warning */
.cost-tracker.warning {
  background: linear-gradient(135deg, #fef9c3 0%, #fef08a 100%);
  border-color: #fbbf24;
}

.cost-tracker.warning .cost-value {
  color: #a16207;
}

.cost-tracker.danger {
  background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
  border-color: #f87171;
}

.cost-tracker.danger .cost-value {
  color: #b91c1c;
}

/* Pulse animation for updates */
@keyframes cost-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.cost-tracker.updated {
  animation: cost-pulse 0.3s ease;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .cost-tracker {
    padding: 4px 8px;
    margin-right: 8px;
  }
  
  .cost-icon {
    font-size: 14px;
  }
  
  .cost-value {
    font-size: 12px;
  }
  
  .cost-tooltip {
    right: -50px;
    min-width: 220px;
  }
}

/* ============ Cost History Modal ============ */
.modal-lg {
  max-width: 700px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

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

.modal-header h3 {
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: var(--radius);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* History Summary Cards */
.history-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.summary-card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 12px 16px;
  text-align: center;
}

.summary-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.summary-value {
  display: block;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

/* History Chart (CSS Bar Chart) */
.history-chart {
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
}

.chart-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 100px;
}

.chart-bar {
  flex: 1;
  min-width: 8px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
  position: relative;
  cursor: pointer;
  transition: opacity 0.2s;
}

.chart-bar:hover {
  opacity: 0.8;
}

.chart-bar-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 10;
}

.chart-bar:hover .chart-bar-tooltip {
  opacity: 1;
}

.chart-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 10px;
  color: var(--text-muted);
}

/* History Table */
.history-table-container {
  flex: 1;
  overflow-y: auto;
  max-height: 300px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.history-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border);
}

.history-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.history-table tr:hover td {
  background: var(--bg-hover);
}

.history-table .cost-cell {
  font-weight: 600;
  font-family: var(--font-mono);
}

.history-table .tokens-cell {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

/* View History Button */
.btn-history {
  width: 100%;
  padding: 8px 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s;
}

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

.tooltip-action {
  margin-top: 8px;
}

/* Mobile adjustments for history modal */
@media (max-width: 768px) {
  .modal-lg {
    max-width: 95%;
    max-height: 90vh;
  }
  
  .history-summary {
    grid-template-columns: 1fr;
  }
  
  .chart-bars {
    height: 80px;
  }
  
  .history-table-container {
    max-height: 200px;
  }
}
