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

:root {
  --sidebar-bg: #1a1b2e;
  --sidebar-text: #c4c6d0;
  --sidebar-hover: #252742;
  --sidebar-active: #2d2f4e;
  --content-bg: #f8f9fa;
  --card-bg: #ffffff;
  --border: #e2e4e9;
  --text: #1a1b2e;
  --text-muted: #6b7280;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--content-bg);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ============ LAYOUT ============ */
.app-layout {
  display: flex;
  height: 100vh;
}

/* ============ SIDEBAR ============ */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.06);
}

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
}

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

.sidebar-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255,255,255,0.4);
}

.btn-icon {
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-icon:hover {
  background: rgba(255,255,255,0.2);
}

.agent-list {
  padding: 0 8px;
}

.agent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}

.agent-item:hover {
  background: var(--sidebar-hover);
}

.agent-item.active {
  background: var(--sidebar-active);
}

.agent-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.agent-avatar-lg {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}

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

.agent-item-name {
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-item-status {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.running { background: var(--success); }
.status-dot.stopped { background: var(--danger); }
.status-dot.paused { background: var(--warning); }
.status-dot.starting { background: var(--warning); animation: pulse-dot 1s ease-in-out infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.btn-text {
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 0;
}

.btn-text:hover {
  color: #fff;
}

/* ============ MAIN CONTENT ============ */
.main-content {
  flex: 1;
  overflow-y: auto;
  background: var(--content-bg);
}

.welcome-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.welcome-inner {
  text-align: center;
  max-width: 400px;
}

.welcome-inner h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.welcome-inner p {
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ============ WORKSPACE ============ */
.agent-workspace {
  padding: 24px;
  max-width: 900px;
  margin: 0 auto;
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

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

.workspace-header-left h2 {
  font-size: 20px;
  font-weight: 600;
}

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

/* Status Pill */
.status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-pill.running { background: #dcfce7; color: #166534; }
.status-pill.stopped { background: #fee2e2; color: #991b1b; }
.status-pill.paused { background: #fef3c7; color: #92400e; }
.status-pill.starting { background: #fef3c7; color: #92400e; animation: pulse-pill 1s ease-in-out infinite; }

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

/* ============ TABS ============ */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 10px 16px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ============ CARDS ============ */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}

.card-body {
  padding: 16px;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover {
  background: #f0f0f3;
  box-shadow: var(--shadow);
}

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

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

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

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

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
}

/* ============ FORMS ============ */
.form-group {
  margin-bottom: 12px;
}

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

input[type="text"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--card-bg);
  color: var(--text);
  transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.form-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 12px;
}

.form-row select {
  width: auto;
  min-width: 100px;
}

.form-row input {
  flex: 1;
}

/* ============ STATS ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

/* ============ DASHBOARD CONTROLS ============ */
.dashboard-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

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

/* ============ DRAFTS ============ */
.drafts-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.drafts-tab {
  padding: 8px 14px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.drafts-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.draft-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.draft-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.draft-author {
  font-weight: 600;
  color: var(--primary);
  font-size: 13px;
}

.draft-score {
  font-weight: 600;
  font-size: 13px;
}

.draft-type-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.draft-type-reply {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}

.draft-type-quote {
  background: rgba(139, 92, 246, 0.15);
  color: #8b5cf6;
}

.draft-source-block {
  background: var(--content-bg);
  border-left: 3px solid var(--border);
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 13px;
  border-radius: 0 4px 4px 0;
}

.draft-reply-block {
  background: #f0fdf4;
  border-left: 3px solid var(--success);
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 13px;
  border-radius: 0 4px 4px 0;
}

.draft-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.draft-source-preview {
  background: var(--content-bg);
  border-left: 3px solid var(--border);
  padding: 10px 14px;
  margin-bottom: 12px;
  border-radius: 0 4px 4px 0;
  font-size: 13px;
}

/* ============ CHAT ============ */
.chat-container {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 500px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.chat-msg {
  margin-bottom: 12px;
  max-width: 80%;
}

.chat-msg.user {
  margin-left: auto;
  text-align: right;
}

.chat-bubble {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.chat-msg.user .chat-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

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

.chat-msg.system .chat-bubble {
  background: #fef9c3;
  border: 1px solid #fde68a;
  font-size: 12px;
  color: #854d0e;
}

.chat-input-bar {
  display: flex;
  border-top: 1px solid var(--border);
  padding: 8px;
  gap: 8px;
}

.chat-input-bar input {
  flex: 1;
  border: 1px solid var(--border);
}

/* ============ LOGS ============ */
.logs-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}

.logs-toolbar select {
  width: auto;
  min-width: 120px;
}

.logs-container {
  background: #0f172a;
  border-radius: var(--radius);
  padding: 12px;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 12px;
  color: #e2e8f0;
  max-height: 600px;
  overflow-y: auto;
}

.log-line {
  padding: 2px 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-line.ERROR { color: #fca5a5; }
.log-line.WARN { color: #fcd34d; }
.log-line.INFO { color: #93c5fd; }
.log-line.DEBUG { color: #6b7280; }

.log-time { color: #64748b; }
.log-component { color: #a78bfa; }

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

.modal {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-width: 480px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-lg {
  max-width: 700px;
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
}

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

/* ============ COLOR PICKER ============ */
.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
}

.color-swatch:hover {
  transform: scale(1.1);
}

.color-swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--card-bg), 0 0 0 4px var(--text);
}

/* ============ STATUS MESSAGES ============ */
.alert {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-top: 8px;
}

.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

/* ============ UTILS ============ */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
  font-size: 13px;
}

/* ============ ITEM LIST ============ */
.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.item-row:last-child {
  border-bottom: none;
}

.item-row-label {
  font-size: 13px;
}

.item-row-tag {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--content-bg);
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 6px;
}

/* ============ SETTINGS FORM ============ */
.setting-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.setting-item:last-child {
  border-bottom: none;
}

.setting-label {
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 2px;
}

.setting-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.setting-input {
  max-width: 200px;
}

.setting-input input {
  width: 100%;
}

/* Query list styling */
.query-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.query-item:last-child {
  border-bottom: none;
}

.query-index {
  color: var(--text-muted);
  font-size: 12px;
  flex-shrink: 0;
}

.query-text {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.query-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.query-badge-last {
  background: #e2e8f0;
  color: #475569;
}

.query-badge-next {
  background: #dbeafe;
  color: #1d4ed8;
}

.query-edit-input {
  flex: 1;
  min-width: 200px;
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-right: 4px;
}

/* ============ AVATAR IMAGES ============ */
.agent-avatar-img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-img-lg {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
}

.avatar-upload-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--content-bg);
}

.avatar-preview-img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
}

.avatar-upload-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ============ REFRESH BUTTON ============ */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.refresh-icon {
  display: inline-block;
}

#btn-refresh.spinning .refresh-icon {
  animation: spin 0.6s ease;
}

/* ============ LOGIN SCREEN ============ */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--sidebar-bg);
}

.login-box {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 32px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 24px;
  color: var(--text);
}

/* ============ SIDEBAR USER INFO ============ */
.sidebar-user-info {
  font-size: 12px;
  color: var(--sidebar-text);
  margin-bottom: 8px;
  padding: 0 0 4px;
}

.sidebar-user-info .user-name {
  font-weight: 600;
  color: #fff;
}

.sidebar-user-info .user-role-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  margin-left: 6px;
}

.user-role-badge.admin {
  background: rgba(239,68,68,0.2);
  color: #fca5a5;
}

.user-role-badge.user {
  background: rgba(99,102,241,0.2);
  color: #a5b4fc;
}

.sidebar-footer-actions {
  display: flex;
  gap: 12px;
}

.agent-count-badge {
  font-size: 10px;
  font-weight: 400;
  color: rgba(255,255,255,0.5);
  text-transform: none;
  letter-spacing: 0;
}

/* ============ AGENT OWNER ============ */
.owner-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 6px;
}

.agent-item-owner {
  font-size: 10px;
  color: rgba(255,255,255,0.35);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ USERS PANEL ============ */
.users-panel {
  padding: 24px;
  max-width: 900px;
  margin: 0 auto;
}

.user-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.user-card-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}

.user-card-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-card-name {
  font-weight: 600;
  font-size: 14px;
}

.user-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
}

.role-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}

.role-badge.admin {
  background: rgba(239,68,68,0.1);
  color: #ef4444;
}

.role-badge.user {
  background: rgba(99,102,241,0.1);
  color: #6366f1;
}

.user-card-actions {
  display: flex;
  gap: 6px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
    min-width: 60px;
  }

  .sidebar-header, .sidebar-section-header span, .agent-item-info, .sidebar-footer {
    display: none;
  }

  .agent-item {
    justify-content: center;
    padding: 8px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .agent-workspace {
    padding: 16px;
  }
}
