/**
 * L12-V3 Phase 10 — DSL editor + workflow dashboards + Gantt styles.
 *
 * Designed to coexist with existing Quiet Canvas theme. Variables come from
 * variables.css. Falls back gracefully when those vars are missing.
 */

/* ── Workflow Selector modal ─────────────────────────────────────── */
.workflow-selector-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.workflow-selector-modal {
  background: var(--bg-elevated, #1f2937);
  color: var(--text-primary, #f1f5f9);
  border-radius: 8px;
  width: min(900px, 100%);
  max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.workflow-selector-modal .modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,.1);
}
.workflow-selector-modal .modal-header h3 { margin: 0; font-size: 18px; }
.workflow-selector-modal .modal-close {
  background: none; border: 0; color: inherit; cursor: pointer; font-size: 24px;
}
.workflow-selector-body {
  padding: 20px; overflow-y: auto; flex: 1;
}
.workflow-selector-empty {
  padding: 32px; text-align: center; opacity: .7;
}
.workflow-selector-group { margin-bottom: 24px; }
.workflow-selector-group h4 {
  margin: 0 0 12px; padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  font-size: 13px; text-transform: uppercase; letter-spacing: .5px;
  opacity: .8;
}
.workflow-selector-card {
  display: block; width: 100%; text-align: left;
  background: var(--bg-base, #111827); color: inherit;
  border: 1px solid rgba(255,255,255,.08); border-radius: 6px;
  padding: 12px 14px; margin-bottom: 8px;
  cursor: pointer; transition: background .12s, border-color .12s;
}
.workflow-selector-card:hover {
  background: rgba(59,130,246,.08); border-color: rgba(59,130,246,.4);
}
.workflow-selector-card:disabled, .workflow-selector-card.ws-card-loading {
  opacity: .5; cursor: progress;
}
.ws-card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.ws-card-name { font-weight: 600; font-size: 14px; }
.ws-card-key { font-size: 11px; opacity: .55; font-family: ui-monospace, monospace; }
.ws-card-desc { margin: 4px 0; font-size: 13px; opacity: .85; }
.ws-card-meta { font-size: 11px; opacity: .55; }
.workflow-selector-modal .modal-footer {
  padding: 12px 20px; border-top: 1px solid rgba(255,255,255,.1);
  text-align: right;
}

/* ── Dashboard shell ─────────────────────────────────────────────── */
.workflow-dashboard {
  padding: 16px;
  font: inherit; color: inherit;
}
.dashboard-loading, .dashboard-error {
  padding: 24px; text-align: center; opacity: .8;
}
.dashboard-error { color: var(--text-error, #f87171); }
.dashboard-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle, rgba(0,0,0,.08));
}
.dashboard-header h2 { margin: 0; font-size: 18px; }
.dashboard-section {
  background: var(--bg-elevated, #f6f5f4);
  border: 1px solid var(--border-subtle, rgba(0,0,0,.08));
  border-radius: 6px; padding: 12px 14px; margin-bottom: 12px;
}
.dashboard-section h3 {
  margin: 0 0 8px; font-size: 13px;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-secondary, rgba(0,0,0,.6));
}
.dashboard-slot-empty {
  padding: 16px; text-align: center;
  color: var(--text-tertiary, rgba(0,0,0,.45));
  font-style: italic;
}
.dashboard-grid {
  display: grid; gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 1100px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .dashboard-gantt-section { grid-column: span 2; }
}

/* ── Status pill ─────────────────────────────────────────────────── */
.dashboard-pill {
  display: inline-flex; gap: 12px; align-items: center;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(0,0,0,.05);
  font-size: 12px;
}
.dashboard-pill.pill--running { background: rgba(96,165,250,.2); }
.dashboard-pill.pill--idle { background: rgba(0,0,0,.06); }
.dashboard-pill .pill-label { font-weight: 600; }
.dashboard-pill .pill-cost { font-family: ui-monospace, monospace; opacity: .85; }
.dashboard-pill .pill-runs { opacity: .6; }

/* ── Editorial dashboard ─────────────────────────────────────────── */
.editorial-progress {
  position: relative;
  height: 24px;
  background: rgba(255,255,255,.06);
  border-radius: 4px; overflow: hidden;
  margin-bottom: 12px;
}
.editorial-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  transition: width .3s ease;
}
.editorial-progress-label {
  position: absolute; inset: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 10px; font-size: 11px; color: #f1f5f9;
}
.editorial-current {
  display: flex; gap: 12px; align-items: center;
  padding: 12px; background: rgba(255,255,255,.04);
  border-radius: 6px; margin-bottom: 12px;
}
.editorial-current.empty { opacity: .55; font-style: italic; padding: 16px; }
.editorial-avatar {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; font-size: 14px;
}
.editorial-current-meta { flex: 1; }
.editorial-current-name { font-weight: 600; }
.editorial-current-action { font-size: 12px; opacity: .8; margin-top: 3px; }
.editorial-last { padding: 8px; }
.editorial-last.empty { opacity: .55; font-style: italic; }
.editorial-last h4 { margin: 0 0 6px; font-size: 13px; }
.editorial-last-meta { font-size: 11px; opacity: .65; margin-bottom: 6px; }
.editorial-last-preview {
  background: rgba(0,0,0,.25); padding: 10px;
  border-radius: 4px; font-size: 11px;
  max-height: 200px; overflow: auto;
  font-family: ui-monospace, monospace;
}
.editorial-controls, .novel-controls {
  display: flex; gap: 8px;
}

/* ── Novel dashboard ─────────────────────────────────────────────── */
.novel-chapter-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.novel-chapter-card {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 4px; padding: 10px;
  font-size: 12px;
}
.novel-chapter-card.status-approved { border-left: 3px solid #4ade80; }
.novel-chapter-card.status-needs_revision { border-left: 3px solid #fbbf24; }
.novel-chapter-card.status-escalated_human { border-left: 3px solid #f87171; }
.novel-chapter-card.status-drafting { border-left: 3px solid #60a5fa; }
.novel-chapter-header {
  display: flex; justify-content: space-between; margin-bottom: 4px;
}
.novel-chapter-num { font-weight: 600; }
.novel-chapter-title { font-size: 13px; margin: 4px 0; opacity: .9; }
.novel-chapter-meta {
  display: flex; justify-content: space-between;
  font-size: 11px; opacity: .65;
}
.novel-invariant-alerts { list-style: none; padding: 0; margin: 0; }
.novel-alert {
  padding: 8px 10px;
  background: rgba(248,113,113,.08);
  border-left: 3px solid #f87171;
  margin-bottom: 6px;
  font-size: 12px;
}
.novel-alert-type { font-weight: 600; margin-right: 8px; }
.novel-alert-time { opacity: .55; font-size: 11px; }
.novel-alert-detail { margin-top: 4px; opacity: .85; }
.novel-ledger-table {
  width: 100%; border-collapse: collapse; font-size: 11px;
}
.novel-ledger-table th, .novel-ledger-table td {
  padding: 4px 8px; border-bottom: 1px solid rgba(255,255,255,.05);
  text-align: left;
}
.novel-ledger-table th {
  font-weight: 600; opacity: .8; font-size: 10px;
  text-transform: uppercase; letter-spacing: .5px;
}

/* ── Status badges (shared) ──────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 600;
  background: rgba(255,255,255,.08);
}
.badge--pending, .badge--idle, .badge--draft { background: rgba(160,160,170,.25); }
.badge--running, .badge--drafting { background: rgba(96,165,250,.3); }
.badge--done, .badge--approved, .badge--reviewed, .badge--published, .badge--active { background: rgba(74,222,128,.3); }
.badge--failed, .badge--escalated_human, .badge--retired { background: rgba(248,113,113,.3); }
.badge--needs_revision, .badge--paused { background: rgba(251,191,36,.3); }
.badge--deprecated { background: rgba(160,160,170,.3); }
.badge--open { background: rgba(96,165,250,.25); }

/* ── Gantt chart ─────────────────────────────────────────────────── */
.agent-runs-gantt {
  display: block; width: 100%;
  background: rgba(0,0,0,.18);
  border-radius: 4px;
}
.gantt-empty {
  padding: 20px; text-align: center; opacity: .55;
  font-style: italic; font-size: 12px;
}

/* ── DSL editor ──────────────────────────────────────────────────── */
.dsl-editor-root {
  display: flex; flex-direction: column; height: 100%;
  font-size: 13px;
}
.dsl-editor-header {
  padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,.1);
}
.dsl-editor-header h2 { margin: 0; font-size: 18px; }
.dsl-editor-body {
  flex: 1; display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
}
.dsl-editor-sidebar {
  padding: 12px; border-right: 1px solid rgba(255,255,255,.08);
  overflow-y: auto;
}
.dsl-editor-sidebar h3 {
  margin: 0 0 8px; font-size: 12px;
  text-transform: uppercase; letter-spacing: .5px; opacity: .7;
}
.dsl-playbook-list { list-style: none; padding: 0; margin: 0; }
.dsl-playbook-item {
  padding: 8px 10px; cursor: pointer; border-radius: 4px;
  margin-bottom: 4px;
  border: 1px solid transparent;
}
.dsl-playbook-item:hover { background: rgba(255,255,255,.04); }
.dsl-playbook-item.selected {
  background: rgba(59,130,246,.15);
  border-color: rgba(59,130,246,.4);
}
.dsl-pb-name { font-weight: 600; }
.dsl-pb-meta { font-size: 11px; opacity: .65; margin-top: 2px; }

.dsl-editor-main {
  padding: 12px; overflow-y: auto;
}
.dsl-editor-toolbar {
  display: flex; gap: 6px; flex-wrap: wrap;
  align-items: center; margin-bottom: 12px;
  padding: 8px; background: rgba(255,255,255,.04);
  border-radius: 4px;
}
.dsl-editor-toolbar label { font-size: 12px; }
.dsl-editor-toolbar select { margin-left: 4px; }
.dsl-editor-message {
  margin-bottom: 8px; padding: 8px 12px; border-radius: 4px;
  font-size: 12px; min-height: 16px;
}
.dsl-editor-message:empty { display: none; }
.dsl-message--success { background: rgba(74,222,128,.15); color: #4ade80; }
.dsl-message--error { background: rgba(248,113,113,.15); color: #f87171; }
.dsl-message--info { background: rgba(96,165,250,.15); color: #60a5fa; }
.dsl-editor-grid {
  display: grid; gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 1300px) {
  .dsl-editor-grid { grid-template-columns: 1fr 1fr; }
}
.dsl-editor-forms { min-width: 0; }
.dsl-editor-preview {
  position: sticky; top: 0;
  background: rgba(0,0,0,.18);
  border-radius: 4px; padding: 8px;
}
.dsl-editor-preview h4 {
  margin: 0 0 8px; font-size: 12px;
  text-transform: uppercase; letter-spacing: .5px; opacity: .7;
}
.dsl-graph-mount {
  width: 100%; height: 500px;
  background: rgba(0,0,0,.2); border-radius: 4px;
}

.dsl-form {
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 4px; padding: 10px;
  margin-bottom: 12px;
}
.dsl-form legend { font-size: 12px; padding: 0 4px; opacity: .75; }
.dsl-form label { display: block; font-size: 12px; margin-bottom: 6px; }
.dsl-form input[type=text], .dsl-form input[type=number],
.dsl-form select, .dsl-form textarea {
  background: rgba(0,0,0,.3); color: inherit;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 3px; padding: 4px 6px;
  font-size: 12px; font-family: inherit;
  width: 100%; box-sizing: border-box;
}
.dsl-meta label { display: inline-block; margin-right: 12px; min-width: 240px; }
.dsl-meta input { display: inline-block; width: auto; min-width: 160px; }
.dsl-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.dsl-table th, .dsl-table td {
  padding: 3px 4px; border-bottom: 1px solid rgba(255,255,255,.05);
  vertical-align: top;
}
.dsl-table th {
  font-size: 10px; text-transform: uppercase; opacity: .65;
}
.dsl-table input, .dsl-table select { font-size: 11px; padding: 2px 4px; }
.dsl-stop {
  padding: 8px; background: rgba(255,255,255,.03);
  border-radius: 3px; margin-bottom: 6px;
}
.dsl-invalid { border-color: #f87171 !important; }
.btn.btn-xs { padding: 2px 6px; font-size: 11px; }
.btn.btn-danger { background: rgba(248,113,113,.2); color: #fca5a5; border: 1px solid rgba(248,113,113,.4); }
.dsl-loading, .dsl-error { padding: 16px; text-align: center; }
.dsl-error { color: #f87171; }
