/* ============================================================================
   AI-Chat Admin UI Styles
   Consistent with chat-page.ts design system
   ============================================================================ */

/* Reset & Base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-input: #0d1b2a;
  --accent: #e94560;
  --accent-hover: #d63651;
  --text-primary: #e5e7eb;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #1a4b8c;
  --border-light: #2563eb;
  --success: #4ade80;
  --warning: #fbbf24;
  --error: #f87171;
  --info: #60a5fa;

  --sidebar-width: 240px;
  --header-height: 60px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* ============================================================================
   Loading Screen
   ============================================================================ */

.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

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

.admin-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  min-height: 100vh;
}

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

.sidebar {
  grid-row: 1 / -1;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  color: var(--accent);
  font-size: 18px;
  font-weight: 600;
}

.sidebar-menu {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}

.sidebar-menu li {
  margin: 4px 8px;
}

.sidebar-menu a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: all 0.2s;
}

.sidebar-menu a:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.sidebar-menu li.active a {
  background: rgba(233, 69, 96, 0.15);
  color: var(--accent);
}

.sidebar-menu .icon {
  font-size: 18px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

/* ============================================================================
   Header
   ============================================================================ */

.header {
  grid-column: 2;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.header-title {
  font-size: 18px;
  font-weight: 500;
}

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

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

.main-content {
  grid-column: 2;
  padding: 24px;
  overflow-y: auto;
  background: var(--bg-primary);
}

/* ============================================================================
   Page Components
   ============================================================================ */

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

.page-header h1 {
  font-size: 24px;
  font-weight: 600;
}

.page-description {
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ============================================================================
   Cards
   ============================================================================ */

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

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

.card-title {
  font-size: 16px;
  font-weight: 600;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

/* Stats Cards */
.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.stat-card .label {
  color: var(--text-muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-card .value {
  font-size: 32px;
  font-weight: 600;
  margin-top: 8px;
}

.stat-card .value.success { color: var(--success); }
.stat-card .value.warning { color: var(--warning); }
.stat-card .value.error { color: var(--error); }
.stat-card .value.info { color: var(--info); }

.stat-card .change {
  font-size: 13px;
  margin-top: 8px;
}

.stat-card .change.positive { color: var(--success); }
.stat-card .change.negative { color: var(--error); }

/* ============================================================================
   Data Table
   ============================================================================ */

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-tertiary);
}

.data-table th:first-child {
  border-radius: var(--radius-md) 0 0 0;
}

.data-table th:last-child {
  border-radius: 0 var(--radius-md) 0 0;
}

.data-table tr.clickable {
  cursor: pointer;
  transition: background 0.2s;
}

.data-table tr.clickable:hover {
  background: var(--bg-tertiary);
}

.data-table td {
  color: var(--text-primary);
}

.data-table .empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
}

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

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

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

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

.btn-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}

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

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

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

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.btn-icon {
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

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

/* ============================================================================
   Forms
   ============================================================================ */

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

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

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 12px 14px;
  font-size: 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: border-color 0.2s;
}

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

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-muted);
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
}

.form-group select {
  cursor: pointer;
}

.form-group .hint {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 6px;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

/* Array Input */
.array-input {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.array-item {
  display: flex;
  gap: 8px;
}

.array-item input {
  flex: 1;
}

/* Inline Fields */
.inline-fields {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.inline-fields select {
  flex: 1;
}

/* ============================================================================
   Modal
   ============================================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

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

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

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

/* ============================================================================
   Toast Notifications
   ============================================================================ */

.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--error); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info { border-left: 3px solid var(--info); }

.toast .icon {
  font-size: 18px;
}

.toast .message {
  flex: 1;
  font-size: 14px;
}

.toast .close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

/* ============================================================================
   Badges & Status
   ============================================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 999px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.badge.success {
  background: rgba(74, 222, 128, 0.15);
  color: var(--success);
}

.badge.error {
  background: rgba(248, 113, 113, 0.15);
  color: var(--error);
}

.badge.warning {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warning);
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

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

.status-indicator.active::before { background: var(--success); }
.status-indicator.inactive::before { background: var(--error); }
.status-indicator.pending::before { background: var(--warning); }

/* ============================================================================
   Empty State
   ============================================================================ */

.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

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

.empty-state h3 {
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  margin-bottom: 20px;
}

/* ============================================================================
   Code & JSON Display
   ============================================================================ */

.code-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 13px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.api-key-display {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

.api-key-display code {
  flex: 1;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ============================================================================
   Loading States
   ============================================================================ */

.loading-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.loading-inline::before {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--border) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================================
   Tabs
   ============================================================================ */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 12px 20px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.2s;
}

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

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

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

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

::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
}

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

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

/* ============================================================================
   Utility Classes
   ============================================================================ */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-sm { font-size: 13px; }
.font-mono { font-family: 'SF Mono', Monaco, monospace; }

/* ============================================================================
   Chat Playground
   ============================================================================ */

.playground-container {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 24px;
  height: calc(100vh - var(--header-height) - 48px);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.chat-controls {
  padding: 16px;
}

.control-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px 0;
}

.toggle-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch .slider {
  position: absolute;
  inset: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 11px;
  cursor: pointer;
  transition: all 0.25s ease;
}

.toggle-switch .slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: all 0.25s ease;
}

.toggle-switch input:checked + .slider {
  background: rgba(233, 69, 96, 0.2);
  border-color: var(--accent);
}

.toggle-switch input:checked + .slider::before {
  transform: translateX(18px);
  background: var(--accent);
}

/* Prompt Editor Modal */
.prompt-editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
  padding: 24px;
}

.prompt-editor {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 860px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
  overflow: hidden;
}

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

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

.prompt-editor-header .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.prompt-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.prompt-editor-toolbar .separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.prompt-editor-toolbar .char-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'SF Mono', Monaco, monospace;
}

.prompt-editor-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.prompt-editor-body textarea {
  flex: 1;
  width: 100%;
  resize: none;
  font-size: 13px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  line-height: 1.6;
  padding: 16px 20px;
  border: none;
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
}

.prompt-editor-body textarea::placeholder {
  color: var(--text-muted);
}

.prompt-editor-body .hint-bar {
  padding: 8px 20px;
  background: var(--bg-tertiary);
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.prompt-editor-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Prompt status bar in debug panel */
.prompt-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.prompt-status-bar .left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.prompt-status-bar h4 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.prompt-status-bar .status-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.prompt-status-bar .status-pill.active {
  background: rgba(233, 69, 96, 0.15);
  color: var(--accent);
}

.prompt-status-bar .status-pill.default {
  background: var(--bg-tertiary);
  color: var(--text-muted);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.empty-chat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
}

.empty-chat .icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-chat h3 {
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.message-wrapper {
  display: flex;
}

.message-wrapper.user {
  justify-content: flex-end;
}

.message-wrapper.assistant {
  justify-content: flex-start;
}

.message-wrapper.system {
  justify-content: center;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.5;
}

.message.user {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.message.system {
  background: rgba(233, 69, 96, 0.1);
  color: var(--accent);
  font-size: 14px;
  border: 1px solid rgba(233, 69, 96, 0.3);
}

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

.intent-badge {
  font-size: 11px;
  background: rgba(233, 69, 96, 0.2);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 8px;
  display: inline-block;
}

.message.loading {
  display: flex;
  gap: 4px;
  padding: 16px;
}

.message.loading span {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.message.loading span:nth-child(1) { animation-delay: -0.32s; }
.message.loading span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

.chat-input {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.chat-input input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
}

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

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

.chat-input input:disabled {
  opacity: 0.5;
}

/* Debug Panel */
.debug-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

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

.debug-sections {
  flex: 1;
  overflow-y: auto;
}

.debug-section {
  margin-bottom: 24px;
}

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

.debug-section h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.config-item {
  background: var(--bg-tertiary);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.config-item.full-width {
  grid-column: span 2;
}

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

.config-item .value {
  color: var(--text-primary);
  font-size: 13px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  background: rgba(233, 69, 96, 0.15);
  color: var(--accent);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.constraint-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.constraint-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}

.constraint-list li:last-child {
  border-bottom: none;
}

.timing-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.timing-item {
  background: var(--bg-tertiary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.timing-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.timing-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--success);
}

.memory-stats,
.emotion-info,
.context-strategy {
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 13px;
}

.emotion-info .label,
.context-strategy .label {
  color: var(--text-muted);
  margin-right: 8px;
}

.emotion-info .confidence {
  color: var(--text-muted);
  margin-left: 4px;
}

/* ============================================================================
   Compression Page
   ============================================================================ */

.compression-page .page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

.compression-page .page-description {
  color: var(--text-muted);
  margin-top: 4px;
}

/* Checkbox label */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* Badge info variant */
.badge.info {
  background: rgba(96, 165, 250, 0.15);
  color: var(--info);
}

/* Job Detail Modal */
.job-detail .detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.job-detail .detail-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.job-detail .detail-item .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.job-detail .detail-item code {
  font-size: 13px;
  color: var(--text-secondary);
  word-break: break-all;
}

.job-detail .result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.job-detail .result-item {
  background: var(--bg-tertiary);
  padding: 12px;
  border-radius: var(--radius-sm);
}

.job-detail .result-item .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.job-detail .result-item .value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.job-detail .error-card {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
}

.job-detail .error-message {
  background: var(--bg-input);
  padding: 12px;
  border-radius: var(--radius-sm);
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
  color: var(--error);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}

.job-detail .config-json {
  background: var(--bg-input);
  padding: 12px;
  border-radius: var(--radius-sm);
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-x: auto;
}

/* Text color utilities */
.text-warning {
  color: var(--warning);
}

.text-center {
  text-align: center;
}

.py-4 {
  padding-top: 16px;
  padding-bottom: 16px;
}

.mb-2 {
  margin-bottom: 8px;
}

/* ============================================================================
   Memory Users Page
   ============================================================================ */

/* User name cell with email subtitle */
.user-name-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-name-cell .text-sm {
  font-weight: 500;
}

.user-name-cell .text-xs {
  font-size: 11px;
}

/* User info header in modal */
.user-info-header {
  text-align: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.user-info-header .user-info-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.user-info-header .user-info-email {
  font-size: 14px;
  margin-top: 4px;
}

.user-info-header code {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
}

/* Memory type grid */
.memory-type-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.memory-type-card {
  background: var(--bg-tertiary);
  padding: 12px;
  border-radius: var(--radius-sm);
}

.memory-type-card .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.memory-type-card .value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Text utilities */
.text-xs {
  font-size: 11px;
}

/* ============================================================================
   Simulator Page
   ============================================================================ */

.simulator-page .page-header {
  margin-bottom: 24px;
}

.simulator-layout {
  display: grid;
  grid-template-columns: 500px 1fr;
  gap: 24px;
  height: calc(100vh - var(--header-height) - 120px);
}

.simulator-config {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.simulator-results {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Scenario Grid */
.scenario-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.scenario-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--bg-tertiary);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
}

.scenario-card:hover {
  border-color: var(--border-light);
}

.scenario-card.active {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}

.scenario-icon {
  font-size: 24px;
  flex-shrink: 0;
}

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

.scenario-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.scenario-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Facts List */
.facts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.fact-item {
  display: flex;
  gap: 8px;
}

.fact-item input {
  flex: 1;
}

/* Tone Options */
.tone-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tone-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  background: var(--bg-tertiary);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
}

.tone-option:hover {
  border-color: var(--border-light);
}

.tone-option.active,
.tone-option:has(input:checked) {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}

.tone-option input {
  margin-top: 2px;
  accent-color: var(--accent);
}

.tone-label {
  font-weight: 500;
  font-size: 14px;
  color: var(--text-primary);
}

.tone-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 4px;
}

/* Mode Indicator */
.mode-indicator {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mode-indicator.confirm {
  background: rgba(74, 222, 128, 0.15);
  color: var(--success);
  border: 1px solid var(--success);
}

.mode-indicator.clarify {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warning);
  border: 1px solid var(--warning);
}

/* Large button */
.btn-lg {
  padding: 14px 24px;
  font-size: 16px;
}

/* Result Cards */
.result-card {
  background: var(--bg-secondary);
}

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

.ai-response {
  background: var(--bg-tertiary);
  padding: 16px;
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  border-left: 3px solid var(--accent);
}

/* Prompt Sections */
.prompt-sections {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prompt-section {
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-input);
  border-bottom: 1px solid var(--border);
}

.section-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
}

.section-length {
  font-size: 12px;
  color: var(--text-muted);
}

.section-preview {
  padding: 12px 14px;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, monospace;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  max-height: 100px;
  overflow-y: auto;
}

/* Full Prompt Toggle */
.full-prompt-toggle {
  margin-top: 16px;
}

.full-prompt-toggle summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  padding: 8px 0;
}

.full-prompt-toggle summary:hover {
  text-decoration: underline;
}

.full-prompt {
  max-height: 400px;
  overflow-y: auto;
  margin-top: 12px;
  font-size: 12px;
}

/* Debug Grid */
.simulator-page .debug-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.simulator-page .debug-item {
  background: var(--bg-tertiary);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

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

.simulator-page .debug-item .value {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}

.simulator-page .debug-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.simulator-page .debug-section h4 {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.simulator-page .cues {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.simulator-page .cues .label {
  font-size: 12px;
  color: var(--text-muted);
}

/* ============================================================================
   Topics Tab — Gantt Chart
   ============================================================================ */

.gantt {
  margin-bottom: 8px;
}

.gantt-ruler {
  display: grid;
  grid-template-columns: 200px 1fr;
  margin-bottom: 2px;
}

.gantt-ruler-spacer {
  /* aligns with label column */
}

.gantt-axis {
  position: relative;
  height: 22px;
  border-bottom: 1px solid var(--border);
}

.gantt-tick {
  position: absolute;
  font-size: 10px;
  color: var(--text-muted);
  transform: translateX(-50%);
  bottom: 4px;
  white-space: nowrap;
}

.gantt-tick::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 1px;
  height: 4px;
  background: var(--border);
}

.gantt-row {
  display: grid;
  grid-template-columns: 200px 1fr auto;
  min-height: 52px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  transition: background 0.15s;
}

.gantt-row:hover,
.gantt-row--active {
  background: rgba(255, 255, 255, 0.03);
}

.gantt-row--active {
  border-left: 2px solid var(--accent);
  padding-left: 0;
}

.gantt-label {
  padding: 10px 16px 10px 0;
}

.gantt-label-title {
  font-weight: 500;
  font-size: 13px;
  color: var(--text-primary);
}

.gantt-label-range {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.gantt-track {
  position: relative;
  height: 52px;
  display: flex;
  align-items: center;
}

.gantt-bar {
  position: absolute;
  height: 28px;
  border-radius: var(--radius-sm);
  min-width: 4px;
  transition: filter 0.15s;
}

.gantt-row:hover .gantt-bar {
  filter: brightness(1.2);
}

.gantt-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 200;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 280px;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.gantt-actions {
  display: flex;
  gap: 6px;
  padding: 0 8px;
  opacity: 0;
  transition: opacity 0.15s;
}

.gantt-row:hover .gantt-actions,
.gantt-row--active .gantt-actions,
.gantt-actions--always {
  opacity: 1;
}

.gantt-default {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px dashed var(--border);
  font-size: 13px;
}

.gantt-default-label {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  min-width: 200px;
}

.gantt-default-title {
  font-weight: 500;
  color: var(--warning);
}

/* Live range preview in form */
.gantt-preview-track {
  position: relative;
  height: 32px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 4px;
}

.gantt-preview-bar {
  position: absolute;
  height: 100%;
  background: var(--accent);
  opacity: 0.7;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: 11px;
  color: white;
  white-space: nowrap;
  overflow: hidden;
}

.gantt-preview-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
}

/* Inline topic form */
.topic-form {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-top: 16px;
  background: rgba(233, 69, 96, 0.04);
}

.topic-form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.topic-form-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
}

.topic-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

/* ============================================================================
   Preview Tab
   ============================================================================ */

.preview-control {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.preview-control input[type="number"] {
  width: 80px;
}

.preview-info {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  font-size: 13px;
}

.preview-info .badge {
  margin-right: 10px;
}

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

.preview-section-chip {
  font-size: 12px;
  padding: 3px 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

.preview-prompt-wrap {
  position: relative;
}

.preview-prompt {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 12px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 500px;
  overflow-y: auto;
  margin: 0;
  font-family: 'SF Mono', Monaco, monospace;
}

.preview-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
}

/* ============================================================================
   Utility additions
   ============================================================================ */

.mb-3 {
  margin-bottom: 12px;
}

.font-medium {
  font-weight: 500;
}

/* ============================================================================
   Prompt Builder Tab — Pipeline Blocks
   ============================================================================ */

.pb-pipeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pb-block {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-secondary);
  transition: border-color 0.2s;
}

.pb-block--open {
  border-color: var(--accent);
}

.pb-block--static {
  opacity: 0.65;
}

.pb-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.pb-block-header:hover {
  background: rgba(255, 255, 255, 0.03);
}

.pb-block-header--static {
  cursor: default;
}

.pb-block-header--static:hover {
  background: none;
}

.pb-block-meta {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.pb-block-index {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-top: 1px;
}

.pb-block--open .pb-block-index {
  background: rgba(233, 69, 96, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.pb-block-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.pb-block-badge {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-muted);
}

.pb-block-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 560px;
}

.pb-block-chevron {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 12px;
}

.pb-block-body {
  padding: 4px 20px 20px 20px;
  border-top: 1px solid var(--border);
}

/* Prompt Builder — version badge variants */
.pb-block-badge--v2 {
  background: rgba(233, 69, 96, 0.15);
  color: var(--accent);
}

.pb-block-badge--all {
  background: rgba(74, 222, 128, 0.12);
  color: var(--success);
}

/* Version legend banner */
.pb-version-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.pb-version-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
}

.pb-version-badge--all {
  background: rgba(74, 222, 128, 0.12);
  color: var(--success);
}

.pb-version-badge--v2 {
  background: rgba(233, 69, 96, 0.15);
  color: var(--accent);
}

/* ============================================================================
   Prompt Builder — Version Toggle
   ============================================================================ */

.pb-version-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  width: fit-content;
}

.pb-version-btn {
  padding: 6px 20px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.pb-version-btn:hover {
  color: var(--text-primary);
}

.pb-version-btn.active {
  background: var(--accent);
  color: white;
}
