/* ── Aletyx Dark Theme ─────────────────────────────────────────── */

:root {
  --bg-primary: #000000;
  --bg-secondary: #0a0a0a;
  --bg-card: #111111;
  --bg-elevated: #1a1a1a;
  --border-color: #222222;
  --border-hover: #333333;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent-orange: #FF7700;
  --accent-orange-hover: #FF8800;
  --status-active: #3B82F6;
  --status-completed: #10B981;
  --status-error: #EF4444;
  --status-suspended: #F59E0B;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

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

button, input, textarea, select {
  font-family: inherit;
  outline: none;
}

button {
  cursor: pointer;
  border: none;
}

/* ── Scrollbar ───────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }

/* ── Header ──────────────────────────────────────────────────── */

.header {
  height: 56px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}

.header-logo {
  height: 28px;
  width: auto;
}

.header-separator {
  width: 1px;
  height: 24px;
  background: var(--border-hover);
}

.header-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ── Container ───────────────────────────────────────────────── */

.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ── Card ────────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text-primary);
}

/* ── Form ────────────────────────────────────────────────────── */

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 0;
}

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

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

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

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

.form-group select {
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a0a0a0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
  font-family: inherit;
}

/* ── Buttons ─────────────────────────────────────────────────── */

.btn-primary {
  background: var(--accent-orange);
  color: #000;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}

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

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

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border-color);
  transition: background 0.15s, border-color 0.15s;
}

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

.btn-danger {
  background: rgba(239,68,68,0.15);
  color: var(--status-error);
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid rgba(239,68,68,0.3);
  transition: background 0.15s;
}

.btn-danger:hover {
  background: rgba(239,68,68,0.25);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

.form-actions-multi {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
}

.prefill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 12px;
}

/* ── Badges ──────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-approve {
  color: var(--status-completed);
  background: rgba(16, 185, 129, 0.15);
}

.badge-deny {
  color: var(--status-error);
  background: rgba(239, 68, 68, 0.15);
}

.badge-review {
  color: var(--status-suspended);
  background: rgba(245, 158, 11, 0.15);
}

.badge-low {
  color: var(--status-completed);
  background: rgba(16, 185, 129, 0.15);
}

.badge-medium {
  color: var(--status-suspended);
  background: rgba(245, 158, 11, 0.15);
}

.badge-high {
  color: var(--status-error);
  background: rgba(239, 68, 68, 0.15);
}

.badge-true {
  color: var(--status-completed);
  background: rgba(16, 185, 129, 0.15);
}

.badge-false {
  color: var(--status-error);
  background: rgba(239, 68, 68, 0.15);
}

.badge-active {
  color: var(--status-active);
  background: rgba(59, 130, 246, 0.15);
}

/* ── Data Grid (key-value display) ───────────────────────────── */

.data-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 0;
}

.data-grid dt {
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.data-grid dd {
  padding: 8px 12px;
  font-size: 14px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
}

/* ── Section ─────────────────────────────────────────────────── */

.section {
  margin-bottom: 24px;
}

.section-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

/* ── Conflict Alert ──────────────────────────────────────────── */

.conflict-alert {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 24px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.conflict-alert-icon {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1.4;
}

.conflict-alert-text {
  font-size: 14px;
  color: var(--status-suspended);
  line-height: 1.5;
}

/* ── Narrative Block ─────────────────────────────────────────── */

.narrative-block {
  background: var(--bg-elevated);
  border-left: 3px solid var(--accent-orange);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-secondary);
  font-style: italic;
  line-height: 1.6;
}

/* ── Loading Spinner ─────────────────────────────────────────── */

.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-hover);
  border-top-color: var(--accent-orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

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

.loading-container {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ── Progress Timeline ───────────────────────────────────────── */

.timeline {
  position: relative;
  padding-left: 28px;
  margin: 20px 0;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--border-color);
}

.timeline-item {
  position: relative;
  padding-bottom: 18px;
  padding-left: 16px;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-dot {
  position: absolute;
  left: -20px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border-hover);
}

.timeline-dot.completed {
  background: var(--status-completed);
}

.timeline-dot.active {
  background: var(--status-active);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.timeline-dot.pending {
  background: var(--border-hover);
}

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

.timeline-label.muted {
  color: var(--text-muted);
}

.timeline-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Improve AI Section ──────────────────────────────────────── */

.improve-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.improved-text {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.6;
}

.improved-text-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent-orange);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

/* ── Execution History ───────────────────────────────────────── */

.history-record {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  overflow: hidden;
}

.history-record-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-color);
}

.history-record-name {
  font-weight: 500;
  font-size: 14px;
}

.history-prompt {
  padding: 10px 14px;
}

.history-data {
  padding: 0 14px 10px;
}

.history-prompt-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent-orange);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.history-prompt-text {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', monospace;
  margin: 0;
}

.clickable:hover {
  color: var(--accent-orange);
}

/* ── Live Feed ──────────────────────────────────────────────── */

.feed-entry {
  animation: feedSlideIn 0.3s ease-out;
}

@keyframes feedSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.toggle-icon {
  display: inline-block;
  font-size: 10px;
  margin-left: 4px;
  transition: transform 0.15s;
}

/* ── Result View ─────────────────────────────────────────────── */

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

.result-card {
  text-align: center;
  padding: 48px 24px;
}

.result-decision {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.result-sub {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* ── Utility ─────────────────────────────────────────────────── */

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

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

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

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

.page-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
}

.subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* ── Executions Table ────────────────────────────────────────── */

.exec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.exec-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-elevated);
}

.exec-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.exec-table tr:hover td {
  background: var(--bg-elevated);
  cursor: pointer;
}

.exec-table .text-muted {
  font-size: 12px;
}

/* ── Detail Banner ──────────────────────────────────────────── */

.detail-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
}

.detail-banner-icon {
  font-size: 36px;
  flex-shrink: 0;
}

.detail-banner-text {
  flex: 1;
}

.detail-banner-decision {
  font-size: 20px;
  font-weight: 700;
}

.detail-banner-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Back Link ──────────────────────────────────────────────── */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  margin-bottom: 16px;
  transition: color 0.15s;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
}

.back-link:hover {
  color: var(--accent-orange);
}

/* ── Detail Action Buttons ──────────────────────────────────── */

.detail-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 640px) {
  .form-row {
    grid-template-columns: 1fr;
  }
  .data-grid {
    grid-template-columns: 140px 1fr;
  }
  .container {
    padding: 20px 16px;
  }
  .exec-table th:nth-child(4),
  .exec-table td:nth-child(4) {
    display: none;
  }
  .exec-table th:nth-child(5),
  .exec-table td:nth-child(5) {
    display: none;
  }
  .detail-banner {
    flex-direction: column;
    text-align: center;
  }
}
