/* ─────────────────────────────────────────────────────────────
   policy-drawer.css
   Slide-in drawer for policy inspection and editing.
   All selectors are scoped to .pd-* / #pd-* to avoid
   collisions with the rest of the app.
   Hooks into existing CSS variables: --muted, --heading,
   --body, --paper, --border, --card where available.
───────────────────────────────────────────────────────────── */

/* ── Overlay ─────────────────────────────────────────────── */

.pd-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
.pd-overlay.open {
  opacity: 1;
  pointer-events: all;
}

/* ── Drawer shell ─────────────────────────────────────────── */

.pd-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 100vw;
  height: 100%;
  background: var(--card, #fff);
  border-left: 1px solid var(--border, #e5e7eb);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.09);
  z-index: 201;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
}
.pd-drawer.open {
  transform: translateX(0);
}

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

.pd-header {
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border, #e5e7eb);
  flex-shrink: 0;
}
.pd-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.pd-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted, #9ca3af);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.12s, background 0.12s;
}
.pd-close:hover {
  color: var(--heading, #111);
  background: var(--paper, #f3f4f6);
}

/* Policy name: monospace, clearly a code identity */
.pd-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--heading, #111);
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  margin-bottom: 11px;
  word-break: break-all;
  line-height: 1.3;
}

.pd-header-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.pd-meta {
  font-size: 11px;
  color: var(--muted, #9ca3af);
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  letter-spacing: 0.2px;
}

/* ── Type badge ───────────────────────────────────────────── */

.pd-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.9px;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 3px;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
}
/* Matches the DOT export colors from engine.js */
.pd-badge--threshold { background: #dbeafe; color: #1d4ed8; }
.pd-badge--gate      { background: #fee2e2; color: #b91c1c; }
.pd-badge--score     { background: #dcfce7; color: #15803d; }
.pd-badge--filter    { background: #fef9c3; color: #92400e; }

/* ── Enabled toggle ───────────────────────────────────────── */

.pd-toggle-label {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  user-select: none;
}
.pd-toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.pd-toggle-track {
  position: relative;
  width: 32px;
  height: 18px;
  background: var(--muted, #9ca3af);
  border-radius: 9px;
  transition: background 0.18s;
  flex-shrink: 0;
}
.pd-toggle-input:checked + .pd-toggle-track {
  background: #22c55e;
}
.pd-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.22);
}
.pd-toggle-input:checked + .pd-toggle-track .pd-toggle-thumb {
  transform: translateX(14px);
}
.pd-toggle-text {
  font-size: 11px;
  color: var(--muted, #9ca3af);
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* ── Scrollable body ─────────────────────────────────────── */

.pd-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.pd-body::-webkit-scrollbar { width: 3px; }
.pd-body::-webkit-scrollbar-track { background: transparent; }
.pd-body::-webkit-scrollbar-thumb {
  background: var(--border, #e5e7eb);
  border-radius: 2px;
}

/* ── Sections ─────────────────────────────────────────────── */

.pd-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border, #e5e7eb);
}
.pd-section:last-child {
  border-bottom: none;
}
.pd-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted, #9ca3af);
  margin-bottom: 10px;
}

/* ── Description ─────────────────────────────────────────── */

.pd-description {
  font-size: 13px;
  line-height: 1.7;
  color: var(--body, #374151);
}

/* ── Dependency flow ─────────────────────────────────────── */

.pd-graph-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.pd-chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.pd-chip {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  padding: 4px 9px;
  border-radius: 4px;
  border: 1px solid transparent;
  line-height: 1;
  white-space: nowrap;
  background: none;
}
/* Clickable: navigates to that policy */
.pd-chip--dep {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
  cursor: pointer;
  transition: background 0.12s;
}
.pd-chip--dep:hover { background: #bfdbfe; }
.pd-chip--dependent {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
  cursor: pointer;
  transition: background 0.12s;
}
.pd-chip--dependent:hover { background: #fde68a; }
/* Non-clickable: the current policy itself */
.pd-chip--self {
  background: var(--paper, #f3f4f6);
  color: var(--heading, #111);
  border-color: var(--border, #d1d5db);
  font-weight: 600;
  cursor: default;
}
.pd-arrow {
  font-size: 14px;
  color: var(--muted, #9ca3af);
  flex-shrink: 0;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* ── Weight section ──────────────────────────────────────── */

.pd-weight-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.pd-weight-range {
  flex: 1;
  accent-color: #22c55e;
  cursor: pointer;
  height: 4px;
}

/* Numeric input: right-aligned, monospace, matches slider value */
.pd-weight-num {
  width: 64px;
  font-size: 13px;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  text-align: right;
  padding: 5px 8px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 5px;
  color: var(--heading, #111);
  background: var(--paper, #f9fafb);
  transition: border-color 0.12s;
  -moz-appearance: textfield;
}
.pd-weight-num::-webkit-outer-spin-button,
.pd-weight-num::-webkit-inner-spin-button { -webkit-appearance: none; }
.pd-weight-num:focus {
  outline: none;
  border-color: #22c55e;
  background: #f0fdf4;
}

/* Proportional bar: all score policies side by side */
.pd-wbar {
  display: flex;
  height: 5px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--paper, #f3f4f6);
  margin-bottom: 10px;
  gap: 1px;
}
.pd-wbar-segment {
  background: var(--border, #d1d5db);
  transition: flex 0.28s ease;
  min-width: 2px;
  border-radius: 1px;
}
.pd-wbar-segment--current {
  background: #22c55e;
}

/* Running sum: valid = muted, invalid = red */
.pd-weight-sum {
  font-size: 11px;
  color: var(--muted, #9ca3af);
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
}
.pd-weight-sum strong { color: var(--heading, #111); }
.pd-weight-sum--warn { color: #b91c1c; }
.pd-weight-sum--warn strong { color: #b91c1c; }

/* ── Params form ─────────────────────────────────────────── */

.pd-params {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.pd-param {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pd-param-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted, #6b7280);
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* Single number / text input */
.pd-param-input {
  font-size: 13px;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  padding: 7px 10px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 5px;
  color: var(--heading, #111);
  background: var(--paper, #f9fafb);
  transition: border-color 0.12s, background 0.12s;
  width: 100%;
  box-sizing: border-box;
}
.pd-param-input:focus {
  outline: none;
  border-color: #6366f1;
  background: #fff;
}

/* ── Tag list (string[]) ─────────────────────────────────── */

.pd-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 5px;
  background: var(--paper, #f9fafb);
  min-height: 38px;
  transition: border-color 0.12s;
}
.pd-tag-list:focus-within {
  border-color: #6366f1;
  background: #fff;
}
.pd-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  background: #e0e7ff;
  color: #3730a3;
  padding: 3px 8px 3px 9px;
  border-radius: 3px;
}
.pd-tag-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: #6366f1;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  opacity: 0.55;
  transition: opacity 0.12s;
  display: flex;
  align-items: center;
}
.pd-tag-remove:hover { opacity: 1; }
.pd-tag-input {
  border: none;
  outline: none;
  background: transparent;
  font-size: 12px;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  color: var(--heading, #111);
  min-width: 60px;
  flex: 1;
}
.pd-tag-input::placeholder { color: var(--muted, #9ca3af); }

/* ── Pair rows ([string,string][]) ───────────────────────── */

.pd-pair-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.pd-pair-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pd-pair-input {
  flex: 1;
  font-size: 12px;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  padding: 6px 8px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 4px;
  color: var(--heading, #111);
  background: var(--paper, #f9fafb);
  transition: border-color 0.12s, background 0.12s;
}
.pd-pair-input:focus {
  outline: none;
  border-color: #6366f1;
  background: #fff;
}
.pd-pair-sep {
  font-size: 13px;
  color: var(--muted, #9ca3af);
  flex-shrink: 0;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
}
.pd-pair-remove {
  background: none;
  border: none;
  font-size: 17px;
  color: var(--muted, #9ca3af);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.12s;
  flex-shrink: 0;
}
.pd-pair-remove:hover { color: #b91c1c; }
.pd-pair-add {
  font-size: 11px;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  color: #6366f1;
  background: none;
  border: 1px dashed #c7d2fe;
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
  margin-top: 2px;
}
.pd-pair-add:hover { background: #eef2ff; border-color: #818cf8; }

/* ── Key→value map ({key: number}) ──────────────────────── */

.pd-map-table {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 5px;
  overflow: hidden;
}
.pd-map-row {
  display: flex;
  align-items: stretch;
}
.pd-map-row:not(:last-child) {
  border-bottom: 1px solid var(--border, #e5e7eb);
}

/* Fixed key column — describes what the value means */
.pd-map-key {
  flex: 1;
  font-size: 12px;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  color: var(--body, #374151);
  padding: 8px 12px;
  background: var(--paper, #f9fafb);
  border-right: 1px solid var(--border, #e5e7eb);
  display: flex;
  align-items: center;
}

/* Editable value column */
.pd-map-val {
  width: 80px;
  font-size: 12px;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  text-align: right;
  padding: 8px 12px;
  border: none;
  outline: none;
  color: var(--heading, #111);
  background: #fff;
  transition: background 0.12s;
  -moz-appearance: textfield;
}
.pd-map-val::-webkit-outer-spin-button,
.pd-map-val::-webkit-inner-spin-button { -webkit-appearance: none; }
.pd-map-val:focus {
  background: #f0fdf4;
  box-shadow: inset 0 0 0 1px #22c55e;
}

/* ── Footer ──────────────────────────────────────────────── */

.pd-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border, #e5e7eb);
  flex-shrink: 0;
  background: var(--card, #fff);
}
.pd-footer-btns {
  display: flex;
  gap: 10px;
}
.pd-btn {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, opacity 0.12s;
  border: none;
}
.pd-btn--ghost {
  background: var(--paper, #f3f4f6);
  color: var(--body, #374151);
  border: 1px solid var(--border, #e5e7eb);
}
.pd-btn--ghost:hover { background: var(--border, #e5e7eb); }
.pd-btn--primary {
  flex: 2;
  background: #111;
  color: #fff;
}
.pd-btn--primary:hover:not(:disabled) { background: #374151; }
.pd-btn--primary:disabled {
  opacity: 0.32;
  cursor: not-allowed;
}

/* ── Inline error banner ─────────────────────────────────── */

.pd-error {
  font-size: 12px;
  font-family: 'DM Mono', 'Fira Code', 'Cascadia Code', monospace;
  color: #b91c1c;
  background: #fee2e2;
  border-radius: 5px;
  padding: 8px 12px;
  line-height: 1.5;
}

/* ── Mobile: full width ──────────────────────────────────── */

@media (max-width: 480px) {
  .pd-drawer {
    width: 100vw;
    border-left: none;
  }
}
