/* Prompt Rules tool — extracted from inline <style> blocks in the haml views. */

/* Scope the gray viewport background + system font to prompt_rules pages
   only, via :has() so this never leaks to other tools. */
body:has(.pr-page),
body:has(.pr-pipeline-page) {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: #f5f5f5;
}

/* ── Page layout ───────────────────────────────────────────────────────── */

.pr-page         { max-width: 900px;  margin: 0 auto; padding: 2rem 1rem; }
.pr-page--wide   { max-width: 1400px; }

.pr-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.pr-header h1 {
  margin: 0;
  font-size: 1.5rem;
  color: #111827;
  line-height: 1.3;
}

.pr-page--wide .pr-header h1 { font-size: 1.75rem; }

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

.pr-card {
  background: #fff;
  border-radius: 0.5rem;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
  margin-bottom: 1.5rem;
}

.pr-card h2 {
  margin: 0 0 1rem;
  font-size: 1.125rem;
  color: #111827;
}

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

.pr-field { margin-bottom: 1rem; padding-right: 2rem; }

.pr-field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.375rem;
}

.pr-field select,
.pr-field input[type=text],
.pr-field input:not([type]),
.pr-field textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  padding: 0.5rem 0.625rem;
  font-size: 0.875rem;
  color: #111827;
  background: #fff;
  font-family: inherit;
}

.pr-field textarea {
  resize: vertical;
  min-height: 600px;
  field-sizing: content;
  line-height: 1.5;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  font-size: 0.8125rem;
}

.pr-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Inside cards the actions bar gets a separator above it.
   Outside cards (e.g. index row actions) it's just flex+gap. */
.pr-card .pr-actions {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
}

.pr-checkbox-row { display: flex; align-items: center; gap: 0.5rem; }
.pr-checkbox-row input[type=checkbox] { width: 1rem; height: 1rem; }

/* ── Index table ───────────────────────────────────────────────────────── */

.pr-table-wrap {
  background: #fff;
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
  overflow: hidden;
}

.pr-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

.pr-table th {
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6b7280;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.pr-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
  color: #111827;
}

.pr-table tr:last-child td { border-bottom: none; }

.pr-active--yes { color: #047857; font-weight: 600; }
.pr-active--no  { color: #9ca3af; }

.pr-empty {
  text-align: center;
  padding: 4rem 1rem;
  color: #6b7280;
  font-size: 1rem;
  background: #fff;
  border-radius: 0.5rem;
}

/* ── Loading state (generating title / output) ─────────────────────────── */

.pr-loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: #f9fafb;
  border-radius: 0.375rem;
  color: #6b7280;
  font-size: 0.875rem;
}

.pr-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid #d1d5db;
  border-top-color: #465A64;
  border-radius: 50%;
  animation: pr-spin 0.8s linear infinite;
}

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

/* ── Tooltip (info icon next to submit buttons) ────────────────────────── */

.pr-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: #e5e7eb;
  color: #4b5563;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: help;
  user-select: none;
  border: none;
  font-family: inherit;
}

.pr-tooltip:hover,
.pr-tooltip:focus { background: #d1d5db; color: #1f2937; outline: none; }

.pr-tooltip-bubble {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  font-weight: 400;
  width: max-content;
  max-width: 260px;
  text-align: left;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 10;
}

.pr-tooltip-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1f2937;
}

.pr-tooltip:hover .pr-tooltip-bubble,
.pr-tooltip:focus .pr-tooltip-bubble { opacity: 1; }

/* ── Buttons (scoped to .pr-page so we don't fight other tools' inline
       definitions of .btn-*). When shared component CSS lands later,
       these can drop the .pr-page prefix and move to components/buttons.css. */

.pr-page .btn-primary,
.pr-pipeline-page .btn-primary {
  padding: 0.5rem 1rem;
  background: #465A64;
  color: #fff;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.pr-page .btn-primary:hover,
.pr-pipeline-page .btn-primary:hover { background: #1d4ed8; }

.pr-page .btn-secondary,
.pr-pipeline-page .btn-secondary {
  padding: 0.5rem 1rem;
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  display: inline-block;
}

.pr-page .btn-secondary:hover,
.pr-pipeline-page .btn-secondary:hover { background: #e5e7eb; }

.pr-page .btn-danger,
.pr-pipeline-page .btn-danger {
  padding: 0.375rem 0.875rem;
  background: #fff;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.pr-page .btn-danger:hover,
.pr-pipeline-page .btn-danger:hover { background: #fef2f2; }

/* ── Shell: sidebar + main two-column layout ──────────────────────────── */

body:has(.pr-shell) { overflow: hidden; }

.pr-shell {
  display: flex;
  height: calc(100dvh - 84px);
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */

.pr-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.pr-sidebar-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e5e7eb;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #374151;
}

.pr-sidebar-header a { color: inherit; text-decoration: none; }
.pr-sidebar-header a:hover { color: #465A64; }

.pr-sidebar-section {
  padding: 0.75rem 1rem 0.25rem;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7280;
  font-weight: 700;
}

.pr-sidebar__item {
  display: block;
  padding: 0.4rem 1rem;
  border-left: 3px solid transparent;
  text-decoration: none;
  color: #374151;
}

.pr-sidebar__item:hover { background: #f9fafb; }

.pr-sidebar__item--active {
  background: #eff6ff;
  border-left-color: #465A64;
}

.pr-sidebar__item-label {
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #111827;
}

.pr-sidebar__item-meta {
  font-size: 0.6875rem;
  color: #9ca3af;
}

.pr-sidebar-new {
  display: block;
  padding: 0.4rem 1rem;
  font-size: 0.8125rem;
  color: #465A64;
  font-weight: 600;
  text-decoration: none;
}

.pr-sidebar-new:hover { background: #f9fafb; }

/* ── Main scrollable area ───────────────────────────────────────────────── */

.pr-main {
  flex: 1;
  overflow-y: auto;
  background: #f5f5f5;
}

.pr-main .pr-page { max-width: 860px; }

/* ── Pipeline index ─────────────────────────────────────────────────────── */

.pr-pipeline-page { max-width: 900px; margin: 0 auto; padding: 2rem 1rem; }

.pr-pipeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}

.pr-pipeline-header h1 { margin: 0; font-size: 1.5rem; color: #111827; }

.pr-stage { margin-bottom: 2rem; }

.pr-stage-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.pr-stage-num {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: #465A64;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pr-stage-header h2 { margin: 0; font-size: 1rem; font-weight: 600; color: #111827; }

.pr-stage-count { font-weight: 400; color: #9ca3af; margin-left: 0.35rem; }
.pr-stage-count--muted { font-size: 0.75rem; font-style: italic; }

.pr-stage-card {
  background: #fff;
  border-radius: 0.5rem;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.12s;
}

.pr-stage-card:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, .13); }

.pr-stage-card-title { font-weight: 600; font-size: 0.9375rem; color: #111827; }

.pr-stage-card-meta { font-size: 0.75rem; color: #9ca3af; }

.pr-stage-card-snippet {
  font-size: 0.75rem;
  color: #6b7280;
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 3rem;
  overflow: hidden;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.pr-stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.pr-stage-list { display: flex; flex-direction: column; gap: 0.5rem; }

.pr-stage-list .pr-stage-card {
  flex-direction: row;
  align-items: center;
}

.pr-stage-list .pr-stage-card-snippet { flex: 1; }

.pr-stage-header__new { margin-left: auto; font-size: 0.8125rem; padding: 0.35rem 0.75rem; }

.pr-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pr-badge--attack      { background: #fee2e2; color: #991b1b; }
.pr-badge--system      { background: #fef9c3; color: #854d0e; }
.pr-badge--policy      { background: #dcfce7; color: #166534; }
.pr-badge--sop         { background: #dbeafe; color: #1e40af; }
.pr-badge--rule        { background: #f3f4f6; color: #374151; }
.pr-badge--classifier  { background: #ede9fe; color: #5b21b6; }

.pr-table__empty { padding: 1.5rem 1rem; color: #9ca3af; font-size: 0.875rem; }

.pr-table__actions { white-space: nowrap; display: flex; gap: 0.375rem; align-items: center; }

.pr-stage-new-rule {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.4rem 1rem;
  background: #fff;
  border: 1px dashed #d1d5db;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #465A64;
  text-decoration: none;
}

.pr-stage-new-rule:hover { background: #f9fafb; border-color: #465A64; }

/* ── Collapsible card (details element) ─────────────────────────────────── */

details.pr-card > summary {
  cursor: pointer;
  font-size: 1.125rem;
  font-weight: 600;
  color: #111827;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

details.pr-card > summary::-webkit-details-marker { display: none; }

details.pr-card > summary::after {
  content: "›";
  margin-left: auto;
  font-size: 1.375rem;
  font-weight: 300;
  color: #9ca3af;
  transition: transform 0.15s;
  line-height: 1;
}

details.pr-card[open] > summary::after { transform: rotate(90deg); }

details.pr-card[open] > summary {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #e5e7eb;
}

/* ── Collapsible inside a form (new page input) ─────────────────────────── */

.pr-new-input {
  margin-bottom: 1rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.375rem;
  overflow: hidden;
}

.pr-new-input > summary {
  cursor: pointer;
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  list-style: none;
  background: #f9fafb;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pr-new-input > summary::-webkit-details-marker { display: none; }

.pr-new-input > summary::after {
  content: "›";
  margin-left: auto;
  font-size: 1.25rem;
  font-weight: 300;
  color: #9ca3af;
  transition: transform 0.15s;
}

.pr-new-input[open] > summary::after { transform: rotate(90deg); }

.pr-new-input > .pr-field { padding: 0.75rem; margin-bottom: 0; }

/* ── Inline collapsible field (details inside a card form) ───────────────── */

details:has(> .pr-field-summary) { margin-bottom: 1.25rem; }

.pr-field-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0;
  user-select: none;
}

.pr-field-summary::-webkit-details-marker { display: none; }

.pr-field-summary::after {
  content: "›";
  font-size: 1.125rem;
  font-weight: 300;
  color: #9ca3af;
  transition: transform 0.15s;
  line-height: 1;
}

details[open] > .pr-field-summary::after { transform: rotate(90deg); }

details[open] > .pr-field-summary { margin-bottom: 0.5rem; }

.pr-plain-textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  padding: 0.5rem 0.625rem;
  font-size: 0.8125rem;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  line-height: 1.5;
  color: #111827;
  background: #fff;
  resize: vertical;
}

/* ── Type radio selector ─────────────────────────────────────────────────── */

.pr-type-radios {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.pr-type-radio {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.875rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  user-select: none;
  transition: border-color 0.1s, background 0.1s;
}

.pr-type-radio:has(input:checked) {
  background: #465A64;
  color: #fff;
  border-color: #465A64;
}

.pr-type-radio:hover:not(:has(input:checked)) { background: #f3f4f6; }

.pr-type-radio input[type=radio] { display: none; }

/* ── Markdown preview (below output card) ──────────────────────────────── */

.pr-preview {
  min-height: 4rem;
  line-height: 1.6;
  color: #111827;
  font-size: 0.9rem;
}

.pr-preview h1, .pr-preview h2, .pr-preview h3, .pr-preview h4 {
  margin: 1rem 0 0.4rem;
  font-weight: 600;
  color: #111827;
}

.pr-preview h1 { font-size: 1rem; }
.pr-preview h2 { font-size: 0.9375rem; }
.pr-preview h3 { font-size: 0.875rem; }
.pr-preview h4 { font-size: 0.8125rem; }

.pr-preview p    { margin: 0.5rem 0; }
.pr-preview ul,
.pr-preview ol   { padding-left: 1.5rem; margin: 0.5rem 0; }
.pr-preview li   { margin: 0.2rem 0; }
.pr-preview hr   { border: none; border-top: 1px solid #e5e7eb; margin: 1rem 0; }

.pr-preview code {
  background: #f3f4f6;
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.85em;
}

.pr-preview pre {
  background: #f3f4f6;
  padding: 1rem;
  border-radius: 0.375rem;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.pr-preview pre code { background: none; padding: 0; }

.pr-preview table { border-collapse: collapse; width: 100%; margin: 0.5rem 0; }
.pr-preview th,
.pr-preview td   { border: 1px solid #d1d5db; padding: 0.375rem 0.625rem; text-align: left; }
.pr-preview th   { background: #f9fafb; font-weight: 600; font-size: 0.8125rem; }
