/* ============================================================
 * Utilities Bunker — Logic Gate Simulator (v2.1)
 * File: /assets/css/modules/electronics/logic-gates.v2.1.css
 * Purpose:
 * - Tool-only layout + gate visualization + truth table polish + work formatting
 * - Mobile-first, 44x44 touch targets, clamp typography
 * Notes:
 * - No changes to /assets/css/ub-toolkit.v2.1.css
 * ============================================================ */

/* ============================== Local tokens (tool-scoped) ============================== */
:root{
  --lg-radius: 16px;
  --lg-gap: 14px;
  --lg-soft: rgba(0,0,0,.06);
  --lg-pin-off: rgba(0,0,0,.25);
  --lg-pin-on: rgba(34,197,94,.95);
  --lg-pin-on-soft: rgba(34,197,94,.25);
}

/* Dark adjustments */
html.ub-theme-dark:root{
  --lg-soft: rgba(255,255,255,.06);
  --lg-pin-off: rgba(255,255,255,.30);
  --lg-pin-on: rgba(34,197,94,.90);
  --lg-pin-on-soft: rgba(34,197,94,.22);
}

/* ============================== Tool hero layout ============================== */
.ub-hero{
  display:grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: var(--lg-gap);
}

/* Stack on tablet/mobile */
@media (max-width: 980px){
  .ub-hero{ grid-template-columns: 1fr; }
}

/* ============================== Gate panel (lab) ============================== */
.ub-lab{
  background: var(--ub-surface-2);
  border: 1px solid var(--ub-border);
  border-radius: var(--lg-radius);
  padding: 12px;
}

.ub-lab-top{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap: 10px;
  flex-wrap:wrap;
  margin-bottom: 8px;
}

.ub-lab-title{
  font-size: clamp(13px, 1.2vw, 14px);
  font-weight: 950;
  letter-spacing: .01em;
}

.ub-lab-sub{
  font-size: 12px;
  color: var(--ub-muted);
  margin-top: 2px;
}

/* ============================== KPI tiles ============================== */
.ub-kpis{
  display:flex;
  flex-wrap:wrap;
  gap: 8px;
  justify-content:flex-end;
}

.ub-kpi{
  min-width: 112px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid var(--ub-border);
  background: var(--ub-card-bg);
}

.ub-kpi .k{
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ub-muted);
}

.ub-kpi .v{
  font-family: var(--ub-mono);
  font-weight: 950;
  font-size: 14px;
  margin-top: 2px;
}

/* ============================== Status pill ============================== */
.ub-risk{
  display:inline-flex;
  align-items:center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--ub-border);
  background: var(--ub-card-bg);
  font-size: 12px;
  font-weight: 950;
  min-height: 44px;
}

.ub-dot{
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ub-muted);
}

/* ============================== Quick gate chips grid (tool) ============================== */
.ub-wheel{
  display:grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 10px;
  margin-top: 10px;
}

.ub-wheel .ub-chip{
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--ub-border);
  background: var(--ub-chip-bg);
  color: var(--ub-chip-text);
  font-weight: 900;
  cursor: pointer;
  user-select:none;
}

.ub-wheel .ub-chip:hover{ background: var(--ub-chip-hover); }

.ub-wheel .ub-chip[aria-pressed="true"]{
  border-color: rgba(249,58,19,.55);
  box-shadow: 0 0 0 4px rgba(249,58,19,.12);
}

/* ============================== Gate visualization ============================== */
.ub-gateviz{
  margin-top: 10px;
  border-radius: 14px;
  border: 1px solid var(--ub-border);
  background: linear-gradient(180deg, var(--ub-card-bg), var(--ub-surface-2));
  overflow:hidden;
}

.ub-gateviz-inner{
  display:grid;
  grid-template-columns: 140px 1fr 120px;
  gap: 10px;
  padding: 12px;
  align-items:center;
}

@media (max-width: 520px){
  .ub-gateviz-inner{
    grid-template-columns: 120px 1fr 110px;
  }
}

.ub-gateviz-foot{
  border-top: 1px solid var(--ub-border);
  padding: 10px 12px;
  background: var(--ub-surface-2);
}

/* Pins */
.ub-gateviz-left, .ub-gateviz-right{
  display:flex;
  flex-direction:column;
  gap: 10px;
}

.ub-gateviz-left .pin,
.ub-gateviz-right .pin{
  display:flex;
  align-items:center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid var(--ub-border);
  background: var(--ub-surface-1);
}

.ub-gateviz-right .pin.out{
  justify-content:space-between;
}

.ub-gateviz .lbl{
  font-family: var(--ub-mono);
  font-weight: 950;
  font-size: 13px;
  min-width: 18px;
  color: var(--ub-text);
}

.ub-gateviz .dot{
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: var(--lg-pin-off);
  box-shadow: 0 0 0 4px rgba(0,0,0,.05);
}

html.ub-theme-dark .ub-gateviz .dot{
  box-shadow: 0 0 0 4px rgba(255,255,255,.06);
}

.ub-gateviz .dot[data-on="1"]{
  background: var(--lg-pin-on);
  box-shadow: 0 0 0 6px var(--lg-pin-on-soft);
}

/* Gate body */
.ub-gateviz-body{
  display:flex;
  flex-direction:column;
  justify-content:center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--ub-border);
  background: var(--ub-surface-2);
  min-height: 160px;
}

.ub-gate-badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width: fit-content;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(249,58,19,.45);
  background: var(--ub-card-bg);
  font-weight: 950;
  letter-spacing: .06em;
  text-transform: uppercase;
  font-size: 12px;
}

.ub-gate-sub{
  color: var(--ub-muted);
  font-size: 12px;
  font-weight: 900;
}

.ub-gate-eq{
  font-family: var(--ub-mono);
  font-weight: 950;
  font-size: 14px;
  color: var(--ub-text);
  overflow-wrap:anywhere;
}

/* ============================== Presets row ============================== */
.ub-preset-row{
  display:flex;
  flex-wrap:wrap;
  gap: 10px;
  margin-top: 10px;
}

.ub-preset-row .ub-chip{
  min-height: 44px;
  padding: 10px 12px;
}

/* ============================== Input toggle grid ============================== */
.ub-togglegrid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 10px;
}

@media (max-width: 520px){
  .ub-togglegrid{ grid-template-columns: 1fr; }
}

/* Ensure toggle chips look “button-like” and accessible */
.ub-togglegrid .ub-chip{
  justify-content:space-between;
  font-family: var(--ub-mono);
  font-weight: 950;
}

.ub-togglegrid .ub-chip[aria-pressed="true"]{
  border-color: rgba(34,197,94,.55);
  box-shadow: 0 0 0 4px rgba(34,197,94,.14);
}

/* ============================== Truth table tweaks ============================== */
.ub-table.is-compact th,
.ub-table.is-compact td{
  padding: 8px 10px;
  font-size: 13px;
}

/* Make Y column stand out a touch */
.ub-table td:last-child,
.ub-table th:last-child{
  font-weight: 950;
}

/* ============================== Work area ============================== */
.ub-work{
  font-family: var(--ub-mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap:anywhere;
}

/* Details styling (tool enhancement) */
.ub-collapsible summary{
  cursor:pointer;
  font-weight: 950;
  min-height: 44px;
  display:flex;
  align-items:center;
}

.ub-collapsible summary:focus{
  outline: none;
  box-shadow: 0 0 0 4px var(--ub-focus);
  border-radius: 12px;
}

/* ============================== Small screens polish ============================== */
@media (max-width: 520px){
  .ub-kpi{ min-width: 98px; }
}
