/* ============================================================
   PEQ Rule Engine — Components
   ============================================================ */

/* ---------- icons ---------- */
.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.icon--sm { width: 16px; height: 16px; }
.icon--lg { width: 28px; height: 28px; }

.icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--cobalt-soft);
  color: var(--cobalt-deep);
}

.icon-tile--teal { background: var(--teal-soft); color: var(--teal-deep); }
.icon-tile--cyan  { background: var(--cyan-soft);  color: var(--cyan); }
.icon-tile--amber { background: var(--unknown-soft); color: var(--unknown); }
.icon-tile--navy  { background: var(--bg-soft);     color: var(--navy-2); }
.icon-tile--shadow { background: var(--shadow-soft); color: var(--shadow); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-size: var(--fs-md);
  font-weight: 600;
  line-height: 1.3;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
  text-decoration: none !important;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--cobalt);
  color: #fff;
  box-shadow: 0 1px 2px rgba(14, 26, 48, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.btn-primary:hover {
  background: var(--cobalt-deep);
}

.btn-outline {
  background: var(--bg-elev);
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn-outline:hover {
  border-color: var(--cobalt);
  color: var(--cobalt-deep);
  background: var(--cobalt-soft);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
}

.btn-ghost:hover {
  background: var(--bg-soft);
  color: var(--ink);
}

.btn-teal {
  background: var(--teal);
  color: #fff;
}

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

.btn-sm {
  padding: 7px 14px;
  font-size: var(--fs-sm);
  border-radius: 7px;
}

.btn-lg {
  padding: 14px 28px;
  font-size: var(--fs-lg);
  border-radius: 10px;
}

.btn[disabled],
.btn.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  border: 1px solid transparent;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.icon-btn:hover {
  background: var(--bg-soft);
  color: var(--ink);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ---------- badges / pills ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink-2);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge--true { background: var(--true-soft); color: var(--true); border-color: transparent; }
.badge--false { background: var(--false-soft); color: var(--false); border-color: transparent; }
.badge--unknown { background: var(--unknown-soft); color: var(--unknown); border-color: transparent; }
.badge--na { background: var(--na-soft); color: var(--na); border-color: transparent; }
.badge--active { background: var(--teal-soft); color: var(--teal-deep); border-color: transparent; }
.badge--shadow { background: var(--shadow-soft); color: var(--shadow); border-color: transparent; }
.badge--draft { background: var(--na-soft); color: var(--na); border-color: transparent; }
.badge--review { background: var(--cobalt-soft); color: var(--cobalt-deep); border-color: transparent; }
.badge--testing { background: var(--cyan-soft); color: var(--cyan); border-color: transparent; }
.badge--deprecated, .badge--retired { background: var(--bg-inset); color: var(--ink-4); border-color: transparent; text-decoration: line-through; }

.badge--solid {
  background: var(--navy);
  color: #fff;
  border-color: transparent;
}

.badge--outline {
  background: transparent;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
}

/* ---------- cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 26px;
  box-shadow: var(--shadow-sm);
}

.card--hover {
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}

.card--hover:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--line-strong);
}

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}

.card-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  line-height: 1.35;
  color: var(--ink);
}

.card-sub {
  font-size: var(--fs-sm);
  color: var(--ink-3);
  margin-top: 3px;
}

.card-body {
  color: var(--ink-2);
  font-size: var(--fs-md);
}

.card-foot {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

/* meta list (ID / version / status rows) */
.meta-list {
  display: grid;
  gap: 6px;
  font-size: var(--fs-sm);
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--line);
}

.meta-row:last-child {
  border-bottom: none;
}

.meta-key {
  color: var(--ink-3);
  flex-shrink: 0;
}

.meta-val {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
}

/* ---------- forms ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.input,
.select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--bg-elev);
  color: var(--ink);
  font-size: var(--fs-md);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--cobalt);
  box-shadow: 0 0 0 3px var(--cobalt-soft);
}

.search-box {
  position: relative;
}

.search-box .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-4);
  pointer-events: none;
}

.search-box .input {
  padding-left: 40px;
}

/* toggle switch */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-2);
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  position: relative;
  width: 38px;
  height: 21px;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background 0.2s var(--ease);
  flex-shrink: 0;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2.5px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s var(--ease);
}

.switch input:checked + .switch-track {
  background: var(--cobalt);
}

.switch input:checked + .switch-track::after {
  transform: translateX(16px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* segmented control (2-4 options) */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.segmented button {
  padding: 5px 13px;
  border-radius: 7px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-2);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button[aria-pressed="true"] {
  background: var(--bg-elev);
  color: var(--cobalt-deep);
  box-shadow: var(--shadow-sm);
}

/* fact control rows (demo/playground) */
.fact-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-elev);
}

.fact-control + .fact-control {
  margin-top: 8px;
}

.fact-control .fact-path {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--ink-2);
}

.fact-control .fact-desc {
  font-size: var(--fs-xs);
  color: var(--ink-3);
}

.fact-control.is-changed {
  border-color: var(--cyan);
  background: var(--cyan-soft);
}

/* ---------- code / rule DSL ---------- */
.code-block {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}

.code-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

.code-block pre {
  padding: 16px 18px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.75;
  color: var(--ink-2);
}

.code-block .kw { color: var(--teal-deep); font-weight: 700; }
.code-block .op { color: var(--ink-3); }
.code-block .val { color: var(--cobalt-deep); }
.code-block .st { color: var(--navy-2); font-weight: 600; }
.code-block .cm { color: var(--ink-4); font-style: italic; }

[data-theme="dark"] .code-block .kw { color: var(--teal); }
[data-theme="dark"] .code-block .val { color: var(--cobalt-deep); }
[data-theme="dark"] .code-block .st { color: #9db8e8; }

/* inline code */
.inline-code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--navy-2);
}

/* rule card */
.rule-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  position: relative;
}

.rule-card:hover .rule-card-title {
  color: var(--cobalt-deep);
}

.rule-card-title {
  font-family: var(--font-mono);
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
  transition: color 0.15s var(--ease);
}

.rule-card-id {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rule-card-when {
  font-size: var(--fs-sm);
  color: var(--ink-3);
  line-height: 1.55;
}

.rule-card-arrow {
  position: absolute;
  right: 20px;
  top: 22px;
  color: var(--ink-4);
  opacity: 0;
  transition: opacity 0.15s var(--ease), transform 0.15s var(--ease);
}

.rule-card:hover .rule-card-arrow {
  opacity: 1;
  transform: translateX(3px);
}

/* diff */
.diff-block {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.8;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  overflow-x: auto;
}

.diff-add { color: var(--true); background: var(--true-soft); }
.diff-del { color: var(--false); background: var(--false-soft); }

/* ---------- callouts ---------- */
.callout {
  display: flex;
  gap: 12px;
  padding: 15px 18px;
  border-radius: var(--r-md);
  border: 1px solid;
  font-size: var(--fs-sm);
  line-height: 1.65;
}

.callout .icon {
  margin-top: 2px;
}

.callout--info {
  background: var(--cobalt-soft);
  border-color: color-mix(in srgb, var(--cobalt) 25%, var(--line));
  color: var(--ink-2);
}

.callout--note {
  background: var(--unknown-soft);
  border-color: color-mix(in srgb, var(--unknown) 25%, var(--line));
  color: var(--ink-2);
}

.callout--sim {
  background: var(--teal-soft);
  border-color: color-mix(in srgb, var(--teal) 25%, var(--line));
  color: var(--ink-2);
}

.callout--warn {
  background: var(--false-soft);
  border-color: color-mix(in srgb, var(--false) 25%, var(--line));
  color: var(--ink-2);
}

.callout-title {
  font-weight: 700;
  color: var(--ink);
  display: block;
  margin-bottom: 2px;
}

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs button {
  padding: 11px 18px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.tabs button:hover {
  color: var(--ink);
}

.tabs button[aria-selected="true"] {
  color: var(--cobalt-deep);
  border-bottom-color: var(--cobalt);
}

.tab-panel[hidden] {
  display: none !important;
}

/* ---------- accordion ---------- */
.accordion-item {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-elev);
  overflow: hidden;
}

.accordion-item + .accordion-item {
  margin-top: 10px;
}

.accordion-item.is-open {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}

.accordion-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 17px 20px;
  text-align: left;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--ink);
}

.accordion-trigger .icon {
  color: var(--ink-4);
  transition: transform 0.2s var(--ease);
  flex-shrink: 0;
}

.accordion-item.is-open .accordion-trigger .icon {
  transform: rotate(45deg);
}

.accordion-panel {
  padding: 0 20px 18px;
  color: var(--ink-2);
  font-size: var(--fs-md);
}

/* ---------- drawer ---------- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 32, 0.45);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease);
}

.drawer-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 100%);
  max-width: 100%;
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  z-index: 160;
  transform: translateX(100%);
  transition: transform 0.28s var(--ease);
  display: flex;
  flex-direction: column;
}

.drawer.is-open {
  transform: translateX(0);
  box-shadow: var(--shadow-lg);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
}

.drawer-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

/* ---------- stepper / steps ---------- */
.steps {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.step {
  display: flex;
  gap: 16px;
  position: relative;
  padding-bottom: 22px;
}

.step:last-child {
  padding-bottom: 0;
}

.step:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 34px;
  bottom: 2px;
  width: 2px;
  background: var(--line);
}

.step-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--ink-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease), transform 0.2s var(--ease);
}

.step.is-active .step-dot {
  background: var(--cobalt);
  border-color: var(--cobalt);
  color: #fff;
  transform: scale(1.12);
}

.step.is-done .step-dot {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.step.is-done:not(:last-child)::before {
  background: var(--teal);
}

.step-body {
  padding-top: 3px;
}

.step-title {
  font-weight: 700;
  color: var(--ink);
  font-size: var(--fs-md);
}

.step.is-active .step-title {
  color: var(--cobalt-deep);
}

.step-desc {
  font-size: var(--fs-sm);
  color: var(--ink-3);
  margin-top: 2px;
}

.step-extra {
  margin-top: 8px;
}

/* ---------- table ---------- */
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow-x: auto;
  background: var(--bg-elev);
}

.table th {
  text-align: left;
  padding: 10px 16px;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
  color: var(--ink-2);
  vertical-align: top;
}

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

/* ---------- media frame (image auto-apply + SVG fallback) ---------- */
.media-frame {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--bg-elev);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.media-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-fallback {
  padding: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 250px;
  background:
    radial-gradient(500px 220px at 70% 0%, rgba(30, 91, 214, 0.06), transparent 60%),
    var(--bg-elev);
}

/* ---------- stat ---------- */
.stat {
  text-align: center;
  padding: 22px 16px;
}

.stat-value {
  font-size: var(--fs-3xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: var(--fs-sm);
  color: var(--ink-3);
  margin-top: 4px;
}

/* ---------- empty state ---------- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  color: var(--ink-3);
  font-size: var(--fs-sm);
}

.empty-state .icon-tile {
  margin: 0 auto 12px;
}

/* ---------- kbd ---------- */
kbd {
  display: inline-block;
  padding: 1px 7px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-soft);
  font-size: 0.78em;
  color: var(--ink-2);
}

/* ---------- skeleton pulse ---------- */
.pulse {
  animation: peq-pulse 2.2s var(--ease) infinite;
}

@keyframes peq-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
